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