Skip to content

Commit 62dbc35

Browse files
committed
fix(LineChart): skip lines at invalid/missing data points (don't force connect)
1 parent 12f0d0d commit 62dbc35

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

.changeset/wicked-dodos-float.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@portaljs/components': patch
3+
---
4+
5+
LineChart: break lines at invalid / missing values (don't connect if there are gaps in values).

packages/components/src/components/LineChart.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ export function LineChart({
4747
color: 'black',
4848
strokeWidth: 1,
4949
tooltip: true,
50+
invalid: "break-paths"
5051
},
5152
data: specData,
5253
...(isMultiYAxis
5354
? {
54-
transform: [{ fold: yAxis, as: ['key', 'value'] }],
55+
transform: [
56+
{ fold: yAxis, as: ['key', 'value'] },
57+
{ filter: 'datum.value != null && datum.value != ""' }
58+
],
5559
}
5660
: {}),
5761
selection: {

packages/components/src/types/properties.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
type URL = string; // Just in case we want to transform it into an object with configurations
99
export interface Data {
1010
url?: URL;
11-
values?: { [key: string]: number | string }[];
11+
values?: { [key: string]: number | string | null | undefined }[];
1212
csv?: string;
1313
}
1414

packages/components/stories/LineChart.stories.ts

+39
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,42 @@ export const FromURL: Story = {
120120
yAxis: 'Price',
121121
},
122122
};
123+
124+
125+
// export const FromURLMulti: Story = {
126+
// name: 'Line chart from URL Multi Column',
127+
// args: {
128+
// data: {
129+
// url: 'https://raw.githubusercontent.com/datasets/sea-level-rise/refs/heads/main/data/epa-sea-level.csv',
130+
// },
131+
// title: 'Sea Level Rise (1880-2023)',
132+
// xAxis: 'Year',
133+
// yAxis: ["CSIRO Adjusted Sea Level", "NOAA Adjusted Sea Level"],
134+
// xAxisType: 'temporal',
135+
// xAxisTimeUnit: 'year',
136+
// yAxisType: 'quantitative'
137+
// },
138+
// };
139+
140+
// export const MultipleSeriesMissingValues: Story = {
141+
// name: 'Line chart with missing values',
142+
// args: {
143+
// data: {
144+
// values: [
145+
// { year: '2020', seriesA: 10, seriesB: 15 },
146+
// { year: '2021', seriesA: 20 }, // seriesB missing
147+
// { year: '2022', seriesA: 15 }, // seriesB missing
148+
// { year: '2023', seriesB: 30 }, // seriesA missing
149+
// { year: '2024', seriesA: 25, seriesB: 35 },
150+
// { year: '2024', seriesA: 20, seriesB: 40 },
151+
// { year: '2024', seriesB: 45 },
152+
// ],
153+
// },
154+
// title: 'Handling Missing Data Points',
155+
// xAxis: 'year',
156+
// yAxis: ['seriesA', 'seriesB'],
157+
// xAxisType: 'temporal',
158+
// xAxisTimeUnit: 'year',
159+
// yAxisType: 'quantitative'
160+
// },
161+
// };

0 commit comments

Comments
 (0)