Skip to content

Commit

Permalink
refactor(column): ♻️ remove ErrorWhisker and Tooltip when error is null
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydrichards committed Nov 6, 2023
1 parent e65ac3c commit 4f7d4c2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/app"
}
]
}
2 changes: 1 addition & 1 deletion app/charts/column/columns-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const useColumnsState = (
);

const getError = (d: Observation) => {
if (!showYStandardError || !getYError) {
if (!showYStandardError || !getYError || getYError(d) === null) {
return;
}

Expand Down
41 changes: 26 additions & 15 deletions app/charts/column/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useTheme } from "@/themes";
export const ErrorWhiskers = () => {
const {
getX,
getYError,
getYErrorRange,
chartData,
yScale,
Expand All @@ -32,23 +33,33 @@ export const ErrorWhiskers = () => {
return [];
}

return chartData.map((d, i) => {
const x0 = xScale(getX(d)) as number;
const bandwidth = xScale.bandwidth();
const barwidth = Math.min(bandwidth, 15);
const [y1, y2] = getYErrorRange(d);
return chartData
.filter((d) => !!getYError?.(d))
.map((d, i) => {
const x0 = xScale(getX(d)) as number;
const bandwidth = xScale.bandwidth();
const barwidth = Math.min(bandwidth, 15);
const [y1, y2] = getYErrorRange(d);

return {
key: `${i}`,
x: x0 + bandwidth / 2 - barwidth / 2,
y1: yScale(y1),
y2: yScale(y2),
width: barwidth,
};
});
}, [chartData, getX, getYErrorRange, showYStandardError, xScale, yScale]);
return {
key: `${i}`,
x: x0 + bandwidth / 2 - barwidth / 2,
y1: yScale(y1),
y2: yScale(y2),
width: barwidth,
};
});
}, [
chartData,
getX,
getYError,
getYErrorRange,
showYStandardError,
xScale,
yScale,
]);

React.useEffect(() => {
React.useEffect(() => {
if (ref.current) {
renderContainer(ref.current, {
id: "columns-error-whiskers",
Expand Down

0 comments on commit 4f7d4c2

Please sign in to comment.