@cloudscape-design/components 3.0.340 → 3.0.342
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/area-chart/chart-container.d.ts +3 -1
- package/area-chart/chart-container.d.ts.map +1 -1
- package/area-chart/chart-container.js +3 -2
- package/area-chart/chart-container.js.map +1 -1
- package/area-chart/internal.d.ts +1 -1
- package/area-chart/internal.d.ts.map +1 -1
- package/area-chart/internal.js +3 -2
- package/area-chart/internal.js.map +1 -1
- package/area-chart/model/index.d.ts +1 -0
- package/area-chart/model/index.d.ts.map +1 -1
- package/area-chart/model/index.js.map +1 -1
- package/area-chart/model/use-chart-model.d.ts +2 -1
- package/area-chart/model/use-chart-model.d.ts.map +1 -1
- package/area-chart/model/use-chart-model.js +8 -2
- package/area-chart/model/use-chart-model.js.map +1 -1
- package/internal/analytics/index.d.ts.map +1 -1
- package/internal/analytics/index.js +1 -0
- package/internal/analytics/index.js.map +1 -1
- package/internal/analytics/interfaces.d.ts +13 -2
- package/internal/analytics/interfaces.d.ts.map +1 -1
- package/internal/analytics/interfaces.js.map +1 -1
- package/internal/components/cartesian-chart/chart-container.d.ts +2 -0
- package/internal/components/cartesian-chart/chart-container.d.ts.map +1 -1
- package/internal/components/cartesian-chart/chart-container.js +16 -3
- package/internal/components/cartesian-chart/chart-container.js.map +1 -1
- package/internal/components/cartesian-chart/interfaces.d.ts +5 -0
- package/internal/components/cartesian-chart/interfaces.d.ts.map +1 -1
- package/internal/components/cartesian-chart/interfaces.js.map +1 -1
- package/internal/components/cartesian-chart/styles.css.js +27 -23
- package/internal/components/cartesian-chart/styles.scoped.css +54 -27
- package/internal/components/cartesian-chart/styles.selectors.js +27 -23
- package/internal/components/chart-plot/index.d.ts +2 -2
- package/internal/components/chart-plot/index.d.ts.map +1 -1
- package/internal/components/chart-plot/index.js +3 -1
- package/internal/components/chart-plot/index.js.map +1 -1
- package/internal/components/chart-wrapper/index.d.ts +1 -0
- package/internal/components/chart-wrapper/index.d.ts.map +1 -1
- package/internal/components/chart-wrapper/index.js +21 -6
- package/internal/components/chart-wrapper/index.js.map +1 -1
- package/internal/components/chart-wrapper/styles.css.js +9 -6
- package/internal/components/chart-wrapper/styles.scoped.css +20 -6
- package/internal/components/chart-wrapper/styles.selectors.js +9 -6
- package/internal/environment.js +1 -1
- package/internal/manifest.json +1 -1
- package/mixed-line-bar-chart/chart-container.d.ts +2 -1
- package/mixed-line-bar-chart/chart-container.d.ts.map +1 -1
- package/mixed-line-bar-chart/chart-container.js +8 -2
- package/mixed-line-bar-chart/chart-container.js.map +1 -1
- package/mixed-line-bar-chart/internal.d.ts +1 -1
- package/mixed-line-bar-chart/internal.d.ts.map +1 -1
- package/mixed-line-bar-chart/internal.js +3 -3
- package/mixed-line-bar-chart/internal.js.map +1 -1
- package/package.json +1 -1
- package/pie-chart/index.d.ts +1 -1
- package/pie-chart/index.d.ts.map +1 -1
- package/pie-chart/index.js +10 -3
- package/pie-chart/index.js.map +1 -1
- package/pie-chart/interfaces.d.ts +5 -0
- package/pie-chart/interfaces.d.ts.map +1 -1
- package/pie-chart/interfaces.js.map +1 -1
- package/pie-chart/labels.d.ts +3 -2
- package/pie-chart/labels.d.ts.map +1 -1
- package/pie-chart/labels.js +4 -4
- package/pie-chart/labels.js.map +1 -1
- package/pie-chart/pie-chart.d.ts +2 -1
- package/pie-chart/pie-chart.d.ts.map +1 -1
- package/pie-chart/pie-chart.js +18 -14
- package/pie-chart/pie-chart.js.map +1 -1
- package/pie-chart/segments.d.ts +3 -2
- package/pie-chart/segments.d.ts.map +1 -1
- package/pie-chart/segments.js +2 -6
- package/pie-chart/segments.js.map +1 -1
- package/pie-chart/styles.css.js +27 -23
- package/pie-chart/styles.scoped.css +58 -38
- package/pie-chart/styles.selectors.js +27 -23
- package/pie-chart/utils.d.ts +12 -2
- package/pie-chart/utils.d.ts.map +1 -1
- package/pie-chart/utils.js +37 -9
- package/pie-chart/utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segments.js","sourceRoot":"lib/default/","sources":["pie-chart/segments.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAe,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"segments.js","sourceRoot":"lib/default/","sources":["pie-chart/segments.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAe,MAAM,UAAU,CAAC;AAK5C,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAe3D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAgC,EAC9D,OAAO,EACP,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,UAAU,GACO;IACjB,MAAM,IAAI,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAE1C,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;QACzD,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC;QACtC,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;QACnE,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,IAAI,CAAC,CAAC;QAElD,MAAM,UAAU,GAAG,GAAG,EAAwC;aAC3D,WAAW,CAAC,WAAW,CAAC;aACxB,WAAW,CAAC,MAAM,CAAC;aACnB,YAAY,CAAC,YAAY,CAAC,CAAC;QAE9B,MA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BACxB,CAAC,CAAC,cAAc,EAAE,CAAC;gBACrB,CAAC,EACD,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAC1C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oBAC9B,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,EAAE,aAAa;oBAC/C,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE,QAAQ;iBACtC,CAAC,EACF,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,gBACtC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EACnE,IAAI,EAAC,QAAQ,0BACS,IAAI,CAAC,wCAAwC,EAAE,0BAA0B,CAAC;gBAEhG,8BAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,aAAa,iBAAc,MAAM,GAAG;gBAChG,8BACE,CAAC,EAAE,eAAe,EAClB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,EACtB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,kBAAkB,CAAC,iBACpD,MAAM,GAClB,CACA,CACL,CAAC;QACJ,CAAC,CAAC;QAEF,gDAAY,QAAQ,IAAE,GAAG,EAAE,eAAe,EAAE,CAAC,EAAC,GAAG,EAAC,OAAO,EAAC,GAAG,iBAAa,MAAM,IAAG,CACjF,CACL,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo } from 'react';\nimport { arc, PieArcDatum } from 'd3-shape';\n\nimport { PieChartProps } from './interfaces';\nimport { Dimension } from './utils';\nimport { InternalChartDatum } from './pie-chart';\nimport styles from './styles.css.js';\nimport clsx from 'clsx';\nimport { useInternalI18n } from '../internal/i18n/context';\n\ninterface SegmentsProps<T> {\n pieData: Array<PieArcDatum<InternalChartDatum<T>>>;\n highlightedSegment: T | null;\n dimensions: Dimension;\n variant: PieChartProps['variant'];\n focusedSegmentRef: React.RefObject<SVGGElement>;\n popoverTrackRef: React.RefObject<SVGCircleElement>;\n segmentAriaRoleDescription?: string;\n onMouseDown: (datum: InternalChartDatum<T>) => void;\n onMouseOver: (datum: InternalChartDatum<T>) => void;\n onMouseOut: (event: React.MouseEvent<SVGElement>) => void;\n}\n\nexport default function Segments<T extends PieChartProps.Datum>({\n pieData,\n highlightedSegment,\n dimensions,\n variant,\n focusedSegmentRef,\n popoverTrackRef,\n segmentAriaRoleDescription,\n onMouseDown,\n onMouseOver,\n onMouseOut,\n}: SegmentsProps<T>) {\n const i18n = useInternalI18n('pie-chart');\n\n const { arcFactory, highlightedArcFactory } = useMemo(() => {\n const radius = dimensions.outerRadius;\n const innerRadius = variant === 'pie' ? 0 : dimensions.innerRadius;\n const cornerRadius = dimensions.cornerRadius || 0;\n\n const arcFactory = arc<PieArcDatum<InternalChartDatum<any>>>()\n .innerRadius(innerRadius)\n .outerRadius(radius)\n .cornerRadius(cornerRadius);\n\n const highlightedArcFactory = arc<PieArcDatum<InternalChartDatum<any>>>()\n .innerRadius(radius + 4)\n .outerRadius(radius + 6);\n\n return {\n arcFactory,\n highlightedArcFactory,\n };\n }, [dimensions, variant]);\n\n const centroid = useMemo(() => {\n for (const datum of pieData) {\n if (datum.data.datum === highlightedSegment) {\n const [centroidLeft, centroidTop] = arcFactory.centroid(datum);\n return { cx: centroidLeft, cy: centroidTop };\n }\n }\n return null;\n }, [highlightedSegment, pieData, arcFactory]);\n\n return (\n <g onMouseLeave={event => onMouseOut(event)}>\n {pieData.map(datum => {\n const isHighlighted = highlightedSegment === datum.data.datum;\n const isDimmed = highlightedSegment !== null && !isHighlighted;\n const arcPath = arcFactory(datum) || undefined;\n const highlightedPath = highlightedArcFactory(datum) || undefined;\n return (\n <g\n key={datum.data.index}\n onMouseDown={e => {\n onMouseDown(datum.data);\n e.preventDefault();\n }}\n onMouseOver={() => onMouseOver(datum.data)}\n className={clsx(styles.segment, {\n [styles['segment--highlighted']]: isHighlighted,\n [styles['segment--dimmed']]: isDimmed,\n })}\n ref={isHighlighted ? focusedSegmentRef : undefined}\n aria-label={`${datum.data.datum.title} (${datum.data.datum.value})`}\n role=\"button\"\n aria-roledescription={i18n('i18nStrings.segmentAriaRoleDescription', segmentAriaRoleDescription)}\n >\n <path d={arcPath} fill={datum.data.color} className={styles.segment__path} aria-hidden=\"true\" />\n <path\n d={highlightedPath}\n fill={datum.data.color}\n className={clsx(styles.segment__path, styles.segment__highlight)}\n aria-hidden=\"true\"\n />\n </g>\n );\n })}\n\n <circle {...centroid} ref={popoverTrackRef} r=\"1\" opacity=\"0\" aria-hidden=\"true\" />\n </g>\n );\n}\n"]}
|
package/pie-chart/styles.css.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"segment__path": "
|
|
5
|
-
"segment": "
|
|
6
|
-
"segment__hover": "
|
|
7
|
-
"label": "
|
|
8
|
-
"root": "
|
|
9
|
-
"content": "
|
|
10
|
-
"content--small": "awsui_content--
|
|
11
|
-
"content--without-labels": "awsui_content--without-
|
|
12
|
-
"content--medium": "awsui_content--
|
|
13
|
-
"content--large": "awsui_content--
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"label
|
|
25
|
-
"label--
|
|
26
|
-
"
|
|
4
|
+
"segment__path": "awsui_segment__path_1edmh_1ng0v_97",
|
|
5
|
+
"segment": "awsui_segment_1edmh_1ng0v_97",
|
|
6
|
+
"segment__hover": "awsui_segment__hover_1edmh_1ng0v_124",
|
|
7
|
+
"label": "awsui_label_1edmh_1ng0v_138",
|
|
8
|
+
"root": "awsui_root_1edmh_1ng0v_156",
|
|
9
|
+
"content": "awsui_content_1edmh_1ng0v_160",
|
|
10
|
+
"content--small": "awsui_content--small_1edmh_1ng0v_160",
|
|
11
|
+
"content--without-labels": "awsui_content--without-labels_1edmh_1ng0v_163",
|
|
12
|
+
"content--medium": "awsui_content--medium_1edmh_1ng0v_166",
|
|
13
|
+
"content--large": "awsui_content--large_1edmh_1ng0v_172",
|
|
14
|
+
"content--fit-height": "awsui_content--fit-height_1edmh_1ng0v_179",
|
|
15
|
+
"status-container": "awsui_status-container_1edmh_1ng0v_183",
|
|
16
|
+
"chart-container": "awsui_chart-container_1edmh_1ng0v_187",
|
|
17
|
+
"chart-container--fit-height": "awsui_chart-container--fit-height_1edmh_1ng0v_191",
|
|
18
|
+
"chart-container-chart-plot": "awsui_chart-container-chart-plot_1edmh_1ng0v_196",
|
|
19
|
+
"chart-container-chart-plot--fit-height": "awsui_chart-container-chart-plot--fit-height_1edmh_1ng0v_199",
|
|
20
|
+
"inner-content": "awsui_inner-content_1edmh_1ng0v_208",
|
|
21
|
+
"segment__highlight": "awsui_segment__highlight_1edmh_1ng0v_222",
|
|
22
|
+
"segment--dimmed": "awsui_segment--dimmed_1edmh_1ng0v_237",
|
|
23
|
+
"segment--highlighted": "awsui_segment--highlighted_1edmh_1ng0v_240",
|
|
24
|
+
"label--dimmed": "awsui_label--dimmed_1edmh_1ng0v_257",
|
|
25
|
+
"label--align-right": "awsui_label--align-right_1edmh_1ng0v_260",
|
|
26
|
+
"label-text": "awsui_label-text_1edmh_1ng0v_268",
|
|
27
|
+
"label__description": "awsui_label__description_1edmh_1ng0v_276",
|
|
28
|
+
"label-line": "awsui_label-line_1edmh_1ng0v_283",
|
|
29
|
+
"label--highlighted": "awsui_label--highlighted_1edmh_1ng0v_287",
|
|
30
|
+
"popover-header": "awsui_popover-header_1edmh_1ng0v_291"
|
|
27
31
|
};
|
|
28
32
|
|
|
@@ -94,57 +94,57 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
94
94
|
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
95
95
|
SPDX-License-Identifier: Apache-2.0
|
|
96
96
|
*/
|
|
97
|
-
.
|
|
97
|
+
.awsui_segment__path_1edmh_1ng0v_97:not(#\9) {
|
|
98
98
|
transition: opacity var(--motion-duration-transition-quick-0viajb, 90ms) var(--motion-easing-transition-quick-191occ, linear);
|
|
99
99
|
}
|
|
100
100
|
@media (prefers-reduced-motion: reduce) {
|
|
101
|
-
.
|
|
101
|
+
.awsui_segment__path_1edmh_1ng0v_97:not(#\9) {
|
|
102
102
|
animation: none;
|
|
103
103
|
transition: none;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
.awsui-motion-disabled .
|
|
106
|
+
.awsui-motion-disabled .awsui_segment__path_1edmh_1ng0v_97:not(#\9), .awsui-mode-entering .awsui_segment__path_1edmh_1ng0v_97:not(#\9) {
|
|
107
107
|
animation: none;
|
|
108
108
|
transition: none;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
.
|
|
111
|
+
.awsui_segment_1edmh_1ng0v_97:not(#\9) {
|
|
112
112
|
transition: opacity var(--motion-duration-transition-quick-0viajb, 90ms) var(--motion-easing-transition-quick-191occ, linear);
|
|
113
113
|
}
|
|
114
114
|
@media (prefers-reduced-motion: reduce) {
|
|
115
|
-
.
|
|
115
|
+
.awsui_segment_1edmh_1ng0v_97:not(#\9) {
|
|
116
116
|
animation: none;
|
|
117
117
|
transition: none;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
.awsui-motion-disabled .
|
|
120
|
+
.awsui-motion-disabled .awsui_segment_1edmh_1ng0v_97:not(#\9), .awsui-mode-entering .awsui_segment_1edmh_1ng0v_97:not(#\9) {
|
|
121
121
|
animation: none;
|
|
122
122
|
transition: none;
|
|
123
123
|
}
|
|
124
|
-
.
|
|
124
|
+
.awsui_segment_1edmh_1ng0v_97 > .awsui_segment__hover_1edmh_1ng0v_124:not(#\9) {
|
|
125
125
|
transition: opacity var(--motion-duration-transition-quick-0viajb, 90ms) var(--motion-easing-transition-quick-191occ, linear);
|
|
126
126
|
}
|
|
127
127
|
@media (prefers-reduced-motion: reduce) {
|
|
128
|
-
.
|
|
128
|
+
.awsui_segment_1edmh_1ng0v_97 > .awsui_segment__hover_1edmh_1ng0v_124:not(#\9) {
|
|
129
129
|
animation: none;
|
|
130
130
|
transition: none;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
.awsui-motion-disabled .
|
|
133
|
+
.awsui-motion-disabled .awsui_segment_1edmh_1ng0v_97 > .awsui_segment__hover_1edmh_1ng0v_124:not(#\9), .awsui-mode-entering .awsui_segment_1edmh_1ng0v_97 > .awsui_segment__hover_1edmh_1ng0v_124:not(#\9) {
|
|
134
134
|
animation: none;
|
|
135
135
|
transition: none;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
.
|
|
138
|
+
.awsui_label_1edmh_1ng0v_138:not(#\9) {
|
|
139
139
|
transition: opacity var(--motion-duration-transition-quick-0viajb, 90ms) var(--motion-easing-transition-quick-191occ, linear);
|
|
140
140
|
}
|
|
141
141
|
@media (prefers-reduced-motion: reduce) {
|
|
142
|
-
.
|
|
142
|
+
.awsui_label_1edmh_1ng0v_138:not(#\9) {
|
|
143
143
|
animation: none;
|
|
144
144
|
transition: none;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
.awsui-motion-disabled .
|
|
147
|
+
.awsui-motion-disabled .awsui_label_1edmh_1ng0v_138:not(#\9), .awsui-mode-entering .awsui_label_1edmh_1ng0v_138:not(#\9) {
|
|
148
148
|
animation: none;
|
|
149
149
|
transition: none;
|
|
150
150
|
}
|
|
@@ -153,39 +153,59 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
153
153
|
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
154
154
|
SPDX-License-Identifier: Apache-2.0
|
|
155
155
|
*/
|
|
156
|
-
.
|
|
156
|
+
.awsui_root_1edmh_1ng0v_156:not(#\9) {
|
|
157
157
|
/* used in test-utils */
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
.
|
|
160
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--small_1edmh_1ng0v_160:not(#\9) {
|
|
161
161
|
min-height: calc(2 * (50px + var(--space-xs-edba2s, 8px) + calc(2 * var(--font-body-m-line-height-ghizru, 20px))));
|
|
162
162
|
}
|
|
163
|
-
.
|
|
163
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--small_1edmh_1ng0v_160.awsui_content--without-labels_1edmh_1ng0v_163:not(#\9) {
|
|
164
164
|
min-height: calc(2 * (50px + var(--space-xs-edba2s, 8px)));
|
|
165
165
|
}
|
|
166
|
-
.
|
|
166
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--medium_1edmh_1ng0v_166:not(#\9) {
|
|
167
167
|
min-height: calc(2 * (100px + var(--space-s-hdd878, 12px) + calc(2 * var(--font-body-m-line-height-ghizru, 20px))));
|
|
168
168
|
}
|
|
169
|
-
.
|
|
169
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--medium_1edmh_1ng0v_166.awsui_content--without-labels_1edmh_1ng0v_163:not(#\9) {
|
|
170
170
|
min-height: calc(2 * (100px + var(--space-s-hdd878, 12px)));
|
|
171
171
|
}
|
|
172
|
-
.
|
|
172
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--large_1edmh_1ng0v_172:not(#\9) {
|
|
173
173
|
min-height: calc(2 * (140px + var(--space-s-hdd878, 12px) + calc(2 * var(--font-body-m-line-height-ghizru, 20px))));
|
|
174
174
|
}
|
|
175
|
-
.
|
|
175
|
+
.awsui_content_1edmh_1ng0v_160.awsui_content--large_1edmh_1ng0v_172.awsui_content--without-labels_1edmh_1ng0v_163:not(#\9) {
|
|
176
176
|
min-height: calc(2 * (140px + var(--space-s-hdd878, 12px)));
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
.
|
|
179
|
+
.awsui_content--fit-height_1edmh_1ng0v_179:not(#\9) {
|
|
180
|
+
flex: 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.awsui_status-container_1edmh_1ng0v_183:not(#\9) {
|
|
180
184
|
/* used in test utils */
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
.awsui_chart-
|
|
187
|
+
.awsui_chart-container_1edmh_1ng0v_187:not(#\9) {
|
|
184
188
|
display: flex;
|
|
185
189
|
flex: 1;
|
|
186
190
|
}
|
|
191
|
+
.awsui_chart-container--fit-height_1edmh_1ng0v_191:not(#\9) {
|
|
192
|
+
height: 100%;
|
|
193
|
+
min-height: inherit;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.awsui_chart-container-chart-plot_1edmh_1ng0v_196:not(#\9) {
|
|
197
|
+
display: contents;
|
|
198
|
+
}
|
|
199
|
+
.awsui_chart-container-chart-plot--fit-height_1edmh_1ng0v_199:not(#\9) {
|
|
200
|
+
display: block;
|
|
201
|
+
position: absolute;
|
|
202
|
+
top: 0;
|
|
203
|
+
right: 0;
|
|
204
|
+
bottom: 0;
|
|
205
|
+
left: 0;
|
|
206
|
+
}
|
|
187
207
|
|
|
188
|
-
.awsui_inner-
|
|
208
|
+
.awsui_inner-content_1edmh_1ng0v_208:not(#\9) {
|
|
189
209
|
display: flex;
|
|
190
210
|
position: absolute;
|
|
191
211
|
flex-direction: column;
|
|
@@ -199,53 +219,53 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
199
219
|
pointer-events: none;
|
|
200
220
|
}
|
|
201
221
|
|
|
202
|
-
.
|
|
222
|
+
.awsui_segment__highlight_1edmh_1ng0v_222:not(#\9) {
|
|
203
223
|
stroke: none;
|
|
204
224
|
opacity: 0;
|
|
205
225
|
}
|
|
206
226
|
|
|
207
|
-
.
|
|
227
|
+
.awsui_segment_1edmh_1ng0v_97:not(#\9) {
|
|
208
228
|
stroke: var(--color-background-container-content-og3y0v, #ffffff);
|
|
209
229
|
stroke-width: 2px;
|
|
210
230
|
stroke-linejoin: round;
|
|
211
231
|
opacity: 1;
|
|
212
232
|
cursor: pointer;
|
|
213
233
|
}
|
|
214
|
-
.
|
|
234
|
+
.awsui_segment_1edmh_1ng0v_97:not(#\9):focus {
|
|
215
235
|
outline: none;
|
|
216
236
|
}
|
|
217
|
-
.
|
|
237
|
+
.awsui_segment_1edmh_1ng0v_97.awsui_segment--dimmed_1edmh_1ng0v_237:not(#\9) {
|
|
218
238
|
opacity: 0.35;
|
|
219
239
|
}
|
|
220
|
-
.
|
|
240
|
+
.awsui_segment_1edmh_1ng0v_97.awsui_segment--highlighted_1edmh_1ng0v_240 > .awsui_segment__highlight_1edmh_1ng0v_222:not(#\9), .awsui_segment_1edmh_1ng0v_97:not(#\9):hover:not(.awsui_segment--dimmed_1edmh_1ng0v_237) > .awsui_segment__highlight_1edmh_1ng0v_222 {
|
|
221
241
|
opacity: 1;
|
|
222
242
|
}
|
|
223
243
|
|
|
224
|
-
.
|
|
244
|
+
.awsui_label_1edmh_1ng0v_138:not(#\9) {
|
|
225
245
|
color: var(--color-text-heading-default-18iw0k, #000716);
|
|
226
246
|
opacity: 1;
|
|
227
247
|
/* stylelint-disable-next-line selector-max-type */
|
|
228
248
|
/* stylelint-disable-next-line selector-max-type */
|
|
229
249
|
}
|
|
230
|
-
.
|
|
250
|
+
.awsui_label_1edmh_1ng0v_138 > line:not(#\9) {
|
|
231
251
|
stroke: var(--color-stroke-chart-line-7sdstd, #7d8998);
|
|
232
252
|
stroke-width: var(--border-divider-section-width-orq175, 2px);
|
|
233
253
|
}
|
|
234
|
-
.
|
|
254
|
+
.awsui_label_1edmh_1ng0v_138 > div:not(#\9) {
|
|
235
255
|
margin-top: -0.75em;
|
|
236
256
|
}
|
|
237
|
-
.
|
|
257
|
+
.awsui_label_1edmh_1ng0v_138.awsui_label--dimmed_1edmh_1ng0v_257:not(#\9) {
|
|
238
258
|
opacity: 0.35;
|
|
239
259
|
}
|
|
240
|
-
.
|
|
260
|
+
.awsui_label_1edmh_1ng0v_138.awsui_label--align-right_1edmh_1ng0v_260:not(#\9) {
|
|
241
261
|
/* stylelint-disable-next-line selector-max-type */
|
|
242
262
|
}
|
|
243
|
-
.
|
|
263
|
+
.awsui_label_1edmh_1ng0v_138.awsui_label--align-right_1edmh_1ng0v_260 > div:not(#\9) {
|
|
244
264
|
text-align: right;
|
|
245
265
|
}
|
|
246
266
|
|
|
247
267
|
/* stylelint-disable-next-line selector-max-type */
|
|
248
|
-
.awsui_label-
|
|
268
|
+
.awsui_label-text_1edmh_1ng0v_268 > text:not(#\9) {
|
|
249
269
|
font-size: var(--font-body-m-size-7dign1, 14px);
|
|
250
270
|
line-height: var(--font-body-m-line-height-ghizru, 20px);
|
|
251
271
|
font-weight: var(--font-display-label-weight-io22e5, 700);
|
|
@@ -253,22 +273,22 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
253
273
|
dominant-baseline: middle;
|
|
254
274
|
}
|
|
255
275
|
|
|
256
|
-
text.
|
|
276
|
+
text.awsui_label__description_1edmh_1ng0v_276:not(#\9) {
|
|
257
277
|
font-size: var(--font-chart-detail-size-gtiv3j, 12px);
|
|
258
278
|
font-weight: 400;
|
|
259
279
|
color: var(--color-text-group-label-qtmgp9, #414d5c);
|
|
260
280
|
fill: var(--color-text-group-label-qtmgp9, #414d5c);
|
|
261
281
|
}
|
|
262
282
|
|
|
263
|
-
.awsui_label-
|
|
283
|
+
.awsui_label-line_1edmh_1ng0v_283:not(#\9) {
|
|
264
284
|
/* used in component code */
|
|
265
285
|
}
|
|
266
286
|
|
|
267
|
-
.awsui_label--
|
|
287
|
+
.awsui_label--highlighted_1edmh_1ng0v_287:not(#\9) {
|
|
268
288
|
/* used in test-utils */
|
|
269
289
|
}
|
|
270
290
|
|
|
271
|
-
.awsui_popover-
|
|
291
|
+
.awsui_popover-header_1edmh_1ng0v_291:not(#\9) {
|
|
272
292
|
display: inline-flex;
|
|
273
293
|
align-items: flex-start;
|
|
274
294
|
}
|
|
@@ -2,28 +2,32 @@
|
|
|
2
2
|
// es-module interop with Babel and Typescript
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
module.exports.default = {
|
|
5
|
-
"segment__path": "
|
|
6
|
-
"segment": "
|
|
7
|
-
"segment__hover": "
|
|
8
|
-
"label": "
|
|
9
|
-
"root": "
|
|
10
|
-
"content": "
|
|
11
|
-
"content--small": "awsui_content--
|
|
12
|
-
"content--without-labels": "awsui_content--without-
|
|
13
|
-
"content--medium": "awsui_content--
|
|
14
|
-
"content--large": "awsui_content--
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"label
|
|
26
|
-
"label--
|
|
27
|
-
"
|
|
5
|
+
"segment__path": "awsui_segment__path_1edmh_1ng0v_97",
|
|
6
|
+
"segment": "awsui_segment_1edmh_1ng0v_97",
|
|
7
|
+
"segment__hover": "awsui_segment__hover_1edmh_1ng0v_124",
|
|
8
|
+
"label": "awsui_label_1edmh_1ng0v_138",
|
|
9
|
+
"root": "awsui_root_1edmh_1ng0v_156",
|
|
10
|
+
"content": "awsui_content_1edmh_1ng0v_160",
|
|
11
|
+
"content--small": "awsui_content--small_1edmh_1ng0v_160",
|
|
12
|
+
"content--without-labels": "awsui_content--without-labels_1edmh_1ng0v_163",
|
|
13
|
+
"content--medium": "awsui_content--medium_1edmh_1ng0v_166",
|
|
14
|
+
"content--large": "awsui_content--large_1edmh_1ng0v_172",
|
|
15
|
+
"content--fit-height": "awsui_content--fit-height_1edmh_1ng0v_179",
|
|
16
|
+
"status-container": "awsui_status-container_1edmh_1ng0v_183",
|
|
17
|
+
"chart-container": "awsui_chart-container_1edmh_1ng0v_187",
|
|
18
|
+
"chart-container--fit-height": "awsui_chart-container--fit-height_1edmh_1ng0v_191",
|
|
19
|
+
"chart-container-chart-plot": "awsui_chart-container-chart-plot_1edmh_1ng0v_196",
|
|
20
|
+
"chart-container-chart-plot--fit-height": "awsui_chart-container-chart-plot--fit-height_1edmh_1ng0v_199",
|
|
21
|
+
"inner-content": "awsui_inner-content_1edmh_1ng0v_208",
|
|
22
|
+
"segment__highlight": "awsui_segment__highlight_1edmh_1ng0v_222",
|
|
23
|
+
"segment--dimmed": "awsui_segment--dimmed_1edmh_1ng0v_237",
|
|
24
|
+
"segment--highlighted": "awsui_segment--highlighted_1edmh_1ng0v_240",
|
|
25
|
+
"label--dimmed": "awsui_label--dimmed_1edmh_1ng0v_257",
|
|
26
|
+
"label--align-right": "awsui_label--align-right_1edmh_1ng0v_260",
|
|
27
|
+
"label-text": "awsui_label-text_1edmh_1ng0v_268",
|
|
28
|
+
"label__description": "awsui_label__description_1edmh_1ng0v_276",
|
|
29
|
+
"label-line": "awsui_label-line_1edmh_1ng0v_283",
|
|
30
|
+
"label--highlighted": "awsui_label--highlighted_1edmh_1ng0v_287",
|
|
31
|
+
"popover-header": "awsui_popover-header_1edmh_1ng0v_291"
|
|
28
32
|
};
|
|
29
33
|
|
package/pie-chart/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentFormatFunction } from '../internal/i18n/context';
|
|
2
2
|
import { PieChartProps } from './interfaces';
|
|
3
|
-
interface Dimension {
|
|
3
|
+
export interface Dimension {
|
|
4
4
|
innerRadius: number;
|
|
5
5
|
outerRadius: number;
|
|
6
6
|
padding: number;
|
|
@@ -10,6 +10,17 @@ interface Dimension {
|
|
|
10
10
|
}
|
|
11
11
|
export declare const dimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension>;
|
|
12
12
|
export declare const refreshDimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension>;
|
|
13
|
+
/**
|
|
14
|
+
* When `size` is a string ("small", "medium" or "large") the predefined pie chart element dimensions for classic and visual refresh are used.
|
|
15
|
+
* When `size` is a number the outer and inner radii are computed and the rest of the dimensions are taken from the closest predefined size.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getDimensionsBySize({ size, hasLabels, visualRefresh, }: {
|
|
18
|
+
size: NonNullable<PieChartProps['size']> | number;
|
|
19
|
+
hasLabels: boolean;
|
|
20
|
+
visualRefresh?: boolean;
|
|
21
|
+
}): Dimension & {
|
|
22
|
+
size: NonNullable<PieChartProps['size']>;
|
|
23
|
+
};
|
|
13
24
|
export declare const defaultDetails: (i18n: ComponentFormatFunction<'pie-chart'>, i18nStrings: PieChartProps.I18nStrings) => (datum: PieChartProps.Datum, dataSum: number) => ({
|
|
14
25
|
key: string;
|
|
15
26
|
value: number;
|
|
@@ -26,5 +37,4 @@ export declare const defaultDetails: (i18n: ComponentFormatFunction<'pie-chart'>
|
|
|
26
37
|
export declare const balanceLabelNodes: (nodes: NodeListOf<SVGGElement>, markers: Array<{
|
|
27
38
|
endY: number;
|
|
28
39
|
}>, leftSide: boolean) => void;
|
|
29
|
-
export {};
|
|
30
40
|
//# sourceMappingURL=utils.d.ts.map
|
package/pie-chart/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"lib/default/","sources":["pie-chart/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"lib/default/","sources":["pie-chart/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAsBlF,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAgBzF,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,SAAS,EACT,aAAa,GACd,EAAE;IACD,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,CAuB3D;AAED,eAAO,MAAM,cAAc,SAClB,wBAAwB,WAAW,CAAC,eAAe,cAAc,WAAW,aAC3E,cAAc,KAAK,WAAW,MAAM;;;;;;IAOzC,CAAC;AAEN;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,UACrB,WAAW,WAAW,CAAC,WACrB,MAAM;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,YACtB,OAAO,SAkElB,CAAC"}
|
package/pie-chart/utils.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import styles from './styles.css.js';
|
|
2
|
+
const paddingLabels = 44; // = 2 * (size-lineHeight-body-100)
|
|
3
|
+
const defaultPadding = 12; // = space-s
|
|
4
|
+
const smallPadding = 8; // = space-xs
|
|
2
5
|
export const dimensionsBySize = {
|
|
3
6
|
small: {
|
|
4
7
|
innerRadius: 33,
|
|
5
8
|
outerRadius: 50,
|
|
6
|
-
innerLabelPadding:
|
|
7
|
-
padding:
|
|
8
|
-
paddingLabels
|
|
9
|
+
innerLabelPadding: smallPadding,
|
|
10
|
+
padding: smallPadding,
|
|
11
|
+
paddingLabels,
|
|
9
12
|
},
|
|
10
13
|
medium: {
|
|
11
14
|
innerRadius: 66,
|
|
12
15
|
outerRadius: 100,
|
|
13
|
-
innerLabelPadding:
|
|
14
|
-
padding:
|
|
15
|
-
paddingLabels
|
|
16
|
+
innerLabelPadding: defaultPadding,
|
|
17
|
+
padding: defaultPadding,
|
|
18
|
+
paddingLabels,
|
|
16
19
|
},
|
|
17
20
|
large: {
|
|
18
21
|
innerRadius: 93,
|
|
19
22
|
outerRadius: 140,
|
|
20
|
-
innerLabelPadding:
|
|
21
|
-
padding:
|
|
22
|
-
paddingLabels
|
|
23
|
+
innerLabelPadding: defaultPadding,
|
|
24
|
+
padding: defaultPadding,
|
|
25
|
+
paddingLabels,
|
|
23
26
|
},
|
|
24
27
|
};
|
|
25
28
|
export const refreshDimensionsBySize = {
|
|
@@ -27,6 +30,31 @@ export const refreshDimensionsBySize = {
|
|
|
27
30
|
medium: Object.assign(Object.assign({}, dimensionsBySize.medium), { innerRadius: 75, cornerRadius: 4 }),
|
|
28
31
|
large: Object.assign(Object.assign({}, dimensionsBySize.large), { innerRadius: 105, cornerRadius: 5 }),
|
|
29
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* When `size` is a string ("small", "medium" or "large") the predefined pie chart element dimensions for classic and visual refresh are used.
|
|
35
|
+
* When `size` is a number the outer and inner radii are computed and the rest of the dimensions are taken from the closest predefined size.
|
|
36
|
+
*/
|
|
37
|
+
export function getDimensionsBySize({ size, hasLabels, visualRefresh, }) {
|
|
38
|
+
if (typeof size === 'string') {
|
|
39
|
+
const dimensions = visualRefresh ? refreshDimensionsBySize[size] : dimensionsBySize[size];
|
|
40
|
+
return Object.assign(Object.assign({}, dimensions), { size });
|
|
41
|
+
}
|
|
42
|
+
const sizeSpec = visualRefresh ? refreshDimensionsBySize : dimensionsBySize;
|
|
43
|
+
const getPixelSize = (d) => d.outerRadius * 2 + d.padding * 2 + (hasLabels ? d.paddingLabels : 0) * 2;
|
|
44
|
+
let matchedSize = 'small';
|
|
45
|
+
if (size > getPixelSize(sizeSpec.medium)) {
|
|
46
|
+
matchedSize = 'medium';
|
|
47
|
+
}
|
|
48
|
+
if (size > getPixelSize(sizeSpec.large)) {
|
|
49
|
+
matchedSize = 'large';
|
|
50
|
+
}
|
|
51
|
+
const padding = sizeSpec[matchedSize].padding;
|
|
52
|
+
const paddingLabels = hasLabels ? sizeSpec[matchedSize].paddingLabels : 0;
|
|
53
|
+
const radiiRatio = sizeSpec[matchedSize].outerRadius / sizeSpec[matchedSize].innerRadius;
|
|
54
|
+
const outerRadius = (size - 2 * paddingLabels - 2 * padding) / 2;
|
|
55
|
+
const innerRadius = outerRadius / radiiRatio;
|
|
56
|
+
return Object.assign(Object.assign({}, sizeSpec[matchedSize]), { outerRadius, innerRadius, size: matchedSize });
|
|
57
|
+
}
|
|
30
58
|
export const defaultDetails = (i18n, i18nStrings) => (datum, dataSum) => [
|
|
31
59
|
{ key: i18n('i18nStrings.detailsValue', i18nStrings.detailsValue) || '', value: datum.value },
|
|
32
60
|
{
|
package/pie-chart/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"lib/default/","sources":["pie-chart/utils.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAWrC,MAAM,CAAC,MAAM,gBAAgB,GAA0D;IACrF,KAAK,EAAE;QACL,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,EAAE;QACf,iBAAiB,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;QACV,aAAa,EAAE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FAAiF;YACjF,MAAM;SACP;QAED,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAEnC,4EAA4E;QAC5E,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;QAErE,IAAI,MAAM,GAAG,CAAC,EAAE;YACd,uBAAuB;YACvB,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,MAAM,GAAG,CAAC,CAAC;YAEzD,wCAAwC;YACxC,MAAM,QAAQ,GAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,aAAa,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAC5E,IAAI,QAAQ,EAAE;gBACZ,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;gBACxB,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;aACnD;YAED,2DAA2D;YAC3D,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC;SACjB;QAED,YAAY,GAAG,GAAG,CAAC;KACpB;AACH,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ComponentFormatFunction } from '../internal/i18n/context';\nimport { PieChartProps } from './interfaces';\nimport styles from './styles.css.js';\n\ninterface Dimension {\n innerRadius: number;\n outerRadius: number;\n padding: number;\n paddingLabels: number;\n innerLabelPadding: number;\n cornerRadius?: number;\n}\n\nexport const dimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension> = {\n small: {\n innerRadius: 33,\n outerRadius: 50,\n innerLabelPadding: 8,\n padding: 8, // = space-xs\n paddingLabels: 44, // = 2 * (size-lineHeight-body-100)\n },\n medium: {\n innerRadius: 66,\n outerRadius: 100,\n innerLabelPadding: 12,\n padding: 12, // = space-s\n paddingLabels: 44, // = 2 * (size-lineHeight-body-100)\n },\n large: {\n innerRadius: 93,\n outerRadius: 140,\n innerLabelPadding: 12,\n padding: 12, // = space-s\n paddingLabels: 44, // = 2 * (size-lineHeight-body-100)\n },\n};\n\nexport const refreshDimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension> = {\n small: {\n ...dimensionsBySize.small,\n innerRadius: 38,\n cornerRadius: 3,\n },\n medium: {\n ...dimensionsBySize.medium,\n innerRadius: 75,\n cornerRadius: 4,\n },\n large: {\n ...dimensionsBySize.large,\n innerRadius: 105,\n cornerRadius: 5,\n },\n};\n\nexport const defaultDetails =\n (i18n: ComponentFormatFunction<'pie-chart'>, i18nStrings: PieChartProps.I18nStrings) =>\n (datum: PieChartProps.Datum, dataSum: number) =>\n [\n { key: i18n('i18nStrings.detailsValue', i18nStrings.detailsValue) || '', value: datum.value },\n {\n key: i18n('i18nStrings.detailsPercentage', i18nStrings.detailsPercentage) || '',\n value: `${((datum.value * 100) / dataSum).toFixed(0)}%`,\n },\n ];\n\n/**\n * Adjusts the position of the given label nodes to avoid visual overlapping.\n * @param nodes List of label nodes of the entire chart (both left and right side)\n * @param markers Markers array that was calculated in <Labels>, but we just need the `endY` values\n * @param leftSide Boolean flag whether we are processing the left or right side of the chart labels\n */\nexport const balanceLabelNodes = (\n nodes: NodeListOf<SVGGElement>,\n markers: Array<{ endY: number }>,\n leftSide: boolean\n) => {\n const MARGIN = 10;\n\n let previousBBox: { x: number; y: number; height: number } | null = null;\n\n // When traversing the right side of labels, we start at the beginning of the array and go forwards.\n // For the left side, we need to traverse backwards from the end, so that overlapping nodes are pushed down in the right order.\n let i = leftSide ? nodes.length - 1 : 0;\n\n while ((leftSide && i >= 0) || (!leftSide && i < nodes.length)) {\n const node = nodes[i];\n\n // Currently using dataset attributes to determine the base position.\n // This implementation can be changed back to using `getBBox` when we drop IE11 support.\n // Unfortunately, there is no good alternative for `getBBox` that is supported by IE11.\n // `getBoundingClientRect` works for width and height calculations in SVG, but the x/y positions are inaccurate.\n const x = parseFloat(node.getAttribute('data-x') || '0');\n const y = parseFloat(node.getAttribute('data-y') || '0');\n const box = {\n x,\n y,\n height: node.getBoundingClientRect().height,\n };\n\n const marker = markers[i];\n\n if (leftSide) {\n i--;\n } else {\n i++;\n }\n\n if (!previousBBox) {\n previousBBox = box;\n node.setAttribute('transform', '');\n continue;\n }\n\n if ((!leftSide && box.x < 0) || (leftSide && box.x >= 0)) {\n // We have reached a label that is on the other side of the chart, so we're done.\n break;\n }\n\n node.setAttribute('transform', '');\n\n // Calculate how much the current node is overlapping with the previous one.\n const offset = previousBBox.y + previousBBox.height + MARGIN - box.y;\n\n if (offset > 0) {\n // Move the label down.\n node.setAttribute('transform', `translate(0 ${offset})`);\n\n // Adjust the attached line accordingly.\n const lineNode = node.parentNode?.querySelector(`.${styles['label-line']}`);\n if (lineNode) {\n const { endY } = marker;\n lineNode.setAttribute('y2', '' + (endY + offset));\n }\n\n // Update the position accordingly to inform the next label\n box.y += offset;\n }\n\n previousBBox = box;\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"lib/default/","sources":["pie-chart/utils.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAWrC,MAAM,aAAa,GAAG,EAAE,CAAC,CAAC,mCAAmC;AAC7D,MAAM,cAAc,GAAG,EAAE,CAAC,CAAC,YAAY;AACvC,MAAM,YAAY,GAAG,CAAC,CAAC,CAAC,aAAa;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAA0D;IACrF,KAAK,EAAE;QACL,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,EAAE;QACf,iBAAiB,EAAE,YAAY;QAC/B,OAAO,EAAE,YAAY;QACrB,aAAa;KACd;IACD,MAAM,EAAE;QACN,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,GAAG;QAChB,iBAAiB,EAAE,cAAc;QACjC,OAAO,EAAE,cAAc;QACvB,aAAa;KACd;IACD,KAAK,EA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YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAEnC,4EAA4E;QAC5E,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;QAErE,IAAI,MAAM,GAAG,CAAC,EAAE;YACd,uBAAuB;YACvB,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,MAAM,GAAG,CAAC,CAAC;YAEzD,wCAAwC;YACxC,MAAM,QAAQ,GAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,aAAa,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAC5E,IAAI,QAAQ,EAAE;gBACZ,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;gBACxB,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;aACnD;YAED,2DAA2D;YAC3D,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC;SACjB;QAED,YAAY,GAAG,GAAG,CAAC;KACpB;AACH,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ComponentFormatFunction } from '../internal/i18n/context';\nimport { PieChartProps } from './interfaces';\nimport styles from './styles.css.js';\n\nexport interface Dimension {\n innerRadius: number;\n outerRadius: number;\n padding: number;\n paddingLabels: number;\n innerLabelPadding: number;\n cornerRadius?: number;\n}\n\nconst paddingLabels = 44; // = 2 * (size-lineHeight-body-100)\nconst defaultPadding = 12; // = space-s\nconst smallPadding = 8; // = space-xs\n\nexport const dimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension> = {\n small: {\n innerRadius: 33,\n outerRadius: 50,\n innerLabelPadding: smallPadding,\n padding: smallPadding,\n paddingLabels,\n },\n medium: {\n innerRadius: 66,\n outerRadius: 100,\n innerLabelPadding: defaultPadding,\n padding: defaultPadding,\n paddingLabels,\n },\n large: {\n innerRadius: 93,\n outerRadius: 140,\n innerLabelPadding: defaultPadding,\n padding: defaultPadding,\n paddingLabels,\n },\n};\n\nexport const refreshDimensionsBySize: Record<NonNullable<PieChartProps['size']>, Dimension> = {\n small: {\n ...dimensionsBySize.small,\n innerRadius: 38,\n cornerRadius: 3,\n },\n medium: {\n ...dimensionsBySize.medium,\n innerRadius: 75,\n cornerRadius: 4,\n },\n large: {\n ...dimensionsBySize.large,\n innerRadius: 105,\n cornerRadius: 5,\n },\n};\n\n/**\n * When `size` is a string (\"small\", \"medium\" or \"large\") the predefined pie chart element dimensions for classic and visual refresh are used.\n * When `size` is a number the outer and inner radii are computed and the rest of the dimensions are taken from the closest predefined size.\n */\nexport function getDimensionsBySize({\n size,\n hasLabels,\n visualRefresh,\n}: {\n size: NonNullable<PieChartProps['size']> | number;\n hasLabels: boolean;\n visualRefresh?: boolean;\n}): Dimension & { size: NonNullable<PieChartProps['size']> } {\n if (typeof size === 'string') {\n const dimensions = visualRefresh ? refreshDimensionsBySize[size] : dimensionsBySize[size];\n return { ...dimensions, size };\n }\n const sizeSpec = visualRefresh ? refreshDimensionsBySize : dimensionsBySize;\n const getPixelSize = (d: Dimension) => d.outerRadius * 2 + d.padding * 2 + (hasLabels ? d.paddingLabels : 0) * 2;\n\n let matchedSize: NonNullable<PieChartProps['size']> = 'small';\n if (size > getPixelSize(sizeSpec.medium)) {\n matchedSize = 'medium';\n }\n if (size > getPixelSize(sizeSpec.large)) {\n matchedSize = 'large';\n }\n\n const padding = sizeSpec[matchedSize].padding;\n const paddingLabels = hasLabels ? sizeSpec[matchedSize].paddingLabels : 0;\n const radiiRatio = sizeSpec[matchedSize].outerRadius / sizeSpec[matchedSize].innerRadius;\n const outerRadius = (size - 2 * paddingLabels - 2 * padding) / 2;\n const innerRadius = outerRadius / radiiRatio;\n\n return { ...sizeSpec[matchedSize], outerRadius, innerRadius, size: matchedSize };\n}\n\nexport const defaultDetails =\n (i18n: ComponentFormatFunction<'pie-chart'>, i18nStrings: PieChartProps.I18nStrings) =>\n (datum: PieChartProps.Datum, dataSum: number) =>\n [\n { key: i18n('i18nStrings.detailsValue', i18nStrings.detailsValue) || '', value: datum.value },\n {\n key: i18n('i18nStrings.detailsPercentage', i18nStrings.detailsPercentage) || '',\n value: `${((datum.value * 100) / dataSum).toFixed(0)}%`,\n },\n ];\n\n/**\n * Adjusts the position of the given label nodes to avoid visual overlapping.\n * @param nodes List of label nodes of the entire chart (both left and right side)\n * @param markers Markers array that was calculated in <Labels>, but we just need the `endY` values\n * @param leftSide Boolean flag whether we are processing the left or right side of the chart labels\n */\nexport const balanceLabelNodes = (\n nodes: NodeListOf<SVGGElement>,\n markers: Array<{ endY: number }>,\n leftSide: boolean\n) => {\n const MARGIN = 10;\n\n let previousBBox: { x: number; y: number; height: number } | null = null;\n\n // When traversing the right side of labels, we start at the beginning of the array and go forwards.\n // For the left side, we need to traverse backwards from the end, so that overlapping nodes are pushed down in the right order.\n let i = leftSide ? nodes.length - 1 : 0;\n\n while ((leftSide && i >= 0) || (!leftSide && i < nodes.length)) {\n const node = nodes[i];\n\n // Currently using dataset attributes to determine the base position.\n // This implementation can be changed back to using `getBBox` when we drop IE11 support.\n // Unfortunately, there is no good alternative for `getBBox` that is supported by IE11.\n // `getBoundingClientRect` works for width and height calculations in SVG, but the x/y positions are inaccurate.\n const x = parseFloat(node.getAttribute('data-x') || '0');\n const y = parseFloat(node.getAttribute('data-y') || '0');\n const box = {\n x,\n y,\n height: node.getBoundingClientRect().height,\n };\n\n const marker = markers[i];\n\n if (leftSide) {\n i--;\n } else {\n i++;\n }\n\n if (!previousBBox) {\n previousBBox = box;\n node.setAttribute('transform', '');\n continue;\n }\n\n if ((!leftSide && box.x < 0) || (leftSide && box.x >= 0)) {\n // We have reached a label that is on the other side of the chart, so we're done.\n break;\n }\n\n node.setAttribute('transform', '');\n\n // Calculate how much the current node is overlapping with the previous one.\n const offset = previousBBox.y + previousBBox.height + MARGIN - box.y;\n\n if (offset > 0) {\n // Move the label down.\n node.setAttribute('transform', `translate(0 ${offset})`);\n\n // Adjust the attached line accordingly.\n const lineNode = node.parentNode?.querySelector(`.${styles['label-line']}`);\n if (lineNode) {\n const { endY } = marker;\n lineNode.setAttribute('y2', '' + (endY + offset));\n }\n\n // Update the position accordingly to inform the next label\n box.y += offset;\n }\n\n previousBBox = box;\n }\n};\n"]}
|