@cloudscape-design/chart-components 1.0.22 → 1.0.23
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-legend.js +2 -2
- package/core/chart-api/chart-extra-legend.js.map +1 -1
- package/core/chart-container.d.ts +3 -2
- package/core/chart-container.js +3 -4
- package/core/chart-container.js.map +1 -1
- package/core/chart-core.js +51 -36
- package/core/chart-core.js.map +1 -1
- package/core/components/core-legend.d.ts +7 -5
- package/core/components/core-legend.js +34 -4
- package/core/components/core-legend.js.map +1 -1
- package/core/interfaces.d.ts +21 -2
- package/core/interfaces.js.map +1 -1
- package/core/styles.css.js +21 -20
- package/core/styles.scoped.css +31 -21
- package/core/styles.selectors.js +21 -20
- package/core/test-classes/styles.css.js +30 -28
- package/core/test-classes/styles.scoped.css +30 -28
- package/core/test-classes/styles.selectors.js +30 -28
- package/core/utils.d.ts +24 -2
- package/core/utils.js +75 -12
- package/core/utils.js.map +1 -1
- package/internal/components/chart-legend/index.d.ts +9 -5
- package/internal/components/chart-legend/index.js +52 -77
- package/internal/components/chart-legend/index.js.map +1 -1
- package/internal/components/chart-legend/styles.css.js +17 -23
- package/internal/components/chart-legend/styles.scoped.css +40 -61
- package/internal/components/chart-legend/styles.selectors.js +17 -23
- package/internal/components/interfaces.d.ts +1 -0
- package/internal/components/interfaces.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/internal-do-not-use/core-legend/index.d.ts +1 -1
- package/internal-do-not-use/core-legend/index.js +29 -3
- package/internal-do-not-use/core-legend/index.js.map +1 -1
- package/package.json +1 -1
- package/test-utils/dom/internal/core.d.ts +1 -0
- package/test-utils/dom/internal/core.js +4 -1
- package/test-utils/dom/internal/core.js.map +1 -1
- package/test-utils/selectors/internal/core.d.ts +1 -0
- package/test-utils/selectors/internal/core.js +4 -1
- package/test-utils/selectors/internal/core.js.map +1 -1
package/core/utils.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type Highcharts from "highcharts";
|
|
2
3
|
import { ChartSeriesMarkerType } from "../internal/components/series-marker";
|
|
3
4
|
import { ChartLabels } from "./i18n-utils";
|
|
4
|
-
import { Rect } from "./interfaces";
|
|
5
|
+
import { CoreChartProps, Rect } from "./interfaces";
|
|
5
6
|
export interface LegendItemSpec {
|
|
6
7
|
id: string;
|
|
7
8
|
name: string;
|
|
8
9
|
markerType: ChartSeriesMarkerType;
|
|
9
10
|
color: string;
|
|
10
11
|
visible: boolean;
|
|
12
|
+
isSecondary: boolean;
|
|
11
13
|
}
|
|
12
14
|
export declare function getSeriesId(series: Highcharts.Series): string;
|
|
13
15
|
export declare function getPointId(point: Highcharts.Point): string;
|
|
@@ -36,7 +38,27 @@ export declare function getSeriesMarkerType(series?: Highcharts.Series): ChartSe
|
|
|
36
38
|
export declare function getSeriesColor(series?: Highcharts.Series): string;
|
|
37
39
|
export declare function getPointColor(point?: Highcharts.Point): string;
|
|
38
40
|
export declare function getChartLegendItems(chart: Highcharts.Chart): readonly LegendItemSpec[];
|
|
39
|
-
export
|
|
41
|
+
export type LegendItemOptions = Highcharts.SeriesOptionsType | Highcharts.PointOptionsType;
|
|
42
|
+
export declare function getVisibleLegendItems(options: Highcharts.Options): {
|
|
43
|
+
primaryItems: LegendItemOptions[];
|
|
44
|
+
secondaryItems: LegendItemOptions[];
|
|
45
|
+
};
|
|
46
|
+
export declare function getLegendsProps(options: CoreChartProps.ChartOptions, legendOptions: CoreChartProps.LegendOptions | undefined): {
|
|
47
|
+
primary: {
|
|
48
|
+
readonly isSecondary: false;
|
|
49
|
+
readonly title: string | undefined;
|
|
50
|
+
readonly actions: import("react").ReactNode;
|
|
51
|
+
readonly alignment: "horizontal" | "vertical";
|
|
52
|
+
readonly horizontalAlignment: CoreChartProps.LegendOptionsHorizontalAlignment | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
secondary: {
|
|
55
|
+
readonly isSecondary: true;
|
|
56
|
+
readonly title: string | undefined;
|
|
57
|
+
readonly actions: import("react").ReactNode;
|
|
58
|
+
readonly alignment: "horizontal" | "vertical";
|
|
59
|
+
readonly horizontalAlignment: "end";
|
|
60
|
+
} | undefined;
|
|
61
|
+
};
|
|
40
62
|
export declare function getPointRect(point: Highcharts.Point): Rect;
|
|
41
63
|
export declare function getGroupRect(points: readonly Highcharts.Point[]): Rect;
|
|
42
64
|
export declare function safeRect(rect: Rect): Rect;
|
package/core/utils.js
CHANGED
|
@@ -1,6 +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 { getChartSeries } from "../internal/utils/chart-series";
|
|
4
|
+
import { castArray } from "../internal/utils/utils";
|
|
4
5
|
import { getFormatter } from "./formatters";
|
|
5
6
|
// The below functions extract unique identifier from series, point, or options. The identifier can be item's ID or name.
|
|
6
7
|
// We expect that items requiring referencing (e.g. in order to control their visibility) have the unique identifier defined.
|
|
@@ -93,8 +94,10 @@ export function getPointColor(point) {
|
|
|
93
94
|
// There exists a Highcharts APIs to access legend items, but it is unfortunately not available, when
|
|
94
95
|
// Highcharts legend is disabled. Instead, we use this custom method to collect legend items from the chart.
|
|
95
96
|
export function getChartLegendItems(chart) {
|
|
97
|
+
var _a, _b, _c;
|
|
96
98
|
const legendItems = [];
|
|
97
|
-
const
|
|
99
|
+
const isInverted = (_a = chart.inverted) !== null && _a !== void 0 ? _a : false;
|
|
100
|
+
const addSeriesItem = (series, isSecondary) => {
|
|
98
101
|
// The pie series is not shown in the legend. Instead, we show pie segments.
|
|
99
102
|
if (series.type === "pie") {
|
|
100
103
|
return;
|
|
@@ -113,10 +116,11 @@ export function getChartLegendItems(chart) {
|
|
|
113
116
|
markerType: getSeriesMarkerType(series),
|
|
114
117
|
color: getSeriesColor(series),
|
|
115
118
|
visible: series.visible,
|
|
119
|
+
isSecondary,
|
|
116
120
|
});
|
|
117
121
|
}
|
|
118
122
|
};
|
|
119
|
-
const addPointItem = (point) => {
|
|
123
|
+
const addPointItem = (point, isSecondary) => {
|
|
120
124
|
if (point.series.type === "pie") {
|
|
121
125
|
legendItems.push({
|
|
122
126
|
id: getPointId(point),
|
|
@@ -124,29 +128,88 @@ export function getChartLegendItems(chart) {
|
|
|
124
128
|
markerType: getSeriesMarkerType(point.series),
|
|
125
129
|
color: getPointColor(point),
|
|
126
130
|
visible: point.visible,
|
|
131
|
+
isSecondary,
|
|
127
132
|
});
|
|
128
133
|
}
|
|
129
134
|
};
|
|
130
135
|
for (const s of getChartSeries(chart.series)) {
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
const valueAxis = isInverted ? s.xAxis : s.yAxis;
|
|
137
|
+
const isSecondary = (_c = (_b = valueAxis === null || valueAxis === void 0 ? void 0 : valueAxis.options) === null || _b === void 0 ? void 0 : _b.opposite) !== null && _c !== void 0 ? _c : false;
|
|
138
|
+
addSeriesItem(s, isSecondary);
|
|
139
|
+
s.data.forEach((p) => addPointItem(p, isSecondary));
|
|
133
140
|
}
|
|
134
141
|
return legendItems;
|
|
135
142
|
}
|
|
136
|
-
export function
|
|
137
|
-
var _a;
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
export function getVisibleLegendItems(options) {
|
|
144
|
+
var _a, _b, _c, _d, _e;
|
|
145
|
+
const isInverted = (_b = (_a = options.chart) === null || _a === void 0 ? void 0 : _a.inverted) !== null && _b !== void 0 ? _b : false;
|
|
146
|
+
const valueAxes = (_c = (isInverted ? castArray(options.xAxis) : castArray(options.yAxis))) !== null && _c !== void 0 ? _c : [];
|
|
147
|
+
const defaultOpposite = valueAxes.length > 0 ? ((_d = valueAxes[0].opposite) !== null && _d !== void 0 ? _d : false) : false;
|
|
148
|
+
const primaryItems = [];
|
|
149
|
+
const secondaryItems = [];
|
|
150
|
+
const addLegendItem = (item) => {
|
|
151
|
+
if (isSecondaryLegendItem(item, isInverted, defaultOpposite, valueAxes)) {
|
|
152
|
+
secondaryItems.push(item);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
primaryItems.push(item);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
(_e = options.series) === null || _e === void 0 ? void 0 : _e.forEach((series) => {
|
|
159
|
+
// The pie series is not shown in the legend. Instead, we show pie segments (points).
|
|
140
160
|
if (series.type === "pie") {
|
|
141
|
-
|
|
161
|
+
if (Array.isArray(series.data)) {
|
|
162
|
+
series.data.forEach((point) => addLegendItem(point));
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
142
165
|
}
|
|
143
166
|
// We only support errorbar series that are linked to other series. Those are not represented separately
|
|
144
167
|
// in the legend, but can be controlled from the outside, using controllable items visibility API.
|
|
145
168
|
if (series.type === "errorbar") {
|
|
146
|
-
return
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (series.showInLegend !== false) {
|
|
172
|
+
addLegendItem(series);
|
|
147
173
|
}
|
|
148
|
-
|
|
149
|
-
}
|
|
174
|
+
});
|
|
175
|
+
return { primaryItems, secondaryItems };
|
|
176
|
+
}
|
|
177
|
+
function isSecondaryLegendItem(item, isInverted, defaultOpposite, valueAxes) {
|
|
178
|
+
var _a, _b, _c;
|
|
179
|
+
// Only items that have an associated axis can be considered secondary
|
|
180
|
+
if (item && typeof item === "object" && ("xAxis" in item || "yAxis" in item)) {
|
|
181
|
+
const axisRef = isInverted ? ((_a = item.xAxis) !== null && _a !== void 0 ? _a : 0) : ((_b = item.yAxis) !== null && _b !== void 0 ? _b : 0);
|
|
182
|
+
// An axis reference can be an index into the axes array or an explicitly passed id
|
|
183
|
+
const valueAxis = typeof axisRef === "number" ? valueAxes[axisRef] : valueAxes.find((a) => a.id === axisRef);
|
|
184
|
+
return (_c = valueAxis === null || valueAxis === void 0 ? void 0 : valueAxis.opposite) !== null && _c !== void 0 ? _c : false;
|
|
185
|
+
}
|
|
186
|
+
return defaultOpposite;
|
|
187
|
+
}
|
|
188
|
+
export function getLegendsProps(options, legendOptions) {
|
|
189
|
+
// While Highcharts supports more than two axes, this
|
|
190
|
+
// implementation supports at most two, in which case one
|
|
191
|
+
// of them must be set as opposite (secondary).
|
|
192
|
+
const { primaryItems, secondaryItems } = getVisibleLegendItems(options);
|
|
193
|
+
return {
|
|
194
|
+
primary: primaryItems.length === 0
|
|
195
|
+
? undefined
|
|
196
|
+
: {
|
|
197
|
+
isSecondary: false,
|
|
198
|
+
title: legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.title,
|
|
199
|
+
actions: legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.actions,
|
|
200
|
+
alignment: (legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.position) === "side" ? "vertical" : "horizontal",
|
|
201
|
+
horizontalAlignment: secondaryItems.length === 0 ? legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.horizontalAlignment : "start",
|
|
202
|
+
},
|
|
203
|
+
secondary: secondaryItems.length === 0
|
|
204
|
+
? undefined
|
|
205
|
+
: {
|
|
206
|
+
isSecondary: true,
|
|
207
|
+
title: legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.secondaryLegendTitle,
|
|
208
|
+
actions: legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.secondaryLegendActions,
|
|
209
|
+
alignment: (legendOptions === null || legendOptions === void 0 ? void 0 : legendOptions.position) === "side" ? "vertical" : "horizontal",
|
|
210
|
+
horizontalAlignment: "end",
|
|
211
|
+
},
|
|
212
|
+
};
|
|
150
213
|
}
|
|
151
214
|
// This function returns coordinates of a rectangle, including the target point.
|
|
152
215
|
// There are differences in how the rectangle is computed, but in all cases it is supposed to
|
package/core/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,OAAO,EAAE,cAAc,EAAE,MAAM,gC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AC5D,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3D,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,KAAK;SACnB;QACH,CAAC,CAAC;YACE,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;YAC1B,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;AACR,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 { ChartSeriesMarkerType } from \"../internal/components/series-marker\";\nimport { getChartSeries } from \"../internal/utils/chart-series\";\nimport { getFormatter } from \"./formatters\";\nimport { ChartLabels } from \"./i18n-utils\";\nimport { Rect } from \"./interfaces\";\n\nexport interface LegendItemSpec {\n id: string;\n name: string;\n markerType: ChartSeriesMarkerType;\n color: string;\n visible: boolean;\n}\n\n// The below functions extract unique identifier from series, point, or options. The identifier can be item's ID or name.\n// We expect that items requiring referencing (e.g. in order to control their visibility) have the unique identifier defined.\n// Otherwise, we return a randomized id that is to ensure no accidental matches.\nexport function getSeriesId(series: Highcharts.Series): string {\n return getOptionsId(series.options);\n}\nexport function getPointId(point: Highcharts.Point): string {\n return getOptionsId(point.options);\n}\nexport function getOptionsId(options: { id?: string; name?: string }): string {\n return options.id ?? options.name ?? noIdPlaceholder();\n}\nfunction noIdPlaceholder(): string {\n const rand = (Math.random() * 1_000_000).toFixed(0).padStart(6, \"0\");\n return \"awsui-no-id-placeholder-\" + rand;\n}\n\n// There are more possible values that series.stacking can take, but we only explicitly support \"normal\".\nexport function isSeriesStacked(series: Highcharts.Series) {\n return (series.options as any).stacking === \"normal\";\n}\n\n// The threshold series are custom series, implemented as a combination of line series, and plot lines.\n// As Highcharts does not support custom series declaration, we annotate threshold series by using the\n// series.custom property. This is then used in our utilities to recognize threshold series, and retrieve\n// the associated threshold value.\ninterface ThresholdOptions<T extends \"x-threshold\" | \"y-threshold\"> {\n custom: {\n awsui: {\n type: T;\n threshold: number;\n };\n };\n}\nexport function createThresholdMetadata<T extends \"x-threshold\" | \"y-threshold\">(\n type: T,\n value: number,\n): ThresholdOptions<T> {\n return { custom: { awsui: { type, threshold: value } } };\n}\nexport function isXThreshold(\n s: Highcharts.Series,\n): s is Highcharts.Series & { options: ThresholdOptions<\"x-threshold\"> } {\n return typeof s.options.custom === \"object\" && s.options.custom.awsui?.type === \"x-threshold\";\n}\nexport function isYThreshold(\n s: Highcharts.Series,\n): s is Highcharts.Series & { options: ThresholdOptions<\"y-threshold\"> } {\n return typeof s.options.custom === \"object\" && s.options.custom.awsui?.type === \"y-threshold\";\n}\n\n// We check point.series explicitly because Highcharts can destroy point objects, replacing the\n// contents with { destroyed: true }, violating the point's TS contract.\n// See: https://github.com/highcharts/highcharts/issues/23175.\nexport function isPointVisible(point: Highcharts.Point) {\n return point.visible && point.series && point.series.visible;\n}\n\nexport function getSeriesMarkerType(series?: Highcharts.Series): ChartSeriesMarkerType {\n if (!series) {\n return \"large-square\";\n }\n const seriesSymbol = \"symbol\" in series && typeof series.symbol === \"string\" ? series.symbol : \"circle\";\n // In Highcharts, dashStyle supports different types of dashes: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-dashstyle-all/\n // Return a dashed legend symbol for all of these dashes, excluding the default \"Solid\" option\n if (\"dashStyle\" in series.options && series.options.dashStyle && series.options.dashStyle !== \"Solid\") {\n return \"dashed\";\n }\n switch (series.type) {\n case \"area\":\n case \"areaspline\":\n return \"hollow-square\";\n case \"line\":\n case \"spline\":\n return \"line\";\n case \"scatter\":\n switch (seriesSymbol) {\n case \"square\":\n return \"square\";\n case \"diamond\":\n return \"diamond\";\n case \"triangle\":\n return \"triangle\";\n case \"triangle-down\":\n return \"triangle-down\";\n case \"circle\":\n default:\n return \"circle\";\n }\n case \"column\":\n case \"pie\":\n return \"large-square\";\n case \"errorbar\":\n default:\n return \"large-square\";\n }\n}\n\n// Highcharts supports color objects to represent gradients and more, but we only support string\n// colors in our markers. In case a non-string color is defined, we use black color as as fallback.\nexport function getSeriesColor(series?: Highcharts.Series): string {\n return typeof series?.color === \"string\" ? series.color : \"black\";\n}\nexport function getPointColor(point?: Highcharts.Point): string {\n return typeof point?.color === \"string\" ? point.color : \"black\";\n}\n\n// The custom legend implementation does not rely on the Highcharts legend. When Highcharts legend is disabled,\n// the chart object does not include information on legend items. Instead, we collect series and pie segments\n// using this custom function, respecting Highcharts' showInLegend flag (defined for series only).\n\n// There exists a Highcharts APIs to access legend items, but it is unfortunately not available, when\n// Highcharts legend is disabled. Instead, we use this custom method to collect legend items from the chart.\nexport function getChartLegendItems(chart: Highcharts.Chart): readonly LegendItemSpec[] {\n const legendItems: LegendItemSpec[] = [];\n const addSeriesItem = (series: Highcharts.Series) => {\n // The pie series is not shown in the legend. Instead, we show pie segments.\n if (series.type === \"pie\") {\n return;\n }\n // We only support errorbar series that are linked to other series. Those are not represented separately\n // in the legend, but can be controlled from the outside, using controllable items visibility API.\n if (series.type === \"errorbar\") {\n return;\n }\n // We respect Highcharts showInLegend option to allow hiding certain series from the legend.\n // The same is not supported for pie chart segments.\n if (series.options.showInLegend !== false) {\n legendItems.push({\n id: getSeriesId(series),\n name: series.name,\n markerType: getSeriesMarkerType(series),\n color: getSeriesColor(series),\n visible: series.visible,\n });\n }\n };\n const addPointItem = (point: Highcharts.Point) => {\n if (point.series.type === \"pie\") {\n legendItems.push({\n id: getPointId(point),\n name: point.name,\n markerType: getSeriesMarkerType(point.series),\n color: getPointColor(point),\n visible: point.visible,\n });\n }\n };\n for (const s of getChartSeries(chart.series)) {\n addSeriesItem(s);\n s.data.forEach(addPointItem);\n }\n return legendItems;\n}\n\nexport function hasVisibleLegendItems(options: Highcharts.Options) {\n return !!options.series?.some((series) => {\n // The pie series is not shown in the legend, but their segments are always shown.\n if (series.type === \"pie\") {\n return Array.isArray(series.data) && series.data.length > 0;\n }\n // We only support errorbar series that are linked to other series. Those are not represented separately\n // in the legend, but can be controlled from the outside, using controllable items visibility API.\n if (series.type === \"errorbar\") {\n return false;\n }\n return series.showInLegend !== false;\n });\n}\n\n// This function returns coordinates of a rectangle, including the target point.\n// There are differences in how the rectangle is computed, but in all cases it is supposed to\n// enclose the point's visual representation in the chart, with no extra offsets.\nexport function getPointRect(point: Highcharts.Point): Rect {\n switch (point.series.type) {\n case \"column\":\n return getColumnPointRect(point);\n case \"errorbar\":\n return getErrorBarPointRect(point);\n default:\n return getDefaultPointRect(point);\n }\n}\n\n// The group rect is only used for cartesian charts. It returns coordinates of a rectangle,\n// which includes all given points, but also stretched vertically or horizontally (in inverted charts)\n// to the entire chart's height or width.\nexport function getGroupRect(points: readonly Highcharts.Point[]): Rect {\n if (points.length === 0) {\n return { x: 0, y: 0, width: 0, height: 0 };\n }\n const chart = points[0].series.chart;\n const rects = points.map(getPointRect);\n const [first, ...rest] = rects;\n let minX = first.x,\n minY = first.y,\n maxX = first.x + first.width,\n maxY = first.y + first.height;\n for (const r of rest) {\n minX = Math.min(minX, r.x);\n minY = Math.min(minY, r.y);\n maxX = Math.max(maxX, r.x + r.width);\n maxY = Math.max(maxY, r.y + r.height);\n }\n return safeRect(\n chart.inverted\n ? { x: chart.plotLeft, y: minY, width: chart.plotWidth, height: maxY - minY }\n : { x: minX, y: chart.plotTop, width: maxX - minX, height: chart.plotHeight },\n );\n}\n\n// We ensure rect width and height are non-zero to ensure its position is calculated correctly in Firefox.\nexport function safeRect(rect: Rect): Rect {\n return { ...rect, width: Math.max(0.1, rect.width), height: Math.max(0.1, rect.height) };\n}\n\nexport function getChartAccessibleDescription(chart: Highcharts.Chart) {\n return chart.options.lang?.accessibility?.chartContainerLabel ?? \"\";\n}\n\nexport function getPointAccessibleDescription(point: Highcharts.Point, labels: ChartLabels) {\n if (point.series.xAxis && point.series.yAxis) {\n const formattedX = getFormatter(point.series.xAxis)(point.x);\n const formattedY = getFormatter(point.series.yAxis)(point.y);\n return `${formattedX} ${formattedY}, ${point.series.name}`;\n } else if (point.series.type === \"pie\") {\n const segmentLabel = labels.chartSegmentLabel ? `${labels.chartSegmentLabel} ` : \"\";\n return `${segmentLabel}${point.name}, ${point.y}. ${point.series.name}`;\n } else {\n return \"\";\n }\n}\n\nexport function getGroupAccessibleDescription(group: readonly Highcharts.Point[]) {\n const firstPoint = group[0];\n return getFormatter(firstPoint.series.xAxis)(firstPoint.x);\n}\n\n// The area-, line-, or scatter series markers are rendered as single graphic elements,\n// and we can use their respective b-boxes to compute rects.\nfunction getDefaultPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (point.graphic) {\n const box = point.graphic.getBBox();\n return getChartRect(box, chart, false);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The column series graphic elements are rectangles, and they are inverted if the chart is inverted,\n// so that rect's width becomes height and vice-versa.\nfunction getColumnPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (point.graphic) {\n return getChartRect(point.graphic.getBBox(), chart, true);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The errorbar series point rect cannot be computed from the respective graphic element (it gives wrong position).\n// Instead, we have to rely on the internal \"whiskers\" element b-box, which can be inverted, too.\nfunction getErrorBarPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (\"whiskers\" in point) {\n return getChartRect((point.whiskers as Highcharts.SVGElement).getBBox(), chart, true);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The point graphic is not present in large charts to optimize performance.\n// In that case we compute point rects from their coordinates. We also assume the point\n// size is small, and thereby give it 0 width and height, which is alright as there is a\n// small offset that we use for focus outline anyways.\n// See: https://www.highcharts.com/blog/news/175-highcharts-performance-boost/\nfunction getPointRectFromCoordinates(point: Highcharts.Point) {\n const chart = point.series.chart;\n const plotX = point.plotX ?? 0;\n const plotY = point.plotY ?? 0;\n return getChartRect({ x: plotX, y: plotY, width: 0, height: 0 }, chart, true);\n}\n\nfunction getChartRect(rect: Rect, chart: Highcharts.Chart, canBeInverted: boolean): Rect {\n return canBeInverted && chart.inverted\n ? {\n x: chart.plotWidth + chart.plotLeft - (rect.y + rect.height),\n y: chart.plotHeight + chart.plotTop - (rect.x + rect.width),\n width: rect.height,\n height: rect.width,\n }\n : {\n x: chart.plotLeft + rect.x,\n y: chart.plotTop + rect.y,\n width: rect.width,\n height: rect.height,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAa5C,yHAAyH;AACzH,6HAA6H;AAC7H,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,MAAyB;IACnD,OAAO,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AACD,MAAM,UAAU,UAAU,CAAC,KAAuB;IAChD,OAAO,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,OAAuC;;IAClE,OAAO,MAAA,MAAA,OAAO,CAAC,EAAE,mCAAI,OAAO,CAAC,IAAI,mCAAI,eAAe,EAAE,CAAC;AACzD,CAAC;AACD,SAAS,eAAe;IACtB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrE,OAAO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,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;YAC5D,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3D,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,KAAK;SACnB;QACH,CAAC,CAAC;YACE,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;YAC1B,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;AACR,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 { ChartSeriesMarkerType } from \"../internal/components/series-marker\";\nimport { getChartSeries } from \"../internal/utils/chart-series\";\nimport { castArray } from \"../internal/utils/utils\";\nimport { getFormatter } from \"./formatters\";\nimport { ChartLabels } from \"./i18n-utils\";\nimport { CoreChartProps, Rect } from \"./interfaces\";\n\nexport interface LegendItemSpec {\n id: string;\n name: string;\n markerType: ChartSeriesMarkerType;\n color: string;\n visible: boolean;\n isSecondary: boolean;\n}\n\n// The below functions extract unique identifier from series, point, or options. The identifier can be item's ID or name.\n// We expect that items requiring referencing (e.g. in order to control their visibility) have the unique identifier defined.\n// Otherwise, we return a randomized id that is to ensure no accidental matches.\nexport function getSeriesId(series: Highcharts.Series): string {\n return getOptionsId(series.options);\n}\nexport function getPointId(point: Highcharts.Point): string {\n return getOptionsId(point.options);\n}\nexport function getOptionsId(options: { id?: string; name?: string }): string {\n return options.id ?? options.name ?? noIdPlaceholder();\n}\nfunction noIdPlaceholder(): string {\n const rand = (Math.random() * 1_000_000).toFixed(0).padStart(6, \"0\");\n return \"awsui-no-id-placeholder-\" + rand;\n}\n\n// There are more possible values that series.stacking can take, but we only explicitly support \"normal\".\nexport function isSeriesStacked(series: Highcharts.Series) {\n return (series.options as any).stacking === \"normal\";\n}\n\n// The threshold series are custom series, implemented as a combination of line series, and plot lines.\n// As Highcharts does not support custom series declaration, we annotate threshold series by using the\n// series.custom property. This is then used in our utilities to recognize threshold series, and retrieve\n// the associated threshold value.\ninterface ThresholdOptions<T extends \"x-threshold\" | \"y-threshold\"> {\n custom: {\n awsui: {\n type: T;\n threshold: number;\n };\n };\n}\nexport function createThresholdMetadata<T extends \"x-threshold\" | \"y-threshold\">(\n type: T,\n value: number,\n): ThresholdOptions<T> {\n return { custom: { awsui: { type, threshold: value } } };\n}\nexport function isXThreshold(\n s: Highcharts.Series,\n): s is Highcharts.Series & { options: ThresholdOptions<\"x-threshold\"> } {\n return typeof s.options.custom === \"object\" && s.options.custom.awsui?.type === \"x-threshold\";\n}\nexport function isYThreshold(\n s: Highcharts.Series,\n): s is Highcharts.Series & { options: ThresholdOptions<\"y-threshold\"> } {\n return typeof s.options.custom === \"object\" && s.options.custom.awsui?.type === \"y-threshold\";\n}\n\n// We check point.series explicitly because Highcharts can destroy point objects, replacing the\n// contents with { destroyed: true }, violating the point's TS contract.\n// See: https://github.com/highcharts/highcharts/issues/23175.\nexport function isPointVisible(point: Highcharts.Point) {\n return point.visible && point.series && point.series.visible;\n}\n\nexport function getSeriesMarkerType(series?: Highcharts.Series): ChartSeriesMarkerType {\n if (!series) {\n return \"large-square\";\n }\n const seriesSymbol = \"symbol\" in series && typeof series.symbol === \"string\" ? series.symbol : \"circle\";\n // In Highcharts, dashStyle supports different types of dashes: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-dashstyle-all/\n // Return a dashed legend symbol for all of these dashes, excluding the default \"Solid\" option\n if (\"dashStyle\" in series.options && series.options.dashStyle && series.options.dashStyle !== \"Solid\") {\n return \"dashed\";\n }\n switch (series.type) {\n case \"area\":\n case \"areaspline\":\n return \"hollow-square\";\n case \"line\":\n case \"spline\":\n return \"line\";\n case \"scatter\":\n switch (seriesSymbol) {\n case \"square\":\n return \"square\";\n case \"diamond\":\n return \"diamond\";\n case \"triangle\":\n return \"triangle\";\n case \"triangle-down\":\n return \"triangle-down\";\n case \"circle\":\n default:\n return \"circle\";\n }\n case \"column\":\n case \"pie\":\n return \"large-square\";\n case \"errorbar\":\n default:\n return \"large-square\";\n }\n}\n\n// Highcharts supports color objects to represent gradients and more, but we only support string\n// colors in our markers. In case a non-string color is defined, we use black color as as fallback.\nexport function getSeriesColor(series?: Highcharts.Series): string {\n return typeof series?.color === \"string\" ? series.color : \"black\";\n}\nexport function getPointColor(point?: Highcharts.Point): string {\n return typeof point?.color === \"string\" ? point.color : \"black\";\n}\n\n// The custom legend implementation does not rely on the Highcharts legend. When Highcharts legend is disabled,\n// the chart object does not include information on legend items. Instead, we collect series and pie segments\n// using this custom function, respecting Highcharts' showInLegend flag (defined for series only).\n\n// There exists a Highcharts APIs to access legend items, but it is unfortunately not available, when\n// Highcharts legend is disabled. Instead, we use this custom method to collect legend items from the chart.\nexport function getChartLegendItems(chart: Highcharts.Chart): readonly LegendItemSpec[] {\n const legendItems: LegendItemSpec[] = [];\n const isInverted = chart.inverted ?? false;\n const addSeriesItem = (series: Highcharts.Series, isSecondary: boolean) => {\n // The pie series is not shown in the legend. Instead, we show pie segments.\n if (series.type === \"pie\") {\n return;\n }\n // We only support errorbar series that are linked to other series. Those are not represented separately\n // in the legend, but can be controlled from the outside, using controllable items visibility API.\n if (series.type === \"errorbar\") {\n return;\n }\n // We respect Highcharts showInLegend option to allow hiding certain series from the legend.\n // The same is not supported for pie chart segments.\n if (series.options.showInLegend !== false) {\n legendItems.push({\n id: getSeriesId(series),\n name: series.name,\n markerType: getSeriesMarkerType(series),\n color: getSeriesColor(series),\n visible: series.visible,\n isSecondary,\n });\n }\n };\n const addPointItem = (point: Highcharts.Point, isSecondary: boolean) => {\n if (point.series.type === \"pie\") {\n legendItems.push({\n id: getPointId(point),\n name: point.name,\n markerType: getSeriesMarkerType(point.series),\n color: getPointColor(point),\n visible: point.visible,\n isSecondary,\n });\n }\n };\n for (const s of getChartSeries(chart.series)) {\n const valueAxis = isInverted ? s.xAxis : s.yAxis;\n const isSecondary = valueAxis?.options?.opposite ?? false;\n addSeriesItem(s, isSecondary);\n s.data.forEach((p) => addPointItem(p, isSecondary));\n }\n return legendItems;\n}\n\nexport type LegendItemOptions = Highcharts.SeriesOptionsType | Highcharts.PointOptionsType;\n\nexport function getVisibleLegendItems(options: Highcharts.Options) {\n const isInverted = options.chart?.inverted ?? false;\n const valueAxes = (isInverted ? castArray(options.xAxis) : castArray(options.yAxis)) ?? [];\n const defaultOpposite = valueAxes.length > 0 ? (valueAxes[0].opposite ?? false) : false;\n\n const primaryItems: LegendItemOptions[] = [];\n const secondaryItems: LegendItemOptions[] = [];\n const addLegendItem = (item: LegendItemOptions) => {\n if (isSecondaryLegendItem(item, isInverted, defaultOpposite, valueAxes)) {\n secondaryItems.push(item);\n } else {\n primaryItems.push(item);\n }\n };\n\n options.series?.forEach((series) => {\n // The pie series is not shown in the legend. Instead, we show pie segments (points).\n if (series.type === \"pie\") {\n if (Array.isArray(series.data)) {\n series.data.forEach((point) => addLegendItem(point));\n }\n return;\n }\n // We only support errorbar series that are linked to other series. Those are not represented separately\n // in the legend, but can be controlled from the outside, using controllable items visibility API.\n if (series.type === \"errorbar\") {\n return;\n }\n if (series.showInLegend !== false) {\n addLegendItem(series);\n }\n });\n\n return { primaryItems, secondaryItems };\n}\n\nfunction isSecondaryLegendItem(\n item: LegendItemOptions,\n isInverted: boolean,\n defaultOpposite: boolean,\n valueAxes: Array<{ id?: string; opposite?: boolean }>,\n): boolean {\n // Only items that have an associated axis can be considered secondary\n if (item && typeof item === \"object\" && (\"xAxis\" in item || \"yAxis\" in item)) {\n const axisRef = isInverted ? (item.xAxis ?? 0) : (item.yAxis ?? 0);\n // An axis reference can be an index into the axes array or an explicitly passed id\n const valueAxis = typeof axisRef === \"number\" ? valueAxes[axisRef] : valueAxes.find((a) => a.id === axisRef);\n return valueAxis?.opposite ?? false;\n }\n return defaultOpposite;\n}\n\nexport function getLegendsProps(\n options: CoreChartProps.ChartOptions,\n legendOptions: CoreChartProps.LegendOptions | undefined,\n) {\n // While Highcharts supports more than two axes, this\n // implementation supports at most two, in which case one\n // of them must be set as opposite (secondary).\n const { primaryItems, secondaryItems } = getVisibleLegendItems(options);\n return {\n primary:\n primaryItems.length === 0\n ? undefined\n : ({\n isSecondary: false,\n title: legendOptions?.title,\n actions: legendOptions?.actions,\n alignment: legendOptions?.position === \"side\" ? \"vertical\" : \"horizontal\",\n horizontalAlignment: secondaryItems.length === 0 ? legendOptions?.horizontalAlignment : \"start\",\n } as const),\n secondary:\n secondaryItems.length === 0\n ? undefined\n : ({\n isSecondary: true,\n title: legendOptions?.secondaryLegendTitle,\n actions: legendOptions?.secondaryLegendActions,\n alignment: legendOptions?.position === \"side\" ? \"vertical\" : \"horizontal\",\n horizontalAlignment: \"end\",\n } as const),\n };\n}\n\n// This function returns coordinates of a rectangle, including the target point.\n// There are differences in how the rectangle is computed, but in all cases it is supposed to\n// enclose the point's visual representation in the chart, with no extra offsets.\nexport function getPointRect(point: Highcharts.Point): Rect {\n switch (point.series.type) {\n case \"column\":\n return getColumnPointRect(point);\n case \"errorbar\":\n return getErrorBarPointRect(point);\n default:\n return getDefaultPointRect(point);\n }\n}\n\n// The group rect is only used for cartesian charts. It returns coordinates of a rectangle,\n// which includes all given points, but also stretched vertically or horizontally (in inverted charts)\n// to the entire chart's height or width.\nexport function getGroupRect(points: readonly Highcharts.Point[]): Rect {\n if (points.length === 0) {\n return { x: 0, y: 0, width: 0, height: 0 };\n }\n const chart = points[0].series.chart;\n const rects = points.map(getPointRect);\n const [first, ...rest] = rects;\n let minX = first.x,\n minY = first.y,\n maxX = first.x + first.width,\n maxY = first.y + first.height;\n for (const r of rest) {\n minX = Math.min(minX, r.x);\n minY = Math.min(minY, r.y);\n maxX = Math.max(maxX, r.x + r.width);\n maxY = Math.max(maxY, r.y + r.height);\n }\n return safeRect(\n chart.inverted\n ? { x: chart.plotLeft, y: minY, width: chart.plotWidth, height: maxY - minY }\n : { x: minX, y: chart.plotTop, width: maxX - minX, height: chart.plotHeight },\n );\n}\n\n// We ensure rect width and height are non-zero to ensure its position is calculated correctly in Firefox.\nexport function safeRect(rect: Rect): Rect {\n return { ...rect, width: Math.max(0.1, rect.width), height: Math.max(0.1, rect.height) };\n}\n\nexport function getChartAccessibleDescription(chart: Highcharts.Chart) {\n return chart.options.lang?.accessibility?.chartContainerLabel ?? \"\";\n}\n\nexport function getPointAccessibleDescription(point: Highcharts.Point, labels: ChartLabels) {\n if (point.series.xAxis && point.series.yAxis) {\n const formattedX = getFormatter(point.series.xAxis)(point.x);\n const formattedY = getFormatter(point.series.yAxis)(point.y);\n return `${formattedX} ${formattedY}, ${point.series.name}`;\n } else if (point.series.type === \"pie\") {\n const segmentLabel = labels.chartSegmentLabel ? `${labels.chartSegmentLabel} ` : \"\";\n return `${segmentLabel}${point.name}, ${point.y}. ${point.series.name}`;\n } else {\n return \"\";\n }\n}\n\nexport function getGroupAccessibleDescription(group: readonly Highcharts.Point[]) {\n const firstPoint = group[0];\n return getFormatter(firstPoint.series.xAxis)(firstPoint.x);\n}\n\n// The area-, line-, or scatter series markers are rendered as single graphic elements,\n// and we can use their respective b-boxes to compute rects.\nfunction getDefaultPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (point.graphic) {\n const box = point.graphic.getBBox();\n return getChartRect(box, chart, false);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The column series graphic elements are rectangles, and they are inverted if the chart is inverted,\n// so that rect's width becomes height and vice-versa.\nfunction getColumnPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (point.graphic) {\n return getChartRect(point.graphic.getBBox(), chart, true);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The errorbar series point rect cannot be computed from the respective graphic element (it gives wrong position).\n// Instead, we have to rely on the internal \"whiskers\" element b-box, which can be inverted, too.\nfunction getErrorBarPointRect(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n if (\"whiskers\" in point) {\n return getChartRect((point.whiskers as Highcharts.SVGElement).getBBox(), chart, true);\n }\n return getPointRectFromCoordinates(point);\n}\n\n// The point graphic is not present in large charts to optimize performance.\n// In that case we compute point rects from their coordinates. We also assume the point\n// size is small, and thereby give it 0 width and height, which is alright as there is a\n// small offset that we use for focus outline anyways.\n// See: https://www.highcharts.com/blog/news/175-highcharts-performance-boost/\nfunction getPointRectFromCoordinates(point: Highcharts.Point) {\n const chart = point.series.chart;\n const plotX = point.plotX ?? 0;\n const plotY = point.plotY ?? 0;\n return getChartRect({ x: plotX, y: plotY, width: 0, height: 0 }, chart, true);\n}\n\nfunction getChartRect(rect: Rect, chart: Highcharts.Chart, canBeInverted: boolean): Rect {\n return canBeInverted && chart.inverted\n ? {\n x: chart.plotWidth + chart.plotLeft - (rect.y + rect.height),\n y: chart.plotHeight + chart.plotTop - (rect.x + rect.width),\n width: rect.height,\n height: rect.width,\n }\n : {\n x: chart.plotLeft + rect.x,\n y: chart.plotTop + rect.y,\n width: rect.width,\n height: rect.height,\n };\n}\n"]}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CoreChartProps } from "../../../core/interfaces";
|
|
3
2
|
import { GetLegendTooltipContentProps, LegendItem, LegendTooltipContent } from "../interfaces";
|
|
3
|
+
export type LegendAlignment = "horizontal" | "vertical";
|
|
4
|
+
export type LegendHorizontalAlignment = "start" | "center" | "end";
|
|
4
5
|
export interface ChartLegendProps {
|
|
5
6
|
items: readonly LegendItem[];
|
|
6
7
|
legendTitle?: string;
|
|
7
8
|
ariaLabel?: string;
|
|
9
|
+
className?: string;
|
|
8
10
|
actions?: React.ReactNode;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
someHighlighted: boolean;
|
|
12
|
+
alignment: LegendAlignment;
|
|
13
|
+
horizontalAlignment: LegendHorizontalAlignment;
|
|
14
|
+
onToggleItem: (itemId: string) => void;
|
|
15
|
+
onSelectItem: (itemId: string) => void;
|
|
11
16
|
onItemHighlightEnter: (item: LegendItem) => void;
|
|
12
17
|
onItemHighlightExit: () => void;
|
|
13
|
-
onItemVisibilityChange: (hiddenItems: string[]) => void;
|
|
14
18
|
getTooltipContent: (props: GetLegendTooltipContentProps) => null | LegendTooltipContent;
|
|
15
19
|
}
|
|
16
|
-
export declare const ChartLegend: ({ items, legendTitle, ariaLabel, actions,
|
|
20
|
+
export declare const ChartLegend: ({ items, legendTitle, ariaLabel, actions, alignment, className, someHighlighted, onToggleItem, onSelectItem, onItemHighlightEnter, onItemHighlightExit, getTooltipContent, horizontalAlignment, }: ChartLegendProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,7 +12,7 @@ import testClasses from "./test-classes/styles.css.js";
|
|
|
12
12
|
const TOOLTIP_BLUR_DELAY = 50;
|
|
13
13
|
const HIGHLIGHT_LOST_DELAY = 50;
|
|
14
14
|
const SCROLL_DELAY = 100;
|
|
15
|
-
export const ChartLegend = ({ items, legendTitle, ariaLabel, actions,
|
|
15
|
+
export const ChartLegend = ({ items, legendTitle, ariaLabel, actions, alignment, className, someHighlighted, onToggleItem, onSelectItem, onItemHighlightEnter, onItemHighlightExit, getTooltipContent, horizontalAlignment, }) => {
|
|
16
16
|
var _a;
|
|
17
17
|
const containerRef = useRef(null);
|
|
18
18
|
const elementsByIndexRef = useRef([]);
|
|
@@ -149,92 +149,67 @@ export const ChartLegend = ({ items, legendTitle, ariaLabel, actions, position,
|
|
|
149
149
|
useEffect(() => {
|
|
150
150
|
navigationAPI.current.updateFocusTarget();
|
|
151
151
|
});
|
|
152
|
-
const
|
|
153
|
-
const visibleItems = items.filter((i) => i.visible).map((i) => i.id);
|
|
154
|
-
if (visibleItems.includes(itemId)) {
|
|
155
|
-
onItemVisibilityChange(visibleItems.filter((visibleItemId) => visibleItemId !== itemId));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
onItemVisibilityChange([...visibleItems, itemId]);
|
|
159
|
-
}
|
|
160
|
-
// Needed for touch devices.
|
|
161
|
-
onItemHighlightExit();
|
|
162
|
-
};
|
|
163
|
-
const selectItem = (itemId) => {
|
|
164
|
-
const visibleItems = items.filter((i) => i.visible).map((i) => i.id);
|
|
165
|
-
if (visibleItems.length === 1 && visibleItems[0] === itemId) {
|
|
166
|
-
onItemVisibilityChange(items.map((i) => i.id));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
onItemVisibilityChange([itemId]);
|
|
170
|
-
}
|
|
171
|
-
// Needed for touch devices.
|
|
172
|
-
onItemHighlightExit();
|
|
173
|
-
};
|
|
152
|
+
const isVertical = alignment === "vertical";
|
|
174
153
|
const tooltipTrack = useRef(null);
|
|
175
154
|
const tooltipTarget = (_a = items.find((item) => item.id === tooltipItemId)) !== null && _a !== void 0 ? _a : null;
|
|
176
155
|
tooltipTrack.current = tooltipItemId ? elementsByIdRef.current[tooltipItemId] : null;
|
|
177
156
|
const tooltipContent = tooltipTarget && getTooltipContent({ legendItem: tooltipTarget });
|
|
178
|
-
const tooltipPosition =
|
|
179
|
-
return (_jsx(SingleTabStopNavigationProvider, { ref: navigationAPI, navigationActive: true, getNextFocusTarget: () => getNextFocusTarget(), onUnregisterActive: (element) => onUnregisterActive(element, navigationAPI), children: _jsxs("div", {
|
|
180
|
-
[styles["root-side"]]: position === "side",
|
|
181
|
-
}), onMouseEnter: () => (isMouseInContainer.current = true), onMouseLeave: () => (isMouseInContainer.current = false), children: [legendTitle && (_jsx(Box, { fontWeight: "bold", className: clsx(testClasses.title, {
|
|
182
|
-
[styles[`legend-title-${horizontalAlignment}`]]: position === "bottom",
|
|
183
|
-
}), children: legendTitle })), _jsxs("div", {
|
|
157
|
+
const tooltipPosition = isVertical ? "left" : "bottom";
|
|
158
|
+
return (_jsx(SingleTabStopNavigationProvider, { ref: navigationAPI, navigationActive: true, getNextFocusTarget: () => getNextFocusTarget(), onUnregisterActive: (element) => onUnregisterActive(element, navigationAPI), children: _jsxs("div", { role: "toolbar", "aria-label": legendTitle || ariaLabel, className: clsx(testClasses.root, styles.root, className), onMouseEnter: () => (isMouseInContainer.current = true), onMouseLeave: () => (isMouseInContainer.current = false), children: [legendTitle && (_jsx(Box, { fontWeight: "bold", className: testClasses.title, textAlign: getBoxTextAlignment(horizontalAlignment), children: legendTitle })), _jsxs("div", {
|
|
184
159
|
// The list element is not focusable. However, the focus lands on it regardless, when testing in Firefox.
|
|
185
160
|
// Setting the tab index to -1 does fix the problem.
|
|
186
|
-
tabIndex: -1, className: clsx(styles.list, {
|
|
187
|
-
[styles[`list-bottom-${horizontalAlignment}`]]:
|
|
188
|
-
[styles["list-bottom"]]:
|
|
189
|
-
[styles["list-side"]]:
|
|
190
|
-
}), children: [actions && (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
elementsByIdRef.current[item.id] = elem;
|
|
161
|
+
tabIndex: -1, ref: containerRef, className: clsx(styles.list, {
|
|
162
|
+
[styles[`list-bottom-${horizontalAlignment}`]]: !isVertical,
|
|
163
|
+
[styles["list-bottom"]]: !isVertical,
|
|
164
|
+
[styles["list-side"]]: isVertical,
|
|
165
|
+
}), children: [actions && (_jsxs(_Fragment, { children: [_jsxs("div", { className: clsx(testClasses.actions, styles.actions, styles["actions-bottom"]), children: [actions, !isVertical && _jsx("div", { className: styles["actions-divider-bottom"] })] }), isVertical && _jsx("div", { className: styles["actions-divider-side"] })] })), items.map((item, index) => {
|
|
166
|
+
const handlers = {
|
|
167
|
+
onMouseEnter: () => {
|
|
168
|
+
showHighlight(item.id);
|
|
169
|
+
showTooltip(item.id);
|
|
170
|
+
},
|
|
171
|
+
onMouseLeave: () => {
|
|
172
|
+
clearHighlight();
|
|
173
|
+
hideTooltip();
|
|
174
|
+
},
|
|
175
|
+
onFocus: () => {
|
|
176
|
+
onFocus(index, item.id);
|
|
177
|
+
},
|
|
178
|
+
onBlur: (event) => {
|
|
179
|
+
onBlur(event);
|
|
180
|
+
},
|
|
181
|
+
onKeyDown,
|
|
182
|
+
};
|
|
183
|
+
const thisTriggerRef = (elem) => {
|
|
184
|
+
if (elem) {
|
|
185
|
+
elementsByIndexRef.current[index] = elem;
|
|
186
|
+
elementsByIdRef.current[item.id] = elem;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
delete elementsByIndexRef.current[index];
|
|
190
|
+
delete elementsByIdRef.current[item.id];
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
return (_jsx(LegendItemTrigger, { ...handlers, ref: thisTriggerRef, onClick: (event) => {
|
|
194
|
+
if (event.metaKey || event.ctrlKey) {
|
|
195
|
+
onToggleItem(item.id);
|
|
222
196
|
}
|
|
223
197
|
else {
|
|
224
|
-
|
|
225
|
-
delete elementsByIdRef.current[index];
|
|
198
|
+
onSelectItem(item.id);
|
|
226
199
|
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
if (event.metaKey || event.ctrlKey) {
|
|
230
|
-
toggleItem(item.id);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
selectItem(item.id);
|
|
234
|
-
}
|
|
235
|
-
}, isHighlighted: item.highlighted, someHighlighted: items.some((item) => item.highlighted), itemId: item.id, label: item.name, visible: item.visible, marker: item.marker }, index));
|
|
236
|
-
}) })] }), tooltipContent && (_jsx(InternalChartTooltip, { trackRef: tooltipTrack, trackKey: tooltipTarget.id, container: null, dismissButton: false, onDismiss: () => { }, position: tooltipPosition, title: tooltipContent.header, onMouseEnter: () => showTooltip(tooltipTarget.id), onMouseLeave: () => hideTooltip(), onBlur: () => hideTooltip(), footer: tooltipContent.footer && (_jsxs(_Fragment, { children: [_jsx("hr", { "aria-hidden": true }), tooltipContent.footer] })), children: tooltipContent.body }))] }) }));
|
|
200
|
+
}, isHighlighted: item.highlighted, someHighlighted: someHighlighted, itemId: item.id, label: item.name, visible: item.visible, marker: item.marker }, index));
|
|
201
|
+
})] }), tooltipContent && (_jsx(InternalChartTooltip, { trackRef: tooltipTrack, trackKey: tooltipTarget.id, container: null, dismissButton: false, onDismiss: () => { }, position: tooltipPosition, title: tooltipContent.header, onMouseEnter: () => showTooltip(tooltipTarget.id), onMouseLeave: () => hideTooltip(), onBlur: () => hideTooltip(), footer: tooltipContent.footer && (_jsxs(_Fragment, { children: [_jsx("hr", { "aria-hidden": true }), tooltipContent.footer] })), children: tooltipContent.body }))] }) }));
|
|
237
202
|
};
|
|
203
|
+
function getBoxTextAlignment(horizontalAlignment) {
|
|
204
|
+
switch (horizontalAlignment) {
|
|
205
|
+
case "start":
|
|
206
|
+
return "left";
|
|
207
|
+
case "center":
|
|
208
|
+
return "center";
|
|
209
|
+
case "end":
|
|
210
|
+
return "right";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
238
213
|
const LegendItemTrigger = forwardRef(({ isHighlighted, someHighlighted, itemId, label, marker, visible, onClick, triggerRef, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, }, ref) => {
|
|
239
214
|
const refObject = useRef(null);
|
|
240
215
|
const mergedRef = useMergeRefs(ref, triggerRef, refObject);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/chart-legend/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AAC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AO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,aAEnB,MAAM,EACP,eAAM,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC,YAAG,KAAK,GAAQ,IAC9C,CACV,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { forwardRef, Ref, useEffect, useMemo, useRef, useState } from \"react\";\nimport clsx from \"clsx\";\n\nimport {\n circleIndex,\n handleKey,\n KeyCode,\n SingleTabStopNavigationAPI,\n SingleTabStopNavigationProvider,\n useMergeRefs,\n useSingleTabStopNavigation,\n} from \"@cloudscape-design/component-toolkit/internal\";\nimport Box from \"@cloudscape-design/components/box\";\nimport { InternalChartTooltip } from \"@cloudscape-design/components/internal/do-not-use/chart-tooltip\";\n\nimport { CoreChartProps } from \"../../../core/interfaces\";\nimport { DebouncedCall } from \"../../utils/utils\";\nimport { GetLegendTooltipContentProps, LegendItem, LegendTooltipContent } from \"../interfaces\";\n\nimport styles from \"./styles.css.js\";\nimport testClasses from \"./test-classes/styles.css.js\";\n\nconst TOOLTIP_BLUR_DELAY = 50;\nconst HIGHLIGHT_LOST_DELAY = 50;\nconst SCROLL_DELAY = 100;\n\nexport interface ChartLegendProps {\n items: readonly LegendItem[];\n legendTitle?: string;\n ariaLabel?: string;\n actions?: React.ReactNode;\n position: \"bottom\" | \"side\";\n horizontalAlignment: CoreChartProps.LegendOptionsHorizontalAlignment;\n onItemHighlightEnter: (item: LegendItem) => void;\n onItemHighlightExit: () => void;\n onItemVisibilityChange: (hiddenItems: string[]) => void;\n getTooltipContent: (props: GetLegendTooltipContentProps) => null | LegendTooltipContent;\n}\n\nexport const ChartLegend = ({\n items,\n legendTitle,\n ariaLabel,\n actions,\n position,\n onItemVisibilityChange,\n onItemHighlightEnter,\n onItemHighlightExit,\n getTooltipContent,\n horizontalAlignment,\n}: ChartLegendProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const elementsByIndexRef = useRef<Record<number, HTMLElement>>([]);\n const elementsByIdRef = useRef<Record<string, HTMLElement>>({});\n const tooltipRef = useRef<HTMLElement>(null);\n const highlightControl = useMemo(() => new DebouncedCall(), []);\n const scrollIntoViewControl = useMemo(() => new DebouncedCall(), []);\n const [selectedIndex, setSelectedIndex] = useState<number>(0);\n const [tooltipItemId, setTooltipItemId] = useState<string | null>(null);\n const { showTooltip, hideTooltip } = useMemo(() => {\n const control = new DebouncedCall();\n return {\n showTooltip(itemId: string) {\n control.call(() => setTooltipItemId(itemId));\n },\n hideTooltip(lock = false) {\n control.call(() => setTooltipItemId(null), TOOLTIP_BLUR_DELAY);\n if (lock) {\n control.lock(TOOLTIP_BLUR_DELAY);\n }\n },\n };\n }, []);\n\n useEffect(() => {\n if (!tooltipItemId) {\n return;\n }\n const onDocumentKeyDown = (event: KeyboardEvent) => {\n if (event.keyCode === KeyCode.escape) {\n hideTooltip(true);\n elementsByIdRef.current[tooltipItemId]?.focus();\n }\n };\n document.addEventListener(\"keydown\", onDocumentKeyDown, true);\n return () => {\n document.removeEventListener(\"keydown\", onDocumentKeyDown, true);\n };\n }, [items, tooltipItemId, hideTooltip]);\n const isMouseInContainer = useRef<boolean>(false);\n\n // Scrolling to the highlighted legend item.\n useEffect(() => {\n const highlightedIndex = items.findIndex((item) => item.highlighted);\n if (highlightedIndex === -1) {\n return;\n }\n scrollIntoViewControl.call(() => {\n if (isMouseInContainer.current) {\n return;\n }\n const container = containerRef.current;\n const element = elementsByIndexRef.current?.[highlightedIndex];\n if (!container || !element) {\n return;\n }\n const elementRect = element.getBoundingClientRect();\n const containerRect = container.getBoundingClientRect();\n const isVisible = elementRect.top >= containerRect.top && elementRect.bottom <= containerRect.bottom;\n if (!isVisible) {\n const elementCenter = elementRect.top + elementRect.height / 2;\n const containerCenter = containerRect.top + containerRect.height / 2;\n const top = container.scrollTop + (elementCenter - containerCenter);\n container.scrollTo({ top, behavior: \"smooth\" });\n }\n }, SCROLL_DELAY);\n }, [items, scrollIntoViewControl]);\n\n const showHighlight = (itemId: string) => {\n const item = items.find((item) => item.id === itemId);\n if (item?.visible) {\n highlightControl.cancelPrevious();\n onItemHighlightEnter(item);\n }\n };\n const clearHighlight = () => {\n highlightControl.call(onItemHighlightExit, HIGHLIGHT_LOST_DELAY);\n };\n\n const navigationAPI = useRef<SingleTabStopNavigationAPI>(null);\n\n function onFocus(index: number, itemId: string) {\n setSelectedIndex(index);\n navigationAPI.current!.updateFocusTarget();\n showHighlight(itemId);\n showTooltip(itemId);\n }\n\n function onBlur(event: React.FocusEvent) {\n navigationAPI.current!.updateFocusTarget();\n\n // Hide tooltip and clear highlight unless focus moves inside tooltip;\n if (tooltipRef.current && event.relatedTarget && !tooltipRef.current.contains(event.relatedTarget)) {\n clearHighlight();\n hideTooltip();\n }\n }\n\n function focusElement(index: number) {\n elementsByIndexRef.current[index]?.focus();\n }\n\n function onKeyDown(event: React.KeyboardEvent<HTMLElement>) {\n if (\n event.keyCode === KeyCode.right ||\n event.keyCode === KeyCode.left ||\n event.keyCode === KeyCode.up ||\n event.keyCode === KeyCode.down ||\n event.keyCode === KeyCode.home ||\n event.keyCode === KeyCode.end ||\n event.keyCode === KeyCode.escape\n ) {\n // Preventing default fixes an issue in Safari+VO when VO additionally interprets arrow keys as its commands.\n event.preventDefault();\n\n const range = [0, items.length - 1] as [number, number];\n\n handleKey(event, {\n onInlineStart: () => focusElement(circleIndex(selectedIndex - 1, range)),\n onInlineEnd: () => focusElement(circleIndex(selectedIndex + 1, range)),\n onBlockStart: () => focusElement(circleIndex(selectedIndex - 1, range)),\n onBlockEnd: () => focusElement(circleIndex(selectedIndex + 1, range)),\n onHome: () => focusElement(0),\n onEnd: () => focusElement(items.length - 1),\n onEscape: () => onItemHighlightExit(),\n });\n }\n }\n\n function getNextFocusTarget(): null | HTMLElement {\n if (containerRef.current) {\n const buttons: HTMLButtonElement[] = Array.from(containerRef.current.querySelectorAll(`.${styles.item}`));\n return buttons[selectedIndex] ?? null;\n }\n return null;\n }\n\n function onUnregisterActive(\n focusableElement: HTMLElement,\n navigationAPI: React.RefObject<{ getFocusTarget: () => HTMLElement | null }>,\n ) {\n const target = navigationAPI.current?.getFocusTarget();\n\n if (target && target.dataset.itemid !== focusableElement.dataset.itemid) {\n target.focus();\n }\n }\n\n useEffect(() => {\n navigationAPI.current!.updateFocusTarget();\n });\n\n const toggleItem = (itemId: string) => {\n const visibleItems = items.filter((i) => i.visible).map((i) => i.id);\n if (visibleItems.includes(itemId)) {\n onItemVisibilityChange(visibleItems.filter((visibleItemId) => visibleItemId !== itemId));\n } else {\n onItemVisibilityChange([...visibleItems, itemId]);\n }\n // Needed for touch devices.\n onItemHighlightExit();\n };\n\n const selectItem = (itemId: string) => {\n const visibleItems = items.filter((i) => i.visible).map((i) => i.id);\n if (visibleItems.length === 1 && visibleItems[0] === itemId) {\n onItemVisibilityChange(items.map((i) => i.id));\n } else {\n onItemVisibilityChange([itemId]);\n }\n // Needed for touch devices.\n onItemHighlightExit();\n };\n\n const tooltipTrack = useRef<null | HTMLElement>(null);\n const tooltipTarget = items.find((item) => item.id === tooltipItemId) ?? null;\n tooltipTrack.current = tooltipItemId ? elementsByIdRef.current[tooltipItemId] : null;\n const tooltipContent = tooltipTarget && getTooltipContent({ legendItem: tooltipTarget });\n const tooltipPosition = position === \"bottom\" ? \"bottom\" : \"left\";\n\n return (\n <SingleTabStopNavigationProvider\n ref={navigationAPI}\n navigationActive={true}\n getNextFocusTarget={() => getNextFocusTarget()}\n onUnregisterActive={(element: HTMLElement) => onUnregisterActive(element, navigationAPI)}\n >\n <div\n ref={containerRef}\n role=\"toolbar\"\n aria-label={legendTitle || ariaLabel}\n className={clsx(testClasses.root, styles.root, {\n [styles[\"root-side\"]]: position === \"side\",\n })}\n onMouseEnter={() => (isMouseInContainer.current = true)}\n onMouseLeave={() => (isMouseInContainer.current = false)}\n >\n {legendTitle && (\n <Box\n fontWeight=\"bold\"\n className={clsx(testClasses.title, {\n [styles[`legend-title-${horizontalAlignment}`]]: position === \"bottom\",\n })}\n >\n {legendTitle}\n </Box>\n )}\n\n <div\n // The list element is not focusable. However, the focus lands on it regardless, when testing in Firefox.\n // Setting the tab index to -1 does fix the problem.\n tabIndex={-1}\n className={clsx(styles.list, {\n [styles[`list-bottom-${horizontalAlignment}`]]: position === \"bottom\",\n [styles[\"list-bottom\"]]: position === \"bottom\",\n [styles[\"list-side\"]]: position === \"side\",\n })}\n >\n {actions && (\n <>\n <div\n className={clsx(testClasses.actions, styles.actions, {\n [styles[\"actions-bottom\"]]: position === \"bottom\",\n [styles[\"actions-side\"]]: position === \"side\",\n })}\n >\n {actions}\n <div\n className={clsx(styles[\"actions-divider\"], {\n [styles[\"actions-divider-bottom\"]]: position === \"bottom\",\n [styles[\"actions-divider-side\"]]: position === \"side\",\n })}\n />\n </div>\n </>\n )}\n <div\n className={clsx({\n [styles[`legend-bottom-${horizontalAlignment}`]]: position === \"bottom\",\n [styles[\"legend-bottom\"]]: position === \"bottom\",\n [styles[\"legend-side\"]]: position === \"side\",\n })}\n >\n {items.map((item, index) => {\n const handlers = {\n onMouseEnter: () => {\n showHighlight(item.id);\n showTooltip(item.id);\n },\n onMouseLeave: () => {\n clearHighlight();\n hideTooltip();\n },\n onFocus: () => {\n onFocus(index, item.id);\n },\n onBlur: (event: React.FocusEvent) => {\n onBlur(event);\n },\n onKeyDown,\n };\n const thisTriggerRef = (elem: null | HTMLElement) => {\n if (elem) {\n elementsByIndexRef.current[index] = elem;\n elementsByIdRef.current[item.id] = elem;\n } else {\n delete elementsByIndexRef.current[index];\n delete elementsByIdRef.current[index];\n }\n };\n return (\n <LegendItemTrigger\n key={index}\n {...handlers}\n ref={thisTriggerRef}\n onClick={(event) => {\n if (event.metaKey || event.ctrlKey) {\n toggleItem(item.id);\n } else {\n selectItem(item.id);\n }\n }}\n isHighlighted={item.highlighted}\n someHighlighted={items.some((item) => item.highlighted)}\n itemId={item.id}\n label={item.name}\n visible={item.visible}\n marker={item.marker}\n />\n );\n })}\n </div>\n </div>\n {tooltipContent && (\n <InternalChartTooltip\n trackRef={tooltipTrack}\n trackKey={tooltipTarget.id}\n container={null}\n dismissButton={false}\n onDismiss={() => {}}\n position={tooltipPosition}\n title={tooltipContent.header}\n onMouseEnter={() => showTooltip(tooltipTarget.id)}\n onMouseLeave={() => hideTooltip()}\n onBlur={() => hideTooltip()}\n footer={\n tooltipContent.footer && (\n <>\n <hr aria-hidden={true} />\n {tooltipContent.footer}\n </>\n )\n }\n >\n {tooltipContent.body}\n </InternalChartTooltip>\n )}\n </div>\n </SingleTabStopNavigationProvider>\n );\n};\n\nconst LegendItemTrigger = forwardRef(\n (\n {\n isHighlighted,\n someHighlighted,\n itemId,\n label,\n marker,\n visible,\n onClick,\n triggerRef,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n onKeyDown,\n }: {\n isHighlighted?: boolean;\n someHighlighted?: boolean;\n itemId: string;\n label: string;\n marker?: React.ReactNode;\n visible: boolean;\n onClick: (event: React.MouseEvent) => void;\n onMarkerClick?: () => void;\n triggerRef?: Ref<HTMLElement>;\n onMouseEnter?: () => void;\n onMouseLeave?: () => void;\n onFocus?: () => void;\n onBlur?: (event: React.FocusEvent) => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;\n },\n ref: Ref<HTMLButtonElement>,\n ) => {\n const refObject = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs(ref, triggerRef, refObject);\n const { tabIndex } = useSingleTabStopNavigation(refObject);\n return (\n <button\n data-itemid={itemId}\n aria-pressed={visible}\n aria-current={isHighlighted}\n className={clsx(testClasses.item, styles.item, {\n [styles[\"item--inactive\"]]: !visible,\n [testClasses[\"hidden-item\"]]: !visible,\n [styles[\"item--dimmed\"]]: someHighlighted && !isHighlighted,\n [testClasses[\"dimmed-item\"]]: someHighlighted && !isHighlighted,\n })}\n ref={mergedRef}\n tabIndex={tabIndex}\n onClick={onClick}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n >\n {marker}\n <span className={styles[\"item-label\"]}>{label}</span>\n </button>\n );\n },\n);\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/chart-legend/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAO,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9E,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EACL,WAAW,EACX,SAAS,EACT,OAAO,EAEP,+BAA+B,EAC/B,YAAY,EACZ,0BAA0B,GAC3B,MAAM,+CAA+C,CAAC;AACvD,OAAO,GAAiB,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iEAAiE,CAAC;AAEvG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAEvD,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,YAAY,GAAG,GAAG,CAAC;AAqBzB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACF,EAAE,EAAE;;IACrB,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,kBAAkB,GAAG,MAAM,CAA8B,EAAE,CAAC,CAAC;IACnE,MAAM,eAAe,GAAG,MAAM,CAA8B,EAA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AAS,EAAE,SAAS,aAEnB,MAAM,EACP,eAAM,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC,YAAG,KAAK,GAAQ,IAC9C,CACV,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { forwardRef, Ref, useEffect, useMemo, useRef, useState } from \"react\";\nimport clsx from \"clsx\";\n\nimport {\n circleIndex,\n handleKey,\n KeyCode,\n SingleTabStopNavigationAPI,\n SingleTabStopNavigationProvider,\n useMergeRefs,\n useSingleTabStopNavigation,\n} from \"@cloudscape-design/component-toolkit/internal\";\nimport Box, { BoxProps } from \"@cloudscape-design/components/box\";\nimport { InternalChartTooltip } from \"@cloudscape-design/components/internal/do-not-use/chart-tooltip\";\n\nimport { DebouncedCall } from \"../../utils/utils\";\nimport { GetLegendTooltipContentProps, LegendItem, LegendTooltipContent } from \"../interfaces\";\n\nimport styles from \"./styles.css.js\";\nimport testClasses from \"./test-classes/styles.css.js\";\n\nconst TOOLTIP_BLUR_DELAY = 50;\nconst HIGHLIGHT_LOST_DELAY = 50;\nconst SCROLL_DELAY = 100;\n\nexport type LegendAlignment = \"horizontal\" | \"vertical\";\nexport type LegendHorizontalAlignment = \"start\" | \"center\" | \"end\";\n\nexport interface ChartLegendProps {\n items: readonly LegendItem[];\n legendTitle?: string;\n ariaLabel?: string;\n className?: string;\n actions?: React.ReactNode;\n someHighlighted: boolean;\n alignment: LegendAlignment;\n horizontalAlignment: LegendHorizontalAlignment;\n onToggleItem: (itemId: string) => void;\n onSelectItem: (itemId: string) => void;\n onItemHighlightEnter: (item: LegendItem) => void;\n onItemHighlightExit: () => void;\n getTooltipContent: (props: GetLegendTooltipContentProps) => null | LegendTooltipContent;\n}\n\nexport const ChartLegend = ({\n items,\n legendTitle,\n ariaLabel,\n actions,\n alignment,\n className,\n someHighlighted,\n onToggleItem,\n onSelectItem,\n onItemHighlightEnter,\n onItemHighlightExit,\n getTooltipContent,\n horizontalAlignment,\n}: ChartLegendProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const elementsByIndexRef = useRef<Record<number, HTMLElement>>([]);\n const elementsByIdRef = useRef<Record<string, HTMLElement>>({});\n const tooltipRef = useRef<HTMLElement>(null);\n const highlightControl = useMemo(() => new DebouncedCall(), []);\n const scrollIntoViewControl = useMemo(() => new DebouncedCall(), []);\n const [selectedIndex, setSelectedIndex] = useState<number>(0);\n const [tooltipItemId, setTooltipItemId] = useState<string | null>(null);\n const { showTooltip, hideTooltip } = useMemo(() => {\n const control = new DebouncedCall();\n return {\n showTooltip(itemId: string) {\n control.call(() => setTooltipItemId(itemId));\n },\n hideTooltip(lock = false) {\n control.call(() => setTooltipItemId(null), TOOLTIP_BLUR_DELAY);\n if (lock) {\n control.lock(TOOLTIP_BLUR_DELAY);\n }\n },\n };\n }, []);\n\n useEffect(() => {\n if (!tooltipItemId) {\n return;\n }\n const onDocumentKeyDown = (event: KeyboardEvent) => {\n if (event.keyCode === KeyCode.escape) {\n hideTooltip(true);\n elementsByIdRef.current[tooltipItemId]?.focus();\n }\n };\n document.addEventListener(\"keydown\", onDocumentKeyDown, true);\n return () => {\n document.removeEventListener(\"keydown\", onDocumentKeyDown, true);\n };\n }, [items, tooltipItemId, hideTooltip]);\n const isMouseInContainer = useRef<boolean>(false);\n\n // Scrolling to the highlighted legend item.\n useEffect(() => {\n const highlightedIndex = items.findIndex((item) => item.highlighted);\n if (highlightedIndex === -1) {\n return;\n }\n scrollIntoViewControl.call(() => {\n if (isMouseInContainer.current) {\n return;\n }\n const container = containerRef.current;\n const element = elementsByIndexRef.current?.[highlightedIndex];\n if (!container || !element) {\n return;\n }\n const elementRect = element.getBoundingClientRect();\n const containerRect = container.getBoundingClientRect();\n const isVisible = elementRect.top >= containerRect.top && elementRect.bottom <= containerRect.bottom;\n if (!isVisible) {\n const elementCenter = elementRect.top + elementRect.height / 2;\n const containerCenter = containerRect.top + containerRect.height / 2;\n const top = container.scrollTop + (elementCenter - containerCenter);\n container.scrollTo({ top, behavior: \"smooth\" });\n }\n }, SCROLL_DELAY);\n }, [items, scrollIntoViewControl]);\n\n const showHighlight = (itemId: string) => {\n const item = items.find((item) => item.id === itemId);\n if (item?.visible) {\n highlightControl.cancelPrevious();\n onItemHighlightEnter(item);\n }\n };\n const clearHighlight = () => {\n highlightControl.call(onItemHighlightExit, HIGHLIGHT_LOST_DELAY);\n };\n\n const navigationAPI = useRef<SingleTabStopNavigationAPI>(null);\n\n function onFocus(index: number, itemId: string) {\n setSelectedIndex(index);\n navigationAPI.current!.updateFocusTarget();\n showHighlight(itemId);\n showTooltip(itemId);\n }\n\n function onBlur(event: React.FocusEvent) {\n navigationAPI.current!.updateFocusTarget();\n\n // Hide tooltip and clear highlight unless focus moves inside tooltip;\n if (tooltipRef.current && event.relatedTarget && !tooltipRef.current.contains(event.relatedTarget)) {\n clearHighlight();\n hideTooltip();\n }\n }\n\n function focusElement(index: number) {\n elementsByIndexRef.current[index]?.focus();\n }\n\n function onKeyDown(event: React.KeyboardEvent<HTMLElement>) {\n if (\n event.keyCode === KeyCode.right ||\n event.keyCode === KeyCode.left ||\n event.keyCode === KeyCode.up ||\n event.keyCode === KeyCode.down ||\n event.keyCode === KeyCode.home ||\n event.keyCode === KeyCode.end ||\n event.keyCode === KeyCode.escape\n ) {\n // Preventing default fixes an issue in Safari+VO when VO additionally interprets arrow keys as its commands.\n event.preventDefault();\n\n const range = [0, items.length - 1] as [number, number];\n\n handleKey(event, {\n onInlineStart: () => focusElement(circleIndex(selectedIndex - 1, range)),\n onInlineEnd: () => focusElement(circleIndex(selectedIndex + 1, range)),\n onBlockStart: () => focusElement(circleIndex(selectedIndex - 1, range)),\n onBlockEnd: () => focusElement(circleIndex(selectedIndex + 1, range)),\n onHome: () => focusElement(0),\n onEnd: () => focusElement(items.length - 1),\n onEscape: () => onItemHighlightExit(),\n });\n }\n }\n\n function getNextFocusTarget(): null | HTMLElement {\n if (containerRef.current) {\n const buttons: HTMLButtonElement[] = Array.from(containerRef.current.querySelectorAll(`.${styles.item}`));\n return buttons[selectedIndex] ?? null;\n }\n return null;\n }\n\n function onUnregisterActive(\n focusableElement: HTMLElement,\n navigationAPI: React.RefObject<{ getFocusTarget: () => HTMLElement | null }>,\n ) {\n const target = navigationAPI.current?.getFocusTarget();\n\n if (target && target.dataset.itemid !== focusableElement.dataset.itemid) {\n target.focus();\n }\n }\n\n useEffect(() => {\n navigationAPI.current!.updateFocusTarget();\n });\n\n const isVertical = alignment === \"vertical\";\n\n const tooltipTrack = useRef<null | HTMLElement>(null);\n const tooltipTarget = items.find((item) => item.id === tooltipItemId) ?? null;\n tooltipTrack.current = tooltipItemId ? elementsByIdRef.current[tooltipItemId] : null;\n const tooltipContent = tooltipTarget && getTooltipContent({ legendItem: tooltipTarget });\n const tooltipPosition = isVertical ? \"left\" : \"bottom\";\n\n return (\n <SingleTabStopNavigationProvider\n ref={navigationAPI}\n navigationActive={true}\n getNextFocusTarget={() => getNextFocusTarget()}\n onUnregisterActive={(element: HTMLElement) => onUnregisterActive(element, navigationAPI)}\n >\n <div\n role=\"toolbar\"\n aria-label={legendTitle || ariaLabel}\n className={clsx(testClasses.root, styles.root, className)}\n onMouseEnter={() => (isMouseInContainer.current = true)}\n onMouseLeave={() => (isMouseInContainer.current = false)}\n >\n {legendTitle && (\n <Box fontWeight=\"bold\" className={testClasses.title} textAlign={getBoxTextAlignment(horizontalAlignment)}>\n {legendTitle}\n </Box>\n )}\n <div\n // The list element is not focusable. However, the focus lands on it regardless, when testing in Firefox.\n // Setting the tab index to -1 does fix the problem.\n tabIndex={-1}\n ref={containerRef}\n className={clsx(styles.list, {\n [styles[`list-bottom-${horizontalAlignment}`]]: !isVertical,\n [styles[\"list-bottom\"]]: !isVertical,\n [styles[\"list-side\"]]: isVertical,\n })}\n >\n {actions && (\n <>\n <div className={clsx(testClasses.actions, styles.actions, styles[\"actions-bottom\"])}>\n {actions}\n {!isVertical && <div className={styles[\"actions-divider-bottom\"]} />}\n </div>\n {isVertical && <div className={styles[\"actions-divider-side\"]} />}\n </>\n )}\n {items.map((item, index) => {\n const handlers = {\n onMouseEnter: () => {\n showHighlight(item.id);\n showTooltip(item.id);\n },\n onMouseLeave: () => {\n clearHighlight();\n hideTooltip();\n },\n onFocus: () => {\n onFocus(index, item.id);\n },\n onBlur: (event: React.FocusEvent) => {\n onBlur(event);\n },\n onKeyDown,\n };\n const thisTriggerRef = (elem: null | HTMLElement) => {\n if (elem) {\n elementsByIndexRef.current[index] = elem;\n elementsByIdRef.current[item.id] = elem;\n } else {\n delete elementsByIndexRef.current[index];\n delete elementsByIdRef.current[item.id];\n }\n };\n return (\n <LegendItemTrigger\n key={index}\n {...handlers}\n ref={thisTriggerRef}\n onClick={(event) => {\n if (event.metaKey || event.ctrlKey) {\n onToggleItem(item.id);\n } else {\n onSelectItem(item.id);\n }\n }}\n isHighlighted={item.highlighted}\n someHighlighted={someHighlighted}\n itemId={item.id}\n label={item.name}\n visible={item.visible}\n marker={item.marker}\n />\n );\n })}\n </div>\n {tooltipContent && (\n <InternalChartTooltip\n trackRef={tooltipTrack}\n trackKey={tooltipTarget.id}\n container={null}\n dismissButton={false}\n onDismiss={() => {}}\n position={tooltipPosition}\n title={tooltipContent.header}\n onMouseEnter={() => showTooltip(tooltipTarget.id)}\n onMouseLeave={() => hideTooltip()}\n onBlur={() => hideTooltip()}\n footer={\n tooltipContent.footer && (\n <>\n <hr aria-hidden={true} />\n {tooltipContent.footer}\n </>\n )\n }\n >\n {tooltipContent.body}\n </InternalChartTooltip>\n )}\n </div>\n </SingleTabStopNavigationProvider>\n );\n};\n\nfunction getBoxTextAlignment(horizontalAlignment: LegendHorizontalAlignment): BoxProps.TextAlign {\n switch (horizontalAlignment) {\n case \"start\":\n return \"left\";\n case \"center\":\n return \"center\";\n case \"end\":\n return \"right\";\n }\n}\n\nconst LegendItemTrigger = forwardRef(\n (\n {\n isHighlighted,\n someHighlighted,\n itemId,\n label,\n marker,\n visible,\n onClick,\n triggerRef,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n onKeyDown,\n }: {\n isHighlighted?: boolean;\n someHighlighted?: boolean;\n itemId: string;\n label: string;\n marker?: React.ReactNode;\n visible: boolean;\n onClick: (event: React.MouseEvent) => void;\n onMarkerClick?: () => void;\n triggerRef?: Ref<HTMLElement>;\n onMouseEnter?: () => void;\n onMouseLeave?: () => void;\n onFocus?: () => void;\n onBlur?: (event: React.FocusEvent) => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;\n },\n ref: Ref<HTMLButtonElement>,\n ) => {\n const refObject = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs(ref, triggerRef, refObject);\n const { tabIndex } = useSingleTabStopNavigation(refObject);\n return (\n <button\n data-itemid={itemId}\n aria-pressed={visible}\n aria-current={isHighlighted}\n className={clsx(testClasses.item, styles.item, {\n [styles[\"item--inactive\"]]: !visible,\n [testClasses[\"hidden-item\"]]: !visible,\n [styles[\"item--dimmed\"]]: someHighlighted && !isHighlighted,\n [testClasses[\"dimmed-item\"]]: someHighlighted && !isHighlighted,\n })}\n ref={mergedRef}\n tabIndex={tabIndex}\n onClick={onClick}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n >\n {marker}\n <span className={styles[\"item-label\"]}>{label}</span>\n </button>\n );\n },\n);\n"]}
|