Skip to content

Commit

Permalink
fix(LineChart): skip lines at invalid/missing data points (don't forc…
Browse files Browse the repository at this point in the history
…e connect)
  • Loading branch information
olayway committed Jan 22, 2025
1 parent 12f0d0d commit 62dbc35
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-dodos-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@portaljs/components': patch
---

LineChart: break lines at invalid / missing values (don't connect if there are gaps in values).
6 changes: 5 additions & 1 deletion packages/components/src/components/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export function LineChart({
color: 'black',
strokeWidth: 1,
tooltip: true,
invalid: "break-paths"
},
data: specData,
...(isMultiYAxis
? {
transform: [{ fold: yAxis, as: ['key', 'value'] }],
transform: [
{ fold: yAxis, as: ['key', 'value'] },
{ filter: 'datum.value != null && datum.value != ""' }
],
}
: {}),
selection: {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/types/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
type URL = string; // Just in case we want to transform it into an object with configurations
export interface Data {
url?: URL;
values?: { [key: string]: number | string }[];
values?: { [key: string]: number | string | null | undefined }[];
csv?: string;
}

Expand Down
39 changes: 39 additions & 0 deletions packages/components/stories/LineChart.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,42 @@ export const FromURL: Story = {
yAxis: 'Price',
},
};


// export const FromURLMulti: Story = {
// name: 'Line chart from URL Multi Column',
// args: {
// data: {
// url: 'https://raw.githubusercontent.com/datasets/sea-level-rise/refs/heads/main/data/epa-sea-level.csv',
// },
// title: 'Sea Level Rise (1880-2023)',
// xAxis: 'Year',
// yAxis: ["CSIRO Adjusted Sea Level", "NOAA Adjusted Sea Level"],
// xAxisType: 'temporal',
// xAxisTimeUnit: 'year',
// yAxisType: 'quantitative'
// },
// };

// export const MultipleSeriesMissingValues: Story = {
// name: 'Line chart with missing values',
// args: {
// data: {
// values: [
// { year: '2020', seriesA: 10, seriesB: 15 },
// { year: '2021', seriesA: 20 }, // seriesB missing
// { year: '2022', seriesA: 15 }, // seriesB missing
// { year: '2023', seriesB: 30 }, // seriesA missing
// { year: '2024', seriesA: 25, seriesB: 35 },
// { year: '2024', seriesA: 20, seriesB: 40 },
// { year: '2024', seriesB: 45 },
// ],
// },
// title: 'Handling Missing Data Points',
// xAxis: 'year',
// yAxis: ['seriesA', 'seriesB'],
// xAxisType: 'temporal',
// xAxisTimeUnit: 'year',
// yAxisType: 'quantitative'
// },
// };

0 comments on commit 62dbc35

Please sign in to comment.