@fluentui/react-charts 9.3.7 → 9.3.8
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/CHANGELOG.md +27 -2
- package/dist/index.d.ts +55 -7
- package/lib/components/AreaChart/AreaChart.js +1 -28
- package/lib/components/AreaChart/AreaChart.js.map +1 -1
- package/lib/components/AreaChart/useAreaChartStyles.styles.js +1 -2
- package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib/components/ChartTable/ChartTable.js +6 -1
- package/lib/components/ChartTable/ChartTable.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
- package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.js +50 -32
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +5 -5
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +4 -3
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +261 -187
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +6 -3
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/FunnelChart/FunnelChart.js +6 -3
- package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib/components/GanttChart/GanttChart.js +1 -1
- package/lib/components/GanttChart/GanttChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.js +6 -3
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +17 -17
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +1 -2
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +2 -4
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/Legends/Legends.js +3 -4
- package/lib/components/Legends/Legends.js.map +1 -1
- package/lib/components/LineChart/LineChart.js +66 -64
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/LineChart/useLineChartStyles.styles.js +1 -2
- package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js +1 -1
- package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +1 -2
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.js +18 -26
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -2
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +13 -78
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +1 -2
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +21 -32
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +1 -2
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib/types/ChartAnnotation.js.map +1 -1
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/Common.styles.js +0 -1
- package/lib/utilities/Common.styles.js.map +1 -1
- package/lib/utilities/Common.styles.raw.js +0 -1
- package/lib/utilities/Common.styles.raw.js.map +1 -1
- package/lib/utilities/image-export-utils.js +4 -4
- package/lib/utilities/image-export-utils.js.map +1 -1
- package/lib/utilities/utilities.js +220 -78
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/AreaChart/AreaChart.js +0 -26
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +0 -2
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ChartTable/ChartTable.js +6 -1
- package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
- package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +49 -31
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +3 -4
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +3 -2
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +261 -186
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +5 -2
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/FunnelChart.js +5 -2
- package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib-commonjs/components/GanttChart/GanttChart.js +1 -1
- package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js +5 -2
- package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +15 -15
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +2 -4
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.js +3 -4
- package/lib-commonjs/components/Legends/Legends.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js +65 -63
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +0 -2
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +0 -2
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +17 -25
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +0 -2
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +12 -77
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +20 -31
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/types/ChartAnnotation.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/Common.styles.js +0 -1
- package/lib-commonjs/utilities/Common.styles.js.map +1 -1
- package/lib-commonjs/utilities/Common.styles.raw.js +0 -1
- package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -1
- package/lib-commonjs/utilities/image-export-utils.js +3 -3
- package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +232 -81
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +9 -9
- package/lib/components/DeclarativeChart/imageExporter.js +0 -223
- package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
- package/lib-commonjs/components/DeclarativeChart/imageExporter.js +0 -233
- package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +0 -1
|
@@ -36,7 +36,6 @@ const useStyles = /*#__PURE__*/__styles({
|
|
|
36
36
|
B0ocmuz: "f1bnz8pu",
|
|
37
37
|
qhf8xq: "f1euv43f",
|
|
38
38
|
fsow6f: "f17mccla",
|
|
39
|
-
Bhzewxz: "fr6rvge",
|
|
40
39
|
De3pzq: "fxugw4r",
|
|
41
40
|
Beyfa6y: 0,
|
|
42
41
|
Bbmb7ep: 0,
|
|
@@ -49,7 +48,7 @@ const useStyles = /*#__PURE__*/__styles({
|
|
|
49
48
|
}, {
|
|
50
49
|
d: [".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}", ".f22iagw{display:flex;}", ".f1vx9l62{flex-direction:column;}", [".f1bnz8pu{padding:var(--spacingHorizontalS);}", {
|
|
51
50
|
p: -1
|
|
52
|
-
}], ".f1euv43f{position:absolute;}", ".f17mccla{text-align:center;}", ".
|
|
51
|
+
}], ".f1euv43f{position:absolute;}", ".f17mccla{text-align:center;}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", [".fq9zq91{border-radius:var(--borderRadiusSmall);}", {
|
|
53
52
|
p: -1
|
|
54
53
|
}], ".f1aehjj5{pointer-events:none;}", ".f19n0e5{color:var(--colorNeutralForeground1);}"]
|
|
55
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__styles","mergeClasses","getTooltipStyle","areaChartClassNames","tooltip","root","xAxis","yAxis","legendContainer","hover","descriptionMessage","axisTitle","chartTitle","opacityChangeOnHover","shapeStyles","chartWrapper","svgTooltip","chart","axisAnnotation","plotContainer","annotationLayer","useStyles","Bahqtrf","Be2twd7","Bhrd7zp","Bg96gwp","mc9l5x","Beiy3e4","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","qhf8xq","fsow6f","
|
|
1
|
+
{"version":3,"names":["__styles","mergeClasses","getTooltipStyle","areaChartClassNames","tooltip","root","xAxis","yAxis","legendContainer","hover","descriptionMessage","axisTitle","chartTitle","opacityChangeOnHover","shapeStyles","chartWrapper","svgTooltip","chart","axisAnnotation","plotContainer","annotationLayer","useStyles","Bahqtrf","Be2twd7","Bhrd7zp","Bg96gwp","mc9l5x","Beiy3e4","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","qhf8xq","fsow6f","De3pzq","Beyfa6y","Bbmb7ep","Btl43ni","B7oj6ja","Dimara","Bkecrkj","sj55zd","d","p","useAreaChartStyles","props","baseStyles"],"sources":["useAreaChartStyles.styles.js"],"sourcesContent":["'use client';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { getTooltipStyle } from '../../utilities/index';\nexport const areaChartClassNames = {\n tooltip: 'fui-ac__tooltip',\n root: '',\n xAxis: '',\n yAxis: '',\n legendContainer: '',\n hover: '',\n descriptionMessage: '',\n axisTitle: '',\n chartTitle: '',\n opacityChangeOnHover: '',\n shapeStyles: '',\n chartWrapper: '',\n svgTooltip: '',\n chart: '',\n axisAnnotation: '',\n plotContainer: '',\n annotationLayer: ''\n};\nconst useStyles = makeStyles({\n tooltip: getTooltipStyle()\n});\n/**\n * Apply styling to the AreaChart slots based on the state\n */ export const useAreaChartStyles = (props)=>{\n const baseStyles = useStyles();\n return {\n tooltip: mergeClasses(areaChartClassNames.tooltip, baseStyles.tooltip /*props.styles?.tooltip*/ )\n };\n};\n"],"mappings":"AAAA,YAAY;;AACZ,SAAAA,QAAA,EAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,eAAe,QAAQ,uBAAuB;AACvD,OAAO,MAAMC,mBAAmB,GAAG;EAC/BC,OAAO,EAAE,iBAAiB;EAC1BC,IAAI,EAAE,EAAE;EACRC,KAAK,EAAE,EAAE;EACTC,KAAK,EAAE,EAAE;EACTC,eAAe,EAAE,EAAE;EACnBC,KAAK,EAAE,EAAE;EACTC,kBAAkB,EAAE,EAAE;EACtBC,SAAS,EAAE,EAAE;EACbC,UAAU,EAAE,EAAE;EACdC,oBAAoB,EAAE,EAAE;EACxBC,WAAW,EAAE,EAAE;EACfC,YAAY,EAAE,EAAE;EAChBC,UAAU,EAAE,EAAE;EACdC,KAAK,EAAE,EAAE;EACTC,cAAc,EAAE,EAAE;EAClBC,aAAa,EAAE,EAAE;EACjBC,eAAe,EAAE;AACrB,CAAC;AACD,MAAMC,SAAS,gBAAGrB,QAAA;EAAAI,OAAA;IAAAkB,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;EAAA;AAAA;EAAAC,CAAA;IAAAC,CAAA;EAAA;IAAAA,CAAA;EAAA;AAAA,CAEjB,CAAC;AACF;AACA;AACA;AAAI,OAAO,MAAMC,kBAAkB,GAAIC,KAAK,IAAG;EAC3C,MAAMC,UAAU,GAAG1B,SAAS,CAAC,CAAC;EAC9B,OAAO;IACHjB,OAAO,EAAEH,YAAY,CAACE,mBAAmB,CAACC,OAAO,EAAE2C,UAAU,CAAC3C,OAAO,CAAC,yBAA0B;EACpG,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ import * as d3 from 'd3-color';
|
|
|
6
6
|
import { getColorContrast } from '../../utilities/colors';
|
|
7
7
|
import { resolveCSSVariables } from '../../utilities/utilities';
|
|
8
8
|
import { useImageExport } from '../../utilities/hooks';
|
|
9
|
+
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
|
|
9
10
|
function invertHexColor(hex) {
|
|
10
11
|
const color = d3.color(hex);
|
|
11
12
|
if (!color) {
|
|
@@ -39,6 +40,9 @@ export const ChartTable = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>
|
|
|
39
40
|
const { headers, rows, width, height } = props;
|
|
40
41
|
const { chartContainerRef: _rootElem } = useImageExport(props.componentRef, true, false);
|
|
41
42
|
const classes = useChartTableStyles(props);
|
|
43
|
+
const arrowAttributes = useArrowNavigationGroup({
|
|
44
|
+
axis: 'grid'
|
|
45
|
+
});
|
|
42
46
|
if (!headers || headers.length === 0) {
|
|
43
47
|
return /*#__PURE__*/ React.createElement("div", null, "No data available");
|
|
44
48
|
}
|
|
@@ -101,7 +105,8 @@ export const ChartTable = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>
|
|
|
101
105
|
className: classes.table,
|
|
102
106
|
style: {
|
|
103
107
|
width: width ? `${width}px` : '100%'
|
|
104
|
-
}
|
|
108
|
+
},
|
|
109
|
+
...arrowAttributes
|
|
105
110
|
}, /*#__PURE__*/ React.createElement("thead", null, /*#__PURE__*/ React.createElement("tr", null, headers.map((header, idx)=>{
|
|
106
111
|
const style = {
|
|
107
112
|
...header === null || header === void 0 ? void 0 : header.style
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/ChartTable/ChartTable.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ChartTableProps } from './ChartTable.types';\nimport { useChartTableStyles } from './useChartTableStyles.styles';\nimport { tokens } from '@fluentui/react-theme';\nimport * as d3 from 'd3-color';\nimport { getColorContrast } from '../../utilities/colors';\nimport { resolveCSSVariables } from '../../utilities/utilities';\nimport { useImageExport } from '../../utilities/hooks';\n\nfunction invertHexColor(hex: string): string {\n const color = d3.color(hex);\n if (!color) {\n return tokens.colorNeutralForeground1!;\n }\n const rgb = color.rgb();\n return d3.rgb(255 - rgb.r, 255 - rgb.g, 255 - rgb.b).formatHex();\n}\n\nfunction getSafeBackgroundColor(chartContainer: HTMLElement, foreground?: string, background?: string): string {\n const fallbackFg = tokens.colorNeutralForeground1;\n const fallbackBg = tokens.colorNeutralBackground1;\n if (!chartContainer) {\n return fallbackBg;\n }\n\n const resolvedFg = resolveCSSVariables(chartContainer, foreground || fallbackFg);\n const resolvedBg = resolveCSSVariables(chartContainer, background || fallbackBg);\n\n const fg = d3.color(resolvedFg);\n const bg = d3.color(resolvedBg);\n\n if (!fg || !bg) {\n return resolvedBg;\n }\n const contrast = getColorContrast(fg.formatHex(), bg.formatHex());\n if (contrast >= 3) {\n return bg.formatHex();\n }\n\n const invertedBg = invertHexColor(bg.formatHex());\n const invertedContrast = getColorContrast(fg.formatHex(), invertedBg);\n return invertedContrast >= 3 ? invertedBg : fallbackBg;\n}\n\nexport const ChartTable: React.FunctionComponent<ChartTableProps> = React.forwardRef<HTMLDivElement, ChartTableProps>(\n (props, forwardedRef) => {\n const { headers, rows, width, height } = props;\n const { chartContainerRef: _rootElem } = useImageExport(props.componentRef, true, false);\n const classes = useChartTableStyles(props);\n\n if (!headers || headers.length === 0) {\n return <div>No data available</div>;\n }\n\n const bgColorSet = new Set<string>();\n headers.forEach(header => {\n const bg = header?.style?.backgroundColor;\n const normalized = d3.color(bg || '')?.formatHex();\n if (normalized) {\n bgColorSet.add(normalized);\n }\n });\n let sharedBackgroundColor: string | undefined;\n let useSharedBackground = false;\n\n /*\n If we have only one or two unique background colors, we can consider using a shared background color\n for the table headers. This is to ensure better contrast with the foreground text.\n For size 1, we will consider that as default color if it satisfies the contrast ratio.\n There could also be a scenario where backgroundcolor array is of size 2, for eg: [\"dimsgray\", \"gray\"],\n which will assign 1st column header bg color to dimsgray and rest to gray. so our logic of shared background\n color won't run here. So will consider for size 2 as well.\n For size greater than this, we will consider that user wants different colors and will let color contrast fail\n if any.\n */\n if (bgColorSet.size === 1 || bgColorSet.size === 2) {\n const candidateBg = bgColorSet.size === 1 ? Array.from(bgColorSet)[0] : Array.from(bgColorSet)[1];\n for (const header of headers) {\n const fg = header?.style?.color;\n if (fg && getColorContrast(fg, candidateBg) >= 3) {\n sharedBackgroundColor = candidateBg;\n useSharedBackground = true;\n break;\n }\n }\n }\n\n return (\n <div\n ref={el => {\n _rootElem.current = el;\n }}\n className={classes.root as string}\n style={{ height: height ? `${height}px` : '650px', overflow: 'hidden' }}\n >\n <svg width={width ?? '100%'} height={height ?? '650px'}>\n <foreignObject x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n <div\n style={{\n maxHeight: height ? `${height}px` : '650px',\n overflowY: 'auto',\n overflowX: 'auto',\n }}\n >\n <table\n className={classes.table}\n style={{\n width: width ? `${width}px` : '100%',\n }}\n >\n <thead>\n <tr>\n {headers.map((header, idx) => {\n const style = { ...header?.style };\n const fg = style.color;\n const bg = style.backgroundColor;\n\n if (useSharedBackground) {\n style.backgroundColor = sharedBackgroundColor;\n } else if (fg || bg) {\n style.backgroundColor = getSafeBackgroundColor(_rootElem.current!, fg, bg);\n }\n return (\n <th key={idx} className={classes.headerCell} style={style} tabIndex={0}>\n {header.value}\n </th>\n );\n })}\n </tr>\n </thead>\n {rows && rows.length > 0 && (\n <tbody>\n {rows.map((row, rowIdx) => (\n <tr key={rowIdx}>\n {row.map((cell, colIdx) => {\n const style = { ...cell?.style };\n const fg = style.color;\n const bg = style.backgroundColor;\n if (fg || bg) {\n style.backgroundColor = getSafeBackgroundColor(_rootElem.current!, fg, bg);\n }\n return (\n <td key={colIdx} className={classes.bodyCell} style={style} tabIndex={0}>\n {cell.value}\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n )}\n </table>\n </div>\n </foreignObject>\n </svg>\n </div>\n );\n },\n);\n\nChartTable.displayName = 'ChartTable';\n"],"names":["React","useChartTableStyles","tokens","d3","getColorContrast","resolveCSSVariables","useImageExport","invertHexColor","hex","color","colorNeutralForeground1","rgb","r","g","b","formatHex","getSafeBackgroundColor","chartContainer","foreground","background","fallbackFg","fallbackBg","colorNeutralBackground1","resolvedFg","resolvedBg","fg","bg","contrast","invertedBg","invertedContrast","ChartTable","forwardRef","props","forwardedRef","headers","rows","width","height","chartContainerRef","_rootElem","componentRef","classes","length","div","bgColorSet","Set","forEach","header","style","backgroundColor","normalized","add","sharedBackgroundColor","useSharedBackground","size","candidateBg","Array","from","ref","el","current","className","root","overflow","svg","foreignObject","x","y","maxHeight","overflowY","overflowX","table","thead","tr","map","idx","th","key","headerCell","tabIndex","value","tbody","row","rowIdx","cell","colIdx","td","bodyCell","displayName"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,mBAAmB,QAAQ,+BAA+B;AACnE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,YAAYC,QAAQ,WAAW;AAC/B,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,eAAeC,GAAW;IACjC,MAAMC,QAAQN,GAAGM,KAAK,CAACD;IACvB,IAAI,CAACC,OAAO;QACV,OAAOP,OAAOQ,uBAAuB;IACvC;IACA,MAAMC,MAAMF,MAAME,GAAG;IACrB,OAAOR,GAAGQ,GAAG,CAAC,MAAMA,IAAIC,CAAC,EAAE,MAAMD,IAAIE,CAAC,EAAE,MAAMF,IAAIG,CAAC,EAAEC,SAAS;AAChE;AAEA,SAASC,uBAAuBC,cAA2B,EAAEC,UAAmB,EAAEC,UAAmB;IACnG,MAAMC,aAAalB,OAAOQ,uBAAuB;IACjD,MAAMW,aAAanB,OAAOoB,uBAAuB;IACjD,IAAI,CAACL,gBAAgB;QACnB,OAAOI;IACT;IAEA,MAAME,aAAalB,oBAAoBY,gBAAgBC,cAAcE;IACrE,MAAMI,aAAanB,oBAAoBY,gBAAgBE,cAAcE;IAErE,MAAMI,KAAKtB,GAAGM,KAAK,CAACc;IACpB,MAAMG,KAAKvB,GAAGM,KAAK,CAACe;IAEpB,IAAI,CAACC,MAAM,CAACC,IAAI;QACd,OAAOF;IACT;IACA,MAAM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,OAAOiC,KAAK;IAGnB,MAGH7C,QAAQA,KAAKO,MAAM,GAAG,mBACrB,oBAACuC,eACE9C,KAAKuC,GAAG,CAAC,CAACQ,KAAKC,uBACd,oBAACV;YAAGI,KAAKM;WACND,IAAIR,GAAG,CAAC,CAACU,MAAMC;YACd,MAAMrC,QAAQ;mBAAKoC,iBAAAA,2BAAAA,KAAMpC,KAAK,AAAd;YAAe;YAC/B,MAAMvB,KAAKuB,MAAMvC,KAAK;YACtB,MAAMiB,KAAKsB,MAAMC,eAAe;YAChC,IAAIxB,MAAMC,IAAI;gBACZsB,MAAMC,eAAe,GAAGjC,uBAAuBuB,UAAUqB,OAAO,EAAGnC,IAAIC;YACzE;YACA,qBACE,oBAAC4D;gBAAGT,KAAKQ;gBAAQxB,WAAWpB,QAAQ8C,QAAQ;gBAAEvC,OAAOA;gBAAO+B,UAAU;eACnEK,KAAKJ,KAAK;QAGjB;AAWtB,GACA;AAEFlD,WAAW0D,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../src/components/ChartTable/ChartTable.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ChartTableProps } from './ChartTable.types';\nimport { useChartTableStyles } from './useChartTableStyles.styles';\nimport { tokens } from '@fluentui/react-theme';\nimport * as d3 from 'd3-color';\nimport { getColorContrast } from '../../utilities/colors';\nimport { resolveCSSVariables } from '../../utilities/utilities';\nimport { useImageExport } from '../../utilities/hooks';\nimport { useArrowNavigationGroup } from '@fluentui/react-tabster';\n\nfunction invertHexColor(hex: string): string {\n const color = d3.color(hex);\n if (!color) {\n return tokens.colorNeutralForeground1!;\n }\n const rgb = color.rgb();\n return d3.rgb(255 - rgb.r, 255 - rgb.g, 255 - rgb.b).formatHex();\n}\n\nfunction getSafeBackgroundColor(chartContainer: HTMLElement, foreground?: string, background?: string): string {\n const fallbackFg = tokens.colorNeutralForeground1;\n const fallbackBg = tokens.colorNeutralBackground1;\n if (!chartContainer) {\n return fallbackBg;\n }\n\n const resolvedFg = resolveCSSVariables(chartContainer, foreground || fallbackFg);\n const resolvedBg = resolveCSSVariables(chartContainer, background || fallbackBg);\n\n const fg = d3.color(resolvedFg);\n const bg = d3.color(resolvedBg);\n\n if (!fg || !bg) {\n return resolvedBg;\n }\n const contrast = getColorContrast(fg.formatHex(), bg.formatHex());\n if (contrast >= 3) {\n return bg.formatHex();\n }\n\n const invertedBg = invertHexColor(bg.formatHex());\n const invertedContrast = getColorContrast(fg.formatHex(), invertedBg);\n return invertedContrast >= 3 ? invertedBg : fallbackBg;\n}\n\nexport const ChartTable: React.FunctionComponent<ChartTableProps> = React.forwardRef<HTMLDivElement, ChartTableProps>(\n (props, forwardedRef) => {\n const { headers, rows, width, height } = props;\n const { chartContainerRef: _rootElem } = useImageExport(props.componentRef, true, false);\n const classes = useChartTableStyles(props);\n const arrowAttributes = useArrowNavigationGroup({ axis: 'grid' });\n\n if (!headers || headers.length === 0) {\n return <div>No data available</div>;\n }\n\n const bgColorSet = new Set<string>();\n headers.forEach(header => {\n const bg = header?.style?.backgroundColor;\n const normalized = d3.color(bg || '')?.formatHex();\n if (normalized) {\n bgColorSet.add(normalized);\n }\n });\n let sharedBackgroundColor: string | undefined;\n let useSharedBackground = false;\n\n /*\n If we have only one or two unique background colors, we can consider using a shared background color\n for the table headers. This is to ensure better contrast with the foreground text.\n For size 1, we will consider that as default color if it satisfies the contrast ratio.\n There could also be a scenario where backgroundcolor array is of size 2, for eg: [\"dimsgray\", \"gray\"],\n which will assign 1st column header bg color to dimsgray and rest to gray. so our logic of shared background\n color won't run here. So will consider for size 2 as well.\n For size greater than this, we will consider that user wants different colors and will let color contrast fail\n if any.\n */\n if (bgColorSet.size === 1 || bgColorSet.size === 2) {\n const candidateBg = bgColorSet.size === 1 ? Array.from(bgColorSet)[0] : Array.from(bgColorSet)[1];\n for (const header of headers) {\n const fg = header?.style?.color;\n if (fg && getColorContrast(fg, candidateBg) >= 3) {\n sharedBackgroundColor = candidateBg;\n useSharedBackground = true;\n break;\n }\n }\n }\n\n return (\n <div\n ref={el => {\n _rootElem.current = el;\n }}\n className={classes.root as string}\n style={{ height: height ? `${height}px` : '650px', overflow: 'hidden' }}\n >\n <svg width={width ?? '100%'} height={height ?? '650px'}>\n <foreignObject x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n <div\n style={{\n maxHeight: height ? `${height}px` : '650px',\n overflowY: 'auto',\n overflowX: 'auto',\n }}\n >\n <table\n className={classes.table}\n style={{\n width: width ? `${width}px` : '100%',\n }}\n {...arrowAttributes}\n >\n <thead>\n <tr>\n {headers.map((header, idx) => {\n const style = { ...header?.style };\n const fg = style.color;\n const bg = style.backgroundColor;\n\n if (useSharedBackground) {\n style.backgroundColor = sharedBackgroundColor;\n } else if (fg || bg) {\n style.backgroundColor = getSafeBackgroundColor(_rootElem.current!, fg, bg);\n }\n return (\n <th key={idx} className={classes.headerCell} style={style} tabIndex={0}>\n {header.value}\n </th>\n );\n })}\n </tr>\n </thead>\n {rows && rows.length > 0 && (\n <tbody>\n {rows.map((row, rowIdx) => (\n <tr key={rowIdx}>\n {row.map((cell, colIdx) => {\n const style = { ...cell?.style };\n const fg = style.color;\n const bg = style.backgroundColor;\n if (fg || bg) {\n style.backgroundColor = getSafeBackgroundColor(_rootElem.current!, fg, bg);\n }\n return (\n <td key={colIdx} className={classes.bodyCell} style={style} tabIndex={0}>\n {cell.value}\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n )}\n </table>\n </div>\n </foreignObject>\n </svg>\n </div>\n );\n },\n);\n\nChartTable.displayName = 'ChartTable';\n"],"names":["React","useChartTableStyles","tokens","d3","getColorContrast","resolveCSSVariables","useImageExport","useArrowNavigationGroup","invertHexColor","hex","color","colorNeutralForeground1","rgb","r","g","b","formatHex","getSafeBackgroundColor","chartContainer","foreground","background","fallbackFg","fallbackBg","colorNeutralBackground1","resolvedFg","resolvedBg","fg","bg","contrast","invertedBg","invertedContrast","ChartTable","forwardRef","props","forwardedRef","headers","rows","width","height","chartContainerRef","_rootElem","componentRef","classes","arrowAttributes","axis","length","div","bgColorSet","Set","forEach","header","style","backgroundColor","normalized","add","sharedBackgroundColor","useSharedBackground","size","candidateBg","Array","from","ref","el","current","className","root","overflow","svg","foreignObject","x","y","maxHeight","overflowY","overflowX","table","thead","tr","map","idx","th","key","headerCell","tabIndex","value","tbody","row","rowIdx","cell","colIdx","td","bodyCell","displayName"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,mBAAmB,QAAQ,+BAA+B;AACnE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,YAAYC,QAAQ,WAAW;AAC/B,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,uBAAuB,QAAQ,0BAA0B;AAElE,SAASC,eAAeC,GAAW;IACjC,MAAMC,QAAQP,GAAGO,KAAK,CAACD;IACvB,IAAI,CAACC,OAAO;QACV,OAAOR,OAAOS,uBAAuB;IACvC;IACA,MAAMC,MAAMF,MAAME,GAAG;IACrB,OAAOT,GAAGS,GAAG,CAAC,MAAMA,IAAIC,CAAC,EAAE,MAAMD,IAAIE,CAAC,EAAE,MAAMF,IAAIG,CAAC,EAAEC,SAAS;AAChE;AAEA,SAASC,uBAAuBC,cAA2B,EAAEC,UAAmB,EAAEC,UAAmB;IACnG,MAAMC,aAAanB,OAAOS,uBAAuB;IACjD,MAAMW,aAAapB,OAAOqB,uBAAuB;IACjD,IAAI,CAACL,gBAAgB;QACnB,OAAOI;IACT;IAEA,MAAME,aAAanB,oBAAoBa,gBAAgBC,cAAcE;IACrE,MAAMI,aAAapB,oBAAoBa,gBAAgBE,cAAcE;IAErE,MAAMI,KAAKvB,GAAGO,KAAK,CAACc;IACpB,MAAMG,KAAKxB,GAAGO,KAAK,CAACe;IAEpB,IAAI,CAACC,MAAM,CAACC,IAAI;QACd,OAAOF;IACT;IACA,MAAMG,WAAWxB,iBAAi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B,QAAQuC,UAAU;YAAE9B,OAAOA;YAAO+B,UAAU;WAClEhC,OAAOiC,KAAK;IAGnB,MAGH/C,QAAQA,KAAKS,MAAM,GAAG,mBACrB,oBAACuC,eACEhD,KAAKyC,GAAG,CAAC,CAACQ,KAAKC,uBACd,oBAACV;YAAGI,KAAKM;WACND,IAAIR,GAAG,CAAC,CAACU,MAAMC;YACd,MAAMrC,QAAQ;mBAAKoC,iBAAAA,2BAAAA,KAAMpC,KAAK,AAAd;YAAe;YAC/B,MAAMzB,KAAKyB,MAAMzC,KAAK;YACtB,MAAMiB,KAAKwB,MAAMC,eAAe;YAChC,IAAI1B,MAAMC,IAAI;gBACZwB,MAAMC,eAAe,GAAGnC,uBAAuBuB,UAAUuB,OAAO,EAAGrC,IAAIC;YACzE;YACA,qBACE,oBAAC8D;gBAAGT,KAAKQ;gBAAQxB,WAAWtB,QAAQgD,QAAQ;gBAAEvC,OAAOA;gBAAO+B,UAAU;eACnEK,KAAKJ,KAAK;QAGjB;AAWtB,GACA;AAEFpD,WAAW4D,WAAW,GAAG"}
|
|
@@ -14,10 +14,6 @@ const ARROW_SIZE_SCALE = 0.35;
|
|
|
14
14
|
const MAX_SIMPLE_MARKUP_DEPTH = 5;
|
|
15
15
|
const CHAR_CODE_LESS_THAN = '<'.codePointAt(0);
|
|
16
16
|
const CHAR_CODE_GREATER_THAN = '>'.codePointAt(0);
|
|
17
|
-
const getAnnotationKey = (annotation, index)=>{
|
|
18
|
-
var _annotation_id, _ref;
|
|
19
|
-
return (_ref = (_annotation_id = annotation.id) !== null && _annotation_id !== void 0 ? _annotation_id : typeof annotation.text === 'string' || typeof annotation.text === 'number' ? String(annotation.text) : undefined) !== null && _ref !== void 0 ? _ref : `annotation-${index}`;
|
|
20
|
-
};
|
|
21
17
|
const decodeSimpleMarkupInput = (input)=>{
|
|
22
18
|
const namedEntities = {
|
|
23
19
|
amp: '&',
|
|
@@ -216,6 +212,40 @@ const normalizeBandOffset = (scale, value)=>{
|
|
|
216
212
|
return position;
|
|
217
213
|
};
|
|
218
214
|
const clamp = (value, min, max)=>Math.max(min, Math.min(max, value));
|
|
215
|
+
const resolveDataCoordinate = (axis, value, context, yAxis = 'primary')=>{
|
|
216
|
+
if (axis === 'x') {
|
|
217
|
+
const xScale = context.xScale;
|
|
218
|
+
if (!xScale) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const parsedValue = value instanceof Date ? value.getTime() : value;
|
|
222
|
+
return normalizeBandOffset(xScale, parsedValue);
|
|
223
|
+
}
|
|
224
|
+
const yScale = yAxis === 'secondary' ? context.yScaleSecondary : context.yScalePrimary;
|
|
225
|
+
if (!yScale) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const parsedValue = value instanceof Date ? value.getTime() : value;
|
|
229
|
+
return normalizeBandOffset(yScale, parsedValue);
|
|
230
|
+
};
|
|
231
|
+
const resolveAxisCoordinate = (axis, coordinateType, value, context, options = {})=>{
|
|
232
|
+
switch(coordinateType){
|
|
233
|
+
case 'data':
|
|
234
|
+
return resolveDataCoordinate(axis, value, context, options.yAxis);
|
|
235
|
+
case 'relative':
|
|
236
|
+
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
return axis === 'x' ? context.plotRect.x + context.plotRect.width * value : context.plotRect.y + context.plotRect.height * value;
|
|
240
|
+
case 'pixel':
|
|
241
|
+
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
return axis === 'x' ? context.plotRect.x + value : context.plotRect.y + value;
|
|
245
|
+
default:
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
219
249
|
const createMeasurementSignature = (annotationContentSignature, containerStyle, contentStyle, layoutClassName, styleClassName)=>JSON.stringify({
|
|
220
250
|
annotationContentSignature,
|
|
221
251
|
containerStyle,
|
|
@@ -223,58 +253,58 @@ const createMeasurementSignature = (annotationContentSignature, containerStyle,
|
|
|
223
253
|
layoutClassName: layoutClassName !== null && layoutClassName !== void 0 ? layoutClassName : '',
|
|
224
254
|
styleClassName: styleClassName !== null && styleClassName !== void 0 ? styleClassName : ''
|
|
225
255
|
});
|
|
256
|
+
const getCoordinateDescriptor = (coordinates)=>{
|
|
257
|
+
switch(coordinates.type){
|
|
258
|
+
case 'data':
|
|
259
|
+
return {
|
|
260
|
+
xType: 'data',
|
|
261
|
+
yType: 'data',
|
|
262
|
+
yAxis: coordinates.yAxis
|
|
263
|
+
};
|
|
264
|
+
case 'relative':
|
|
265
|
+
return {
|
|
266
|
+
xType: 'relative',
|
|
267
|
+
yType: 'relative'
|
|
268
|
+
};
|
|
269
|
+
case 'pixel':
|
|
270
|
+
return {
|
|
271
|
+
xType: 'pixel',
|
|
272
|
+
yType: 'pixel'
|
|
273
|
+
};
|
|
274
|
+
case 'mixed':
|
|
275
|
+
return {
|
|
276
|
+
xType: coordinates.xCoordinateType,
|
|
277
|
+
yType: coordinates.yCoordinateType,
|
|
278
|
+
yAxis: coordinates.yAxis
|
|
279
|
+
};
|
|
280
|
+
default:
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
226
284
|
const resolveCoordinates = (annotation, context)=>{
|
|
227
285
|
const { coordinates, layout } = annotation;
|
|
228
286
|
if (!coordinates) {
|
|
229
287
|
return undefined;
|
|
230
288
|
}
|
|
289
|
+
const descriptor = getCoordinateDescriptor(coordinates);
|
|
290
|
+
if (!descriptor) {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
231
293
|
var _layout_offsetX;
|
|
232
294
|
const offsetX = (_layout_offsetX = layout === null || layout === void 0 ? void 0 : layout.offsetX) !== null && _layout_offsetX !== void 0 ? _layout_offsetX : 0;
|
|
233
295
|
var _layout_offsetY;
|
|
234
296
|
const offsetY = (_layout_offsetY = layout === null || layout === void 0 ? void 0 : layout.offsetY) !== null && _layout_offsetY !== void 0 ? _layout_offsetY : 0;
|
|
297
|
+
const anchorX = resolveAxisCoordinate('x', descriptor.xType, coordinates.x, context);
|
|
298
|
+
const anchorY = resolveAxisCoordinate('y', descriptor.yType, coordinates.y, context, {
|
|
299
|
+
yAxis: descriptor.yAxis
|
|
300
|
+
});
|
|
301
|
+
if (anchorX === undefined || anchorY === undefined) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
235
304
|
const anchor = {
|
|
236
|
-
x:
|
|
237
|
-
y:
|
|
305
|
+
x: anchorX,
|
|
306
|
+
y: anchorY
|
|
238
307
|
};
|
|
239
|
-
switch(coordinates.type){
|
|
240
|
-
case 'data':
|
|
241
|
-
{
|
|
242
|
-
const { x, y, yAxis = 'primary' } = coordinates;
|
|
243
|
-
const xScale = context.xScale;
|
|
244
|
-
const yScale = yAxis === 'secondary' ? context.yScaleSecondary : context.yScalePrimary;
|
|
245
|
-
if (!xScale || !yScale) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
const xValue = normalizeBandOffset(xScale, x instanceof Date ? x.getTime() : x);
|
|
249
|
-
const yValue = normalizeBandOffset(yScale, y instanceof Date ? y.getTime() : y);
|
|
250
|
-
if (typeof xValue !== 'number' || typeof yValue !== 'number') {
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
anchor.x = xValue;
|
|
254
|
-
anchor.y = yValue;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case 'relative':
|
|
258
|
-
{
|
|
259
|
-
if (typeof coordinates.x !== 'number' || typeof coordinates.y !== 'number') {
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
anchor.x = context.plotRect.x + context.plotRect.width * coordinates.x;
|
|
263
|
-
anchor.y = context.plotRect.y + context.plotRect.height * coordinates.y;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
case 'pixel':
|
|
267
|
-
{
|
|
268
|
-
if (typeof coordinates.x !== 'number' || typeof coordinates.y !== 'number') {
|
|
269
|
-
return undefined;
|
|
270
|
-
}
|
|
271
|
-
anchor.x = context.plotRect.x + coordinates.x;
|
|
272
|
-
anchor.y = context.plotRect.y + coordinates.y;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
default:
|
|
276
|
-
return undefined;
|
|
277
|
-
}
|
|
278
308
|
let left = anchor.x + offsetX;
|
|
279
309
|
let top = anchor.y + offsetY;
|
|
280
310
|
if (layout === null || layout === void 0 ? void 0 : layout.clipToBounds) {
|
|
@@ -293,12 +323,20 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
293
323
|
const { annotations: annotationsProp, context } = props;
|
|
294
324
|
const classes = useChartAnnotationLayerStyles(props);
|
|
295
325
|
const idPrefix = useId('chart-annotation');
|
|
326
|
+
const autoKeyPrefix = useId('chart-annotation-item');
|
|
296
327
|
const [measurements, setMeasurements] = React.useState({});
|
|
297
|
-
const resolvedAnnotations = React.useMemo(()=>
|
|
328
|
+
const resolvedAnnotations = React.useMemo(()=>{
|
|
329
|
+
let fallbackIndex = 0;
|
|
330
|
+
return (annotationsProp !== null && annotationsProp !== void 0 ? annotationsProp : []).map((annotation)=>{
|
|
331
|
+
var _annotation_id;
|
|
332
|
+
return {
|
|
298
333
|
annotation,
|
|
299
|
-
key:
|
|
300
|
-
}
|
|
301
|
-
|
|
334
|
+
key: (_annotation_id = annotation.id) !== null && _annotation_id !== void 0 ? _annotation_id : `${autoKeyPrefix}-${fallbackIndex++}`
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
}, [
|
|
338
|
+
annotationsProp,
|
|
339
|
+
autoKeyPrefix
|
|
302
340
|
]);
|
|
303
341
|
React.useEffect(()=>{
|
|
304
342
|
setMeasurements((prev)=>{
|
|
@@ -354,7 +392,7 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
354
392
|
const measurementElements = [];
|
|
355
393
|
const connectors = [];
|
|
356
394
|
resolvedAnnotations.forEach(({ annotation, key })=>{
|
|
357
|
-
var _annotation_style, _annotation_style1, _annotation_style2, _annotation_style3, _annotation_style4, _annotation_style5, _annotation_style6, _annotation_style7, _annotation_style8, _annotation_style9, _annotation_style10, _annotation_style11, _annotation_style12, _annotation_style13, _annotation_style14, _annotation_style15, _annotation_style16, _annotation_style17, _annotation_accessibility, _annotation_accessibility1, _annotation_accessibility2;
|
|
395
|
+
var _annotation_style, _annotation_style1, _annotation_style2, _annotation_style3, _annotation_style4, _annotation_style5, _annotation_style6, _annotation_style7, _annotation_style8, _annotation_style9, _annotation_style10, _annotation_style11, _annotation_style12, _annotation_style13, _annotation_style14, _annotation_style15, _annotation_style16, _annotation_style17, _annotation_style18, _annotation_accessibility, _annotation_accessibility1, _annotation_accessibility2;
|
|
358
396
|
const resolved = resolveCoordinates(annotation, context);
|
|
359
397
|
if (!resolved) {
|
|
360
398
|
return;
|
|
@@ -376,28 +414,30 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
376
414
|
const containerStyle = {
|
|
377
415
|
maxWidth: layout === null || layout === void 0 ? void 0 : layout.maxWidth,
|
|
378
416
|
...hasCustomBackground ? {
|
|
379
|
-
backgroundColor: applyOpacityToColor(baseBackgroundColor, backgroundOpacity
|
|
417
|
+
backgroundColor: applyOpacityToColor(baseBackgroundColor, backgroundOpacity, {
|
|
418
|
+
preserveOriginalOpacity: ((_annotation_style4 = annotation.style) === null || _annotation_style4 === void 0 ? void 0 : _annotation_style4.opacity) === undefined
|
|
419
|
+
})
|
|
380
420
|
} : {
|
|
381
421
|
backgroundColor: applyOpacityToColor(tokens.colorNeutralBackground1, DEFAULT_ANNOTATION_BACKGROUND_OPACITY)
|
|
382
422
|
},
|
|
383
|
-
borderColor: (
|
|
384
|
-
borderWidth: (
|
|
385
|
-
borderStyle: (_annotation_style_borderStyle = (
|
|
386
|
-
borderRadius: (
|
|
387
|
-
padding: (
|
|
388
|
-
boxShadow: (
|
|
423
|
+
borderColor: (_annotation_style5 = annotation.style) === null || _annotation_style5 === void 0 ? void 0 : _annotation_style5.borderColor,
|
|
424
|
+
borderWidth: (_annotation_style6 = annotation.style) === null || _annotation_style6 === void 0 ? void 0 : _annotation_style6.borderWidth,
|
|
425
|
+
borderStyle: (_annotation_style_borderStyle = (_annotation_style7 = annotation.style) === null || _annotation_style7 === void 0 ? void 0 : _annotation_style7.borderStyle) !== null && _annotation_style_borderStyle !== void 0 ? _annotation_style_borderStyle : ((_annotation_style8 = annotation.style) === null || _annotation_style8 === void 0 ? void 0 : _annotation_style8.borderColor) ? 'solid' : undefined,
|
|
426
|
+
borderRadius: (_annotation_style9 = annotation.style) === null || _annotation_style9 === void 0 ? void 0 : _annotation_style9.borderRadius,
|
|
427
|
+
padding: (_annotation_style10 = annotation.style) === null || _annotation_style10 === void 0 ? void 0 : _annotation_style10.padding,
|
|
428
|
+
boxShadow: (_annotation_style11 = annotation.style) === null || _annotation_style11 === void 0 ? void 0 : _annotation_style11.boxShadow
|
|
389
429
|
};
|
|
390
430
|
const contentStyle = {
|
|
391
|
-
color: (
|
|
392
|
-
fontSize: (
|
|
393
|
-
fontWeight: (
|
|
431
|
+
color: (_annotation_style12 = annotation.style) === null || _annotation_style12 === void 0 ? void 0 : _annotation_style12.textColor,
|
|
432
|
+
fontSize: (_annotation_style13 = annotation.style) === null || _annotation_style13 === void 0 ? void 0 : _annotation_style13.fontSize,
|
|
433
|
+
fontWeight: (_annotation_style14 = annotation.style) === null || _annotation_style14 === void 0 ? void 0 : _annotation_style14.fontWeight,
|
|
394
434
|
opacity: 1
|
|
395
435
|
};
|
|
396
|
-
if (typeof ((
|
|
436
|
+
if (typeof ((_annotation_style15 = annotation.style) === null || _annotation_style15 === void 0 ? void 0 : _annotation_style15.rotation) === 'number' && !Number.isNaN(annotation.style.rotation)) {
|
|
397
437
|
containerStyle.transform = `rotate(${annotation.style.rotation}deg)`;
|
|
398
438
|
containerStyle.transformOrigin = '50% 50%';
|
|
399
439
|
}
|
|
400
|
-
const measurementSignature = createMeasurementSignature(annotationMarkupSignature, containerStyle, contentStyle, layout === null || layout === void 0 ? void 0 : layout.className, (
|
|
440
|
+
const measurementSignature = createMeasurementSignature(annotationMarkupSignature, containerStyle, contentStyle, layout === null || layout === void 0 ? void 0 : layout.className, (_annotation_style16 = annotation.style) === null || _annotation_style16 === void 0 ? void 0 : _annotation_style16.className);
|
|
401
441
|
const measurementEntry = measurements[key];
|
|
402
442
|
const isMeasurementValid = (measurementEntry === null || measurementEntry === void 0 ? void 0 : measurementEntry.signature) === measurementSignature;
|
|
403
443
|
const measuredSize = isMeasurementValid ? measurementEntry : undefined;
|
|
@@ -464,7 +504,7 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
464
504
|
...containerStyle
|
|
465
505
|
};
|
|
466
506
|
if (!isMeasurementValid) {
|
|
467
|
-
var
|
|
507
|
+
var _annotation_style19, _annotation_style20;
|
|
468
508
|
measurementElements.push(/*#__PURE__*/ React.createElement("div", {
|
|
469
509
|
key: `${key}-measurement`,
|
|
470
510
|
ref: (node)=>{
|
|
@@ -475,13 +515,13 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
475
515
|
}
|
|
476
516
|
}
|
|
477
517
|
},
|
|
478
|
-
className: mergeClasses(classes.annotation, classes.measurement, layout === null || layout === void 0 ? void 0 : layout.className, (
|
|
518
|
+
className: mergeClasses(classes.annotation, classes.measurement, layout === null || layout === void 0 ? void 0 : layout.className, (_annotation_style19 = annotation.style) === null || _annotation_style19 === void 0 ? void 0 : _annotation_style19.className),
|
|
479
519
|
style: measurementStyle,
|
|
480
520
|
"aria-hidden": true,
|
|
481
521
|
"data-annotation-key": key,
|
|
482
522
|
"data-chart-annotation-measurement": "true"
|
|
483
523
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
484
|
-
className: mergeClasses(classes.annotationContent, layout === null || layout === void 0 ? void 0 : layout.className, (
|
|
524
|
+
className: mergeClasses(classes.annotationContent, layout === null || layout === void 0 ? void 0 : layout.className, (_annotation_style20 = annotation.style) === null || _annotation_style20 === void 0 ? void 0 : _annotation_style20.className),
|
|
485
525
|
style: contentStyle
|
|
486
526
|
}, renderSimpleMarkup(annotationMarkupNodes, `${key}-measurement`))));
|
|
487
527
|
}
|
|
@@ -495,11 +535,11 @@ export const ChartAnnotationLayer = /*#__PURE__*/ React.memo((props)=>{
|
|
|
495
535
|
className: mergeClasses(classes.annotationForeignObject),
|
|
496
536
|
"data-annotation-key": key
|
|
497
537
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
498
|
-
className: mergeClasses(classes.annotation, layout === null || layout === void 0 ? void 0 : layout.className, (
|
|
538
|
+
className: mergeClasses(classes.annotation, layout === null || layout === void 0 ? void 0 : layout.className, (_annotation_style17 = annotation.style) === null || _annotation_style17 === void 0 ? void 0 : _annotation_style17.className),
|
|
499
539
|
style: containerStyle,
|
|
500
540
|
"data-annotation-key": key
|
|
501
541
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
502
|
-
className: mergeClasses(classes.annotationContent, (
|
|
542
|
+
className: mergeClasses(classes.annotationContent, (_annotation_style18 = annotation.style) === null || _annotation_style18 === void 0 ? void 0 : _annotation_style18.className),
|
|
503
543
|
style: contentStyle,
|
|
504
544
|
role: (_annotation_accessibility_role = (_annotation_accessibility = annotation.accessibility) === null || _annotation_accessibility === void 0 ? void 0 : _annotation_accessibility.role) !== null && _annotation_accessibility_role !== void 0 ? _annotation_accessibility_role : 'note',
|
|
505
545
|
"aria-label": (_annotation_accessibility_ariaLabel = (_annotation_accessibility1 = annotation.accessibility) === null || _annotation_accessibility1 === void 0 ? void 0 : _annotation_accessibility1.ariaLabel) !== null && _annotation_accessibility_ariaLabel !== void 0 ? _annotation_accessibility_ariaLabel : annotationPlainText ? annotationPlainText : undefined,
|