@cloudscape-design/components-themeable 3.0.352 → 3.0.353
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/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/internal/components/cartesian-chart/styles.scss +38 -3
- package/lib/internal/scss/internal/components/chart-wrapper/styles.scss +17 -0
- package/lib/internal/scss/mixed-line-bar-chart/styles.scss +0 -1
- package/lib/internal/scss/pie-chart/styles.scss +22 -0
- package/lib/internal/template/area-chart/chart-container.d.ts +3 -1
- package/lib/internal/template/area-chart/chart-container.d.ts.map +1 -1
- package/lib/internal/template/area-chart/chart-container.js +3 -2
- package/lib/internal/template/area-chart/chart-container.js.map +1 -1
- package/lib/internal/template/area-chart/internal.d.ts +1 -1
- package/lib/internal/template/area-chart/internal.d.ts.map +1 -1
- package/lib/internal/template/area-chart/internal.js +3 -2
- package/lib/internal/template/area-chart/internal.js.map +1 -1
- package/lib/internal/template/area-chart/model/index.d.ts +1 -0
- package/lib/internal/template/area-chart/model/index.d.ts.map +1 -1
- package/lib/internal/template/area-chart/model/index.js.map +1 -1
- package/lib/internal/template/area-chart/model/use-chart-model.d.ts +2 -1
- package/lib/internal/template/area-chart/model/use-chart-model.d.ts.map +1 -1
- package/lib/internal/template/area-chart/model/use-chart-model.js +8 -2
- package/lib/internal/template/area-chart/model/use-chart-model.js.map +1 -1
- package/lib/internal/template/internal/analytics/index.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/index.js +1 -0
- package/lib/internal/template/internal/analytics/index.js.map +1 -1
- package/lib/internal/template/internal/analytics/interfaces.d.ts +13 -2
- package/lib/internal/template/internal/analytics/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/cartesian-chart/chart-container.d.ts +2 -0
- package/lib/internal/template/internal/components/cartesian-chart/chart-container.d.ts.map +1 -1
- package/lib/internal/template/internal/components/cartesian-chart/chart-container.js +16 -3
- package/lib/internal/template/internal/components/cartesian-chart/chart-container.js.map +1 -1
- package/lib/internal/template/internal/components/cartesian-chart/interfaces.d.ts +5 -0
- package/lib/internal/template/internal/components/cartesian-chart/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/components/cartesian-chart/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/cartesian-chart/styles.css.js +27 -23
- package/lib/internal/template/internal/components/cartesian-chart/styles.scoped.css +54 -27
- package/lib/internal/template/internal/components/cartesian-chart/styles.selectors.js +27 -23
- package/lib/internal/template/internal/components/chart-plot/index.d.ts +2 -2
- package/lib/internal/template/internal/components/chart-plot/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/chart-plot/index.js +3 -1
- package/lib/internal/template/internal/components/chart-plot/index.js.map +1 -1
- package/lib/internal/template/internal/components/chart-wrapper/index.d.ts +1 -0
- package/lib/internal/template/internal/components/chart-wrapper/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/chart-wrapper/index.js +21 -6
- package/lib/internal/template/internal/components/chart-wrapper/index.js.map +1 -1
- package/lib/internal/template/internal/components/chart-wrapper/styles.css.js +9 -6
- package/lib/internal/template/internal/components/chart-wrapper/styles.scoped.css +20 -6
- package/lib/internal/template/internal/components/chart-wrapper/styles.selectors.js +9 -6
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/mixed-line-bar-chart/chart-container.d.ts +2 -1
- package/lib/internal/template/mixed-line-bar-chart/chart-container.d.ts.map +1 -1
- package/lib/internal/template/mixed-line-bar-chart/chart-container.js +8 -2
- package/lib/internal/template/mixed-line-bar-chart/chart-container.js.map +1 -1
- package/lib/internal/template/mixed-line-bar-chart/internal.d.ts +1 -1
- package/lib/internal/template/mixed-line-bar-chart/internal.d.ts.map +1 -1
- package/lib/internal/template/mixed-line-bar-chart/internal.js +3 -3
- package/lib/internal/template/mixed-line-bar-chart/internal.js.map +1 -1
- package/lib/internal/template/pie-chart/index.d.ts +1 -1
- package/lib/internal/template/pie-chart/index.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/index.js +10 -3
- package/lib/internal/template/pie-chart/index.js.map +1 -1
- package/lib/internal/template/pie-chart/interfaces.d.ts +5 -0
- package/lib/internal/template/pie-chart/interfaces.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/interfaces.js.map +1 -1
- package/lib/internal/template/pie-chart/labels.d.ts +3 -2
- package/lib/internal/template/pie-chart/labels.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/labels.js +4 -4
- package/lib/internal/template/pie-chart/labels.js.map +1 -1
- package/lib/internal/template/pie-chart/pie-chart.d.ts +2 -1
- package/lib/internal/template/pie-chart/pie-chart.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/pie-chart.js +18 -14
- package/lib/internal/template/pie-chart/pie-chart.js.map +1 -1
- package/lib/internal/template/pie-chart/segments.d.ts +3 -2
- package/lib/internal/template/pie-chart/segments.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/segments.js +2 -6
- package/lib/internal/template/pie-chart/segments.js.map +1 -1
- package/lib/internal/template/pie-chart/styles.css.js +27 -23
- package/lib/internal/template/pie-chart/styles.scoped.css +58 -38
- package/lib/internal/template/pie-chart/styles.selectors.js +27 -23
- package/lib/internal/template/pie-chart/utils.d.ts +12 -2
- package/lib/internal/template/pie-chart/utils.d.ts.map +1 -1
- package/lib/internal/template/pie-chart/utils.js +37 -9
- package/lib/internal/template/pie-chart/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
{
|
|
@@ -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,EAAE,EAAE,mCAAmC;KACvD;IACD,MAAM,EAAE;QACN,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,GAAG;QAChB,iBAAiB,EAAE,EAAE;QACrB,OAAO,EAAE,EAAE;QACX,aAAa,EAAE,EAAE,EAAE,mCAAmC;KACvD;IACD,KAAK,EAAE;QACL,WAAW,EAAE,EAAE;Q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,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,EAAE;QACL,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,GAAG;QAChB,iBAAiB,EAAE,cAAc;QACjC,OAAO,EAAE,cAAc;QACvB,aAAa;KACd;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAA0D;IAC5F,KAAK,kCACA,gBAAgB,CAAC,KAAK,KACzB,WAAW,EAAE,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AI,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"]}
|