@cloudscape-design/chart-components 1.0.0
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/LICENSE +175 -0
- package/NOTICE +1 -0
- package/README.md +25 -0
- package/cartesian-chart/chart-cartesian-internal.d.ts +10 -0
- package/cartesian-chart/chart-cartesian-internal.js +99 -0
- package/cartesian-chart/chart-cartesian-internal.js.map +1 -0
- package/cartesian-chart/chart-series-cartesian.d.ts +7 -0
- package/cartesian-chart/chart-series-cartesian.js +95 -0
- package/cartesian-chart/chart-series-cartesian.js.map +1 -0
- package/cartesian-chart/index.d.ts +5 -0
- package/cartesian-chart/index.js +133 -0
- package/cartesian-chart/index.js.map +1 -0
- package/cartesian-chart/interfaces.d.ts +166 -0
- package/cartesian-chart/interfaces.js +4 -0
- package/cartesian-chart/interfaces.js.map +1 -0
- package/cartesian-chart/test-classes/styles.css.js +6 -0
- package/cartesian-chart/test-classes/styles.scoped.css +7 -0
- package/cartesian-chart/test-classes/styles.selectors.js +7 -0
- package/core/chart-api/chart-extra-axis-titles.d.ts +10 -0
- package/core/chart-api/chart-extra-axis-titles.js +42 -0
- package/core/chart-api/chart-extra-axis-titles.js.map +1 -0
- package/core/chart-api/chart-extra-context.d.ts +41 -0
- package/core/chart-api/chart-extra-context.js +93 -0
- package/core/chart-api/chart-extra-context.js.map +1 -0
- package/core/chart-api/chart-extra-highlight.d.ts +20 -0
- package/core/chart-api/chart-extra-highlight.js +205 -0
- package/core/chart-api/chart-extra-highlight.js.map +1 -0
- package/core/chart-api/chart-extra-legend.d.ts +27 -0
- package/core/chart-api/chart-extra-legend.js +118 -0
- package/core/chart-api/chart-extra-legend.js.map +1 -0
- package/core/chart-api/chart-extra-navigation.d.ts +84 -0
- package/core/chart-api/chart-extra-navigation.js +470 -0
- package/core/chart-api/chart-extra-navigation.js.map +1 -0
- package/core/chart-api/chart-extra-nodata.d.ts +15 -0
- package/core/chart-api/chart-extra-nodata.js +45 -0
- package/core/chart-api/chart-extra-nodata.js.map +1 -0
- package/core/chart-api/chart-extra-pointer.d.ts +33 -0
- package/core/chart-api/chart-extra-pointer.js +173 -0
- package/core/chart-api/chart-extra-pointer.js.map +1 -0
- package/core/chart-api/chart-extra-tooltip.d.ts +33 -0
- package/core/chart-api/chart-extra-tooltip.js +209 -0
- package/core/chart-api/chart-extra-tooltip.js.map +1 -0
- package/core/chart-api/index.d.ts +75 -0
- package/core/chart-api/index.js +383 -0
- package/core/chart-api/index.js.map +1 -0
- package/core/chart-container.d.ts +20 -0
- package/core/chart-container.js +55 -0
- package/core/chart-container.js.map +1 -0
- package/core/chart-core.d.ts +7 -0
- package/core/chart-core.js +287 -0
- package/core/chart-core.js.map +1 -0
- package/core/components/core-application.d.ts +6 -0
- package/core/components/core-application.js +16 -0
- package/core/components/core-application.js.map +1 -0
- package/core/components/core-filters.d.ts +9 -0
- package/core/components/core-filters.js +22 -0
- package/core/components/core-filters.js.map +1 -0
- package/core/components/core-legend.d.ts +13 -0
- package/core/components/core-legend.js +27 -0
- package/core/components/core-legend.js.map +1 -0
- package/core/components/core-no-data.d.ts +6 -0
- package/core/components/core-no-data.js +48 -0
- package/core/components/core-no-data.js.map +1 -0
- package/core/components/core-slots.d.ts +7 -0
- package/core/components/core-slots.js +11 -0
- package/core/components/core-slots.js.map +1 -0
- package/core/components/core-tooltip.d.ts +7 -0
- package/core/components/core-tooltip.js +183 -0
- package/core/components/core-tooltip.js.map +1 -0
- package/core/components/core-vertical-axis-title.d.ts +5 -0
- package/core/components/core-vertical-axis-title.js +15 -0
- package/core/components/core-vertical-axis-title.js.map +1 -0
- package/core/formatters.d.ts +2 -0
- package/core/formatters.js +113 -0
- package/core/formatters.js.map +1 -0
- package/core/i18n-utils.d.ts +21 -0
- package/core/i18n-utils.js +18 -0
- package/core/i18n-utils.js.map +1 -0
- package/core/interfaces.d.ts +436 -0
- package/core/interfaces.js +4 -0
- package/core/interfaces.js.map +1 -0
- package/core/styles.css.js +25 -0
- package/core/styles.scoped.css +115 -0
- package/core/styles.selectors.js +26 -0
- package/core/test-classes/styles.css.js +33 -0
- package/core/test-classes/styles.scoped.css +34 -0
- package/core/test-classes/styles.selectors.js +34 -0
- package/core/utils.d.ts +45 -0
- package/core/utils.js +262 -0
- package/core/utils.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/internal/api-docs/components/cartesian-chart.js +571 -0
- package/internal/api-docs/components/index.d.ts +3 -0
- package/internal/api-docs/components/index.js +4 -0
- package/internal/api-docs/components/interfaces.d.ts +81 -0
- package/internal/api-docs/components/pie-chart.js +430 -0
- package/internal/api-docs/test-utils-doc/dom.js +4 -0
- package/internal/api-docs/test-utils-doc/selectors.js +4 -0
- package/internal/base-component/get-data-attributes.d.ts +1 -0
- package/internal/base-component/get-data-attributes.js +12 -0
- package/internal/base-component/get-data-attributes.js.map +1 -0
- package/internal/base-component/use-base-component.d.ts +13 -0
- package/internal/base-component/use-base-component.js +18 -0
- package/internal/base-component/use-base-component.js.map +1 -0
- package/internal/base-component/use-telemetry.d.ts +2 -0
- package/internal/base-component/use-telemetry.js +8 -0
- package/internal/base-component/use-telemetry.js.map +1 -0
- package/internal/chart-styles.d.ts +88 -0
- package/internal/chart-styles.js +145 -0
- package/internal/chart-styles.js.map +1 -0
- package/internal/components/chart-legend/index.d.ts +14 -0
- package/internal/components/chart-legend/index.js +245 -0
- package/internal/components/chart-legend/index.js.map +1 -0
- package/internal/components/chart-legend/styles.css.js +22 -0
- package/internal/components/chart-legend/styles.scoped.css +233 -0
- package/internal/components/chart-legend/styles.selectors.js +23 -0
- package/internal/components/chart-legend/test-classes/styles.css.js +11 -0
- package/internal/components/chart-legend/test-classes/styles.scoped.css +12 -0
- package/internal/components/chart-legend/test-classes/styles.selectors.js +12 -0
- package/internal/components/chart-series-filter/index.d.ts +17 -0
- package/internal/components/chart-series-filter/index.js +14 -0
- package/internal/components/chart-series-filter/index.js.map +1 -0
- package/internal/components/interfaces.d.ts +17 -0
- package/internal/components/interfaces.js +4 -0
- package/internal/components/interfaces.js.map +1 -0
- package/internal/components/series-details/index.d.ts +23 -0
- package/internal/components/series-details/index.js +45 -0
- package/internal/components/series-details/index.js.map +1 -0
- package/internal/components/series-details/styles.css.js +22 -0
- package/internal/components/series-details/styles.scoped.css +150 -0
- package/internal/components/series-details/styles.selectors.js +23 -0
- package/internal/components/series-details/test-classes/styles.css.js +10 -0
- package/internal/components/series-details/test-classes/styles.scoped.css +11 -0
- package/internal/components/series-details/test-classes/styles.selectors.js +11 -0
- package/internal/components/series-marker/index.d.ts +8 -0
- package/internal/components/series-marker/index.js +45 -0
- package/internal/components/series-marker/index.js.map +1 -0
- package/internal/components/series-marker/interfaces.d.ts +1 -0
- package/internal/components/series-marker/interfaces.js +4 -0
- package/internal/components/series-marker/interfaces.js.map +1 -0
- package/internal/components/series-marker/render-marker.d.ts +3 -0
- package/internal/components/series-marker/render-marker.js +74 -0
- package/internal/components/series-marker/render-marker.js.map +1 -0
- package/internal/components/series-marker/styles.css.js +7 -0
- package/internal/components/series-marker/styles.scoped.css +55 -0
- package/internal/components/series-marker/styles.selectors.js +8 -0
- package/internal/environment.d.ts +4 -0
- package/internal/environment.js +5 -0
- package/internal/environment.json +7 -0
- package/internal/events/index.d.ts +23 -0
- package/internal/events/index.js +41 -0
- package/internal/events/index.js.map +1 -0
- package/internal/generated/styles/tokens.d.ts +756 -0
- package/internal/generated/styles/tokens.js +756 -0
- package/internal/generated/theming/index.cjs +12584 -0
- package/internal/generated/theming/index.cjs.d.ts +2399 -0
- package/internal/generated/theming/index.d.ts +2399 -0
- package/internal/generated/theming/index.js +12584 -0
- package/internal/manifest.json +3 -0
- package/internal/styles.css.js +6 -0
- package/internal/styles.scoped.css +13 -0
- package/internal/styles.selectors.js +7 -0
- package/internal/utils/apply-display-name.d.ts +1 -0
- package/internal/utils/apply-display-name.js +6 -0
- package/internal/utils/apply-display-name.js.map +1 -0
- package/internal/utils/async-store.d.ts +19 -0
- package/internal/utils/async-store.js +58 -0
- package/internal/utils/async-store.js.map +1 -0
- package/internal/utils/chart-series.d.ts +8 -0
- package/internal/utils/chart-series.js +11 -0
- package/internal/utils/chart-series.js.map +1 -0
- package/internal/utils/renderer-utils.d.ts +17 -0
- package/internal/utils/renderer-utils.js +95 -0
- package/internal/utils/renderer-utils.js.map +1 -0
- package/internal/utils/series-data.d.ts +2 -0
- package/internal/utils/series-data.js +8 -0
- package/internal/utils/series-data.js.map +1 -0
- package/internal/utils/test-i18n-provider.d.ts +8 -0
- package/internal/utils/test-i18n-provider.js +8 -0
- package/internal/utils/test-i18n-provider.js.map +1 -0
- package/internal/utils/use-previous.d.ts +4 -0
- package/internal/utils/use-previous.js +14 -0
- package/internal/utils/use-previous.js.map +1 -0
- package/internal/utils/utils.d.ts +16 -0
- package/internal/utils/utils.js +49 -0
- package/internal/utils/utils.js.map +1 -0
- package/internal-do-not-use/core-chart/index.d.ts +4 -0
- package/internal-do-not-use/core-chart/index.js +13 -0
- package/internal-do-not-use/core-chart/index.js.map +1 -0
- package/internal-do-not-use/core-legend/index.d.ts +2 -0
- package/internal-do-not-use/core-legend/index.js +11 -0
- package/internal-do-not-use/core-legend/index.js.map +1 -0
- package/package.json +106 -0
- package/pie-chart/chart-inner-area.d.ts +10 -0
- package/pie-chart/chart-inner-area.js +63 -0
- package/pie-chart/chart-inner-area.js.map +1 -0
- package/pie-chart/chart-pie-internal.d.ts +11 -0
- package/pie-chart/chart-pie-internal.js +103 -0
- package/pie-chart/chart-pie-internal.js.map +1 -0
- package/pie-chart/index.d.ts +5 -0
- package/pie-chart/index.js +48 -0
- package/pie-chart/index.js.map +1 -0
- package/pie-chart/interfaces.d.ts +101 -0
- package/pie-chart/interfaces.js +4 -0
- package/pie-chart/interfaces.js.map +1 -0
- package/pie-chart/test-classes/styles.css.js +8 -0
- package/pie-chart/test-classes/styles.scoped.css +9 -0
- package/pie-chart/test-classes/styles.selectors.js +9 -0
- package/test-utils/dom/cartesian-chart/index.d.ts +14 -0
- package/test-utils/dom/cartesian-chart/index.js +24 -0
- package/test-utils/dom/cartesian-chart/index.js.map +1 -0
- package/test-utils/dom/cartesian-chart/tooltip.d.ts +28 -0
- package/test-utils/dom/cartesian-chart/tooltip.js +48 -0
- package/test-utils/dom/cartesian-chart/tooltip.js.map +1 -0
- package/test-utils/dom/index.d.ts +46 -0
- package/test-utils/dom/index.js +35 -0
- package/test-utils/dom/index.js.map +1 -0
- package/test-utils/dom/internal/base.d.ts +93 -0
- package/test-utils/dom/internal/base.js +146 -0
- package/test-utils/dom/internal/base.js.map +1 -0
- package/test-utils/dom/internal/core.d.ts +14 -0
- package/test-utils/dom/internal/core.js +37 -0
- package/test-utils/dom/internal/core.js.map +1 -0
- package/test-utils/dom/pie-chart/index.d.ts +17 -0
- package/test-utils/dom/pie-chart/index.js +29 -0
- package/test-utils/dom/pie-chart/index.js.map +1 -0
- package/test-utils/selectors/cartesian-chart/index.d.ts +14 -0
- package/test-utils/selectors/cartesian-chart/index.js +24 -0
- package/test-utils/selectors/cartesian-chart/index.js.map +1 -0
- package/test-utils/selectors/cartesian-chart/tooltip.d.ts +28 -0
- package/test-utils/selectors/cartesian-chart/tooltip.js +48 -0
- package/test-utils/selectors/cartesian-chart/tooltip.js.map +1 -0
- package/test-utils/selectors/index.d.ts +46 -0
- package/test-utils/selectors/index.js +32 -0
- package/test-utils/selectors/index.js.map +1 -0
- package/test-utils/selectors/internal/base.d.ts +93 -0
- package/test-utils/selectors/internal/base.js +146 -0
- package/test-utils/selectors/internal/base.js.map +1 -0
- package/test-utils/selectors/internal/core.d.ts +14 -0
- package/test-utils/selectors/internal/core.js +37 -0
- package/test-utils/selectors/internal/core.js.map +1 -0
- package/test-utils/selectors/pie-chart/index.d.ts +17 -0
- package/test-utils/selectors/pie-chart/index.js +29 -0
- package/test-utils/selectors/pie-chart/index.js.map +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import * as Styles from "../internal/chart-styles";
|
|
5
|
+
import { getChartSeries } from "../internal/utils/chart-series";
|
|
6
|
+
import testClasses from "./test-classes/styles.css.js";
|
|
7
|
+
export function useInnerArea(series, innerAreaProps) {
|
|
8
|
+
const hasDonutSeries = series.some((s) => s.type === "donut");
|
|
9
|
+
const innerAreaRef = useRef(new ChartInnerDescriptions());
|
|
10
|
+
const onChartRender = function () {
|
|
11
|
+
innerAreaRef.current.destroy();
|
|
12
|
+
if (hasDonutSeries && findVisibleSeries(this.series).length > 0) {
|
|
13
|
+
innerAreaRef.current.create(innerAreaProps, this);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return { onChartRender };
|
|
17
|
+
}
|
|
18
|
+
class ChartInnerDescriptions {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.titleElement = null;
|
|
21
|
+
this.descriptionElement = null;
|
|
22
|
+
}
|
|
23
|
+
create({ innerAreaTitle, innerAreaDescription }, chart) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const centerX = chart.plotLeft + getChartSeries(chart.series)[0].center[0];
|
|
26
|
+
const centerY = chart.plotTop + getChartSeries(chart.series)[0].center[1];
|
|
27
|
+
if (innerAreaTitle) {
|
|
28
|
+
this.titleElement = chart.renderer
|
|
29
|
+
.text(innerAreaTitle, -9999, -9999)
|
|
30
|
+
.attr({ zIndex: 5, class: testClasses["inner-value"] })
|
|
31
|
+
.css(Styles.innerAreaTitleCss)
|
|
32
|
+
.add();
|
|
33
|
+
}
|
|
34
|
+
if (innerAreaDescription) {
|
|
35
|
+
this.descriptionElement = chart.renderer
|
|
36
|
+
.text(innerAreaDescription, -9999, -9999)
|
|
37
|
+
.attr({ zIndex: 5, class: testClasses["inner-description"] })
|
|
38
|
+
.css(Styles.innerAreaDescriptionCss)
|
|
39
|
+
.add();
|
|
40
|
+
}
|
|
41
|
+
const titleBox = (_a = this.titleElement) === null || _a === void 0 ? void 0 : _a.getBBox();
|
|
42
|
+
const descriptionBox = (_b = this.descriptionElement) === null || _b === void 0 ? void 0 : _b.getBBox();
|
|
43
|
+
if (titleBox && descriptionBox) {
|
|
44
|
+
this.titleElement.attr({ x: centerX - titleBox.width / 2, y: centerY - titleBox.height / 4 });
|
|
45
|
+
this.descriptionElement.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 2 });
|
|
46
|
+
}
|
|
47
|
+
else if (titleBox) {
|
|
48
|
+
this.titleElement.attr({ x: centerX - titleBox.width / 2, y: centerY + titleBox.height / 4 });
|
|
49
|
+
}
|
|
50
|
+
else if (descriptionBox) {
|
|
51
|
+
this.descriptionElement.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 4 });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
(_a = this.titleElement) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
57
|
+
(_b = this.descriptionElement) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function findVisibleSeries(series) {
|
|
61
|
+
return series.filter((s) => s.visible && s.data.some((d) => d.y !== null && d.visible));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=chart-inner-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-inner-area.js","sourceRoot":"","sources":["../../../src/pie-chart/chart-inner-area.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAOvD,MAAM,UAAU,YAAY,CAAC,MAA8C,EAAE,c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AE,OAAO,GAAG,cAAc,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;SAClH;IACH,CAAC;IAEM,OAAO;;QACZ,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,EAAE,CAAC;QAC7B,MAAA,IAAI,CAAC,kBAAkB,0CAAE,OAAO,EAAE,CAAC;IACrC,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,MAA2B;IACpD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useRef } from \"react\";\nimport type Highcharts from \"highcharts\";\n\nimport * as Styles from \"../internal/chart-styles\";\nimport { getChartSeries } from \"../internal/utils/chart-series\";\nimport { PieChartProps } from \"./interfaces\";\n\nimport testClasses from \"./test-classes/styles.css.js\";\n\ninterface InnerAreaProps {\n innerAreaTitle?: string;\n innerAreaDescription?: string;\n}\n\nexport function useInnerArea(series: readonly PieChartProps.SeriesOptions[], innerAreaProps: InnerAreaProps) {\n const hasDonutSeries = series.some((s) => s.type === \"donut\");\n const innerAreaRef = useRef(new ChartInnerDescriptions());\n const onChartRender: Highcharts.ChartRenderCallbackFunction = function () {\n innerAreaRef.current.destroy();\n if (hasDonutSeries && findVisibleSeries(this.series).length > 0) {\n innerAreaRef.current.create(innerAreaProps, this);\n }\n };\n return { onChartRender };\n}\n\nclass ChartInnerDescriptions {\n private titleElement: null | Highcharts.SVGElement = null;\n private descriptionElement: null | Highcharts.SVGElement = null;\n\n public create({ innerAreaTitle, innerAreaDescription }: InnerAreaProps, chart: Highcharts.Chart) {\n const centerX = chart.plotLeft + getChartSeries(chart.series)[0].center[0];\n const centerY = chart.plotTop + getChartSeries(chart.series)[0].center[1];\n\n if (innerAreaTitle) {\n this.titleElement = chart.renderer\n .text(innerAreaTitle, -9999, -9999)\n .attr({ zIndex: 5, class: testClasses[\"inner-value\"] })\n .css(Styles.innerAreaTitleCss)\n .add();\n }\n if (innerAreaDescription) {\n this.descriptionElement = chart.renderer\n .text(innerAreaDescription, -9999, -9999)\n .attr({ zIndex: 5, class: testClasses[\"inner-description\"] })\n .css(Styles.innerAreaDescriptionCss)\n .add();\n }\n\n const titleBox = this.titleElement?.getBBox();\n const descriptionBox = this.descriptionElement?.getBBox();\n\n if (titleBox && descriptionBox) {\n this.titleElement!.attr({ x: centerX - titleBox.width / 2, y: centerY - titleBox.height / 4 });\n this.descriptionElement!.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 2 });\n } else if (titleBox) {\n this.titleElement!.attr({ x: centerX - titleBox.width / 2, y: centerY + titleBox.height / 4 });\n } else if (descriptionBox) {\n this.descriptionElement!.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 4 });\n }\n }\n\n public destroy() {\n this.titleElement?.destroy();\n this.descriptionElement?.destroy();\n }\n}\n\nfunction findVisibleSeries(series: Highcharts.Series[]) {\n return series.filter((s) => s.visible && s.data.some((d) => d.y !== null && d.visible));\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
|
|
3
|
+
import { SomeRequired } from "../internal/utils/utils";
|
|
4
|
+
import { PieChartProps } from "./interfaces";
|
|
5
|
+
interface InternalPieChartProps extends InternalBaseComponentProps, Omit<PieChartProps, "series"> {
|
|
6
|
+
series: readonly PieChartProps.SeriesOptions[];
|
|
7
|
+
tooltip: SomeRequired<PieChartProps.TooltipOptions, "enabled" | "size">;
|
|
8
|
+
legend: SomeRequired<PieChartProps.LegendOptions, "enabled">;
|
|
9
|
+
}
|
|
10
|
+
export declare const InternalPieChart: import("react").ForwardRefExoticComponent<InternalPieChartProps & import("react").RefAttributes<PieChartProps.Ref>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
5
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
6
|
+
import { useControllableState } from "@cloudscape-design/component-toolkit";
|
|
7
|
+
import { InternalCoreChart } from "../core/chart-core";
|
|
8
|
+
import { getOptionsId } from "../core/utils";
|
|
9
|
+
import * as Styles from "../internal/chart-styles";
|
|
10
|
+
import { fireNonCancelableEvent } from "../internal/events";
|
|
11
|
+
import { useInnerArea } from "./chart-inner-area";
|
|
12
|
+
import testClasses from "./test-classes/styles.css.js";
|
|
13
|
+
export const InternalPieChart = forwardRef(({ series: originalSeries, tooltip, ...props }, ref) => {
|
|
14
|
+
const apiRef = useRef(null);
|
|
15
|
+
// When visibleSegments and onVisibleSegmentsChange are provided - the segments visibility can be controlled from the outside.
|
|
16
|
+
// Otherwise - the component handles segments visibility using its internal state.
|
|
17
|
+
useControllableState(props.visibleSegments, props.onVisibleSegmentsChange, undefined, {
|
|
18
|
+
componentName: "PieChart",
|
|
19
|
+
propertyName: "visibleSegments",
|
|
20
|
+
changeHandlerName: "onVisibleSegmentsChange",
|
|
21
|
+
});
|
|
22
|
+
const allSegmentIds = originalSeries.flatMap((s) => s.data.map((d) => getOptionsId(d)));
|
|
23
|
+
const onVisibleSegmentsChange = ({ detail: { items } }) => {
|
|
24
|
+
const visibleSegments = items.filter((i) => i.visible).map((i) => i.id);
|
|
25
|
+
fireNonCancelableEvent(props.onVisibleSegmentsChange, { visibleSegments });
|
|
26
|
+
};
|
|
27
|
+
// Converting donut series to Highcharts pie series.
|
|
28
|
+
const series = originalSeries.map((s) => {
|
|
29
|
+
const data = s.data;
|
|
30
|
+
const style = s.type === "pie" ? Styles.pieSeries : Styles.donutSeries;
|
|
31
|
+
return { ...s, type: "pie", data, ...style };
|
|
32
|
+
});
|
|
33
|
+
// Pie chart imperative API.
|
|
34
|
+
useImperativeHandle(ref, () => ({
|
|
35
|
+
setVisibleSegments: (visibleSegmentsIds) => { var _a; return (_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.setItemsVisible(visibleSegmentsIds); },
|
|
36
|
+
showAllSegments: () => { var _a; return (_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.setItemsVisible(allSegmentIds); },
|
|
37
|
+
}));
|
|
38
|
+
// Get inner area title and description for donut chart.
|
|
39
|
+
const innerArea = useInnerArea(originalSeries, props);
|
|
40
|
+
// We convert pie tooltip options to the core chart's getTooltipContent callback,
|
|
41
|
+
// ensuring no internal types are exposed to the consumer-defined render functions.
|
|
42
|
+
const getTooltipContent = () => {
|
|
43
|
+
const transformDetailsProps = ({ point, }) => {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
return {
|
|
46
|
+
totalValue: (_a = point.total) !== null && _a !== void 0 ? _a : 0,
|
|
47
|
+
segmentValue: (_b = point.y) !== null && _b !== void 0 ? _b : 0,
|
|
48
|
+
segmentId: getOptionsId(point.options),
|
|
49
|
+
segmentName: (_c = point.name) !== null && _c !== void 0 ? _c : "",
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const transformSlotProps = (props) => {
|
|
53
|
+
const point = props.items[0].point;
|
|
54
|
+
return transformDetailsProps({ point });
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
header: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.header) ? (props) => tooltip.header(transformSlotProps(props)) : undefined,
|
|
58
|
+
details: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.details) ? (props) => tooltip.details(transformDetailsProps(props)) : undefined,
|
|
59
|
+
body: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.body) ? (props) => tooltip.body(transformSlotProps(props)) : undefined,
|
|
60
|
+
footer: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.footer) ? (props) => tooltip.footer(transformSlotProps(props)) : undefined,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
// Convert pie segment props to Highcharts segment data labels.
|
|
64
|
+
const segmentDataLabels = {
|
|
65
|
+
position: "left",
|
|
66
|
+
formatter() {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const { segmentTitle, segmentDescription } = props;
|
|
69
|
+
const segmentProps = {
|
|
70
|
+
// For pie series, we expect y, total, and name to be always present, and y to be non-null for any visible segment.
|
|
71
|
+
// However, these are optional in Highcharts types, so we need to do a fallback.
|
|
72
|
+
totalValue: (_a = this.total) !== null && _a !== void 0 ? _a : 0,
|
|
73
|
+
segmentValue: (_b = this.y) !== null && _b !== void 0 ? _b : 0,
|
|
74
|
+
segmentId: this.options.id,
|
|
75
|
+
segmentName: (_c = this.options.name) !== null && _c !== void 0 ? _c : "",
|
|
76
|
+
};
|
|
77
|
+
const title = segmentTitle ? segmentTitle(segmentProps) : this.name;
|
|
78
|
+
const description = segmentDescription === null || segmentDescription === void 0 ? void 0 : segmentDescription(segmentProps);
|
|
79
|
+
if (title || description) {
|
|
80
|
+
return renderToStaticMarkup(_jsxs("text", { children: [title ? _jsx("tspan", { children: title }) : null, _jsx("br", {}), description ? _jsx("tspan", { style: Styles.segmentDescriptionCss, children: description }) : null] }));
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
},
|
|
84
|
+
useHTML: false,
|
|
85
|
+
};
|
|
86
|
+
const highchartsOptions = {
|
|
87
|
+
chart: {
|
|
88
|
+
events: {
|
|
89
|
+
render(event) {
|
|
90
|
+
innerArea.onChartRender.call(this, event);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
plotOptions: {
|
|
95
|
+
pie: {
|
|
96
|
+
dataLabels: segmentDataLabels,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
series,
|
|
100
|
+
};
|
|
101
|
+
return (_jsx(InternalCoreChart, { ...props, callback: (api) => (apiRef.current = api), options: highchartsOptions, tooltip: tooltip, getTooltipContent: getTooltipContent, visibleItems: props.visibleSegments, onVisibleItemsChange: onVisibleSegmentsChange, className: testClasses.root }));
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=chart-pie-internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-pie-internal.js","sourceRoot":"","sources":["../../../src/pie-chart/chart-pie-internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAQvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACxC,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,KAAK,EAAyB,EAAE,GAAiC,EAAE,EAAE;IAC1G,MAAM,MAAM,GAAG,MAAM,CAAiC,IAAI,CAAC,CAAC;IAE5D,8HAA8H;IAC9H,kFAAkF;IAClF,o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K,CAAC,CAAC,CAAC,0BAAQ,KAAK,GAAS,CAAC,CAAC,CAAC,IAAI,EACtC,cAAM,EACL,WAAW,CAAC,CAAC,CAAC,gBAAO,KAAK,EAAE,MAAM,CAAC,qBAAqB,YAAG,WAAW,GAAS,CAAC,CAAC,CAAC,IAAI,IAClF,CACR,CAAC;aACH;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,EAAE,KAAK;KACf,CAAC;IAEF,MAAM,iBAAiB,GAAuB;QAC5C,KAAK,EAAE;YACL,MAAM,EAAE;gBACN,MAAM,CAAC,KAAK;oBACV,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC5C,CAAC;aACF;SACF;QACD,WAAW,EAAE;YACX,GAAG,EAAE;gBACH,UAAU,EAAE,iBAAiB;aAC9B;SACF;QACD,MAAM;KACP,CAAC;IAEF,OAAO,CACL,KAAC,iBAAiB,OACZ,KAAK,EACT,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,EACzC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,KAAK,CAAC,eAAe,EACnC,oBAAoB,EAAE,uBAAuB,EAC7C,SAAS,EAAE,WAAW,CAAC,IAAI,GAC3B,CACH,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, useImperativeHandle, useRef } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport type Highcharts from \"highcharts\";\n\nimport { useControllableState } from \"@cloudscape-design/component-toolkit\";\n\nimport { InternalCoreChart } from \"../core/chart-core\";\nimport { CoreChartProps } from \"../core/interfaces\";\nimport { getOptionsId } from \"../core/utils\";\nimport { InternalBaseComponentProps } from \"../internal/base-component/use-base-component\";\nimport * as Styles from \"../internal/chart-styles\";\nimport { fireNonCancelableEvent } from \"../internal/events\";\nimport { SomeRequired, Writeable } from \"../internal/utils/utils\";\nimport { useInnerArea } from \"./chart-inner-area\";\nimport { PieChartProps } from \"./interfaces\";\n\nimport testClasses from \"./test-classes/styles.css.js\";\n\ninterface InternalPieChartProps extends InternalBaseComponentProps, Omit<PieChartProps, \"series\"> {\n series: readonly PieChartProps.SeriesOptions[];\n tooltip: SomeRequired<PieChartProps.TooltipOptions, \"enabled\" | \"size\">;\n legend: SomeRequired<PieChartProps.LegendOptions, \"enabled\">;\n}\n\nexport const InternalPieChart = forwardRef(\n ({ series: originalSeries, tooltip, ...props }: InternalPieChartProps, ref: React.Ref<PieChartProps.Ref>) => {\n const apiRef = useRef<null | CoreChartProps.ChartAPI>(null);\n\n // When visibleSegments and onVisibleSegmentsChange are provided - the segments visibility can be controlled from the outside.\n // Otherwise - the component handles segments visibility using its internal state.\n useControllableState(props.visibleSegments, props.onVisibleSegmentsChange, undefined, {\n componentName: \"PieChart\",\n propertyName: \"visibleSegments\",\n changeHandlerName: \"onVisibleSegmentsChange\",\n });\n const allSegmentIds = originalSeries.flatMap((s) => s.data.map((d) => getOptionsId(d)));\n const onVisibleSegmentsChange: CoreChartProps[\"onVisibleItemsChange\"] = ({ detail: { items } }) => {\n const visibleSegments = items.filter((i) => i.visible).map((i) => i.id);\n fireNonCancelableEvent(props.onVisibleSegmentsChange, { visibleSegments });\n };\n\n // Converting donut series to Highcharts pie series.\n const series: Highcharts.SeriesOptionsType[] = originalSeries.map((s) => {\n const data = s.data as Writeable<PieChartProps.PieSegmentOptions[]>;\n const style = s.type === \"pie\" ? Styles.pieSeries : Styles.donutSeries;\n return { ...s, type: \"pie\", data, ...style };\n });\n\n // Pie chart imperative API.\n useImperativeHandle(ref, () => ({\n setVisibleSegments: (visibleSegmentsIds) => apiRef.current?.setItemsVisible(visibleSegmentsIds),\n showAllSegments: () => apiRef.current?.setItemsVisible(allSegmentIds),\n }));\n\n // Get inner area title and description for donut chart.\n const innerArea = useInnerArea(originalSeries, props);\n\n // We convert pie tooltip options to the core chart's getTooltipContent callback,\n // ensuring no internal types are exposed to the consumer-defined render functions.\n const getTooltipContent: CoreChartProps[\"getTooltipContent\"] = () => {\n const transformDetailsProps = ({\n point,\n }: CoreChartProps.TooltipDetailsProps): PieChartProps.TooltipDetailsRenderProps => {\n return {\n totalValue: point.total ?? 0,\n segmentValue: point.y ?? 0,\n segmentId: getOptionsId(point.options),\n segmentName: point.name ?? \"\",\n };\n };\n const transformSlotProps = (props: CoreChartProps.TooltipSlotProps): PieChartProps.TooltipDetailsRenderProps => {\n const point = props.items[0].point;\n return transformDetailsProps({ point });\n };\n return {\n header: tooltip?.header ? (props) => tooltip.header!(transformSlotProps(props)) : undefined,\n details: tooltip?.details ? (props) => tooltip.details!(transformDetailsProps(props)) : undefined,\n body: tooltip?.body ? (props) => tooltip.body!(transformSlotProps(props)) : undefined,\n footer: tooltip?.footer ? (props) => tooltip.footer!(transformSlotProps(props)) : undefined,\n };\n };\n\n // Convert pie segment props to Highcharts segment data labels.\n const segmentDataLabels:\n | Highcharts.SeriesPieDataLabelsOptionsObject\n | Highcharts.SeriesPieDataLabelsOptionsObject[] = {\n position: \"left\",\n formatter() {\n const { segmentTitle, segmentDescription } = props;\n const segmentProps = {\n // For pie series, we expect y, total, and name to be always present, and y to be non-null for any visible segment.\n // However, these are optional in Highcharts types, so we need to do a fallback.\n totalValue: this.total ?? 0,\n segmentValue: this.y ?? 0,\n segmentId: this.options.id,\n segmentName: this.options.name ?? \"\",\n };\n const title = segmentTitle ? segmentTitle(segmentProps) : this.name;\n const description = segmentDescription?.(segmentProps);\n if (title || description) {\n return renderToStaticMarkup(\n <text>\n {title ? <tspan>{title}</tspan> : null}\n <br />\n {description ? <tspan style={Styles.segmentDescriptionCss}>{description}</tspan> : null}\n </text>,\n );\n }\n return null;\n },\n useHTML: false,\n };\n\n const highchartsOptions: Highcharts.Options = {\n chart: {\n events: {\n render(event) {\n innerArea.onChartRender.call(this, event);\n },\n },\n },\n plotOptions: {\n pie: {\n dataLabels: segmentDataLabels,\n },\n },\n series,\n };\n\n return (\n <InternalCoreChart\n {...props}\n callback={(api) => (apiRef.current = api)}\n options={highchartsOptions}\n tooltip={tooltip}\n getTooltipContent={getTooltipContent}\n visibleItems={props.visibleSegments}\n onVisibleItemsChange={onVisibleSegmentsChange}\n className={testClasses.root}\n />\n );\n },\n);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PieChartProps } from "./interfaces";
|
|
3
|
+
export type { PieChartProps };
|
|
4
|
+
declare const PieChart: import("react").ForwardRefExoticComponent<PieChartProps & import("react").RefAttributes<PieChartProps.Ref>>;
|
|
5
|
+
export default PieChart;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
import { getDataAttributes } from "../internal/base-component/get-data-attributes";
|
|
6
|
+
import useBaseComponent from "../internal/base-component/use-base-component";
|
|
7
|
+
import { applyDisplayName } from "../internal/utils/apply-display-name";
|
|
8
|
+
import { InternalPieChart } from "./chart-pie-internal";
|
|
9
|
+
const PieChart = forwardRef(({ fitHeight = false, ...props }, ref) => {
|
|
10
|
+
// We transform options before propagating them to the internal chart to ensure only those
|
|
11
|
+
// defined in the component's contract can be propagated down to the underlying Highcharts.
|
|
12
|
+
// Additionally, we assign all default options, including the nested ones.
|
|
13
|
+
const series = transformSeries(props.series);
|
|
14
|
+
const tooltip = transformTooltip(props.tooltip);
|
|
15
|
+
const legend = transformLegend(props.legend);
|
|
16
|
+
const baseComponentProps = useBaseComponent("PieChart", { props: { fitHeight } });
|
|
17
|
+
return (_jsx(InternalPieChart, { ref: ref, ...props, fitHeight: fitHeight, series: series, tooltip: tooltip, legend: legend, ...getDataAttributes(props), ...baseComponentProps }));
|
|
18
|
+
});
|
|
19
|
+
applyDisplayName(PieChart, "PieChart");
|
|
20
|
+
export default PieChart;
|
|
21
|
+
function transformSeries(series) {
|
|
22
|
+
if (!series) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
switch (series.type) {
|
|
26
|
+
case "pie":
|
|
27
|
+
case "donut":
|
|
28
|
+
return [
|
|
29
|
+
{ type: series.type, id: series.id, name: series.name, color: series.color, data: transformData(series.data) },
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function transformData(data) {
|
|
34
|
+
return data.map((d) => ({ id: d.id, name: d.name, color: d.color, y: d.y }));
|
|
35
|
+
}
|
|
36
|
+
function transformTooltip(tooltip) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return {
|
|
39
|
+
...tooltip,
|
|
40
|
+
enabled: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.enabled) !== null && _a !== void 0 ? _a : true,
|
|
41
|
+
size: (_b = tooltip === null || tooltip === void 0 ? void 0 : tooltip.size) !== null && _b !== void 0 ? _b : "medium",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function transformLegend(legend) {
|
|
45
|
+
var _a;
|
|
46
|
+
return { ...legend, enabled: (_a = legend === null || legend === void 0 ? void 0 : legend.enabled) !== null && _a !== void 0 ? _a : true };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pie-chart/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,gBAAgB,MAAM,+CAA+C,CA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,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;aAC/G,CAAC;KACL;AACH,CAAC;AAED,SAAS,aAAa,CAAC,IAAgD;IACrE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,gBAAgB,CACvB,OAAsC;;IAEtC,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,IAAI;QACjC,IAAI,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,QAAQ;KAChC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,MAAoC;;IAC3D,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,IAAI,EAAE,CAAC;AACzD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { forwardRef } from \"react\";\n\nimport { getDataAttributes } from \"../internal/base-component/get-data-attributes\";\nimport useBaseComponent from \"../internal/base-component/use-base-component\";\nimport { applyDisplayName } from \"../internal/utils/apply-display-name\";\nimport { SomeRequired } from \"../internal/utils/utils\";\nimport { InternalPieChart } from \"./chart-pie-internal\";\nimport { PieChartProps } from \"./interfaces\";\n\nexport type { PieChartProps };\n\nconst PieChart = forwardRef(({ fitHeight = false, ...props }: PieChartProps, ref: React.Ref<PieChartProps.Ref>) => {\n // We transform options before propagating them to the internal chart to ensure only those\n // defined in the component's contract can be propagated down to the underlying Highcharts.\n // Additionally, we assign all default options, including the nested ones.\n const series = transformSeries(props.series);\n const tooltip = transformTooltip(props.tooltip);\n const legend = transformLegend(props.legend);\n\n const baseComponentProps = useBaseComponent(\"PieChart\", { props: { fitHeight } });\n\n return (\n <InternalPieChart\n ref={ref}\n {...props}\n fitHeight={fitHeight}\n series={series}\n tooltip={tooltip}\n legend={legend}\n {...getDataAttributes(props)}\n {...baseComponentProps}\n />\n );\n});\n\napplyDisplayName(PieChart, \"PieChart\");\n\nexport default PieChart;\n\nfunction transformSeries(series: null | PieChartProps.SeriesOptions): readonly PieChartProps.SeriesOptions[] {\n if (!series) {\n return [];\n }\n switch (series.type) {\n case \"pie\":\n case \"donut\":\n return [\n { type: series.type, id: series.id, name: series.name, color: series.color, data: transformData(series.data) },\n ];\n }\n}\n\nfunction transformData(data: readonly PieChartProps.PieSegmentOptions[]): readonly PieChartProps.PieSegmentOptions[] {\n return data.map((d) => ({ id: d.id, name: d.name, color: d.color, y: d.y }));\n}\n\nfunction transformTooltip(\n tooltip?: PieChartProps.TooltipOptions,\n): SomeRequired<PieChartProps.TooltipOptions, \"enabled\" | \"size\"> {\n return {\n ...tooltip,\n enabled: tooltip?.enabled ?? true,\n size: tooltip?.size ?? \"medium\",\n };\n}\n\nfunction transformLegend(legend?: PieChartProps.LegendOptions): SomeRequired<PieChartProps.LegendOptions, \"enabled\"> {\n return { ...legend, enabled: legend?.enabled ?? true };\n}\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import * as CoreTypes from "../core/interfaces";
|
|
3
|
+
import { NonCancelableEventHandler } from "../internal/events";
|
|
4
|
+
export interface PieChartProps extends CoreTypes.BaseChartOptions, CoreTypes.WithPieI18nStrings {
|
|
5
|
+
/**
|
|
6
|
+
* Defines series options of the chart.
|
|
7
|
+
* This property corresponds to [series](https://api.highcharts.com/highcharts/series), and extends it
|
|
8
|
+
* with an additional "donut" series type.
|
|
9
|
+
*
|
|
10
|
+
* Supported series types:
|
|
11
|
+
* * [pie](https://api.highcharts.com/highcharts/series.pie).
|
|
12
|
+
* * donut - the pie series with predefined inner radius.
|
|
13
|
+
*/
|
|
14
|
+
series: null | PieChartProps.SeriesOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Defines tooltip options of the chart, including:
|
|
17
|
+
* * `enabled` - (optional, boolean) - Hides the tooltip when set to false.
|
|
18
|
+
* * `size` - (optional, "small" | "medium" | "large") - Specifies max tooltip size.
|
|
19
|
+
* * `details` - (optional, function) - Provides a list of key-value pairs as tooltip's body.
|
|
20
|
+
* * `header` - (optional, function) - Renders a custom tooltip header.
|
|
21
|
+
* * `body` - (optional, function) - Renders a custom tooltip body.
|
|
22
|
+
* * `footer` - (optional, function) - Renders a custom tooltip footer.
|
|
23
|
+
*/
|
|
24
|
+
tooltip?: PieChartProps.TooltipOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Specifies which segments to show using their IDs. By default, all segments are visible and managed by the component.
|
|
27
|
+
* If a segment doesn't have an ID, its name is used. When using this property, manage state updates with `onVisibleSegmentsChange`.
|
|
28
|
+
*/
|
|
29
|
+
visibleSegments?: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* A callback function, triggered when segments visibility changes as a result of user interaction with the legend or filter.
|
|
32
|
+
*/
|
|
33
|
+
onVisibleSegmentsChange?: NonCancelableEventHandler<{
|
|
34
|
+
visibleSegments: string[];
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* A function that determines the title of a segment displayed on the chart. The title appears above the segment
|
|
38
|
+
* description defined by `segmentDescription`. By default, it displays the segment name. You can hide the title
|
|
39
|
+
* by returning an empty string from the function.
|
|
40
|
+
*/
|
|
41
|
+
segmentTitle?: (props: PieChartProps.SegmentTitleRenderProps) => string;
|
|
42
|
+
/**
|
|
43
|
+
* A function determining the segment description displayed on the chart below the segment title.
|
|
44
|
+
*/
|
|
45
|
+
segmentDescription?: (props: PieChartProps.SegmentDescriptionRenderProps) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Title displayed in the donut chart's inner area.
|
|
48
|
+
*/
|
|
49
|
+
innerAreaTitle?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Description text displayed in the donut chart's inner area.
|
|
52
|
+
*/
|
|
53
|
+
innerAreaDescription?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare namespace PieChartProps {
|
|
56
|
+
export interface Ref {
|
|
57
|
+
/**
|
|
58
|
+
* Controls segments visibility and works with both controlled and uncontrolled visibility modes.
|
|
59
|
+
*/
|
|
60
|
+
setVisibleSegments(visibleSegments: readonly string[]): void;
|
|
61
|
+
/**
|
|
62
|
+
* Functions similarly to `setVisibleSeries`, but applies to all series and doesn't require series IDs as input.
|
|
63
|
+
* Use this when implementing clear-filter actions in no-match states.
|
|
64
|
+
*/
|
|
65
|
+
showAllSegments(): void;
|
|
66
|
+
}
|
|
67
|
+
export type SeriesOptions = PieSeriesOptions | DonutSeriesOptions;
|
|
68
|
+
export type PieSeriesOptions = CoreTypes.PieSeriesOptions;
|
|
69
|
+
export type DonutSeriesOptions = CoreTypes.DonutSeriesOptions;
|
|
70
|
+
export type PieSegmentOptions = CoreTypes.PieSegmentOptions;
|
|
71
|
+
export interface TooltipOptions {
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
size?: "small" | "medium" | "large";
|
|
74
|
+
details?: (props: TooltipDetailsRenderProps) => readonly TooltipDetail[];
|
|
75
|
+
header?: (props: TooltipHeaderRenderProps) => React.ReactNode;
|
|
76
|
+
body?: (props: TooltipBodyRenderProps) => React.ReactNode;
|
|
77
|
+
footer?: (props: TooltipFooterRenderProps) => React.ReactNode;
|
|
78
|
+
}
|
|
79
|
+
export type TooltipDetailsRenderProps = TooltipSlotRenderProps;
|
|
80
|
+
export type TooltipHeaderRenderProps = TooltipSlotRenderProps;
|
|
81
|
+
export type TooltipBodyRenderProps = TooltipSlotRenderProps;
|
|
82
|
+
export type TooltipFooterRenderProps = TooltipSlotRenderProps;
|
|
83
|
+
interface TooltipSlotRenderProps {
|
|
84
|
+
segmentId?: string;
|
|
85
|
+
segmentName: string;
|
|
86
|
+
segmentValue: number;
|
|
87
|
+
totalValue: number;
|
|
88
|
+
}
|
|
89
|
+
export type TooltipDetail = CoreTypes.BaseTooltipDetail;
|
|
90
|
+
export type SegmentTitleRenderProps = SegmentDescriptionRenderProps;
|
|
91
|
+
export interface SegmentDescriptionRenderProps {
|
|
92
|
+
segmentId?: string;
|
|
93
|
+
segmentName: string;
|
|
94
|
+
segmentValue: number;
|
|
95
|
+
totalValue: number;
|
|
96
|
+
}
|
|
97
|
+
export type LegendOptions = CoreTypes.BaseLegendOptions;
|
|
98
|
+
export type FilterOptions = CoreTypes.BaseFilterOptions;
|
|
99
|
+
export type NoDataOptions = CoreTypes.BaseNoDataOptions;
|
|
100
|
+
export {};
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/pie-chart/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport * as CoreTypes from \"../core/interfaces\";\nimport { NonCancelableEventHandler } from \"../internal/events\";\n\n// PieChartProps is the type for PieChart React component properties. Unlike in Highcharts API,\n// we pass options directly to the component, instead of grouping them all into a single \"options\" property.\n// We do still organize related options in groups, e.g.: \"SeriesOptions\", \"TooltipOptions\".\nexport interface PieChartProps extends CoreTypes.BaseChartOptions, CoreTypes.WithPieI18nStrings {\n /**\n * Defines series options of the chart.\n * This property corresponds to [series](https://api.highcharts.com/highcharts/series), and extends it\n * with an additional \"donut\" series type.\n *\n * Supported series types:\n * * [pie](https://api.highcharts.com/highcharts/series.pie).\n * * donut - the pie series with predefined inner radius.\n */\n series: null | PieChartProps.SeriesOptions;\n\n /**\n * Defines tooltip options of the chart, including:\n * * `enabled` - (optional, boolean) - Hides the tooltip when set to false.\n * * `size` - (optional, \"small\" | \"medium\" | \"large\") - Specifies max tooltip size.\n * * `details` - (optional, function) - Provides a list of key-value pairs as tooltip's body.\n * * `header` - (optional, function) - Renders a custom tooltip header.\n * * `body` - (optional, function) - Renders a custom tooltip body.\n * * `footer` - (optional, function) - Renders a custom tooltip footer.\n */\n tooltip?: PieChartProps.TooltipOptions;\n\n /**\n * Specifies which segments to show using their IDs. By default, all segments are visible and managed by the component.\n * If a segment doesn't have an ID, its name is used. When using this property, manage state updates with `onVisibleSegmentsChange`.\n */\n visibleSegments?: readonly string[];\n\n /**\n * A callback function, triggered when segments visibility changes as a result of user interaction with the legend or filter.\n */\n onVisibleSegmentsChange?: NonCancelableEventHandler<{ visibleSegments: string[] }>;\n\n /**\n * A function that determines the title of a segment displayed on the chart. The title appears above the segment\n * description defined by `segmentDescription`. By default, it displays the segment name. You can hide the title\n * by returning an empty string from the function.\n */\n segmentTitle?: (props: PieChartProps.SegmentTitleRenderProps) => string;\n\n /**\n * A function determining the segment description displayed on the chart below the segment title.\n */\n segmentDescription?: (props: PieChartProps.SegmentDescriptionRenderProps) => string;\n\n /**\n * Title displayed in the donut chart's inner area.\n */\n innerAreaTitle?: string;\n\n /**\n * Description text displayed in the donut chart's inner area.\n */\n innerAreaDescription?: string;\n}\n\nexport namespace PieChartProps {\n export interface Ref {\n /**\n * Controls segments visibility and works with both controlled and uncontrolled visibility modes.\n */\n setVisibleSegments(visibleSegments: readonly string[]): void;\n /**\n * Functions similarly to `setVisibleSeries`, but applies to all series and doesn't require series IDs as input.\n * Use this when implementing clear-filter actions in no-match states.\n */\n showAllSegments(): void;\n }\n\n export type SeriesOptions = PieSeriesOptions | DonutSeriesOptions;\n\n export type PieSeriesOptions = CoreTypes.PieSeriesOptions;\n\n export type DonutSeriesOptions = CoreTypes.DonutSeriesOptions;\n\n export type PieSegmentOptions = CoreTypes.PieSegmentOptions;\n\n export interface TooltipOptions {\n enabled?: boolean;\n size?: \"small\" | \"medium\" | \"large\";\n details?: (props: TooltipDetailsRenderProps) => readonly TooltipDetail[];\n header?: (props: TooltipHeaderRenderProps) => React.ReactNode;\n body?: (props: TooltipBodyRenderProps) => React.ReactNode;\n footer?: (props: TooltipFooterRenderProps) => React.ReactNode;\n }\n\n export type TooltipDetailsRenderProps = TooltipSlotRenderProps;\n export type TooltipHeaderRenderProps = TooltipSlotRenderProps;\n export type TooltipBodyRenderProps = TooltipSlotRenderProps;\n export type TooltipFooterRenderProps = TooltipSlotRenderProps;\n interface TooltipSlotRenderProps {\n segmentId?: string;\n segmentName: string;\n segmentValue: number;\n totalValue: number;\n }\n\n export type TooltipDetail = CoreTypes.BaseTooltipDetail;\n\n export type SegmentTitleRenderProps = SegmentDescriptionRenderProps;\n export interface SegmentDescriptionRenderProps {\n segmentId?: string;\n segmentName: string;\n segmentValue: number;\n totalValue: number;\n }\n\n export type LegendOptions = CoreTypes.BaseLegendOptions;\n\n export type FilterOptions = CoreTypes.BaseFilterOptions;\n\n export type NoDataOptions = CoreTypes.BaseNoDataOptions;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
.awsui_root_w23ep_1jii0_5:not(#\9),
|
|
6
|
+
.awsui_inner-value_w23ep_1jii0_6:not(#\9),
|
|
7
|
+
.awsui_inner-description_w23ep_1jii0_7:not(#\9) {
|
|
8
|
+
/* used in test-utils */
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
|
|
2
|
+
// es-module interop with Babel and Typescript
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
module.exports.default = {
|
|
5
|
+
"root": "awsui_root_w23ep_1jii0_5",
|
|
6
|
+
"inner-value": "awsui_inner-value_w23ep_1jii0_6",
|
|
7
|
+
"inner-description": "awsui_inner-description_w23ep_1jii0_7"
|
|
8
|
+
};
|
|
9
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ElementWrapper } from "@cloudscape-design/test-utils-core/dom";
|
|
2
|
+
import BaseChartWrapper from "../internal/base";
|
|
3
|
+
import { CartesianChartTooltipWrapper } from "./tooltip";
|
|
4
|
+
export default class CartesianChartWrapper extends BaseChartWrapper {
|
|
5
|
+
static rootSelector: string;
|
|
6
|
+
/**
|
|
7
|
+
* Finds chart's tooltip when visible.
|
|
8
|
+
*/
|
|
9
|
+
findTooltip(): null | CartesianChartTooltipWrapper;
|
|
10
|
+
/**
|
|
11
|
+
* Finds series elements. Use this to assert the number of visible series.
|
|
12
|
+
*/
|
|
13
|
+
findSeries(): Array<ElementWrapper>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const base_1 = require("../internal/base");
|
|
6
|
+
const tooltip_1 = require("./tooltip");
|
|
7
|
+
const styles_selectors_js_1 = require("../../../cartesian-chart/test-classes/styles.selectors.js");
|
|
8
|
+
class CartesianChartWrapper extends base_1.default {
|
|
9
|
+
/**
|
|
10
|
+
* Finds chart's tooltip when visible.
|
|
11
|
+
*/
|
|
12
|
+
findTooltip() {
|
|
13
|
+
return this.findComponent(`.${tooltip_1.CartesianChartTooltipWrapper.rootSelector}`, tooltip_1.CartesianChartTooltipWrapper);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Finds series elements. Use this to assert the number of visible series.
|
|
17
|
+
*/
|
|
18
|
+
findSeries() {
|
|
19
|
+
return this.findAllByClassName("highcharts-series");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = CartesianChartWrapper;
|
|
23
|
+
CartesianChartWrapper.rootSelector = styles_selectors_js_1.default.root;
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/test-utils/dom/cartesian-chart/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAItC,2CAAgD;AAChD,uCAAyD;AAEzD,mGAAoF;AAEpF,MAAqB,qBAAsB,SAAQ,cAAgB;IAGjE;;OAEG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,sCAA4B,CAAC,YAAY,EAAE,EAAE,sCAA4B,CAAC,CAAC;IAC3G,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IACtD,CAAC;;AAfH,wCAgBC;AAfQ,kCAAY,GAAW,6BAAW,CAAC,IAAI,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ElementWrapper } from \"@cloudscape-design/test-utils-core/dom\";\n\nimport BaseChartWrapper from \"../internal/base\";\nimport { CartesianChartTooltipWrapper } from \"./tooltip\";\n\nimport testClasses from \"../../../cartesian-chart/test-classes/styles.selectors.js\";\n\nexport default class CartesianChartWrapper extends BaseChartWrapper {\n static rootSelector: string = testClasses.root;\n\n /**\n * Finds chart's tooltip when visible.\n */\n public findTooltip(): null | CartesianChartTooltipWrapper {\n return this.findComponent(`.${CartesianChartTooltipWrapper.rootSelector}`, CartesianChartTooltipWrapper);\n }\n\n /**\n * Finds series elements. Use this to assert the number of visible series.\n */\n public findSeries(): Array<ElementWrapper> {\n return this.findAllByClassName(\"highcharts-series\");\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import ChartTooltipWrapper from "@cloudscape-design/components/test-utils/dom/internal/chart-tooltip";
|
|
2
|
+
import { ComponentWrapper, ElementWrapper } from "@cloudscape-design/test-utils-core/dom";
|
|
3
|
+
export declare class CartesianChartTooltipWrapper extends ChartTooltipWrapper {
|
|
4
|
+
/**
|
|
5
|
+
* Finds matched tooltip points.
|
|
6
|
+
*/
|
|
7
|
+
findPoints(): PointDetailsItemWrapper[];
|
|
8
|
+
}
|
|
9
|
+
export declare class PointDetailsSubItemWrapper extends ComponentWrapper {
|
|
10
|
+
/**
|
|
11
|
+
* Finds tooltip point key.
|
|
12
|
+
*/
|
|
13
|
+
findKey(): ElementWrapper;
|
|
14
|
+
/**
|
|
15
|
+
* Finds tooltip point value.
|
|
16
|
+
*/
|
|
17
|
+
findValue(): ElementWrapper;
|
|
18
|
+
/**
|
|
19
|
+
* Finds tooltip point description when defined.
|
|
20
|
+
*/
|
|
21
|
+
findDescription(): null | ElementWrapper;
|
|
22
|
+
}
|
|
23
|
+
export declare class PointDetailsItemWrapper extends PointDetailsSubItemWrapper {
|
|
24
|
+
/**
|
|
25
|
+
* Finds point sub-items when defined.
|
|
26
|
+
*/
|
|
27
|
+
findSubItems(): Array<PointDetailsSubItemWrapper>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PointDetailsItemWrapper = exports.PointDetailsSubItemWrapper = exports.CartesianChartTooltipWrapper = void 0;
|
|
6
|
+
const chart_tooltip_1 = require("@cloudscape-design/components/test-utils/dom/internal/chart-tooltip");
|
|
7
|
+
const dom_1 = require("@cloudscape-design/test-utils-core/dom");
|
|
8
|
+
const styles_selectors_js_1 = require("../../../internal/components/series-details/test-classes/styles.selectors.js");
|
|
9
|
+
class CartesianChartTooltipWrapper extends chart_tooltip_1.default {
|
|
10
|
+
/**
|
|
11
|
+
* Finds matched tooltip points.
|
|
12
|
+
*/
|
|
13
|
+
findPoints() {
|
|
14
|
+
return this.findAll(`.${styles_selectors_js_1.default["list-item"]}`).map((wrapper) => new PointDetailsItemWrapper(wrapper.getElement()));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.CartesianChartTooltipWrapper = CartesianChartTooltipWrapper;
|
|
18
|
+
class PointDetailsSubItemWrapper extends dom_1.ComponentWrapper {
|
|
19
|
+
/**
|
|
20
|
+
* Finds tooltip point key.
|
|
21
|
+
*/
|
|
22
|
+
findKey() {
|
|
23
|
+
return this.findByClassName(styles_selectors_js_1.default.key);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Finds tooltip point value.
|
|
27
|
+
*/
|
|
28
|
+
findValue() {
|
|
29
|
+
return this.findByClassName(styles_selectors_js_1.default.value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Finds tooltip point description when defined.
|
|
33
|
+
*/
|
|
34
|
+
findDescription() {
|
|
35
|
+
return this.findByClassName(styles_selectors_js_1.default.description);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.PointDetailsSubItemWrapper = PointDetailsSubItemWrapper;
|
|
39
|
+
class PointDetailsItemWrapper extends PointDetailsSubItemWrapper {
|
|
40
|
+
/**
|
|
41
|
+
* Finds point sub-items when defined.
|
|
42
|
+
*/
|
|
43
|
+
findSubItems() {
|
|
44
|
+
return this.findAll(`.${styles_selectors_js_1.default["inner-list-item"]}`).map((wrapper) => new PointDetailsSubItemWrapper(wrapper.getElement()));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.PointDetailsItemWrapper = PointDetailsItemWrapper;
|
|
48
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../../../../src/test-utils/dom/cartesian-chart/tooltip.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,uGAAsG;AACtG,gEAA0F;AAE1F,sHAAoH;AAEpH,MAAa,4BAA6B,SAAQ,uBAAmB;IACnE;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,6BAAwB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,CAClE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC;CACF;AATD,oEASC;AAED,MAAa,0BAA2B,SAAQ,sBAAgB;IAC9D;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,eAAe,CAAC,6BAAwB,CAAC,GAAG,CAAE,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,eAAe,CAAC,6BAAwB,CAAC,KAAK,CAAE,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,eAAe,CAAC,6BAAwB,CAAC,WAAW,CAAC,CAAC;IACpE,CAAC;CACF;AArBD,gEAqBC;AAED,MAAa,uBAAwB,SAAQ,0BAA0B;IACrE;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,6BAAwB,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,CACxE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAClE,CAAC;IACJ,CAAC;CACF;AATD,0DASC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport ChartTooltipWrapper from \"@cloudscape-design/components/test-utils/dom/internal/chart-tooltip\";\nimport { ComponentWrapper, ElementWrapper } from \"@cloudscape-design/test-utils-core/dom\";\n\nimport seriesDetailsTestClasses from \"../../../internal/components/series-details/test-classes/styles.selectors.js\";\n\nexport class CartesianChartTooltipWrapper extends ChartTooltipWrapper {\n /**\n * Finds matched tooltip points.\n */\n findPoints() {\n return this.findAll(`.${seriesDetailsTestClasses[\"list-item\"]}`).map(\n (wrapper) => new PointDetailsItemWrapper(wrapper.getElement()),\n );\n }\n}\n\nexport class PointDetailsSubItemWrapper extends ComponentWrapper {\n /**\n * Finds tooltip point key.\n */\n findKey(): ElementWrapper {\n return this.findByClassName(seriesDetailsTestClasses.key)!;\n }\n\n /**\n * Finds tooltip point value.\n */\n findValue(): ElementWrapper {\n return this.findByClassName(seriesDetailsTestClasses.value)!;\n }\n\n /**\n * Finds tooltip point description when defined.\n */\n findDescription(): null | ElementWrapper {\n return this.findByClassName(seriesDetailsTestClasses.description);\n }\n}\n\nexport class PointDetailsItemWrapper extends PointDetailsSubItemWrapper {\n /**\n * Finds point sub-items when defined.\n */\n findSubItems(): Array<PointDetailsSubItemWrapper> {\n return this.findAll(`.${seriesDetailsTestClasses[\"inner-list-item\"]}`).map(\n (wrapper) => new PointDetailsSubItemWrapper(wrapper.getElement()),\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ElementWrapper } from "@cloudscape-design/test-utils-core/dom";
|
|
2
|
+
export { ElementWrapper };
|
|
3
|
+
import CartesianChartWrapper from "./cartesian-chart";
|
|
4
|
+
import PieChartWrapper from "./pie-chart";
|
|
5
|
+
export { CartesianChartWrapper, PieChartWrapper };
|
|
6
|
+
declare module "@cloudscape-design/test-utils-core/dist/dom" {
|
|
7
|
+
interface ElementWrapper {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the wrapper of the first cartesian chart that matches the specified CSS selector.
|
|
10
|
+
* If no CSS selector is specified, returns the wrapper of the first cartesian chart.
|
|
11
|
+
* If no matching chart is found, returns `null`.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} [selector] CSS Selector
|
|
14
|
+
* @returns {CartesianChartWrapper | null}
|
|
15
|
+
*/
|
|
16
|
+
findCartesianHighcharts(selector?: string): CartesianChartWrapper | null;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the wrapper of the first pie chart that matches the specified CSS selector.
|
|
19
|
+
* If no CSS selector is specified, returns the wrapper of the first pie chart.
|
|
20
|
+
* If no matching chart is found, returns `null`.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} [selector] CSS Selector
|
|
23
|
+
* @returns {PieChartWrapper | null}
|
|
24
|
+
*/
|
|
25
|
+
findPieHighcharts(selector?: string): PieChartWrapper | null;
|
|
26
|
+
/**
|
|
27
|
+
* Returns an array of cartesian chart wrappers that matches the specified CSS selector.
|
|
28
|
+
* If no CSS selector is specified, returns all cartesian charts inside the current wrapper.
|
|
29
|
+
* If no matching chart is found, returns an empty array.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} [selector] CSS Selector
|
|
32
|
+
* @returns {CartesianChartWrapper[]}
|
|
33
|
+
*/
|
|
34
|
+
findAllCartesianHighcharts(selector?: string): Array<CartesianChartWrapper>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns an array of pie chart wrappers that matches the specified CSS selector.
|
|
37
|
+
* If no CSS selector is specified, returns all pie charts inside the current wrapper.
|
|
38
|
+
* If no matching chart is found, returns an empty array.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} [selector] CSS Selector
|
|
41
|
+
* @returns {PieChartWrapper[]}
|
|
42
|
+
*/
|
|
43
|
+
findAllPieHighcharts(selector?: string): Array<PieChartWrapper>;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export default function wrapper(root?: Element): ElementWrapper<Element>;
|