Skip to content

Commit 432a314

Browse files
ryugarajRaj Jaiswal
andauthored
fix: Extra datapoints being rendered when navigator is enabled (#49)
* fix: do not add point for internal series * fix: filter out internal series from chart * link isInternal prop request to highcharts --------- Co-authored-by: Raj Jaiswal <[email protected]>
1 parent 413c0f4 commit 432a314

File tree

14 files changed

+58
-14
lines changed

14 files changed

+58
-14
lines changed

pages/03-core/core-line-chart.page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import Highcharts from "highcharts";
45
import { omit } from "lodash";
56

67
import Button from "@cloudscape-design/components/button";
@@ -96,6 +97,7 @@ export default function () {
9697
>
9798
<CoreChart
9899
{...omit(chartProps.cartesian, "ref")}
100+
highcharts={Highcharts}
99101
options={{
100102
lang: {
101103
accessibility: {
@@ -111,6 +113,11 @@ export default function () {
111113
},
112114
],
113115
yAxis: [{ title: { text: "Events" } }],
116+
chart: {
117+
zooming: {
118+
type: "x",
119+
},
120+
},
114121
}}
115122
chartHeight={400}
116123
tooltip={{ placement: "outside" }}

src/cartesian-chart/__tests__/cartesian-chart-visibility.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import { vi } from "vitest";
88
import "@cloudscape-design/components/test-utils/dom";
99
import { CartesianChartProps } from "../../../lib/components/cartesian-chart";
1010
import { toggleLegendItem } from "../../core/__tests__/common";
11+
import { getChartSeries } from "../../internal/utils/chart-series";
1112
import { getChart, ref, renderCartesianChart, renderStatefulCartesianChart } from "./common";
1213

1314
function getVisibilityState() {
1415
const legend = getChart().findLegend();
1516
const chart = highcharts.charts.find((c) => c)!;
16-
const series = chart.series;
17+
const series = getChartSeries(chart.series);
1718
const hiddenSeries = series.filter((s) => !s.visible);
1819
return {
1920
allLegendItems: legend?.findItems().map((w) => w.getElement().textContent) ?? [],

src/core/__tests__/chart-core-visibility.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import highcharts from "highcharts";
55
import { vi } from "vitest";
66

77
import "@cloudscape-design/components/test-utils/dom";
8+
import { getChartSeries } from "../../internal/utils/chart-series";
89
import { createChartWrapper, renderChart, renderStatefulChart, selectLegendItem, toggleLegendItem } from "./common";
910

1011
const onVisibleItemsChange = vi.fn();
@@ -58,9 +59,9 @@ const pieSeries: Highcharts.SeriesOptionsType[] = [
5859
function getVisibilityState() {
5960
const legend = createChartWrapper().findLegend();
6061
const chart = highcharts.charts.find((c) => c)!;
61-
const series = chart.series;
62+
const series = getChartSeries(chart.series);
6263
const hiddenSeries = series.filter((s) => !s.visible);
63-
const points = chart.series.flatMap((s) => s.data);
64+
const points = getChartSeries(chart.series).flatMap((s) => s.data);
6465
const hiddenPoints = points.filter((p) => !p.visible);
6566
return {
6667
allLegendItems: legend?.findItems().map((w) => w.getElement().textContent) ?? [],

src/core/chart-api/chart-extra-axis-titles.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import AsyncStore from "../../internal/utils/async-store";
5+
import { getChartSeries } from "../../internal/utils/chart-series";
56
import { castArray, isEqualArrays } from "../../internal/utils/utils";
67
import { ChartExtraContext } from "./chart-extra-context";
78

@@ -30,7 +31,7 @@ export class ChartExtraAxisTitles extends AsyncStore<ReactiveAxisTitlesState> {
3031

3132
function getVerticalAxesTitles(chart: Highcharts.Chart) {
3233
const isInverted = !!chart.options.chart?.inverted;
33-
const hasSeries = chart.series.filter((s) => s.type !== "pie").length > 0;
34+
const hasSeries = getChartSeries(chart.series).filter((s) => s.type !== "pie").length > 0;
3435

3536
// We extract multiple titles as there can be multiple axes. This supports up to 2 axes by
3637
// using space-between placement of the labels in the corresponding component.

src/core/chart-api/chart-extra-context.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import type Highcharts from "highcharts";
55

6+
import { getChartSeries } from "../../internal/utils/chart-series";
67
import { ChartLabels } from "../i18n-utils";
78
import { ChartHighlightProps, CoreLegendItem, Rect } from "../interfaces";
89
import { getGroupRect, isSeriesStacked } from "../utils";
@@ -93,7 +94,8 @@ function computeDerivedState(chart: Highcharts.Chart): ChartExtraContext.Derived
9394
pointsByX.set(point.x, xPoints);
9495
};
9596
const compareX = (a: number, b: number) => a - b;
96-
for (const s of chart.series) {
97+
98+
for (const s of getChartSeries(chart.series)) {
9799
const seriesX = new Set<number>();
98100
if (s.visible) {
99101
for (const d of s.data) {

src/core/chart-api/chart-extra-legend.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type Highcharts from "highcharts";
55

66
import { ChartSeriesMarker, ChartSeriesMarkerType } from "../../internal/components/series-marker";
77
import AsyncStore from "../../internal/utils/async-store";
8+
import { getChartSeries } from "../../internal/utils/chart-series";
89
import { isEqualArrays } from "../../internal/utils/utils";
910
import { CoreLegendItem } from "../interfaces";
1011
import { getChartLegendItems, getPointId, getSeriesId } from "../utils";
@@ -128,7 +129,7 @@ function updateItemsVisibility(
128129
return nextVisible;
129130
};
130131

131-
for (const series of chart.series) {
132+
for (const series of getChartSeries(chart.series)) {
132133
if (availableItemsSet.has(getSeriesId(series))) {
133134
series.setVisible(getVisibleAndCount(getSeriesId(series), series.visible), false);
134135
}

src/core/chart-api/chart-extra-nodata.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type Highcharts from "highcharts";
55

66
import AsyncStore from "../../internal/utils/async-store";
7+
import { getChartSeries } from "../../internal/utils/chart-series";
78
import { ChartExtraContext } from "./chart-extra-context";
89

910
// The reactive state is used to propagate updates to the corresponding no-data React component.
@@ -51,7 +52,7 @@ export class ChartExtraNodata extends AsyncStore<ReactiveNodataState> {
5152
function findAllSeriesWithData(chart: Highcharts.Chart) {
5253
// When a series becomes hidden, Highcharts no longer computes the data array, so the series.data is empty.
5354
// That is why we assert the data from series.options instead.
54-
return chart.series.filter((s) => {
55+
return getChartSeries(chart.series).filter((s) => {
5556
const data = "data" in s.options && s.options.data && Array.isArray(s.options.data) ? s.options.data : [];
5657
return data.some((i) => i !== null && (typeof i === "object" && "y" in i ? i.y !== null : true));
5758
});

src/core/chart-api/chart-extra-pointer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import type Highcharts from "highcharts";
55

6+
import { getChartSeries } from "../../internal/utils/chart-series";
67
import { DebouncedCall } from "../../internal/utils/utils";
78
import { isPointVisible } from "../utils";
89
import { ChartExtraContext } from "./chart-extra-context";
@@ -77,7 +78,7 @@ export class ChartExtraPointer {
7778
private onChartMousemove = (event: MouseEvent) => {
7879
const chart = this.context.chart();
7980
// In pie charts there is no support for groups - only a single point can be hovered at a time.
80-
if (chart.series.some((s) => s.type === "pie")) {
81+
if (getChartSeries(chart.series).some((s) => s.type === "pie")) {
8182
return;
8283
}
8384
// The plotX and plotY are pointer coordinates, normalized against the chart plot.

src/core/chart-api/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useRef } from "react";
55
import type Highcharts from "highcharts";
66

77
import { ReadonlyAsyncStore } from "../../internal/utils/async-store";
8+
import { getChartSeries } from "../../internal/utils/chart-series";
89
import { Writeable } from "../../internal/utils/utils";
910
import {
1011
getChartAccessibleDescription,
@@ -326,7 +327,7 @@ export class ChartAPI {
326327
private resetColorCounter() {
327328
const chart = this.context.chart();
328329
if ("colorCounter" in chart && typeof chart.colorCounter === "number") {
329-
chart.colorCounter = chart.series.length;
330+
chart.colorCounter = getChartSeries(chart.series).length;
330331
}
331332
}
332333

src/core/components/core-tooltip.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import LiveRegion from "@cloudscape-design/components/live-region";
1010

1111
import ChartSeriesDetails, { ChartSeriesDetailItem } from "../../internal/components/series-details";
1212
import { useSelector } from "../../internal/utils/async-store";
13+
import { getChartSeries } from "../../internal/utils/chart-series";
1314
import { ChartAPI } from "../chart-api";
1415
import { getFormatter } from "../formatters";
1516
import {
@@ -148,7 +149,7 @@ function getTooltipContentCartesian(
148149
const chart = group[0].series.chart;
149150
const getSeriesMarker = (series: Highcharts.Series) =>
150151
api.renderMarker(getSeriesMarkerType(series), getSeriesColor(series), true);
151-
const matchedItems = findTooltipSeriesItems(chart.series, group);
152+
const matchedItems = findTooltipSeriesItems(getChartSeries(chart.series), group);
152153
const detailItems: ChartSeriesDetailItem[] = matchedItems.map((item) => {
153154
const valueFormatter = getFormatter(item.point.series.yAxis);
154155
const itemY = isXThreshold(item.point.series) ? null : (item.point.y ?? null);

0 commit comments

Comments
 (0)