@cloudscape-design/chart-components 1.0.88 → 1.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/chart-api/chart-extra-axis-titles.js +2 -2
- package/core/chart-api/chart-extra-axis-titles.js.map +1 -1
- package/core/chart-api/chart-extra-context.d.ts +5 -4
- package/core/chart-api/chart-extra-context.js +5 -6
- package/core/chart-api/chart-extra-context.js.map +1 -1
- package/core/chart-api/chart-extra-highlight.js +14 -16
- package/core/chart-api/chart-extra-highlight.js.map +1 -1
- package/core/chart-api/chart-extra-legend.js +3 -3
- package/core/chart-api/chart-extra-legend.js.map +1 -1
- package/core/chart-api/chart-extra-navigation.js +1 -1
- package/core/chart-api/chart-extra-navigation.js.map +1 -1
- package/core/chart-api/chart-extra-nodata.js +3 -3
- package/core/chart-api/chart-extra-nodata.js.map +1 -1
- package/core/chart-api/chart-extra-pointer.d.ts +2 -1
- package/core/chart-api/chart-extra-pointer.js +2 -3
- package/core/chart-api/chart-extra-pointer.js.map +1 -1
- package/core/chart-api/chart-extra-tooltip.js +3 -3
- package/core/chart-api/chart-extra-tooltip.js.map +1 -1
- package/core/chart-api/index.js +4 -5
- package/core/chart-api/index.js.map +1 -1
- package/core/components/core-tooltip.js +3 -4
- package/core/components/core-tooltip.js.map +1 -1
- package/core/utils.d.ts +11 -10
- package/core/utils.js +3 -3
- package/core/utils.js.map +1 -1
- package/internal/components/series-marker/render-marker.d.ts +2 -1
- package/internal/components/series-marker/render-marker.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/generated/styles/tokens.d.ts +4 -0
- package/internal/generated/styles/tokens.js +4 -0
- package/internal/generated/theming/index.cjs +132 -0
- package/internal/generated/theming/index.cjs.d.ts +36 -0
- package/internal/generated/theming/index.d.ts +36 -0
- package/internal/generated/theming/index.js +132 -0
- package/internal/manifest.json +1 -1
- package/internal/utils/highcharts.d.ts +40 -0
- package/internal/utils/highcharts.js +55 -0
- package/internal/utils/highcharts.js.map +1 -0
- package/package.json +1 -1
- package/pie-chart/chart-inner-area.js +5 -5
- package/pie-chart/chart-inner-area.js.map +1 -1
- package/internal/utils/chart-series.d.ts +0 -16
- package/internal/utils/chart-series.js +0 -27
- package/internal/utils/chart-series.js.map +0 -1
- package/internal/utils/series-data.d.ts +0 -3
- package/internal/utils/series-data.js +0 -18
- package/internal/utils/series-data.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import AsyncStore from "../../internal/utils/async-store";
|
|
4
|
-
import { getChartSeries } from "../../internal/utils/
|
|
4
|
+
import { getChartSeries } from "../../internal/utils/highcharts";
|
|
5
5
|
import { castArray, isEqualArrays } from "../../internal/utils/utils";
|
|
6
6
|
// Chart helper to fetch chart vertical axis labels for them to be rendered in a slot above the chart.
|
|
7
7
|
// See: https://github.com/highcharts/highcharts/issues/23174.
|
|
@@ -21,7 +21,7 @@ export class ChartExtraAxisTitles extends AsyncStore {
|
|
|
21
21
|
function getVerticalAxesTitles(chart) {
|
|
22
22
|
var _a, _b, _c;
|
|
23
23
|
const isInverted = !!((_a = chart.options.chart) === null || _a === void 0 ? void 0 : _a.inverted);
|
|
24
|
-
const hasSeries = getChartSeries(chart
|
|
24
|
+
const hasSeries = getChartSeries(chart).filter((s) => s.type !== "pie").length > 0;
|
|
25
25
|
// We extract multiple titles as there can be multiple axes. This supports up to 2 axes by
|
|
26
26
|
// using space-between placement of the labels in the corresponding component.
|
|
27
27
|
let titles = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-extra-axis-titles.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-axis-titles.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,E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KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEnF,0FAA0F;IAC1F,8EAA8E;IAC9E,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;QAC5B,MAAM,GAAG,CAAC,MAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;aAC5C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;aAC9B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,eAAC,OAAA,MAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAA,EAAA,CAAC;aACrC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,SAAS,IAAI,CAAC,UAAU,EAAE,CAAC;QAC7B,MAAM,GAAG,CAAC,MAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;aAC5C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;aAC9B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,eAAC,OAAA,MAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAA,EAAA,CAAC;aACrC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport AsyncStore from \"../../internal/utils/async-store\";\nimport { getChartSeries, SafeChart } from \"../../internal/utils/highcharts\";\nimport { castArray, isEqualArrays } from \"../../internal/utils/utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\n// The reactive state is used to propagate changes to the corresponding vertical axis titles React component.\nexport interface ReactiveAxisTitlesState {\n verticalAxesTitles: readonly string[];\n}\n\n// Chart helper to fetch chart vertical axis labels for them to be rendered in a slot above the chart.\n// See: https://github.com/highcharts/highcharts/issues/23174.\nexport class ChartExtraAxisTitles extends AsyncStore<ReactiveAxisTitlesState> {\n private context: ChartExtraContext;\n constructor(context: ChartExtraContext) {\n super({ verticalAxesTitles: [] });\n this.context = context;\n }\n\n public onChartRender = () => {\n const nextTitles = getVerticalAxesTitles(this.context.chart());\n const currentTitles = this.get().verticalAxesTitles;\n if (!isEqualArrays(currentTitles, nextTitles, (s1, s2) => s1 === s2)) {\n this.set(() => ({ verticalAxesTitles: nextTitles }));\n }\n };\n}\n\nfunction getVerticalAxesTitles(chart: SafeChart) {\n const isInverted = !!chart.options.chart?.inverted;\n const hasSeries = getChartSeries(chart).filter((s) => s.type !== \"pie\").length > 0;\n\n // We extract multiple titles as there can be multiple axes. This supports up to 2 axes by\n // using space-between placement of the labels in the corresponding component.\n let titles: string[] = [];\n if (hasSeries && isInverted) {\n titles = (castArray(chart.options.xAxis) ?? [])\n .filter((axis) => axis.visible)\n .map((axis) => axis.title?.text ?? \"\")\n .filter(Boolean);\n }\n if (hasSeries && !isInverted) {\n titles = (castArray(chart.options.yAxis) ?? [])\n .filter((axis) => axis.visible)\n .map((axis) => axis.title?.text ?? \"\")\n .filter(Boolean);\n }\n return titles;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type Highcharts from "highcharts";
|
|
2
2
|
import { NonCancelableEventHandler } from "../../internal/events";
|
|
3
|
+
import { SafeChart, SafeSeries } from "../../internal/utils/highcharts";
|
|
3
4
|
import { ChartLabels } from "../i18n-utils";
|
|
4
5
|
import { CoreChartProps, Rect } from "../interfaces";
|
|
5
6
|
export interface ChartExtraContext {
|
|
@@ -7,8 +8,8 @@ export interface ChartExtraContext {
|
|
|
7
8
|
handlers: ChartExtraContext.Handlers;
|
|
8
9
|
state: ChartExtraContext.State;
|
|
9
10
|
derived: ChartExtraContext.DerivedState;
|
|
10
|
-
chartOrNull: null |
|
|
11
|
-
chart: () =>
|
|
11
|
+
chartOrNull: null | SafeChart;
|
|
12
|
+
chart: () => SafeChart;
|
|
12
13
|
}
|
|
13
14
|
export declare namespace ChartExtraContext {
|
|
14
15
|
interface Settings {
|
|
@@ -31,7 +32,7 @@ export declare namespace ChartExtraContext {
|
|
|
31
32
|
interface DerivedState {
|
|
32
33
|
allX: number[];
|
|
33
34
|
getPointsByX: (x: number) => Highcharts.Point[];
|
|
34
|
-
getSeriesPoints: (series:
|
|
35
|
+
getSeriesPoints: (series: SafeSeries) => Highcharts.Point[];
|
|
35
36
|
groupRects: {
|
|
36
37
|
group: Highcharts.Point[];
|
|
37
38
|
rect: Rect;
|
|
@@ -39,4 +40,4 @@ export declare namespace ChartExtraContext {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
export declare function createChartContext(): ChartExtraContext;
|
|
42
|
-
export declare function updateChartContext(context: ChartExtraContext, chart:
|
|
43
|
+
export declare function updateChartContext(context: ChartExtraContext, chart: SafeChart): void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { getChartSeries } from "../../internal/utils/
|
|
4
|
-
import { getSeriesData } from "../../internal/utils/series-data";
|
|
3
|
+
import { getChartSeries, getSeriesData } from "../../internal/utils/highcharts";
|
|
5
4
|
import { getGroupRect, isSeriesStacked } from "../utils";
|
|
6
5
|
// The context is created when the chart component is rendered for the first time.
|
|
7
6
|
// On every subsequent render the settings and state are updated directly in the context object.
|
|
@@ -46,10 +45,10 @@ function computeDerivedState(chart) {
|
|
|
46
45
|
pointsByX.set(point.x, xPoints);
|
|
47
46
|
};
|
|
48
47
|
const compareX = (a, b) => a - b;
|
|
49
|
-
for (const s of getChartSeries(chart
|
|
48
|
+
for (const s of getChartSeries(chart)) {
|
|
50
49
|
const seriesX = new Set();
|
|
51
50
|
if (s.visible) {
|
|
52
|
-
for (const d of getSeriesData(s
|
|
51
|
+
for (const d of getSeriesData(s)) {
|
|
53
52
|
// Points with y=null represent the absence of value, there is no need to include them and those
|
|
54
53
|
// should have no impact on computed rects or navigation.
|
|
55
54
|
// Although "d" can't be undefined according to Highcharts API, it does become undefined for chart containing more datapoints
|
|
@@ -71,7 +70,7 @@ function computeDerivedState(chart) {
|
|
|
71
70
|
// (primary + its linked children), all members share the same flat list: points sorted by X,
|
|
72
71
|
// with family members interleaved in series order within the same X value.
|
|
73
72
|
const seriesPointsMap = new WeakMap();
|
|
74
|
-
for (const s of getChartSeries(chart
|
|
73
|
+
for (const s of getChartSeries(chart)) {
|
|
75
74
|
if (seriesPointsMap.has(s)) {
|
|
76
75
|
continue; // Already computed as part of a family.
|
|
77
76
|
}
|
|
@@ -81,7 +80,7 @@ function computeDerivedState(chart) {
|
|
|
81
80
|
const familyPoints = [];
|
|
82
81
|
for (const x of Array.from(familyXSet).sort(compareX)) {
|
|
83
82
|
for (const member of family) {
|
|
84
|
-
const point = getSeriesData(member
|
|
83
|
+
const point = getSeriesData(member).find((d) => d.x === x && d.y !== null);
|
|
85
84
|
if (point && familyXSet.has(x)) {
|
|
86
85
|
familyPoints.push(point);
|
|
87
86
|
familyXSet.delete(x); // We ignore points that share X coordinate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-extra-context.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-context.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AA6CzD,kFAAkF;AAClF,gGAAgG;AAChG,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,QAAQ,EAAE;YACR,OAAO,EAAE,EAAE;YACX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AAK,CAAC;QAC7G,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { NonCancelableEventHandler } from \"../../internal/events\";\nimport { getChartSeries } from \"../../internal/utils/chart-series\";\nimport { getSeriesData } from \"../../internal/utils/series-data\";\nimport { ChartLabels } from \"../i18n-utils\";\nimport { CoreChartProps, Rect } from \"../interfaces\";\nimport { getGroupRect, isSeriesStacked } from \"../utils\";\n\n// Chart API context is used for dependency injection for chart utilities.\n// It is initialized on chart render, and includes the chart instance, consumer\n// settings and state, and derived state, which is computed from the chart instance\n// on each render, and reused across utilities to avoid duplicate work.\n\nexport interface ChartExtraContext {\n settings: ChartExtraContext.Settings;\n handlers: ChartExtraContext.Handlers;\n state: ChartExtraContext.State;\n derived: ChartExtraContext.DerivedState;\n chartOrNull: null | Highcharts.Chart;\n chart: () => Highcharts.Chart;\n}\n\nexport namespace ChartExtraContext {\n export interface Settings {\n chartId: string;\n noDataEnabled: boolean;\n legendEnabled: boolean;\n tooltipEnabled: boolean;\n keyboardNavigationEnabled: boolean;\n labels: ChartLabels;\n getItemOptions?: CoreChartProps.GetItemOptions;\n }\n\n export interface Handlers {\n onHighlight?: NonCancelableEventHandler<CoreChartProps.HighlightChangeDetail>;\n onClearHighlight?: NonCancelableEventHandler<CoreChartProps.HighlightClearDetail>;\n onVisibleItemsChange?: NonCancelableEventHandler<CoreChartProps.VisibleItemsChangeDetail>;\n }\n\n export interface State {\n visibleItems?: readonly string[];\n }\n\n export interface DerivedState {\n allX: number[];\n getPointsByX: (x: number) => Highcharts.Point[];\n getSeriesPoints: (series: Highcharts.Series) => Highcharts.Point[];\n groupRects: { group: Highcharts.Point[]; rect: Rect }[];\n }\n}\n\n// The context is created when the chart component is rendered for the first time.\n// On every subsequent render the settings and state are updated directly in the context object.\nexport function createChartContext(): ChartExtraContext {\n return {\n settings: {\n chartId: \"\",\n noDataEnabled: false,\n legendEnabled: false,\n tooltipEnabled: false,\n keyboardNavigationEnabled: false,\n labels: {},\n },\n handlers: {},\n state: {},\n chart: () => {\n // Before the first chart render there is no chart instance, which is required for most of the utilities.\n // Instead of doing null checks in each utility, an attempt to access the chart instance before it is ready\n // will cause an exception, indicating an logical error in the code.\n throw new Error(\"Invariant violation: using chart API before initialization.\");\n },\n chartOrNull: null,\n derived: { allX: [], getPointsByX: () => [], getSeriesPoints: () => [], groupRects: [] },\n };\n}\n\n// The update method is called on every chart render, before any other initialization code.\n// This ensures the context state is up to date and can be used for subsequent computations.\nexport function updateChartContext(context: ChartExtraContext, chart: Highcharts.Chart) {\n context.chart = () => chart;\n context.chartOrNull = chart;\n context.derived = computeDerivedState(chart);\n}\n\nfunction computeDerivedState(chart: Highcharts.Chart): ChartExtraContext.DerivedState {\n const allXSet = new Set<number>();\n const allXInSeries = new WeakMap<Highcharts.Series, number[]>();\n const pointsByX = new Map<number, Highcharts.Point[]>();\n const getXPoints = (x: number) => pointsByX.get(x) ?? [];\n const addPoint = (point: Highcharts.Point) => {\n const xPoints = getXPoints(point.x);\n xPoints.push(point);\n pointsByX.set(point.x, xPoints);\n };\n const compareX = (a: number, b: number) => a - b;\n\n for (const s of getChartSeries(chart.series)) {\n const seriesX = new Set<number>();\n if (s.visible) {\n for (const d of getSeriesData(s.data)) {\n // Points with y=null represent the absence of value, there is no need to include them and those\n // should have no impact on computed rects or navigation.\n\n // Although \"d\" can't be undefined according to Highcharts API, it does become undefined for chart containing more datapoints\n // than the cropThreshold for that series (specific cases of re-rendering the chart with updated options listening to setExteme updates)\n if (d.visible && d.y !== null) {\n seriesX.add(d.x);\n allXSet.add(d.x);\n addPoint(d);\n }\n }\n }\n allXInSeries.set(s, Array.from(seriesX));\n }\n for (const [, points] of pointsByX) {\n sortPoints(points);\n }\n const allX = Array.from(allXSet).sort(compareX);\n\n // For each series, compute the ordered list of points to navigate through. For a linked family\n // (primary + its linked children), all members share the same flat list: points sorted by X,\n // with family members interleaved in series order within the same X value.\n const seriesPointsMap = new WeakMap<Highcharts.Series, Highcharts.Point[]>();\n for (const s of getChartSeries(chart.series)) {\n if (seriesPointsMap.has(s)) {\n continue; // Already computed as part of a family.\n }\n const master = s.linkedParent ?? s;\n const family = [master, ...master.linkedSeries];\n const familyXSet = new Set(family.flatMap((m) => allXInSeries.get(m) ?? []));\n const familyPoints: Highcharts.Point[] = [];\n for (const x of Array.from(familyXSet).sort(compareX)) {\n for (const member of family) {\n const point = getSeriesData(member.data).find((d) => d.x === x && d.y !== null);\n if (point && familyXSet.has(x)) {\n familyPoints.push(point);\n familyXSet.delete(x); // We ignore points that share X coordinate.\n }\n }\n }\n for (const member of family) {\n seriesPointsMap.set(member, familyPoints);\n }\n }\n return {\n allX,\n getPointsByX: (x) => pointsByX.get(x) ?? [],\n getSeriesPoints: (s) => seriesPointsMap.get(s) ?? [],\n // Group rects are computed for every available x coordinate, each including at least one point with matching x value.\n // They enclose all matching points of the group and are used to match hover position and place the tooltip or focus outline.\n groupRects: allX.map((x) => ({\n group: getXPoints(x),\n rect: getGroupRect(getXPoints(x)),\n })),\n };\n}\n\n// The points are sorted to ensure consistent navigation, including inverted chart orientation.\n// The order of series in grouped column charts is kept, while stacked series are sorted by their\n// respective positions in the plot.\nfunction sortPoints(group: Highcharts.Point[]) {\n const reversed = !!group[0]?.series.yAxis?.reversed;\n group.sort((a, b) => {\n const ay = a.plotY === undefined || (a.series.type === \"column\" && !isSeriesStacked(a.series)) ? 0 : a.plotY;\n const by = b.plotY === undefined || (b.series.type === \"column\" && !isSeriesStacked(b.series)) ? 0 : b.plotY;\n return !reversed ? ay - by : by - ay;\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chart-extra-context.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra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CAAC,CAAC,KAAK,CAAC;QAC7G,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC7G,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { NonCancelableEventHandler } from \"../../internal/events\";\nimport { getChartSeries, getSeriesData, SafeChart, SafeSeries } from \"../../internal/utils/highcharts\";\nimport { ChartLabels } from \"../i18n-utils\";\nimport { CoreChartProps, Rect } from \"../interfaces\";\nimport { getGroupRect, isSeriesStacked } from \"../utils\";\n\n// Chart API context is used for dependency injection for chart utilities.\n// It is initialized on chart render, and includes the chart instance, consumer\n// settings and state, and derived state, which is computed from the chart instance\n// on each render, and reused across utilities to avoid duplicate work.\n\nexport interface ChartExtraContext {\n settings: ChartExtraContext.Settings;\n handlers: ChartExtraContext.Handlers;\n state: ChartExtraContext.State;\n derived: ChartExtraContext.DerivedState;\n chartOrNull: null | SafeChart;\n chart: () => SafeChart;\n}\n\nexport namespace ChartExtraContext {\n export interface Settings {\n chartId: string;\n noDataEnabled: boolean;\n legendEnabled: boolean;\n tooltipEnabled: boolean;\n keyboardNavigationEnabled: boolean;\n labels: ChartLabels;\n getItemOptions?: CoreChartProps.GetItemOptions;\n }\n\n export interface Handlers {\n onHighlight?: NonCancelableEventHandler<CoreChartProps.HighlightChangeDetail>;\n onClearHighlight?: NonCancelableEventHandler<CoreChartProps.HighlightClearDetail>;\n onVisibleItemsChange?: NonCancelableEventHandler<CoreChartProps.VisibleItemsChangeDetail>;\n }\n\n export interface State {\n visibleItems?: readonly string[];\n }\n\n export interface DerivedState {\n allX: number[];\n getPointsByX: (x: number) => Highcharts.Point[];\n getSeriesPoints: (series: SafeSeries) => Highcharts.Point[];\n groupRects: { group: Highcharts.Point[]; rect: Rect }[];\n }\n}\n\n// The context is created when the chart component is rendered for the first time.\n// On every subsequent render the settings and state are updated directly in the context object.\nexport function createChartContext(): ChartExtraContext {\n return {\n settings: {\n chartId: \"\",\n noDataEnabled: false,\n legendEnabled: false,\n tooltipEnabled: false,\n keyboardNavigationEnabled: false,\n labels: {},\n },\n handlers: {},\n state: {},\n chart: () => {\n // Before the first chart render there is no chart instance, which is required for most of the utilities.\n // Instead of doing null checks in each utility, an attempt to access the chart instance before it is ready\n // will cause an exception, indicating an logical error in the code.\n throw new Error(\"Invariant violation: using chart API before initialization.\");\n },\n chartOrNull: null,\n derived: { allX: [], getPointsByX: () => [], getSeriesPoints: () => [], groupRects: [] },\n };\n}\n\n// The update method is called on every chart render, before any other initialization code.\n// This ensures the context state is up to date and can be used for subsequent computations.\nexport function updateChartContext(context: ChartExtraContext, chart: SafeChart) {\n context.chart = () => chart;\n context.chartOrNull = chart;\n context.derived = computeDerivedState(chart);\n}\n\nfunction computeDerivedState(chart: SafeChart): ChartExtraContext.DerivedState {\n const allXSet = new Set<number>();\n const allXInSeries = new WeakMap<SafeSeries, number[]>();\n const pointsByX = new Map<number, Highcharts.Point[]>();\n const getXPoints = (x: number) => pointsByX.get(x) ?? [];\n const addPoint = (point: Highcharts.Point) => {\n const xPoints = getXPoints(point.x);\n xPoints.push(point);\n pointsByX.set(point.x, xPoints);\n };\n const compareX = (a: number, b: number) => a - b;\n\n for (const s of getChartSeries(chart)) {\n const seriesX = new Set<number>();\n if (s.visible) {\n for (const d of getSeriesData(s)) {\n // Points with y=null represent the absence of value, there is no need to include them and those\n // should have no impact on computed rects or navigation.\n\n // Although \"d\" can't be undefined according to Highcharts API, it does become undefined for chart containing more datapoints\n // than the cropThreshold for that series (specific cases of re-rendering the chart with updated options listening to setExteme updates)\n if (d.visible && d.y !== null) {\n seriesX.add(d.x);\n allXSet.add(d.x);\n addPoint(d);\n }\n }\n }\n allXInSeries.set(s, Array.from(seriesX));\n }\n for (const [, points] of pointsByX) {\n sortPoints(points);\n }\n const allX = Array.from(allXSet).sort(compareX);\n\n // For each series, compute the ordered list of points to navigate through. For a linked family\n // (primary + its linked children), all members share the same flat list: points sorted by X,\n // with family members interleaved in series order within the same X value.\n const seriesPointsMap = new WeakMap<SafeSeries, Highcharts.Point[]>();\n for (const s of getChartSeries(chart)) {\n if (seriesPointsMap.has(s)) {\n continue; // Already computed as part of a family.\n }\n const master = s.linkedParent ?? s;\n const family = [master, ...master.linkedSeries];\n const familyXSet = new Set(family.flatMap((m) => allXInSeries.get(m) ?? []));\n const familyPoints: Highcharts.Point[] = [];\n for (const x of Array.from(familyXSet).sort(compareX)) {\n for (const member of family) {\n const point = getSeriesData(member).find((d) => d.x === x && d.y !== null);\n if (point && familyXSet.has(x)) {\n familyPoints.push(point);\n familyXSet.delete(x); // We ignore points that share X coordinate.\n }\n }\n }\n for (const member of family) {\n seriesPointsMap.set(member, familyPoints);\n }\n }\n return {\n allX,\n getPointsByX: (x) => pointsByX.get(x) ?? [],\n getSeriesPoints: (s) => seriesPointsMap.get(s) ?? [],\n // Group rects are computed for every available x coordinate, each including at least one point with matching x value.\n // They enclose all matching points of the group and are used to match hover position and place the tooltip or focus outline.\n groupRects: allX.map((x) => ({\n group: getXPoints(x),\n rect: getGroupRect(getXPoints(x)),\n })),\n };\n}\n\n// The points are sorted to ensure consistent navigation, including inverted chart orientation.\n// The order of series in grouped column charts is kept, while stacked series are sorted by their\n// respective positions in the plot.\nfunction sortPoints(group: Highcharts.Point[]) {\n const reversed = !!group[0]?.series.yAxis?.reversed;\n group.sort((a, b) => {\n const ay = a.plotY === undefined || (a.series.type === \"column\" && !isSeriesStacked(a.series)) ? 0 : a.plotY;\n const by = b.plotY === undefined || (b.series.type === \"column\" && !isSeriesStacked(b.series)) ? 0 : b.plotY;\n return !reversed ? ay - by : by - ay;\n });\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import * as Styles from "../../internal/chart-styles";
|
|
4
|
-
import { getLinkedSeries, getMasterSeries } from "../../internal/utils/
|
|
5
|
-
import { getSeriesData } from "../../internal/utils/series-data";
|
|
4
|
+
import { getChartSeries, getLinkedSeries, getMasterSeries, getSeriesData, } from "../../internal/utils/highcharts";
|
|
6
5
|
import { getPointId, getSeriesId } from "../utils";
|
|
7
6
|
const SET_STATE_LOCK = Symbol("awsui-set-state-lock");
|
|
8
7
|
// Chart helper that mutes Highcharts default highlighting behavior and offers custom methods
|
|
@@ -17,10 +16,10 @@ export class ChartExtraHighlight {
|
|
|
17
16
|
// The method highlights specified series or points (by id). It is used when hovering over the legend items.
|
|
18
17
|
this.highlightChartItems = (itemIds) => {
|
|
19
18
|
const itemIdsSet = new Set(itemIds);
|
|
20
|
-
for (const s of this.context.chart()
|
|
19
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
21
20
|
// In pie charts it is the points, not series, that are shown in the legend, and can be highlighted.
|
|
22
21
|
if (s.type === "pie") {
|
|
23
|
-
for (const p of getSeriesData(s
|
|
22
|
+
for (const p of getSeriesData(s)) {
|
|
24
23
|
if (itemIdsSet.has(getPointId(p))) {
|
|
25
24
|
this.setPointState(p, "hover");
|
|
26
25
|
}
|
|
@@ -48,12 +47,12 @@ export class ChartExtraHighlight {
|
|
|
48
47
|
includedSeriesIds.add(getSeriesId(s));
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
|
-
for (const s of this.context.chart()
|
|
50
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
52
51
|
this.setSeriesState(s, includedSeries.has(s) ? "" : "inactive");
|
|
53
52
|
// For column series we ensure only one group/stack that matches selected X is highlighted.
|
|
54
53
|
// See: https://github.com/highcharts/highcharts/issues/23076.
|
|
55
54
|
if (s.type === "column") {
|
|
56
|
-
for (const d of getSeriesData(s
|
|
55
|
+
for (const d of getSeriesData(s)) {
|
|
57
56
|
this.setPointState(d, includedPoints.has(d) ? "" : "inactive");
|
|
58
57
|
}
|
|
59
58
|
}
|
|
@@ -65,19 +64,19 @@ export class ChartExtraHighlight {
|
|
|
65
64
|
this.highlightChartPoint = (point) => {
|
|
66
65
|
const masterSeries = getMasterSeries(point);
|
|
67
66
|
const linkedSeries = new Set(getLinkedSeries(point));
|
|
68
|
-
for (const s of this.context.chart()
|
|
67
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
69
68
|
// For pie charts it is important that the hover actions comes last, as otherwise the segment's highlight "halo"
|
|
70
69
|
// is removed whenever any segment is made inactive.
|
|
71
70
|
this.setSeriesState(s, linkedSeries.has(s) ? "hover" : "inactive");
|
|
72
71
|
if (s.type === "pie") {
|
|
73
|
-
for (const d of getSeriesData(s
|
|
72
|
+
for (const d of getSeriesData(s)) {
|
|
74
73
|
this.setPointState(d, "inactive");
|
|
75
74
|
}
|
|
76
75
|
this.setPointState(point, "hover");
|
|
77
76
|
}
|
|
78
77
|
// For column series we ensure only one group/stack that matches selected X is highlighted.
|
|
79
78
|
else if (s.type === "column") {
|
|
80
|
-
for (const d of getSeriesData(s
|
|
79
|
+
for (const d of getSeriesData(s)) {
|
|
81
80
|
this.setPointState(d, d === point ? "hover" : "inactive");
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -87,10 +86,9 @@ export class ChartExtraHighlight {
|
|
|
87
86
|
};
|
|
88
87
|
// Removes dimmed state from all series and points.
|
|
89
88
|
this.clearChartItemsHighlight = () => {
|
|
90
|
-
|
|
91
|
-
for (const s of (_a = this.context.chart().series) !== null && _a !== void 0 ? _a : []) {
|
|
89
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
92
90
|
this.setSeriesState(s, "");
|
|
93
|
-
for (const p of getSeriesData(s
|
|
91
|
+
for (const p of getSeriesData(s)) {
|
|
94
92
|
this.setPointState(p, "");
|
|
95
93
|
}
|
|
96
94
|
}
|
|
@@ -105,7 +103,7 @@ export class ChartExtraHighlight {
|
|
|
105
103
|
// We replace `setState` method on Highcharts series and points with a custom implementation, that
|
|
106
104
|
// prevents Highcharts from altering it. Instead, every state change is explicitly done by the helper.
|
|
107
105
|
this.overrideStateSetters = () => {
|
|
108
|
-
for (const s of this.context.chart()
|
|
106
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
109
107
|
// We ensure the replacement is done only once by assigning a custom property to the function.
|
|
110
108
|
// If the property is present - it means the method was already replaced.
|
|
111
109
|
if (s.setState[SET_STATE_LOCK] === undefined) {
|
|
@@ -119,7 +117,7 @@ export class ChartExtraHighlight {
|
|
|
119
117
|
overridden[SET_STATE_LOCK] = true;
|
|
120
118
|
s.setState = overridden;
|
|
121
119
|
}
|
|
122
|
-
for (const d of getSeriesData(s
|
|
120
|
+
for (const d of getSeriesData(s)) {
|
|
123
121
|
if (d.setState[SET_STATE_LOCK] === undefined) {
|
|
124
122
|
const original = d.setState;
|
|
125
123
|
// The overridden setState method does nothing unless setState[SET_STATE_LOCK] === false.
|
|
@@ -158,7 +156,7 @@ export class ChartExtraHighlight {
|
|
|
158
156
|
restoreHighlightState() {
|
|
159
157
|
var _a;
|
|
160
158
|
const inactiveSeriesIds = new Set();
|
|
161
|
-
for (const s of this.context.chart()
|
|
159
|
+
for (const s of getChartSeries(this.context.chart())) {
|
|
162
160
|
const prevState = this.seriesState.get(getSeriesId(s));
|
|
163
161
|
if (prevState) {
|
|
164
162
|
this.setSeriesState(s, prevState);
|
|
@@ -166,7 +164,7 @@ export class ChartExtraHighlight {
|
|
|
166
164
|
if (prevState === "inactive") {
|
|
167
165
|
inactiveSeriesIds.add(getSeriesId(s));
|
|
168
166
|
}
|
|
169
|
-
for (const p of getSeriesData(s
|
|
167
|
+
for (const p of getSeriesData(s)) {
|
|
170
168
|
const prevState = (_a = this.pointState.get(getSeriesId(s))) === null || _a === void 0 ? void 0 : _a.get(this.getPointKey(p));
|
|
171
169
|
if (prevState) {
|
|
172
170
|
this.setPointState(p, prevState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-extra-highlight.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-highlight.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGnD,MAAM,cAAc,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAKtD,6FAA6F;AAC7F,8DAA8D;AAC9D,MAAM,OAAO,mBAAmB;IAE9B,YAAY,OAA0B;QAItC,sGAAsG;QACtG,oGAAoG;QACpG,kFAAkF;QAC1E,gBAAW,GAAG,IAAI,GAAG,EAA4C,CAAC;QAClE,eAAU,GAAG,IAAI,GAAG,EAAwD,CAAC;QAOrF,4GAA4G;QACrG,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;YAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC;gBAC5C,oGAAoG;gBACpG,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;oBACrB,KAAK,MAAM,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;wBACtC,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAA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AG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACrE,CAAC;CAwCF;AAED,+FAA+F;AAC/F,qGAAqG;AACrG,SAAS,iBAAiB,CAAC,KAAuB,EAAE,QAAqC;IACvF,gBAAgB,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,WACvC,OAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA,EAAA,CACtF,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAuB,EAAE,EAA6D;;IAC9G,MAAA,KAAK,CAAC,IAAI,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,sEAAsE;QACtE,IAAI,mBAAmB,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAA+B,EAAE,EAAE;gBACjE,wFAAwF;gBACxF,oFAAoF;gBACpF,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;oBACpB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport * as Styles from \"../../internal/chart-styles\";\nimport { getLinkedSeries, getMasterSeries } from \"../../internal/utils/chart-series\";\nimport { getSeriesData } from \"../../internal/utils/series-data\";\nimport { getPointId, getSeriesId } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\nconst SET_STATE_LOCK = Symbol(\"awsui-set-state-lock\");\n\ntype SeriesSetStateWithLock = Highcharts.Series[\"setState\"] & { [SET_STATE_LOCK]: boolean };\ntype PointSetStateWithLock = Highcharts.Point[\"setState\"] & { [SET_STATE_LOCK]: boolean };\n\n// Chart helper that mutes Highcharts default highlighting behavior and offers custom methods\n// for customized control over series and points highlighting.\nexport class ChartExtraHighlight {\n private context: ChartExtraContext;\n constructor(context: ChartExtraContext) {\n this.context = context;\n }\n\n // We keep track of the previously highlighted series and points to recover highlight state if needed.\n // The recover is necessary if the chart was re-rendered while the highlighting is set. For example,\n // when triggered a state update from the consumer-provided tooltip footer action.\n private seriesState = new Map<string, \"\" | Highcharts.SeriesStateValue>();\n private pointState = new Map<string, Map<string, \"\" | Highcharts.PointStateValue>>();\n\n public onChartRender() {\n this.overrideStateSetters();\n this.restoreHighlightState();\n }\n\n // The method highlights specified series or points (by id). It is used when hovering over the legend items.\n public highlightChartItems = (itemIds: readonly string[]) => {\n const itemIdsSet = new Set(itemIds);\n for (const s of this.context.chart().series) {\n // In pie charts it is the points, not series, that are shown in the legend, and can be highlighted.\n if (s.type === \"pie\") {\n for (const p of getSeriesData(s.data)) {\n if (itemIdsSet.has(getPointId(p))) {\n this.setPointState(p, \"hover\");\n }\n }\n } else {\n const seriesActive = itemIdsSet.has(getSeriesId(s));\n const masterSeriesActive = s.linkedParent ? itemIdsSet.has(getSeriesId(s.linkedParent)) : false;\n this.setSeriesState(s, seriesActive || masterSeriesActive ? \"\" : \"inactive\");\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => itemIdsSet.has(lineId));\n };\n\n // This method is similar to the above, but it takes a group of points. The cartesian chart points\n // do not have IDs, so we match points and series by their references instead. This is used to control\n // highlight state when chart elements are hovered or focused.\n public highlightChartGroup = (points: readonly Highcharts.Point[]) => {\n const includedPoints = new Set<Highcharts.Point>();\n const includedSeries = new Set<Highcharts.Series>();\n const includedSeriesIds = new Set<string>();\n points.forEach((point) => {\n includedPoints.add(point);\n getLinkedSeries(point).forEach((s) => {\n includedSeries.add(s);\n includedSeriesIds.add(getSeriesId(s));\n });\n });\n for (const s of this.context.chart().series) {\n this.setSeriesState(s, includedSeries.has(s) ? \"\" : \"inactive\");\n // For column series we ensure only one group/stack that matches selected X is highlighted.\n // See: https://github.com/highcharts/highcharts/issues/23076.\n if (s.type === \"column\") {\n for (const d of getSeriesData(s.data)) {\n this.setPointState(d, includedPoints.has(d) ? \"\" : \"inactive\");\n }\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => includedSeriesIds.has(lineId));\n };\n\n // This method is similar to the above, but it takes a single point. This is used for point highlighting\n // in cartesian charts, and for pie chart segments.\n public highlightChartPoint = (point: Highcharts.Point) => {\n const masterSeries = getMasterSeries(point);\n const linkedSeries = new Set(getLinkedSeries(point));\n for (const s of this.context.chart().series) {\n // For pie charts it is important that the hover actions comes last, as otherwise the segment's highlight \"halo\"\n // is removed whenever any segment is made inactive.\n this.setSeriesState(s, linkedSeries.has(s) ? \"hover\" : \"inactive\");\n if (s.type === \"pie\") {\n for (const d of getSeriesData(s.data)) {\n this.setPointState(d, \"inactive\");\n }\n this.setPointState(point, \"hover\");\n }\n // For column series we ensure only one group/stack that matches selected X is highlighted.\n else if (s.type === \"column\") {\n for (const d of getSeriesData(s.data)) {\n this.setPointState(d, d === point ? \"hover\" : \"inactive\");\n }\n }\n }\n // Highlight threshold series plot lines.\n setPlotLinesState(this.context.chart(), (lineId) => lineId === getSeriesId(masterSeries));\n };\n\n // Removes dimmed state from all series and points.\n public clearChartItemsHighlight = () => {\n for (const s of this.context.chart().series ?? []) {\n this.setSeriesState(s, \"\");\n for (const p of getSeriesData(s.data)) {\n this.setPointState(p, \"\");\n }\n }\n setPlotLinesState(this.context.chart(), () => true);\n };\n\n // Makes the specified series active or dimmed.\n private setSeriesState(series: Highcharts.Series, state: \"\" | Highcharts.SeriesStateValue) {\n (series.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] = false;\n series.setState(state, false);\n this.updateStoredSeriesState(series, state);\n (series.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] = true;\n }\n\n // Makes the specified point active or dimmed.\n private setPointState(point: Highcharts.Point, state: \"\" | Highcharts.PointStateValue) {\n (point.setState as PointSetStateWithLock)[SET_STATE_LOCK] = false;\n point.setState(state, true);\n this.updateStoredPointState(point, state);\n (point.setState as PointSetStateWithLock)[SET_STATE_LOCK] = true;\n }\n\n // Restores series and points highlight state after chart's re-render.\n private restoreHighlightState() {\n const inactiveSeriesIds = new Set<string>();\n for (const s of this.context.chart().series) {\n const prevState = this.seriesState.get(getSeriesId(s));\n if (prevState) {\n this.setSeriesState(s, prevState);\n }\n if (prevState === \"inactive\") {\n inactiveSeriesIds.add(getSeriesId(s));\n }\n for (const p of getSeriesData(s.data)) {\n const prevState = this.pointState.get(getSeriesId(s))?.get(this.getPointKey(p));\n if (prevState) {\n this.setPointState(p, prevState);\n }\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => !inactiveSeriesIds.has(lineId));\n }\n\n private updateStoredSeriesState(series: Highcharts.Series, state: \"\" | Highcharts.SeriesStateValue) {\n this.seriesState.set(getSeriesId(series), state);\n }\n\n private updateStoredPointState(point: Highcharts.Point, state: \"\" | Highcharts.PointStateValue) {\n const pointStateInSeries = this.pointState.get(getSeriesId(point.series)) ?? new Map();\n pointStateInSeries.set(this.getPointKey(point), state);\n this.pointState.set(getSeriesId(point.series), pointStateInSeries);\n }\n\n // The points normally don't have ID's or names. In that case, the points are identified by\n // the combination of x and y values. This is only used to restore the highlight state after re-render.\n private getPointKey = (point: Highcharts.Point) => {\n return point.options.id ?? `${point.x}:${point.y ?? \"null\"}`;\n };\n\n // We replace `setState` method on Highcharts series and points with a custom implementation, that\n // prevents Highcharts from altering it. Instead, every state change is explicitly done by the helper.\n private overrideStateSetters = () => {\n for (const s of this.context.chart().series) {\n // We ensure the replacement is done only once by assigning a custom property to the function.\n // If the property is present - it means the method was already replaced.\n if ((s.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] === undefined) {\n const original = s.setState;\n // The overridden setState method does nothing unless setState[SET_STATE_LOCK] === false.\n const overridden: Highcharts.Series[\"setState\"] = (...args) => {\n if ((overridden as SeriesSetStateWithLock)[SET_STATE_LOCK] === false) {\n original.call(s, ...args);\n }\n };\n (overridden as SeriesSetStateWithLock)[SET_STATE_LOCK] = true;\n s.setState = overridden;\n }\n for (const d of getSeriesData(s.data)) {\n if ((d.setState as PointSetStateWithLock)[SET_STATE_LOCK] === undefined) {\n const original = d.setState;\n // The overridden setState method does nothing unless setState[SET_STATE_LOCK] === false.\n const overridden: Highcharts.Point[\"setState\"] = (...args) => {\n if ((overridden as PointSetStateWithLock)[SET_STATE_LOCK] === false) {\n original.call(d, ...args);\n }\n };\n (overridden as PointSetStateWithLock)[SET_STATE_LOCK] = true;\n d.setState = overridden;\n }\n }\n }\n };\n}\n\n// The cartesian chart thresholds are represented with invisible series and visible plot lines.\n// When the corresponding series are highlighted, we need to make the not matching plot lines dimmed.\nfunction setPlotLinesState(chart: Highcharts.Chart, isActive: (lineId: string) => boolean) {\n iteratePlotLines(chart, (lineId, line) =>\n line.svgElem?.attr({ opacity: !isActive(lineId) ? Styles.dimmedPlotLineOpacity : 1 }),\n );\n}\n\nfunction iteratePlotLines(chart: Highcharts.Chart, cb: (lineId: string, line: Highcharts.PlotLineOrBand) => void) {\n chart.axes?.forEach((axis) => {\n // The Highcharts `Axis.plotLinesAndBands` API is not covered with TS.\n if (\"plotLinesAndBands\" in axis && Array.isArray(axis.plotLinesAndBands)) {\n axis.plotLinesAndBands.forEach((line: Highcharts.PlotLineOrBand) => {\n // We explicitly do not touch plot lines that have no ID, assuming those are decorative.\n // Only plot lines that define ID can be dimmed when certain series get highlighted.\n if (line.options.id) {\n cb(line.options.id, line);\n }\n });\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chart-extra-highlight.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-highlight.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,GAGd,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGnD,MAAM,cAAc,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAKtD,6FAA6F;AAC7F,8DAA8D;AAC9D,MAAM,OAAO,mBAAmB;IAE9B,YAAY,OAA0B;QAItC,sGAAsG;QACtG,oGAAoG;QACpG,kFAAkF;QAC1E,gBAAW,GAAG,IAAI,GAAG,EAA4C,CAAC;QAClE,eAAU,GAAG,IAAI,GAAG,EAAwD,CAAC;QAOrF,4GAA4G;QACrG,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;YAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,KAAK,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC;gBACrD,oGAAoG;gBACpG,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;oBACrB,KAAK,MAAM,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;wBACjC,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAClC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;wBACjC,CAAC;oBACH,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,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,KAAgB,EAAE,QAAqC;IAChF,gBAAgB,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,WACvC,OAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA,EAAA,CACtF,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAgB,EAAE,EAA6D;;IACvG,MAAA,KAAK,CAAC,IAAI,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,sEAAsE;QACtE,IAAI,mBAAmB,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAA+B,EAAE,EAAE;gBACjE,wFAAwF;gBACxF,oFAAoF;gBACpF,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;oBACpB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport * as Styles from \"../../internal/chart-styles\";\nimport {\n getChartSeries,\n getLinkedSeries,\n getMasterSeries,\n getSeriesData,\n SafeChart,\n SafeSeries,\n} from \"../../internal/utils/highcharts\";\nimport { getPointId, getSeriesId } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\nconst SET_STATE_LOCK = Symbol(\"awsui-set-state-lock\");\n\ntype SeriesSetStateWithLock = SafeSeries[\"setState\"] & { [SET_STATE_LOCK]: boolean };\ntype PointSetStateWithLock = Highcharts.Point[\"setState\"] & { [SET_STATE_LOCK]: boolean };\n\n// Chart helper that mutes Highcharts default highlighting behavior and offers custom methods\n// for customized control over series and points highlighting.\nexport class ChartExtraHighlight {\n private context: ChartExtraContext;\n constructor(context: ChartExtraContext) {\n this.context = context;\n }\n\n // We keep track of the previously highlighted series and points to recover highlight state if needed.\n // The recover is necessary if the chart was re-rendered while the highlighting is set. For example,\n // when triggered a state update from the consumer-provided tooltip footer action.\n private seriesState = new Map<string, \"\" | Highcharts.SeriesStateValue>();\n private pointState = new Map<string, Map<string, \"\" | Highcharts.PointStateValue>>();\n\n public onChartRender() {\n this.overrideStateSetters();\n this.restoreHighlightState();\n }\n\n // The method highlights specified series or points (by id). It is used when hovering over the legend items.\n public highlightChartItems = (itemIds: readonly string[]) => {\n const itemIdsSet = new Set(itemIds);\n for (const s of getChartSeries(this.context.chart())) {\n // In pie charts it is the points, not series, that are shown in the legend, and can be highlighted.\n if (s.type === \"pie\") {\n for (const p of getSeriesData(s)) {\n if (itemIdsSet.has(getPointId(p))) {\n this.setPointState(p, \"hover\");\n }\n }\n } else {\n const seriesActive = itemIdsSet.has(getSeriesId(s));\n const masterSeriesActive = s.linkedParent ? itemIdsSet.has(getSeriesId(s.linkedParent)) : false;\n this.setSeriesState(s, seriesActive || masterSeriesActive ? \"\" : \"inactive\");\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => itemIdsSet.has(lineId));\n };\n\n // This method is similar to the above, but it takes a group of points. The cartesian chart points\n // do not have IDs, so we match points and series by their references instead. This is used to control\n // highlight state when chart elements are hovered or focused.\n public highlightChartGroup = (points: readonly Highcharts.Point[]) => {\n const includedPoints = new Set<Highcharts.Point>();\n const includedSeries = new Set<SafeSeries>();\n const includedSeriesIds = new Set<string>();\n points.forEach((point) => {\n includedPoints.add(point);\n getLinkedSeries(point).forEach((s) => {\n includedSeries.add(s);\n includedSeriesIds.add(getSeriesId(s));\n });\n });\n for (const s of getChartSeries(this.context.chart())) {\n this.setSeriesState(s, includedSeries.has(s) ? \"\" : \"inactive\");\n // For column series we ensure only one group/stack that matches selected X is highlighted.\n // See: https://github.com/highcharts/highcharts/issues/23076.\n if (s.type === \"column\") {\n for (const d of getSeriesData(s)) {\n this.setPointState(d, includedPoints.has(d) ? \"\" : \"inactive\");\n }\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => includedSeriesIds.has(lineId));\n };\n\n // This method is similar to the above, but it takes a single point. This is used for point highlighting\n // in cartesian charts, and for pie chart segments.\n public highlightChartPoint = (point: Highcharts.Point) => {\n const masterSeries = getMasterSeries(point);\n const linkedSeries = new Set(getLinkedSeries(point));\n for (const s of getChartSeries(this.context.chart())) {\n // For pie charts it is important that the hover actions comes last, as otherwise the segment's highlight \"halo\"\n // is removed whenever any segment is made inactive.\n this.setSeriesState(s, linkedSeries.has(s) ? \"hover\" : \"inactive\");\n if (s.type === \"pie\") {\n for (const d of getSeriesData(s)) {\n this.setPointState(d, \"inactive\");\n }\n this.setPointState(point, \"hover\");\n }\n // For column series we ensure only one group/stack that matches selected X is highlighted.\n else if (s.type === \"column\") {\n for (const d of getSeriesData(s)) {\n this.setPointState(d, d === point ? \"hover\" : \"inactive\");\n }\n }\n }\n // Highlight threshold series plot lines.\n setPlotLinesState(this.context.chart(), (lineId) => lineId === getSeriesId(masterSeries));\n };\n\n // Removes dimmed state from all series and points.\n public clearChartItemsHighlight = () => {\n for (const s of getChartSeries(this.context.chart())) {\n this.setSeriesState(s, \"\");\n for (const p of getSeriesData(s)) {\n this.setPointState(p, \"\");\n }\n }\n setPlotLinesState(this.context.chart(), () => true);\n };\n\n // Makes the specified series active or dimmed.\n private setSeriesState(series: SafeSeries, state: \"\" | Highcharts.SeriesStateValue) {\n (series.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] = false;\n series.setState(state, false);\n this.updateStoredSeriesState(series, state);\n (series.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] = true;\n }\n\n // Makes the specified point active or dimmed.\n private setPointState(point: Highcharts.Point, state: \"\" | Highcharts.PointStateValue) {\n (point.setState as PointSetStateWithLock)[SET_STATE_LOCK] = false;\n point.setState(state, true);\n this.updateStoredPointState(point, state);\n (point.setState as PointSetStateWithLock)[SET_STATE_LOCK] = true;\n }\n\n // Restores series and points highlight state after chart's re-render.\n private restoreHighlightState() {\n const inactiveSeriesIds = new Set<string>();\n for (const s of getChartSeries(this.context.chart())) {\n const prevState = this.seriesState.get(getSeriesId(s));\n if (prevState) {\n this.setSeriesState(s, prevState);\n }\n if (prevState === \"inactive\") {\n inactiveSeriesIds.add(getSeriesId(s));\n }\n for (const p of getSeriesData(s)) {\n const prevState = this.pointState.get(getSeriesId(s))?.get(this.getPointKey(p));\n if (prevState) {\n this.setPointState(p, prevState);\n }\n }\n }\n setPlotLinesState(this.context.chart(), (lineId) => !inactiveSeriesIds.has(lineId));\n }\n\n private updateStoredSeriesState(series: SafeSeries, state: \"\" | Highcharts.SeriesStateValue) {\n this.seriesState.set(getSeriesId(series), state);\n }\n\n private updateStoredPointState(point: Highcharts.Point, state: \"\" | Highcharts.PointStateValue) {\n const pointStateInSeries = this.pointState.get(getSeriesId(point.series)) ?? new Map();\n pointStateInSeries.set(this.getPointKey(point), state);\n this.pointState.set(getSeriesId(point.series), pointStateInSeries);\n }\n\n // The points normally don't have ID's or names. In that case, the points are identified by\n // the combination of x and y values. This is only used to restore the highlight state after re-render.\n private getPointKey = (point: Highcharts.Point) => {\n return point.options.id ?? `${point.x}:${point.y ?? \"null\"}`;\n };\n\n // We replace `setState` method on Highcharts series and points with a custom implementation, that\n // prevents Highcharts from altering it. Instead, every state change is explicitly done by the helper.\n private overrideStateSetters = () => {\n for (const s of getChartSeries(this.context.chart())) {\n // We ensure the replacement is done only once by assigning a custom property to the function.\n // If the property is present - it means the method was already replaced.\n if ((s.setState as SeriesSetStateWithLock)[SET_STATE_LOCK] === undefined) {\n const original = s.setState;\n // The overridden setState method does nothing unless setState[SET_STATE_LOCK] === false.\n const overridden: SafeSeries[\"setState\"] = (...args) => {\n if ((overridden as SeriesSetStateWithLock)[SET_STATE_LOCK] === false) {\n original.call(s, ...args);\n }\n };\n (overridden as SeriesSetStateWithLock)[SET_STATE_LOCK] = true;\n s.setState = overridden;\n }\n for (const d of getSeriesData(s)) {\n if ((d.setState as PointSetStateWithLock)[SET_STATE_LOCK] === undefined) {\n const original = d.setState;\n // The overridden setState method does nothing unless setState[SET_STATE_LOCK] === false.\n const overridden: Highcharts.Point[\"setState\"] = (...args) => {\n if ((overridden as PointSetStateWithLock)[SET_STATE_LOCK] === false) {\n original.call(d, ...args);\n }\n };\n (overridden as PointSetStateWithLock)[SET_STATE_LOCK] = true;\n d.setState = overridden;\n }\n }\n }\n };\n}\n\n// The cartesian chart thresholds are represented with invisible series and visible plot lines.\n// When the corresponding series are highlighted, we need to make the not matching plot lines dimmed.\nfunction setPlotLinesState(chart: SafeChart, isActive: (lineId: string) => boolean) {\n iteratePlotLines(chart, (lineId, line) =>\n line.svgElem?.attr({ opacity: !isActive(lineId) ? Styles.dimmedPlotLineOpacity : 1 }),\n );\n}\n\nfunction iteratePlotLines(chart: SafeChart, cb: (lineId: string, line: Highcharts.PlotLineOrBand) => void) {\n chart.axes?.forEach((axis) => {\n // The Highcharts `Axis.plotLinesAndBands` API is not covered with TS.\n if (\"plotLinesAndBands\" in axis && Array.isArray(axis.plotLinesAndBands)) {\n axis.plotLinesAndBands.forEach((line: Highcharts.PlotLineOrBand) => {\n // We explicitly do not touch plot lines that have no ID, assuming those are decorative.\n // Only plot lines that define ID can be dimmed when certain series get highlighted.\n if (line.options.id) {\n cb(line.options.id, line);\n }\n });\n }\n });\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { ChartSeriesMarker } from "../../internal/components/series-marker";
|
|
3
3
|
import { fireNonCancelableEvent } from "../../internal/events";
|
|
4
4
|
import AsyncStore from "../../internal/utils/async-store";
|
|
5
|
-
import { getChartSeries, getMasterSeries } from "../../internal/utils/
|
|
5
|
+
import { getChartSeries, getMasterSeries, getSeriesData } from "../../internal/utils/highcharts";
|
|
6
6
|
import { isEqualArrays } from "../../internal/utils/utils";
|
|
7
7
|
import { getChartLegendItems, getPointId, getSeriesId } from "../utils";
|
|
8
8
|
// Chart helper that implements custom legend behaviors.
|
|
@@ -107,11 +107,11 @@ function updateItemsVisibility(chart, legendItems, visibleItems) {
|
|
|
107
107
|
updatesCounter += nextVisible !== visible ? 1 : 0;
|
|
108
108
|
return nextVisible;
|
|
109
109
|
};
|
|
110
|
-
for (const series of getChartSeries(chart
|
|
110
|
+
for (const series of getChartSeries(chart)) {
|
|
111
111
|
if (availableItemsSet.has(getSeriesId(series))) {
|
|
112
112
|
series.setVisible(getVisibleAndCount(getSeriesId(series), series.visible), false);
|
|
113
113
|
}
|
|
114
|
-
for (const point of series
|
|
114
|
+
for (const point of getSeriesData(series, { includeHiddenPoints: true })) {
|
|
115
115
|
if (typeof point.setVisible === "function" && availableItemsSet.has(getPointId(point))) {
|
|
116
116
|
point.setVisible(getVisibleAndCount(getPointId(point), point.visible), false);
|
|
117
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-extra-legend.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-legend.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,yCAAyC,CAAC;AAEnG,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQxE,wDAAwD;AACxD,MAAM,OAAO,gBAAiB,SAA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AU,KAAK,UAAU,IAAI,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACvF,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;YAChF,CAAC;QACH,CAAC;IACH,CAAC;IAED,+GAA+G;IAC/G,gHAAgH;IAChH,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { LegendItem } from \"../../internal/components/interfaces\";\nimport { ChartSeriesMarker, ChartSeriesMarkerType } from \"../../internal/components/series-marker\";\nimport { ChartSeriesMarkerStatus } from \"../../internal/components/series-marker/interfaces\";\nimport { fireNonCancelableEvent } from \"../../internal/events\";\nimport AsyncStore from \"../../internal/utils/async-store\";\nimport { getChartSeries, getMasterSeries } from \"../../internal/utils/chart-series\";\nimport { isEqualArrays } from \"../../internal/utils/utils\";\nimport { CoreChartProps } from \"../interfaces\";\nimport { getChartLegendItems, getPointId, getSeriesId } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\n// The reactive state is used to propagate changes in legend items to the core legend React component.\nexport interface ReactiveLegendState {\n items: readonly CoreChartProps.LegendItem[];\n}\n\n// Chart helper that implements custom legend behaviors.\nexport class ChartExtraLegend extends AsyncStore<ReactiveLegendState> {\n private context: ChartExtraContext;\n private visibilityMode: \"internal\" | \"external\" = \"external\";\n\n constructor(context: ChartExtraContext) {\n super({ items: [] });\n this.context = context;\n }\n\n public onChartRender = () => {\n this.initLegend();\n this.updateItemsVisibility();\n };\n\n // If visible items are explicitly provided, we use them to update visibility of chart's series or points (by ID).\n // If not provided, the visibility state is managed internally.\n public updateItemsVisibility = () => {\n if (this.context.state.visibleItems) {\n this.visibilityMode = \"external\";\n updateItemsVisibility(this.context.chart(), this.get().items, this.context.state.visibleItems);\n } else {\n this.visibilityMode = \"internal\";\n }\n };\n\n // A callback to be called when items visibility changes from the outside or from the legend.\n public onItemVisibilityChange = (visibleItems: readonly string[], detail: CoreChartProps.InteractionKind) => {\n const currentItems = this.get().items;\n const updatedItems = currentItems.map((i) => ({ ...i, visible: visibleItems.includes(i.id) }));\n if (this.visibilityMode === \"internal\") {\n this.updateLegendItems(updatedItems);\n updateItemsVisibility(this.context.chart(), this.get().items, visibleItems);\n }\n fireNonCancelableEvent(this.context.handlers.onVisibleItemsChange, { items: updatedItems, ...detail });\n };\n\n // Updates legend highlight state when chart's point is highlighted.\n public onHighlightPoint = (point: Highcharts.Point) => {\n const masterSeries = getMasterSeries(point);\n const visibleItems = point.series.type === \"pie\" ? [getPointId(point)] : [getSeriesId(masterSeries)];\n this.onHighlightItems(visibleItems);\n };\n\n // Updates legend highlight state when chart's group of points is highlighted.\n public onHighlightGroup = (group: readonly Highcharts.Point[]) => {\n const visibleItems = group.map((point) => getSeriesId(getMasterSeries(point)));\n this.onHighlightItems(visibleItems);\n };\n\n // Updates legend highlight state given an explicit list of item IDs. This is used to update state\n // when a legend item gets hovered or focused.\n public onHighlightItems = (highlightedItems: readonly string[]) => {\n const currentItems = this.get().items;\n const updatedItems = currentItems.map(({ ...i }) => ({ ...i, highlighted: highlightedItems.includes(i.id) }));\n this.updateLegendItems(updatedItems);\n };\n\n // Clears legend highlight state.\n public onClearHighlight = () => {\n const nextItems = this.get().items.map(({ ...item }) => ({ ...item, highlighted: false }));\n this.updateLegendItems(nextItems);\n };\n\n private initLegend = () => {\n const prevState = this.get().items.reduce((map, item) => map.set(item.id, item), new Map<string, LegendItem>());\n const itemSpecs = getChartLegendItems({\n chart: this.context.chart(),\n getItemOptions: this.context.settings.getItemOptions,\n itemMarkerStatusAriaLabel: this.context.settings.labels.itemMarkerLabel,\n });\n const legendItems = itemSpecs.map(\n ({ id, name, color, markerType, visible, status, isSecondary, markerAriaLabel }) => {\n const marker = this.renderMarker({ type: markerType, color, visible, status, ariaLabel: markerAriaLabel });\n return { id, name, marker, visible, isSecondary, highlighted: prevState.get(id)?.highlighted ?? false };\n },\n );\n this.updateLegendItems(legendItems);\n };\n\n private updateLegendItems = (nextItems: CoreChartProps.LegendItem[]) => {\n function isLegendItemsEqual(a: CoreChartProps.LegendItem, b: CoreChartProps.LegendItem) {\n return (\n a.id === b.id &&\n a.name === b.name &&\n a.marker === b.marker &&\n a.visible === b.visible &&\n a.highlighted === b.highlighted &&\n a.isSecondary === b.isSecondary\n );\n }\n if (!isEqualArrays(this.get().items, nextItems, isLegendItemsEqual)) {\n this.set(() => ({ items: nextItems }));\n }\n };\n\n // The chart markers derive from type and color and are cached to avoid unnecessary renders,\n // and allow comparing them by reference.\n private markersCache = new Map<string, React.ReactNode>();\n public renderMarker({\n type,\n status = \"default\",\n color,\n visible = true,\n ariaLabel,\n }: {\n type: ChartSeriesMarkerType;\n color: string;\n visible?: boolean;\n status?: ChartSeriesMarkerStatus;\n ariaLabel?: string;\n }): React.ReactNode {\n const key = `${type}:${color}:${visible}:${status}`;\n const marker = this.markersCache.get(key) ?? (\n <ChartSeriesMarker type={type} color={color} visible={visible} status={status} ariaLabel={ariaLabel} />\n );\n this.markersCache.set(key, marker);\n return marker;\n }\n}\n\nfunction updateItemsVisibility(\n chart: Highcharts.Chart,\n legendItems: readonly CoreChartProps.LegendItem[],\n visibleItems?: readonly string[],\n) {\n const availableItemsSet = new Set(legendItems.map((i) => i.id));\n const visibleItemsSet = new Set(visibleItems);\n\n let updatesCounter = 0;\n const getVisibleAndCount = (id: string, visible: boolean) => {\n const nextVisible = visibleItemsSet.has(id);\n updatesCounter += nextVisible !== visible ? 1 : 0;\n return nextVisible;\n };\n\n for (const series of getChartSeries(chart.series)) {\n if (availableItemsSet.has(getSeriesId(series))) {\n series.setVisible(getVisibleAndCount(getSeriesId(series), series.visible), false);\n }\n for (const point of series.data) {\n if (typeof point.setVisible === \"function\" && availableItemsSet.has(getPointId(point))) {\n point.setVisible(getVisibleAndCount(getPointId(point), point.visible), false);\n }\n }\n }\n\n // The call `seriesOrPoint.setVisible(visible, false)` does not trigger the chart redraw, as it would otherwise\n // impact the performance. Instead, we trigger the redraw explicitly, if any change to visibility has been made.\n if (updatesCounter > 0) {\n chart.redraw();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chart-extra-legend.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-legend.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,yCAAyC,CAAC;AAEnG,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAa,MAAM,iCAAiC,CAAC;AAC5G,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQxE,wDAAwD;AACxD,MAAM,OAAO,gBAAiB,SAAQ,UAA+B;IAInE,YAAY,OAA0B;QACpC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAHf,mBAAc,GAA4B,UAAU,CAAC;QAOtD,kBAAa,GAAG,GAAG,EAAE;YAC1B,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEF,kHAAkH;QAClH,+DAA+D;QACxD,0BAAqB,GAAG,GAAG,EAAE;YAClC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;gBACpC,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;gBACjC,qBAAqB,CAAC,IAAI,CAAC,OAAO,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n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { LegendItem } from \"../../internal/components/interfaces\";\nimport { ChartSeriesMarker, ChartSeriesMarkerType } from \"../../internal/components/series-marker\";\nimport { ChartSeriesMarkerStatus } from \"../../internal/components/series-marker/interfaces\";\nimport { fireNonCancelableEvent } from \"../../internal/events\";\nimport AsyncStore from \"../../internal/utils/async-store\";\nimport { getChartSeries, getMasterSeries, getSeriesData, SafeChart } from \"../../internal/utils/highcharts\";\nimport { isEqualArrays } from \"../../internal/utils/utils\";\nimport { CoreChartProps } from \"../interfaces\";\nimport { getChartLegendItems, getPointId, getSeriesId } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\n// The reactive state is used to propagate changes in legend items to the core legend React component.\nexport interface ReactiveLegendState {\n items: readonly CoreChartProps.LegendItem[];\n}\n\n// Chart helper that implements custom legend behaviors.\nexport class ChartExtraLegend extends AsyncStore<ReactiveLegendState> {\n private context: ChartExtraContext;\n private visibilityMode: \"internal\" | \"external\" = \"external\";\n\n constructor(context: ChartExtraContext) {\n super({ items: [] });\n this.context = context;\n }\n\n public onChartRender = () => {\n this.initLegend();\n this.updateItemsVisibility();\n };\n\n // If visible items are explicitly provided, we use them to update visibility of chart's series or points (by ID).\n // If not provided, the visibility state is managed internally.\n public updateItemsVisibility = () => {\n if (this.context.state.visibleItems) {\n this.visibilityMode = \"external\";\n updateItemsVisibility(this.context.chart(), this.get().items, this.context.state.visibleItems);\n } else {\n this.visibilityMode = \"internal\";\n }\n };\n\n // A callback to be called when items visibility changes from the outside or from the legend.\n public onItemVisibilityChange = (visibleItems: readonly string[], detail: CoreChartProps.InteractionKind) => {\n const currentItems = this.get().items;\n const updatedItems = currentItems.map((i) => ({ ...i, visible: visibleItems.includes(i.id) }));\n if (this.visibilityMode === \"internal\") {\n this.updateLegendItems(updatedItems);\n updateItemsVisibility(this.context.chart(), this.get().items, visibleItems);\n }\n fireNonCancelableEvent(this.context.handlers.onVisibleItemsChange, { items: updatedItems, ...detail });\n };\n\n // Updates legend highlight state when chart's point is highlighted.\n public onHighlightPoint = (point: Highcharts.Point) => {\n const masterSeries = getMasterSeries(point);\n const visibleItems = point.series.type === \"pie\" ? [getPointId(point)] : [getSeriesId(masterSeries)];\n this.onHighlightItems(visibleItems);\n };\n\n // Updates legend highlight state when chart's group of points is highlighted.\n public onHighlightGroup = (group: readonly Highcharts.Point[]) => {\n const visibleItems = group.map((point) => getSeriesId(getMasterSeries(point)));\n this.onHighlightItems(visibleItems);\n };\n\n // Updates legend highlight state given an explicit list of item IDs. This is used to update state\n // when a legend item gets hovered or focused.\n public onHighlightItems = (highlightedItems: readonly string[]) => {\n const currentItems = this.get().items;\n const updatedItems = currentItems.map(({ ...i }) => ({ ...i, highlighted: highlightedItems.includes(i.id) }));\n this.updateLegendItems(updatedItems);\n };\n\n // Clears legend highlight state.\n public onClearHighlight = () => {\n const nextItems = this.get().items.map(({ ...item }) => ({ ...item, highlighted: false }));\n this.updateLegendItems(nextItems);\n };\n\n private initLegend = () => {\n const prevState = this.get().items.reduce((map, item) => map.set(item.id, item), new Map<string, LegendItem>());\n const itemSpecs = getChartLegendItems({\n chart: this.context.chart(),\n getItemOptions: this.context.settings.getItemOptions,\n itemMarkerStatusAriaLabel: this.context.settings.labels.itemMarkerLabel,\n });\n const legendItems = itemSpecs.map(\n ({ id, name, color, markerType, visible, status, isSecondary, markerAriaLabel }) => {\n const marker = this.renderMarker({ type: markerType, color, visible, status, ariaLabel: markerAriaLabel });\n return { id, name, marker, visible, isSecondary, highlighted: prevState.get(id)?.highlighted ?? false };\n },\n );\n this.updateLegendItems(legendItems);\n };\n\n private updateLegendItems = (nextItems: CoreChartProps.LegendItem[]) => {\n function isLegendItemsEqual(a: CoreChartProps.LegendItem, b: CoreChartProps.LegendItem) {\n return (\n a.id === b.id &&\n a.name === b.name &&\n a.marker === b.marker &&\n a.visible === b.visible &&\n a.highlighted === b.highlighted &&\n a.isSecondary === b.isSecondary\n );\n }\n if (!isEqualArrays(this.get().items, nextItems, isLegendItemsEqual)) {\n this.set(() => ({ items: nextItems }));\n }\n };\n\n // The chart markers derive from type and color and are cached to avoid unnecessary renders,\n // and allow comparing them by reference.\n private markersCache = new Map<string, React.ReactNode>();\n public renderMarker({\n type,\n status = \"default\",\n color,\n visible = true,\n ariaLabel,\n }: {\n type: ChartSeriesMarkerType;\n color: string;\n visible?: boolean;\n status?: ChartSeriesMarkerStatus;\n ariaLabel?: string;\n }): React.ReactNode {\n const key = `${type}:${color}:${visible}:${status}`;\n const marker = this.markersCache.get(key) ?? (\n <ChartSeriesMarker type={type} color={color} visible={visible} status={status} ariaLabel={ariaLabel} />\n );\n this.markersCache.set(key, marker);\n return marker;\n }\n}\n\nfunction updateItemsVisibility(\n chart: SafeChart,\n legendItems: readonly CoreChartProps.LegendItem[],\n visibleItems?: readonly string[],\n) {\n const availableItemsSet = new Set(legendItems.map((i) => i.id));\n const visibleItemsSet = new Set(visibleItems);\n\n let updatesCounter = 0;\n const getVisibleAndCount = (id: string, visible: boolean) => {\n const nextVisible = visibleItemsSet.has(id);\n updatesCounter += nextVisible !== visible ? 1 : 0;\n return nextVisible;\n };\n\n for (const series of getChartSeries(chart)) {\n if (availableItemsSet.has(getSeriesId(series))) {\n series.setVisible(getVisibleAndCount(getSeriesId(series), series.visible), false);\n }\n for (const point of getSeriesData(series, { includeHiddenPoints: true })) {\n if (typeof point.setVisible === \"function\" && availableItemsSet.has(getPointId(point))) {\n point.setVisible(getVisibleAndCount(getPointId(point), point.visible), false);\n }\n }\n }\n\n // The call `seriesOrPoint.setVisible(visible, false)` does not trigger the chart redraw, as it would otherwise\n // impact the performance. Instead, we trigger the redraw explicitly, if any change to visibility has been made.\n if (updatesCounter > 0) {\n chart.redraw();\n }\n}\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { circleIndex, getIsRtl, handleKey as toolkitHandleKey, KeyCode, } from "@cloudscape-design/component-toolkit/internal";
|
|
4
4
|
import * as Styles from "../../internal/chart-styles";
|
|
5
|
+
import { isPointVisible } from "../../internal/utils/highcharts";
|
|
5
6
|
import { SVGRendererPool } from "../../internal/utils/renderer-utils";
|
|
6
|
-
import { isPointVisible } from "../../internal/utils/series-data";
|
|
7
7
|
import { getGroupRect, getPointRect, isXThreshold } from "../utils";
|
|
8
8
|
// In charts with many data points one can navigate faster by using Page Down/Up keys that
|
|
9
9
|
// navigate PAGE_SIZE_PERCENTAGE of the points forwards or backwards.
|