@fluentui/react-charting 5.23.18 → 5.23.20

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.
Files changed (43) hide show
  1. package/CHANGELOG.json +37 -1
  2. package/CHANGELOG.md +21 -2
  3. package/dist/react-charting.d.ts +38 -0
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +18 -0
  7. package/lib/DeclarativeChart.d.ts +1 -0
  8. package/lib/DeclarativeChart.js +2 -0
  9. package/lib/DeclarativeChart.js.map +1 -0
  10. package/lib/components/DeclarativeChart/DeclarativeChart.d.ts +36 -0
  11. package/lib/components/DeclarativeChart/DeclarativeChart.js +70 -0
  12. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -0
  13. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -0
  14. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +460 -0
  15. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -0
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +1 -0
  18. package/lib/index.js.map +1 -1
  19. package/lib-amd/DeclarativeChart.d.ts +1 -0
  20. package/lib-amd/DeclarativeChart.js +6 -0
  21. package/lib-amd/DeclarativeChart.js.map +1 -0
  22. package/lib-amd/components/DeclarativeChart/DeclarativeChart.d.ts +36 -0
  23. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +60 -0
  24. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -0
  25. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -0
  26. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +473 -0
  27. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -0
  28. package/lib-amd/index.d.ts +2 -0
  29. package/lib-amd/index.js +3 -2
  30. package/lib-amd/index.js.map +1 -1
  31. package/lib-commonjs/DeclarativeChart.d.ts +1 -0
  32. package/lib-commonjs/DeclarativeChart.js +5 -0
  33. package/lib-commonjs/DeclarativeChart.js.map +1 -0
  34. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.d.ts +36 -0
  35. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +73 -0
  36. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -0
  37. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -0
  38. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +476 -0
  39. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -0
  40. package/lib-commonjs/index.d.ts +2 -0
  41. package/lib-commonjs/index.js +3 -1
  42. package/lib-commonjs/index.js.map +1 -1
  43. package/package.json +1 -1
@@ -119,6 +119,15 @@ export const DataVizPalette: {
119
119
  highSuccess: string;
120
120
  };
121
121
 
122
+ // @public
123
+ export const DeclarativeChart: React_2.FunctionComponent<DeclarativeChartProps>;
124
+
125
+ // @public
126
+ export interface DeclarativeChartProps extends React_2.RefAttributes<HTMLDivElement> {
127
+ chartSchema: Schema;
128
+ onSchemaChange?: (eventData: Schema) => void;
129
+ }
130
+
122
131
  // @public
123
132
  export const DonutChart: React_2.FunctionComponent<IDonutChartProps>;
124
133
 
@@ -1591,6 +1600,15 @@ export const PieChart: React_2.FunctionComponent<IPieChartProps>;
1591
1600
  // @public
1592
1601
  export const SankeyChart: React_2.FunctionComponent<ISankeyChartProps>;
1593
1602
 
1603
+ // @public (undocumented)
1604
+ export interface Schema {
1605
+ accesibilityLabels?: {
1606
+ [key: string]: string;
1607
+ };
1608
+ plotlySchema: any;
1609
+ selectedLegends?: string[];
1610
+ }
1611
+
1594
1612
  // @public (undocumented)
1595
1613
  export const Shape: React_2.FC<IShapeProps>;
1596
1614
 
@@ -0,0 +1 @@
1
+ export * from './components/DeclarativeChart/DeclarativeChart';
@@ -0,0 +1,2 @@
1
+ export * from './components/DeclarativeChart/DeclarativeChart';
2
+ //# sourceMappingURL=DeclarativeChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeclarativeChart.js","sourceRoot":"../src/","sources":["DeclarativeChart.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC","sourcesContent":["export * from './components/DeclarativeChart/DeclarativeChart';\n"]}
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ export interface Schema {
3
+ /**
4
+ * Plotly schema represented as JSON object
5
+ */
6
+ plotlySchema: any;
7
+ /**
8
+ * The legends selected by the user to persist in the chart
9
+ */
10
+ selectedLegends?: string[];
11
+ /**
12
+ * Dictionary for localizing the accessibility labels
13
+ */
14
+ accesibilityLabels?: {
15
+ [key: string]: string;
16
+ };
17
+ }
18
+ /**
19
+ * DeclarativeChart props.
20
+ * {@docCategory DeclarativeChart}
21
+ */
22
+ export interface DeclarativeChartProps extends React.RefAttributes<HTMLDivElement> {
23
+ /**
24
+ * The schema representing the chart data, layout and configuration
25
+ */
26
+ chartSchema: Schema;
27
+ /**
28
+ * Callback when an event occurs
29
+ */
30
+ onSchemaChange?: (eventData: Schema) => void;
31
+ }
32
+ /**
33
+ * DeclarativeChart component.
34
+ * {@docCategory DeclarativeChart}
35
+ */
36
+ export declare const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps>;
@@ -0,0 +1,70 @@
1
+ import { __assign } from "tslib";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ import * as React from 'react';
5
+ import { DonutChart } from '../DonutChart/index';
6
+ import { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';
7
+ import { transformPlotlyJsonToDonutProps, transformPlotlyJsonToVSBCProps, transformPlotlyJsonToScatterChartProps, transformPlotlyJsonToHorizontalBarWithAxisProps, isDateArray, isNumberArray, transformPlotlyJsonToHeatmapProps, transformPlotlyJsonToSankeyProps, transformPlotlyJsonToGaugeProps, transformPlotlyJsonToGVBCProps, transformPlotlyJsonToVBCProps, } from './PlotlySchemaAdapter';
8
+ import { LineChart } from '../LineChart/index';
9
+ import { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';
10
+ import { AreaChart } from '../AreaChart/index';
11
+ import { HeatMapChart } from '../HeatMapChart/index';
12
+ import { SankeyChart } from '../SankeyChart/SankeyChart';
13
+ import { GaugeChart } from '../GaugeChart/index';
14
+ import { GroupedVerticalBarChart } from '../GroupedVerticalBarChart/index';
15
+ import { VerticalBarChart } from '../VerticalBarChart/index';
16
+ var useColorMapping = function () {
17
+ var colorMap = React.useRef(new Map());
18
+ return colorMap;
19
+ };
20
+ /**
21
+ * DeclarativeChart component.
22
+ * {@docCategory DeclarativeChart}
23
+ */
24
+ export var DeclarativeChart = React.forwardRef(function (props, forwardedRef) {
25
+ var _a, _b, _c, _d;
26
+ var plotlySchema = props.chartSchema.plotlySchema;
27
+ var xValues = plotlySchema.data[0].x;
28
+ var isXDate = isDateArray(xValues);
29
+ var isXNumber = isNumberArray(xValues);
30
+ var colorMap = useColorMapping();
31
+ switch (plotlySchema.data[0].type) {
32
+ case 'pie':
33
+ return React.createElement(DonutChart, __assign({}, transformPlotlyJsonToDonutProps(plotlySchema, colorMap)));
34
+ case 'bar':
35
+ var orientation_1 = plotlySchema.data[0].orientation;
36
+ if (orientation_1 === 'h') {
37
+ return (React.createElement(HorizontalBarChartWithAxis, __assign({}, transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap))));
38
+ }
39
+ else {
40
+ if (['group', 'overlay'].includes((_a = plotlySchema === null || plotlySchema === void 0 ? void 0 : plotlySchema.layout) === null || _a === void 0 ? void 0 : _a.barmode)) {
41
+ return React.createElement(GroupedVerticalBarChart, __assign({}, transformPlotlyJsonToGVBCProps(plotlySchema, colorMap)));
42
+ }
43
+ return React.createElement(VerticalStackedBarChart, __assign({}, transformPlotlyJsonToVSBCProps(plotlySchema, colorMap)));
44
+ }
45
+ case 'scatter':
46
+ var isAreaChart = plotlySchema.data.some(function (series) { return series.fill === 'tonexty'; });
47
+ if (isXDate || isXNumber) {
48
+ if (isAreaChart) {
49
+ return React.createElement(AreaChart, __assign({}, transformPlotlyJsonToScatterChartProps(plotlySchema, true, colorMap)));
50
+ }
51
+ return React.createElement(LineChart, __assign({}, transformPlotlyJsonToScatterChartProps(plotlySchema, false, colorMap)));
52
+ }
53
+ return React.createElement(VerticalStackedBarChart, __assign({}, transformPlotlyJsonToVSBCProps(plotlySchema, colorMap)));
54
+ case 'heatmap':
55
+ return React.createElement(HeatMapChart, __assign({}, transformPlotlyJsonToHeatmapProps(plotlySchema)));
56
+ case 'sankey':
57
+ return React.createElement(SankeyChart, __assign({}, transformPlotlyJsonToSankeyProps(plotlySchema, colorMap)));
58
+ case 'indicator':
59
+ if ((_d = (_c = (_b = plotlySchema === null || plotlySchema === void 0 ? void 0 : plotlySchema.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.mode) === null || _d === void 0 ? void 0 : _d.includes('gauge')) {
60
+ return React.createElement(GaugeChart, __assign({}, transformPlotlyJsonToGaugeProps(plotlySchema, colorMap)));
61
+ }
62
+ return React.createElement("div", null, "Unsupported Schema");
63
+ case 'histogram':
64
+ return React.createElement(VerticalBarChart, __assign({}, transformPlotlyJsonToVBCProps(plotlySchema, colorMap)));
65
+ default:
66
+ return React.createElement("div", null, "Unsupported Schema");
67
+ }
68
+ });
69
+ DeclarativeChart.displayName = 'DeclarativeChart';
70
+ //# sourceMappingURL=DeclarativeChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeclarativeChart.js","sourceRoot":"../src/","sources":["components/DeclarativeChart/DeclarativeChart.tsx"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,uDAAuD;AACvD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,E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AAC;QAC/E,KAAK,QAAQ;YACX,OAAO,oBAAC,WAAW,eAAK,gCAAgC,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAI,CAAC;QACvF,KAAK,WAAW;YACd,IAAI,MAAA,MAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,0CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACpD,OAAO,oBAAC,UAAU,eAAK,+BAA+B,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAI,CAAC;aACpF;YACD,OAAO,sDAA6B,CAAC;QACvC,KAAK,WAAW;YACd,OAAO,oBAAC,gBAAgB,eAAK,6BAA6B,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAI,CAAC;QACzF;YACE,OAAO,sDAA6B,CAAC;KACxC;AACH,CAAC,CAAC,CAAC;AACH,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from 'react';\nimport { DonutChart } from '../DonutChart/index';\nimport { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';\nimport {\n transformPlotlyJsonToDonutProps,\n transformPlotlyJsonToVSBCProps,\n transformPlotlyJsonToScatterChartProps,\n transformPlotlyJsonToHorizontalBarWithAxisProps,\n isDateArray,\n isNumberArray,\n transformPlotlyJsonToHeatmapProps,\n transformPlotlyJsonToSankeyProps,\n transformPlotlyJsonToGaugeProps,\n transformPlotlyJsonToGVBCProps,\n transformPlotlyJsonToVBCProps,\n} from './PlotlySchemaAdapter';\nimport { LineChart } from '../LineChart/index';\nimport { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';\nimport { AreaChart } from '../AreaChart/index';\nimport { HeatMapChart } from '../HeatMapChart/index';\nimport { SankeyChart } from '../SankeyChart/SankeyChart';\nimport { GaugeChart } from '../GaugeChart/index';\nimport { GroupedVerticalBarChart } from '../GroupedVerticalBarChart/index';\nimport { VerticalBarChart } from '../VerticalBarChart/index';\n\nexport interface Schema {\n /**\n * Plotly schema represented as JSON object\n */\n plotlySchema: any;\n\n /**\n * The legends selected by the user to persist in the chart\n */\n selectedLegends?: string[];\n\n /**\n * Dictionary for localizing the accessibility labels\n */\n accesibilityLabels?: { [key: string]: string };\n}\n\n/**\n * DeclarativeChart props.\n * {@docCategory DeclarativeChart}\n */\nexport interface DeclarativeChartProps extends React.RefAttributes<HTMLDivElement> {\n /**\n * The schema representing the chart data, layout and configuration\n */\n chartSchema: Schema;\n\n /**\n * Callback when an event occurs\n */\n onSchemaChange?: (eventData: Schema) => void;\n}\n\nconst useColorMapping = () => {\n const colorMap = React.useRef(new Map<string, string>());\n return colorMap;\n};\n\n/**\n * DeclarativeChart component.\n * {@docCategory DeclarativeChart}\n */\nexport const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> = React.forwardRef<\n HTMLDivElement,\n DeclarativeChartProps\n>((props, forwardedRef) => {\n const { plotlySchema } = props.chartSchema;\n const xValues = plotlySchema.data[0].x;\n const isXDate = isDateArray(xValues);\n const isXNumber = isNumberArray(xValues);\n const colorMap = useColorMapping();\n\n switch (plotlySchema.data[0].type) {\n case 'pie':\n return <DonutChart {...transformPlotlyJsonToDonutProps(plotlySchema, colorMap)} />;\n case 'bar':\n const orientation = plotlySchema.data[0].orientation;\n if (orientation === 'h') {\n return (\n <HorizontalBarChartWithAxis {...transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap)} />\n );\n } else {\n if (['group', 'overlay'].includes(plotlySchema?.layout?.barmode)) {\n return <GroupedVerticalBarChart {...transformPlotlyJsonToGVBCProps(plotlySchema, colorMap)} />;\n }\n return <VerticalStackedBarChart {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap)} />;\n }\n case 'scatter':\n const isAreaChart = plotlySchema.data.some((series: any) => series.fill === 'tonexty');\n if (isXDate || isXNumber) {\n if (isAreaChart) {\n return <AreaChart {...transformPlotlyJsonToScatterChartProps(plotlySchema, true, colorMap)} />;\n }\n return <LineChart {...transformPlotlyJsonToScatterChartProps(plotlySchema, false, colorMap)} />;\n }\n return <VerticalStackedBarChart {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap)} />;\n case 'heatmap':\n return <HeatMapChart {...transformPlotlyJsonToHeatmapProps(plotlySchema)} />;\n case 'sankey':\n return <SankeyChart {...transformPlotlyJsonToSankeyProps(plotlySchema, colorMap)} />;\n case 'indicator':\n if (plotlySchema?.data?.[0]?.mode?.includes('gauge')) {\n return <GaugeChart {...transformPlotlyJsonToGaugeProps(plotlySchema, colorMap)} />;\n }\n return <div>Unsupported Schema</div>;\n case 'histogram':\n return <VerticalBarChart {...transformPlotlyJsonToVBCProps(plotlySchema, colorMap)} />;\n default:\n return <div>Unsupported Schema</div>;\n }\n});\nDeclarativeChart.displayName = 'DeclarativeChart';\n"]}
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { IDonutChartProps } from '../DonutChart/index';
3
+ import { ISankeyChartProps } from '../SankeyChart/index';
4
+ import { IVerticalStackedBarChartProps } from '../VerticalStackedBarChart/index';
5
+ import { IHorizontalBarChartWithAxisProps } from '../HorizontalBarChartWithAxis/index';
6
+ import { ILineChartProps } from '../LineChart/index';
7
+ import { IAreaChartProps } from '../AreaChart/index';
8
+ import { IHeatMapChartProps } from '../HeatMapChart/index';
9
+ import { IGaugeChartProps } from '../GaugeChart/index';
10
+ import { IGroupedVerticalBarChartProps } from '../GroupedVerticalBarChart/index';
11
+ import { IVerticalBarChartProps } from '../VerticalBarChart/index';
12
+ export declare const isDateArray: (array: any[]) => boolean;
13
+ export declare const isNumberArray: (array: any[]) => boolean;
14
+ export declare const getColor: (legendLabel: string, colorMap: React.MutableRefObject<Map<string, string>>) => string;
15
+ export declare const transformPlotlyJsonToDonutProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IDonutChartProps;
16
+ export declare const transformPlotlyJsonToVSBCProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IVerticalStackedBarChartProps;
17
+ export declare const transformPlotlyJsonToGVBCProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IGroupedVerticalBarChartProps;
18
+ export declare const transformPlotlyJsonToVBCProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IVerticalBarChartProps;
19
+ export declare const transformPlotlyJsonToScatterChartProps: (jsonObj: any, isAreaChart: boolean, colorMap: React.MutableRefObject<Map<string, string>>) => ILineChartProps | IAreaChartProps;
20
+ export declare const transformPlotlyJsonToHorizontalBarWithAxisProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IHorizontalBarChartWithAxisProps;
21
+ export declare const transformPlotlyJsonToHeatmapProps: (jsonObj: any) => IHeatMapChartProps;
22
+ export declare const transformPlotlyJsonToSankeyProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => ISankeyChartProps;
23
+ export declare const transformPlotlyJsonToGaugeProps: (jsonObj: any, colorMap: React.MutableRefObject<Map<string, string>>) => IGaugeChartProps;
24
+ /**
25
+ * Interate iteratively through the trace object and find all the array attributes.
26
+ * 1 trace record = 1 series of data
27
+ * @param trace
28
+ */
29
+ export declare function findArrayAttributes(trace: any): void;
@@ -0,0 +1,460 @@
1
+ import { __assign } from "tslib";
2
+ import { bin as d3Bin, extent as d3Extent, sum as d3Sum, min as d3Min, max as d3Max, merge as d3Merge } from 'd3-array';
3
+ import { scaleLinear as d3ScaleLinear } from 'd3-scale';
4
+ import { format as d3Format, precisionFixed as d3PrecisionFixed } from 'd3-format';
5
+ import { getNextColor } from '../../utilities/colors';
6
+ var isDate = function (value) { return !isNaN(Date.parse(value)); };
7
+ var isNumber = function (value) { return !isNaN(parseFloat(value)) && isFinite(value); };
8
+ export var isDateArray = function (array) { return isArrayOrTypedArray(array) && array.every(isDate); };
9
+ export var isNumberArray = function (array) { return isArrayOrTypedArray(array) && array.every(isNumber); };
10
+ export var getColor = function (legendLabel, colorMap) {
11
+ if (!colorMap.current.has(legendLabel)) {
12
+ var nextColor = getNextColor(colorMap.current.size + 1);
13
+ colorMap.current.set(legendLabel, nextColor);
14
+ return nextColor;
15
+ }
16
+ return colorMap.current.get(legendLabel);
17
+ };
18
+ export var transformPlotlyJsonToDonutProps = function (jsonObj, colorMap) {
19
+ var _a, _b;
20
+ var data = jsonObj.data, layout = jsonObj.layout;
21
+ var firstData = data[0];
22
+ var donutData = (_a = firstData.labels) === null || _a === void 0 ? void 0 : _a.map(function (label, index) {
23
+ var _a;
24
+ var color = getColor(label, colorMap);
25
+ return {
26
+ legend: label,
27
+ data: (_a = firstData.values) === null || _a === void 0 ? void 0 : _a[index],
28
+ color: color,
29
+ };
30
+ });
31
+ var width = (layout === null || layout === void 0 ? void 0 : layout.width) || 440;
32
+ var height = (layout === null || layout === void 0 ? void 0 : layout.height) || 220;
33
+ var hideLabels = firstData.textinfo ? !['value', 'percent'].includes(firstData.textinfo) : false;
34
+ var donutMarginHorizontal = hideLabels ? 0 : 80;
35
+ var donutMarginVertical = 40 + (hideLabels ? 0 : 40);
36
+ var innerRadius = firstData.hole
37
+ ? firstData.hole * (Math.min(width - donutMarginHorizontal, height - donutMarginVertical) / 2)
38
+ : 0;
39
+ var styles = {
40
+ root: {
41
+ '[class^="arcLabel"]': {
42
+ fontSize: (_b = firstData.textfont) === null || _b === void 0 ? void 0 : _b.size,
43
+ },
44
+ },
45
+ };
46
+ return {
47
+ data: {
48
+ chartTitle: layout === null || layout === void 0 ? void 0 : layout.title,
49
+ chartData: donutData,
50
+ },
51
+ hideLegend: (layout === null || layout === void 0 ? void 0 : layout.showlegend) === false ? true : false,
52
+ width: width,
53
+ height: height,
54
+ innerRadius: innerRadius,
55
+ hideLabels: hideLabels,
56
+ showLabelsInPercent: firstData.textinfo ? firstData.textinfo === 'percent' : true,
57
+ styles: styles,
58
+ };
59
+ };
60
+ export var transformPlotlyJsonToVSBCProps = function (jsonObj, colorMap) {
61
+ var data = jsonObj.data, layout = jsonObj.layout;
62
+ var mapXToDataPoints = {};
63
+ var yMaxValue = 0;
64
+ data.forEach(function (series, index1) {
65
+ var _a;
66
+ (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, index2) {
67
+ var _a, _b, _c;
68
+ if (!mapXToDataPoints[x]) {
69
+ mapXToDataPoints[x] = { xAxisPoint: x, chartData: [], lineData: [] };
70
+ }
71
+ var legend = series.name || "Series ".concat(index1 + 1);
72
+ if (series.type === 'bar') {
73
+ var color = getColor(legend, colorMap);
74
+ mapXToDataPoints[x].chartData.push({
75
+ legend: legend,
76
+ data: (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2],
77
+ color: color,
78
+ });
79
+ }
80
+ else if (series.type === 'line') {
81
+ var color = getColor(legend, colorMap);
82
+ mapXToDataPoints[x].lineData.push({
83
+ legend: legend,
84
+ y: (_b = series.y) === null || _b === void 0 ? void 0 : _b[index2],
85
+ color: color,
86
+ });
87
+ }
88
+ yMaxValue = Math.max(yMaxValue, (_c = series.y) === null || _c === void 0 ? void 0 : _c[index2]);
89
+ });
90
+ });
91
+ return {
92
+ data: Object.values(mapXToDataPoints),
93
+ chartTitle: layout === null || layout === void 0 ? void 0 : layout.title,
94
+ // width: layout?.width,
95
+ // height: layout?.height,
96
+ barWidth: 'auto',
97
+ yMaxValue: yMaxValue,
98
+ };
99
+ };
100
+ export var transformPlotlyJsonToGVBCProps = function (jsonObj, colorMap) {
101
+ var data = jsonObj.data, layout = jsonObj.layout;
102
+ var mapXToDataPoints = {};
103
+ data.forEach(function (series, index1) {
104
+ var _a;
105
+ (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, index2) {
106
+ var _a;
107
+ if (!mapXToDataPoints[x]) {
108
+ mapXToDataPoints[x] = { name: x.toString(), series: [] };
109
+ }
110
+ if (series.type === 'bar') {
111
+ var legend = series.name || "Series ".concat(index1 + 1);
112
+ var color = getColor(legend, colorMap);
113
+ mapXToDataPoints[x].series.push({
114
+ key: legend,
115
+ data: (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2],
116
+ color: color,
117
+ legend: legend,
118
+ });
119
+ }
120
+ });
121
+ });
122
+ return {
123
+ data: Object.values(mapXToDataPoints),
124
+ chartTitle: layout === null || layout === void 0 ? void 0 : layout.title,
125
+ // width: layout?.width,
126
+ // height: layout?.height,
127
+ barwidth: 'auto',
128
+ };
129
+ };
130
+ export var transformPlotlyJsonToVBCProps = function (jsonObj, colorMap) {
131
+ var data = jsonObj.data, layout = jsonObj.layout;
132
+ var vbcData = [];
133
+ data.forEach(function (series, index) {
134
+ var _a, _b, _c;
135
+ if (!series.x) {
136
+ return;
137
+ }
138
+ var scale = d3ScaleLinear()
139
+ .domain(d3Extent(series.x))
140
+ .nice();
141
+ var _d = scale.domain(), xMin = _d[0], xMax = _d[1];
142
+ xMin = typeof ((_a = series.xbins) === null || _a === void 0 ? void 0 : _a.start) === 'number' ? series.xbins.start : xMin;
143
+ xMax = typeof ((_b = series.xbins) === null || _b === void 0 ? void 0 : _b.end) === 'number' ? series.xbins.end : xMax;
144
+ var bin = d3Bin().domain([xMin, xMax]);
145
+ if (typeof ((_c = series.xbins) === null || _c === void 0 ? void 0 : _c.size) === 'number') {
146
+ var thresholds = [];
147
+ var th = xMin;
148
+ var precision = d3PrecisionFixed(series.xbins.size);
149
+ var format = d3Format(".".concat(precision, "f"));
150
+ while (th < xMax + series.xbins.size) {
151
+ thresholds.push(parseFloat(format(th)));
152
+ th += series.xbins.size;
153
+ }
154
+ xMin = thresholds[0];
155
+ xMax = thresholds[thresholds.length - 1];
156
+ bin.domain([xMin, xMax]).thresholds(thresholds);
157
+ }
158
+ var buckets = bin(series.x);
159
+ // If the start or end of xbins is specified, then the number of datapoints may become less than x.length
160
+ var totalDataPoints = d3Merge(buckets).length;
161
+ buckets.forEach(function (bucket) {
162
+ var legend = series.name || "Series ".concat(index + 1);
163
+ var color = getColor(legend, colorMap);
164
+ var y = bucket.length;
165
+ if (series.histnorm === 'percent') {
166
+ y = (bucket.length / totalDataPoints) * 100;
167
+ }
168
+ else if (series.histnorm === 'probability') {
169
+ y = bucket.length / totalDataPoints;
170
+ }
171
+ else if (series.histnorm === 'density') {
172
+ y = bucket.x0 === bucket.x1 ? 0 : bucket.length / (bucket.x1 - bucket.x0);
173
+ }
174
+ else if (series.histnorm === 'probability density') {
175
+ y = bucket.x0 === bucket.x1 ? 0 : bucket.length / (totalDataPoints * (bucket.x1 - bucket.x0));
176
+ }
177
+ else if (series.histfunc === 'sum') {
178
+ y = d3Sum(bucket);
179
+ }
180
+ else if (series.histfunc === 'avg') {
181
+ y = bucket.length === 0 ? 0 : d3Sum(bucket) / bucket.length;
182
+ }
183
+ else if (series.histfunc === 'min') {
184
+ y = d3Min(bucket);
185
+ }
186
+ else if (series.histfunc === 'max') {
187
+ y = d3Max(bucket);
188
+ }
189
+ vbcData.push({
190
+ x: (bucket.x1 + bucket.x0) / 2,
191
+ y: y,
192
+ legend: legend,
193
+ color: color,
194
+ xAxisCalloutData: "[".concat(bucket.x0, " - ").concat(bucket.x1, ")"),
195
+ });
196
+ });
197
+ });
198
+ return {
199
+ data: vbcData,
200
+ chartTitle: layout === null || layout === void 0 ? void 0 : layout.title,
201
+ // width: layout?.width,
202
+ // height: layout?.height,
203
+ hideLegend: true,
204
+ barWidth: 24,
205
+ };
206
+ };
207
+ export var transformPlotlyJsonToScatterChartProps = function (jsonObj, isAreaChart, colorMap) {
208
+ var data = jsonObj.data, layout = jsonObj.layout;
209
+ var chartData = data.map(function (series, index) {
210
+ var xValues = series.x;
211
+ var isString = typeof xValues[0] === 'string';
212
+ var isXDate = isDateArray(xValues);
213
+ var isXNumber = isNumberArray(xValues);
214
+ var legend = series.name || "Series ".concat(index + 1);
215
+ var lineColor = getColor(legend, colorMap);
216
+ return {
217
+ legend: legend,
218
+ data: xValues.map(function (x, i) { return ({
219
+ x: isString ? (isXDate ? new Date(x) : isXNumber ? parseFloat(x) : x) : x,
220
+ y: series.y[i],
221
+ }); }),
222
+ color: lineColor,
223
+ };
224
+ });
225
+ var chartProps = {
226
+ chartTitle: layout.title || '',
227
+ lineChartData: chartData,
228
+ };
229
+ if (isAreaChart) {
230
+ return {
231
+ data: chartProps,
232
+ };
233
+ }
234
+ else {
235
+ return {
236
+ data: chartProps,
237
+ };
238
+ }
239
+ };
240
+ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (jsonObj, colorMap) {
241
+ var _a, _b;
242
+ var data = jsonObj.data, layout = jsonObj.layout;
243
+ var chartData = data
244
+ .map(function (series, index) {
245
+ return series.y.map(function (yValue, i) {
246
+ var color = getColor(yValue, colorMap);
247
+ return {
248
+ x: series.x[i],
249
+ y: yValue,
250
+ legend: yValue,
251
+ color: color,
252
+ };
253
+ });
254
+ })
255
+ .flat();
256
+ var chartHeight = layout.height || 350;
257
+ var margin = ((_a = layout.margin) === null || _a === void 0 ? void 0 : _a.l) || 0;
258
+ var padding = ((_b = layout.margin) === null || _b === void 0 ? void 0 : _b.pad) || 0;
259
+ var availableHeight = chartHeight - margin - padding;
260
+ var numberOfBars = data[0].y.length;
261
+ var gapFactor = 0.5;
262
+ var barHeight = availableHeight / (numberOfBars * (1 + gapFactor));
263
+ return {
264
+ data: chartData,
265
+ chartTitle: layout.title || '',
266
+ barHeight: barHeight,
267
+ showYAxisLables: true,
268
+ styles: {
269
+ root: {
270
+ height: chartHeight,
271
+ width: layout.width || 600,
272
+ },
273
+ },
274
+ };
275
+ };
276
+ export var transformPlotlyJsonToHeatmapProps = function (jsonObj) {
277
+ var _a, _b, _c;
278
+ var data = jsonObj.data, layout = jsonObj.layout;
279
+ var firstData = data[0];
280
+ var heatmapDataPoints = [];
281
+ var zMin = Number.POSITIVE_INFINITY;
282
+ var zMax = Number.NEGATIVE_INFINITY;
283
+ (_a = firstData.x) === null || _a === void 0 ? void 0 : _a.forEach(function (xVal, xIdx) {
284
+ var _a;
285
+ (_a = firstData.y) === null || _a === void 0 ? void 0 : _a.forEach(function (yVal, yIdx) {
286
+ var _a, _b, _c, _d;
287
+ var zVal = (_b = (_a = firstData.z) === null || _a === void 0 ? void 0 : _a[yIdx]) === null || _b === void 0 ? void 0 : _b[xIdx];
288
+ heatmapDataPoints.push({
289
+ x: ((_c = layout.xaxis) === null || _c === void 0 ? void 0 : _c.type) === 'date' ? new Date(xVal) : xVal,
290
+ y: ((_d = layout.yaxis) === null || _d === void 0 ? void 0 : _d.type) === 'date' ? new Date(yVal) : yVal,
291
+ value: zVal,
292
+ });
293
+ zMin = Math.min(zMin, zVal);
294
+ zMax = Math.max(zMax, zVal);
295
+ });
296
+ });
297
+ var heatmapData = {
298
+ legend: firstData.name || '',
299
+ data: heatmapDataPoints,
300
+ value: 0,
301
+ };
302
+ // Convert normalized values to actual values
303
+ var domainValuesForColorScale = (_b = firstData.colorscale) === null || _b === void 0 ? void 0 : _b.map(function (arr) { return arr[0] * (zMax - zMin) + zMin; });
304
+ var rangeValuesForColorScale = (_c = firstData.colorscale) === null || _c === void 0 ? void 0 : _c.map(function (arr) { return arr[1]; });
305
+ return {
306
+ data: [heatmapData],
307
+ domainValuesForColorScale: domainValuesForColorScale,
308
+ rangeValuesForColorScale: rangeValuesForColorScale,
309
+ hideLegend: true,
310
+ };
311
+ };
312
+ export var transformPlotlyJsonToSankeyProps = function (jsonObj, colorMap) {
313
+ var _a;
314
+ var data = jsonObj.data, layout = jsonObj.layout;
315
+ var _b = data[0], link = _b.link, node = _b.node;
316
+ var validLinks = link.value
317
+ .map(function (val, index) { return ({
318
+ value: val,
319
+ source: link.source[index],
320
+ target: link.target[index],
321
+ }); })
322
+ // eslint-disable-next-line @typescript-eslint/no-shadow
323
+ //@ts-expect-error Dynamic link object. Ignore for now.
324
+ .filter(function (x) { return x.source !== x.target; }); // Filter out self-references (circular links)
325
+ var sankeyChartData = {
326
+ nodes: node.label.map(function (label, index) {
327
+ var color = getColor(label, colorMap);
328
+ return {
329
+ nodeId: index,
330
+ name: label,
331
+ color: color,
332
+ };
333
+ }),
334
+ links: validLinks.map(function (validLink, index) {
335
+ return __assign({}, validLink);
336
+ }),
337
+ };
338
+ var width = (layout === null || layout === void 0 ? void 0 : layout.width) || 440;
339
+ var height = (layout === null || layout === void 0 ? void 0 : layout.height) || 220;
340
+ var styles = {
341
+ root: {
342
+ fontSize: (_a = layout.font) === null || _a === void 0 ? void 0 : _a.size,
343
+ },
344
+ };
345
+ var shouldResize = width + height;
346
+ return {
347
+ data: {
348
+ chartTitle: layout === null || layout === void 0 ? void 0 : layout.title,
349
+ SankeyChartData: sankeyChartData,
350
+ },
351
+ width: width,
352
+ height: height,
353
+ styles: styles,
354
+ shouldResize: shouldResize,
355
+ enableReflow: true,
356
+ };
357
+ };
358
+ export var transformPlotlyJsonToGaugeProps = function (jsonObj, colorMap) {
359
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
360
+ var data = jsonObj.data, layout = jsonObj.layout;
361
+ var firstData = data[0];
362
+ var segments = (_b = (_a = firstData.gauge) === null || _a === void 0 ? void 0 : _a.steps) === null || _b === void 0 ? void 0 : _b.map(function (step, index) {
363
+ var _a, _b;
364
+ var legend = step.name || "Segment ".concat(index + 1);
365
+ var color = getColor(legend, colorMap);
366
+ return {
367
+ legend: legend,
368
+ size: ((_a = step.range) === null || _a === void 0 ? void 0 : _a[1]) - ((_b = step.range) === null || _b === void 0 ? void 0 : _b[0]),
369
+ color: color,
370
+ };
371
+ });
372
+ var sublabel;
373
+ var sublabelColor;
374
+ if (typeof ((_c = firstData.delta) === null || _c === void 0 ? void 0 : _c.reference) === 'number') {
375
+ var diff = firstData.value - firstData.delta.reference;
376
+ if (diff >= 0) {
377
+ sublabel = "\u25B2 ".concat(diff);
378
+ var color = getColor(((_d = firstData.delta.increasing) === null || _d === void 0 ? void 0 : _d.color) || '', colorMap);
379
+ sublabelColor = color;
380
+ }
381
+ else {
382
+ sublabel = "\u25BC ".concat(Math.abs(diff));
383
+ var color = getColor(((_e = firstData.delta.decreasing) === null || _e === void 0 ? void 0 : _e.color) || '', colorMap);
384
+ sublabelColor = color;
385
+ }
386
+ }
387
+ var styles = {
388
+ sublabel: {
389
+ fill: sublabelColor,
390
+ },
391
+ };
392
+ return {
393
+ segments: segments,
394
+ chartValue: firstData.value,
395
+ chartTitle: (_f = firstData.title) === null || _f === void 0 ? void 0 : _f.text,
396
+ sublabel: sublabel,
397
+ // range values can be null
398
+ minValue: (_k = (_j = (_h = (_g = firstData.gauge) === null || _g === void 0 ? void 0 : _g.axis) === null || _h === void 0 ? void 0 : _h.range) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : undefined,
399
+ maxValue: (_p = (_o = (_m = (_l = firstData.gauge) === null || _l === void 0 ? void 0 : _l.axis) === null || _m === void 0 ? void 0 : _m.range) === null || _o === void 0 ? void 0 : _o[1]) !== null && _p !== void 0 ? _p : undefined,
400
+ chartValueFormat: function () { return firstData.value; },
401
+ width: layout === null || layout === void 0 ? void 0 : layout.width,
402
+ height: layout === null || layout === void 0 ? void 0 : layout.height,
403
+ hideLegend: true,
404
+ styles: styles,
405
+ };
406
+ };
407
+ function isTypedArray(a) {
408
+ return ArrayBuffer.isView(a) && !(a instanceof DataView);
409
+ }
410
+ function isArrayOrTypedArray(a) {
411
+ return Array.isArray(a) || isTypedArray(a);
412
+ }
413
+ function isPlainObject(obj) {
414
+ if (window && window.process && window.process.versions) {
415
+ return Object.prototype.toString.call(obj) === '[object Object]';
416
+ }
417
+ return (Object.prototype.toString.call(obj) === '[object Object]' &&
418
+ Object.getPrototypeOf(obj).hasOwnProperty('hasOwnProperty'));
419
+ }
420
+ var arrayAttributes = [];
421
+ var stack = [];
422
+ var isArrayStack = [];
423
+ var baseContainer, baseAttrName;
424
+ /**
425
+ * Interate iteratively through the trace object and find all the array attributes.
426
+ * 1 trace record = 1 series of data
427
+ * @param trace
428
+ */
429
+ export function findArrayAttributes(trace) {
430
+ // Init basecontainer and baseAttrName
431
+ crawlIntoTrace(baseContainer, 0, '');
432
+ for (var _i = 0, arrayAttributes_1 = arrayAttributes; _i < arrayAttributes_1.length; _i++) {
433
+ var attribute = arrayAttributes_1[_i];
434
+ console.log(attribute);
435
+ }
436
+ }
437
+ function crawlIntoTrace(container, i, astrPartial) {
438
+ var item = container[stack[i]];
439
+ var newAstrPartial = astrPartial + stack[i];
440
+ if (i === stack.length - 1) {
441
+ if (isArrayOrTypedArray(item)) {
442
+ arrayAttributes.push(baseAttrName + newAstrPartial);
443
+ }
444
+ }
445
+ else {
446
+ if (isArrayStack[i]) {
447
+ if (Array.isArray(item)) {
448
+ for (var j = 0; j < item.length; j++) {
449
+ if (isPlainObject(item[j])) {
450
+ crawlIntoTrace(item[j], i + 1, newAstrPartial + '[' + j + '].');
451
+ }
452
+ }
453
+ }
454
+ }
455
+ else if (isPlainObject(item)) {
456
+ crawlIntoTrace(item, i + 1, newAstrPartial + '.');
457
+ }
458
+ }
459
+ }
460
+ //# sourceMappingURL=PlotlySchemaAdapter.js.map