@fluentui/react-charts 9.2.2 → 9.2.4
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 +74 -2
- package/dist/index.d.ts +187 -15
- package/lib/components/AreaChart/AreaChart.js +7 -4
- package/lib/components/AreaChart/AreaChart.js.map +1 -1
- package/lib/components/AreaChart/useAreaChartStyles.styles.js +4 -3
- package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib/components/AreaChart/useAreaChartStyles.styles.raw.js +5 -16
- package/lib/components/AreaChart/useAreaChartStyles.styles.raw.js.map +1 -1
- package/lib/components/ChartTable/ChartTable.js +90 -6
- package/lib/components/ChartTable/ChartTable.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.js +83 -38
- 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 +19 -3
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +8 -23
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +214 -107
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js +25 -1
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +1618 -259
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/Arc/useArcStyles.styles.js +8 -3
- package/lib/components/DonutChart/Arc/useArcStyles.styles.js.map +1 -1
- package/lib/components/DonutChart/Arc/useArcStyles.styles.raw.js +6 -2
- package/lib/components/DonutChart/Arc/useArcStyles.styles.raw.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +8 -3
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib/components/DonutChart/useDonutChartStyles.styles.js +21 -4
- package/lib/components/DonutChart/useDonutChartStyles.styles.js.map +1 -1
- package/lib/components/DonutChart/useDonutChartStyles.styles.raw.js +8 -4
- package/lib/components/DonutChart/useDonutChartStyles.styles.raw.js.map +1 -1
- package/lib/components/FunnelChart/FunnelChart.js +4 -2
- package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib/components/FunnelChart/funnelGeometry.js.map +1 -1
- package/lib/components/GanttChart/useGanttChartStyles.styles.js +2 -1
- package/lib/components/GanttChart/useGanttChartStyles.styles.js.map +1 -1
- package/lib/components/GanttChart/useGanttChartStyles.styles.raw.js +2 -1
- package/lib/components/GanttChart/useGanttChartStyles.styles.raw.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.js +1 -2
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +31 -10
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +6 -18
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js +6 -22
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js.map +1 -1
- package/lib/components/HeatMapChart/HeatMapChart.js +175 -114
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +2 -1
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -1
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js +2 -1
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js.map +1 -1
- package/lib/components/HorizontalBarChart/HorizontalBarChart.js +1 -1
- package/lib/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +7 -3
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.raw.js +5 -2
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.raw.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +26 -6
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +2 -1
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js +2 -1
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js.map +1 -1
- package/lib/components/LineChart/LineChart.js +349 -176
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/LineChart/LineChart.types.js.map +1 -1
- package/lib/components/LineChart/useLineChartStyles.styles.js +28 -8
- package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib/components/LineChart/useLineChartStyles.styles.raw.js +9 -14
- package/lib/components/LineChart/useLineChartStyles.styles.raw.js.map +1 -1
- package/lib/components/ResponsiveContainer/withResponsiveContainer.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +12 -25
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.raw.js +2 -12
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.raw.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.js +139 -81
- 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 +29 -8
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js +10 -15
- package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +28 -5
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +10 -7
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js +7 -20
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +159 -47
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +9 -7
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js +6 -20
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js.map +1 -1
- package/lib/types/DataPoint.js +3 -1
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/Common.styles.js +47 -0
- package/lib/utilities/Common.styles.js.map +1 -0
- package/lib/utilities/Common.styles.raw.js +47 -0
- package/lib/utilities/Common.styles.raw.js.map +1 -0
- package/lib/utilities/SVGTooltipText.js.map +1 -1
- package/lib/utilities/image-export-utils.js.map +1 -1
- package/lib/utilities/index.js +1 -0
- package/lib/utilities/index.js.map +1 -1
- package/lib/utilities/scatterpolar-utils.js +52 -0
- package/lib/utilities/scatterpolar-utils.js.map +1 -0
- package/lib/utilities/utilities.js +324 -147
- package/lib/utilities/utilities.js.map +1 -1
- package/lib/utilities/vbc-utils.js.map +1 -1
- package/lib-commonjs/components/AreaChart/AreaChart.js +6 -3
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +2 -1
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.raw.js +4 -15
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/ChartTable/ChartTable.js +90 -6
- package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +83 -37
- 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 +17 -2
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +6 -22
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +212 -107
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js +31 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +1652 -260
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.js +12 -3
- package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.raw.js +6 -2
- package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +7 -2
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js +32 -4
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.raw.js +8 -4
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/FunnelChart.js +4 -2
- package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/funnelGeometry.js.map +1 -1
- package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.js +2 -1
- package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.raw.js +2 -1
- package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js +1 -2
- package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +30 -9
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +4 -20
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js +5 -21
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +174 -113
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +2 -1
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js +2 -1
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js +1 -1
- package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +10 -3
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.raw.js +5 -2
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +25 -5
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +2 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js +2 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js +347 -175
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +35 -5
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.raw.js +7 -13
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/ResponsiveContainer/withResponsiveContainer.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +23 -33
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.raw.js +1 -12
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +137 -79
- 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 +39 -6
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js +9 -14
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +27 -4
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +7 -4
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js +5 -18
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +158 -46
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +7 -4
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js +5 -19
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js +3 -1
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/Common.styles.js +71 -0
- package/lib-commonjs/utilities/Common.styles.js.map +1 -0
- package/lib-commonjs/utilities/Common.styles.raw.js +71 -0
- package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -0
- package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
- package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
- package/lib-commonjs/utilities/index.js +1 -0
- package/lib-commonjs/utilities/index.js.map +1 -1
- package/lib-commonjs/utilities/scatterpolar-utils.js +67 -0
- package/lib-commonjs/utilities/scatterpolar-utils.js.map +1 -0
- package/lib-commonjs/utilities/utilities.js +337 -137
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/lib-commonjs/utilities/vbc-utils.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* eslint-disable one-var */ /* eslint-disable vars-on-top */ /* eslint-disable no-var */ import * as React from 'react';
|
|
2
2
|
import { bin as d3Bin, extent as d3Extent, sum as d3Sum, min as d3Min, max as d3Max, range as d3Range } from 'd3-array';
|
|
3
3
|
import { scaleLinear as d3ScaleLinear } from 'd3-scale';
|
|
4
|
+
import { format as d3Format } from 'd3-format';
|
|
4
5
|
import { DataVizPalette, getColorFromToken } from '../../utilities/colors';
|
|
5
|
-
import { findNumericMinMaxOfY } from '../../utilities/utilities';
|
|
6
|
-
import {
|
|
6
|
+
import { DEFAULT_DATE_STRING, findNumericMinMaxOfY, formatScientificLimitWidth, MIN_DONUT_RADIUS, calculatePrecision, precisionRound } from '../../utilities/utilities';
|
|
7
|
+
import { isArrayOrTypedArray, isDate, isDateArray, isNumberArray, isStringArray, isYearArray, isInvalidValue, formatToLocaleString, isNumber, isObjectArray, getAxisIds, getAxisKey } from '@fluentui/chart-utilities';
|
|
7
8
|
import { curveCardinal as d3CurveCardinal } from 'd3-shape';
|
|
8
|
-
import { extractColor, resolveColor } from './PlotlyColorAdapter';
|
|
9
|
+
import { getOpacity, extractColor, resolveColor, createColorScale } from './PlotlyColorAdapter';
|
|
10
|
+
import { rgb } from 'd3-color';
|
|
11
|
+
export const NON_PLOT_KEY_PREFIX = 'nonplot_';
|
|
12
|
+
export const SINGLE_REPEAT = 'repeat(1, 1fr)';
|
|
9
13
|
const dashOptions = {
|
|
10
14
|
dot: {
|
|
11
15
|
strokeDasharray: '1, 5',
|
|
@@ -54,6 +58,47 @@ function getTitles(layout) {
|
|
|
54
58
|
};
|
|
55
59
|
return titles;
|
|
56
60
|
}
|
|
61
|
+
const getXAxisTickFormat = (series, layout)=>{
|
|
62
|
+
const xAxis = getXAxisProperties(series, layout);
|
|
63
|
+
if (xAxis === null || xAxis === void 0 ? void 0 : xAxis.tickformat) {
|
|
64
|
+
return {
|
|
65
|
+
tickFormat: xAxis === null || xAxis === void 0 ? void 0 : xAxis.tickformat
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {};
|
|
69
|
+
};
|
|
70
|
+
const getYAxisTickFormat = (series, layout)=>{
|
|
71
|
+
const yAxis = getYAxisProperties(series, layout);
|
|
72
|
+
if (yAxis === null || yAxis === void 0 ? void 0 : yAxis.tickformat) {
|
|
73
|
+
return {
|
|
74
|
+
yAxisTickFormat: d3Format(yAxis === null || yAxis === void 0 ? void 0 : yAxis.tickformat)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {};
|
|
78
|
+
};
|
|
79
|
+
const getYMinMaxValues = (series, layout)=>{
|
|
80
|
+
var _getYAxisProperties;
|
|
81
|
+
const range = (_getYAxisProperties = getYAxisProperties(series, layout)) === null || _getYAxisProperties === void 0 ? void 0 : _getYAxisProperties.range;
|
|
82
|
+
if (range && range.length === 2) {
|
|
83
|
+
return {
|
|
84
|
+
yMinValue: range[0],
|
|
85
|
+
yMaxValue: range[1]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {};
|
|
89
|
+
};
|
|
90
|
+
const getYAxisProperties = (series, layout)=>{
|
|
91
|
+
return layout === null || layout === void 0 ? void 0 : layout.yaxis;
|
|
92
|
+
};
|
|
93
|
+
const getXAxisProperties = (series, layout)=>{
|
|
94
|
+
return layout === null || layout === void 0 ? void 0 : layout.xaxis;
|
|
95
|
+
};
|
|
96
|
+
const getFormattedCalloutYData = (yVal, yAxisFormat)=>{
|
|
97
|
+
if (typeof (yAxisFormat === null || yAxisFormat === void 0 ? void 0 : yAxisFormat.yAxisTickFormat) === 'function' && typeof yVal === 'number') {
|
|
98
|
+
return yAxisFormat.yAxisTickFormat(yVal);
|
|
99
|
+
}
|
|
100
|
+
return formatToLocaleString(yVal);
|
|
101
|
+
};
|
|
57
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
103
|
export const correctYearMonth = (xValues)=>{
|
|
59
104
|
const presentYear = new Date().getFullYear();
|
|
@@ -64,24 +109,35 @@ export const correctYearMonth = (xValues)=>{
|
|
|
64
109
|
const parsedDate = `${possiblyMonthValue} 01, ${presentYear}`;
|
|
65
110
|
return isDate(parsedDate) ? new Date(parsedDate) : null;
|
|
66
111
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
112
|
+
const filteredDateIndexPairs = dates.map((date, index)=>[
|
|
113
|
+
date,
|
|
114
|
+
index
|
|
115
|
+
]).filter(([date])=>date !== null);
|
|
116
|
+
for(let i = filteredDateIndexPairs.length - 1; i > 0; i--){
|
|
117
|
+
const currentDate = filteredDateIndexPairs[i][0];
|
|
118
|
+
const previousDate = filteredDateIndexPairs[i - 1][0];
|
|
119
|
+
const currentMonth = currentDate.getMonth();
|
|
120
|
+
const previousMonth = previousDate.getMonth();
|
|
121
|
+
const currentYear = currentDate.getFullYear();
|
|
122
|
+
const previousYear = previousDate.getFullYear();
|
|
72
123
|
if (previousMonth >= currentMonth) {
|
|
73
|
-
|
|
124
|
+
filteredDateIndexPairs[i - 1][0].setFullYear(currentYear - 1);
|
|
74
125
|
} else if (previousYear > currentYear) {
|
|
75
|
-
|
|
126
|
+
filteredDateIndexPairs[i - 1][0].setFullYear(currentYear);
|
|
76
127
|
}
|
|
128
|
+
dates[filteredDateIndexPairs[i - 1][1]] = filteredDateIndexPairs[i - 1][0];
|
|
77
129
|
}
|
|
78
130
|
xValues = xValues.map((month, index)=>{
|
|
131
|
+
if (dates[index] === null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
79
134
|
return `${month} 01, ${dates[index].getFullYear()}`;
|
|
80
135
|
});
|
|
81
136
|
return xValues;
|
|
82
137
|
};
|
|
83
|
-
const usesSecondaryYScale = (series)=>{
|
|
84
|
-
|
|
138
|
+
const usesSecondaryYScale = (series, layout)=>{
|
|
139
|
+
var _layout_yaxis2, _layout_yaxis21;
|
|
140
|
+
return series.yaxis === 'y2' && ((layout === null || layout === void 0 ? void 0 : (_layout_yaxis2 = layout.yaxis2) === null || _layout_yaxis2 === void 0 ? void 0 : _layout_yaxis2.anchor) === 'x' || (layout === null || layout === void 0 ? void 0 : (_layout_yaxis21 = layout.yaxis2) === null || _layout_yaxis21 === void 0 ? void 0 : _layout_yaxis21.side) === 'right');
|
|
85
141
|
};
|
|
86
142
|
const getSecondaryYAxisValues = (data, layout, maxAllowedMinY, minAllowedMaxY)=>{
|
|
87
143
|
var _layout_yaxis2, _layout_yaxis21, _layout_yaxis2_title, _layout_yaxis22;
|
|
@@ -89,7 +145,7 @@ const getSecondaryYAxisValues = (data, layout, maxAllowedMinY, minAllowedMaxY)=>
|
|
|
89
145
|
let yMinValue;
|
|
90
146
|
let yMaxValue;
|
|
91
147
|
data.forEach((series)=>{
|
|
92
|
-
if (usesSecondaryYScale(series)) {
|
|
148
|
+
if (usesSecondaryYScale(series, layout)) {
|
|
93
149
|
containsSecondaryYAxis = true;
|
|
94
150
|
const yValues = series.y;
|
|
95
151
|
if (yValues) {
|
|
@@ -123,32 +179,199 @@ export const _getGaugeAxisColor = (colorway, colorwayType, color, colorMap, isDa
|
|
|
123
179
|
const extractedColors = extractColor(colorway, colorwayType, color, colorMap, isDarkTheme);
|
|
124
180
|
return resolveColor(extractedColors, 0, '', colorMap, isDarkTheme);
|
|
125
181
|
};
|
|
126
|
-
export const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
182
|
+
export const resolveXAxisPoint = (x, isXYearCategory, isXString, isXDate, isXNumber)=>{
|
|
183
|
+
if (x === null || x === undefined) {
|
|
184
|
+
return '';
|
|
185
|
+
}
|
|
186
|
+
if (isXYearCategory) {
|
|
187
|
+
return x.toString();
|
|
188
|
+
}
|
|
189
|
+
if (isXString) {
|
|
190
|
+
if (isXDate) {
|
|
191
|
+
const date = new Date(x);
|
|
192
|
+
return date;
|
|
193
|
+
}
|
|
194
|
+
if (isXNumber) {
|
|
195
|
+
return parseFloat(x);
|
|
196
|
+
}
|
|
197
|
+
return x;
|
|
198
|
+
}
|
|
199
|
+
return x;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Checks if a key should be ignored during normalization
|
|
203
|
+
* @param key The key to check
|
|
204
|
+
* @returns true if the key should be ignored
|
|
205
|
+
*/ const shouldIgnoreKey = (key)=>{
|
|
206
|
+
const lowerKey = key.toLowerCase();
|
|
207
|
+
if (lowerKey.includes('style') || lowerKey === 'style') {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
// Use regex to match common CSS property patterns
|
|
211
|
+
// (color, fill, stroke, border, background, font, shadow, outline, etc.)
|
|
212
|
+
const cssKeyRegex = new RegExp('^(color|fill|stroke|border|background|font|shadow|outline|margin|padding|gap|align|justify|display|flex|grid|' + 'text|line|letter|word|vertical|horizontal|overflow|position|top|right|bottom|left|zindex|z-index|opacity|' + 'filter|clip|cursor|resize|transition|animation|transform|box|column|row|direction|visibility|' + 'content|width|height|aspect|image|user|pointer|caret|scroll|%)|(-webkit-|-moz-|-ms-|-o-)', 'i');
|
|
213
|
+
if (cssKeyRegex.test(lowerKey)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Flattens a nested object into a single level object with dot notation keys
|
|
220
|
+
* @param obj Object to flatten
|
|
221
|
+
* @param prefix Optional prefix for keys
|
|
222
|
+
* @returns Flattened object
|
|
223
|
+
*/ const flattenObject = (obj, prefix = '')=>{
|
|
224
|
+
const flattened = {};
|
|
225
|
+
for(const key in obj){
|
|
226
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
227
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
228
|
+
const value = obj[key];
|
|
229
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date)) {
|
|
230
|
+
// Recursively flatten nested objects
|
|
231
|
+
Object.assign(flattened, flattenObject(value, newKey));
|
|
232
|
+
} else {
|
|
233
|
+
flattened[newKey] = value;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return flattened;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Normalizes an array of objects by flattening nested structures and creating grouped data
|
|
241
|
+
* Uses json_normalize approach with D3 color detection and filtering
|
|
242
|
+
* @param data Array of objects to normalize
|
|
243
|
+
* @returns Object containing traces for grouped vertical bar chart
|
|
244
|
+
*/ export const normalizeObjectArrayForGVBC = (data, xLabels)=>{
|
|
245
|
+
if (!data || data.length === 0) {
|
|
246
|
+
return {
|
|
247
|
+
traces: [],
|
|
248
|
+
x: []
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// Use provided xLabels if available, otherwise default to Item 1, Item 2, ...
|
|
252
|
+
const x = xLabels && xLabels.length === data.length ? xLabels : data.map((_, index)=>`Item ${index + 1}`);
|
|
253
|
+
// First, flatten all objects and collect all unique keys, excluding style keys
|
|
254
|
+
const flattenedObjects = data.map((item, index)=>{
|
|
255
|
+
if (typeof item === 'object' && item !== null) {
|
|
256
|
+
const flattened = flattenObject(item);
|
|
257
|
+
// Only keep keys where the value is numeric (number or numeric string) and not a style key
|
|
258
|
+
const filtered = {};
|
|
259
|
+
Object.keys(flattened).forEach((key)=>{
|
|
260
|
+
const value = flattened[key];
|
|
261
|
+
if (!shouldIgnoreKey(key) && (typeof value === 'number' || typeof value === 'string' && isNumber(value))) {
|
|
262
|
+
filtered[key] = value;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return filtered;
|
|
266
|
+
} else if (typeof item === 'number' || typeof item === 'string' && isNumber(item)) {
|
|
267
|
+
// Only keep primitive numeric values
|
|
268
|
+
return {
|
|
269
|
+
[x[index] || `item_${index}`]: item
|
|
143
270
|
};
|
|
144
271
|
} else {
|
|
145
|
-
|
|
272
|
+
// Non-numeric primitive, ignore by returning empty object
|
|
273
|
+
return {};
|
|
146
274
|
}
|
|
147
275
|
});
|
|
276
|
+
// Collect all unique keys across all objects
|
|
277
|
+
const allKeys = new Set();
|
|
278
|
+
flattenedObjects.forEach((obj)=>{
|
|
279
|
+
Object.keys(obj).forEach((key)=>allKeys.add(key));
|
|
280
|
+
});
|
|
281
|
+
// Create traces for each key (property)
|
|
282
|
+
const traces = [];
|
|
283
|
+
allKeys.forEach((key)=>{
|
|
284
|
+
const yValues = [];
|
|
285
|
+
let hasValidData = false;
|
|
286
|
+
let isNumericData = false;
|
|
287
|
+
flattenedObjects.forEach((obj, index)=>{
|
|
288
|
+
const value = obj[key];
|
|
289
|
+
if (typeof value === 'number') {
|
|
290
|
+
yValues.push(value);
|
|
291
|
+
hasValidData = true;
|
|
292
|
+
isNumericData = true;
|
|
293
|
+
} else if (typeof value === 'string' && isNumber(value)) {
|
|
294
|
+
yValues.push(parseFloat(value));
|
|
295
|
+
hasValidData = true;
|
|
296
|
+
isNumericData = true;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
// Only create trace if we have valid numeric data
|
|
300
|
+
if (hasValidData && isNumericData) {
|
|
301
|
+
const trace = {
|
|
302
|
+
type: 'bar',
|
|
303
|
+
name: key,
|
|
304
|
+
x,
|
|
305
|
+
y: yValues
|
|
306
|
+
};
|
|
307
|
+
traces.push(trace);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return {
|
|
311
|
+
traces,
|
|
312
|
+
x
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
export const transformPlotlyJsonToDonutProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
316
|
+
var _input_layout, _input_layout_template_layout, _input_layout_template, _input_layout1, _input_layout2, _firstData_marker, _input_layout3, _input_layout4, _input_layout5, _input_layout6;
|
|
317
|
+
const firstData = input.data[0];
|
|
318
|
+
var _input_layout_piecolorway, _input_layout_piecolorway1;
|
|
319
|
+
// extract colors for each series only once
|
|
320
|
+
// use piecolorway if available
|
|
321
|
+
// otherwise, default to colorway from template
|
|
322
|
+
const colors = extractColor((_input_layout_piecolorway = (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.piecolorway) !== null && _input_layout_piecolorway !== void 0 ? _input_layout_piecolorway : (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_template = _input_layout1.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_input_layout_piecolorway1 = (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.piecolorway) !== null && _input_layout_piecolorway1 !== void 0 ? _input_layout_piecolorway1 : firstData === null || firstData === void 0 ? void 0 : (_firstData_marker = firstData.marker) === null || _firstData_marker === void 0 ? void 0 : _firstData_marker.colors, colorMap, isDarkTheme);
|
|
323
|
+
const mapLegendToDataPoint = {};
|
|
324
|
+
if (colors) {
|
|
325
|
+
var _firstData_labels;
|
|
326
|
+
(_firstData_labels = firstData.labels) === null || _firstData_labels === void 0 ? void 0 : _firstData_labels.forEach((label, index)=>{
|
|
327
|
+
const value = getNumberAtIndexOrDefault(firstData.values, index);
|
|
328
|
+
if (isInvalidValue(value) || value < 0) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const legend = `${label}`;
|
|
332
|
+
// resolve color for each legend from the extracted colors
|
|
333
|
+
const color = resolveColor(colors, index, legend, colorMap, isDarkTheme);
|
|
334
|
+
if (!mapLegendToDataPoint[legend]) {
|
|
335
|
+
mapLegendToDataPoint[legend] = {
|
|
336
|
+
legend,
|
|
337
|
+
data: value,
|
|
338
|
+
color
|
|
339
|
+
};
|
|
340
|
+
} else {
|
|
341
|
+
mapLegendToDataPoint[legend].data += value;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
// Sort labels by value descending before mapping
|
|
346
|
+
if (firstData.labels && firstData.values) {
|
|
347
|
+
const labelValuePairs = firstData.labels.map((label, index)=>({
|
|
348
|
+
label,
|
|
349
|
+
value: getNumberAtIndexOrDefault(firstData.values, index),
|
|
350
|
+
index
|
|
351
|
+
}));
|
|
352
|
+
// Filter out invalid values
|
|
353
|
+
const validPairs = labelValuePairs.filter((pair)=>!isInvalidValue(pair.value));
|
|
354
|
+
// Sort descending by value
|
|
355
|
+
validPairs.sort((a, b)=>b.value - a.value);
|
|
356
|
+
validPairs.forEach((pair, sortedIdx)=>{
|
|
357
|
+
const legend = `${pair.label}`;
|
|
358
|
+
const color = resolveColor(colors, sortedIdx, legend, colorMap, isDarkTheme);
|
|
359
|
+
if (!mapLegendToDataPoint[legend]) {
|
|
360
|
+
mapLegendToDataPoint[legend] = {
|
|
361
|
+
legend,
|
|
362
|
+
data: pair.value,
|
|
363
|
+
color
|
|
364
|
+
};
|
|
365
|
+
} else {
|
|
366
|
+
mapLegendToDataPoint[legend].data += pair.value;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
148
371
|
var _input_layout_width;
|
|
149
|
-
const width = (_input_layout_width = (
|
|
372
|
+
const width = (_input_layout_width = (_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : _input_layout3.width) !== null && _input_layout_width !== void 0 ? _input_layout_width : 440;
|
|
150
373
|
var _input_layout_height;
|
|
151
|
-
const height = (_input_layout_height = (
|
|
374
|
+
const height = (_input_layout_height = (_input_layout4 = input.layout) === null || _input_layout4 === void 0 ? void 0 : _input_layout4.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 220;
|
|
152
375
|
const hideLabels = firstData.textinfo ? ![
|
|
153
376
|
'value',
|
|
154
377
|
'percent',
|
|
@@ -156,15 +379,15 @@ export const transformPlotlyJsonToDonutProps = (input, colorMap, colorwayType, i
|
|
|
156
379
|
].includes(firstData.textinfo) : false;
|
|
157
380
|
const donutMarginHorizontal = hideLabels ? 0 : 80;
|
|
158
381
|
const donutMarginVertical = 40 + (hideLabels ? 0 : 40);
|
|
159
|
-
const innerRadius = firstData.hole ? firstData.hole * (Math.min(width - donutMarginHorizontal, height - donutMarginVertical) / 2) :
|
|
382
|
+
const innerRadius = firstData.hole ? firstData.hole * (Math.min(width - donutMarginHorizontal, height - donutMarginVertical) / 2) : MIN_DONUT_RADIUS;
|
|
160
383
|
const { chartTitle } = getTitles(input.layout);
|
|
161
384
|
return {
|
|
162
385
|
data: {
|
|
163
386
|
chartTitle,
|
|
164
387
|
chartData: Object.values(mapLegendToDataPoint)
|
|
165
388
|
},
|
|
166
|
-
hideLegend: ((
|
|
167
|
-
width: (
|
|
389
|
+
hideLegend: isMultiPlot || ((_input_layout5 = input.layout) === null || _input_layout5 === void 0 ? void 0 : _input_layout5.showlegend) === false,
|
|
390
|
+
width: (_input_layout6 = input.layout) === null || _input_layout6 === void 0 ? void 0 : _input_layout6.width,
|
|
168
391
|
height,
|
|
169
392
|
innerRadius,
|
|
170
393
|
hideLabels,
|
|
@@ -175,66 +398,88 @@ export const transformPlotlyJsonToDonutProps = (input, colorMap, colorwayType, i
|
|
|
175
398
|
roundCorners: true
|
|
176
399
|
};
|
|
177
400
|
};
|
|
178
|
-
export const transformPlotlyJsonToVSBCProps = (input, colorMap, colorwayType, isDarkTheme, fallbackVSBC)=>{
|
|
401
|
+
export const transformPlotlyJsonToVSBCProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme, fallbackVSBC)=>{
|
|
179
402
|
var _input_layout, _input_layout1, _vsbcData_;
|
|
180
403
|
const mapXToDataPoints = {};
|
|
181
404
|
let yMaxValue = 0;
|
|
182
405
|
const secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
|
|
183
|
-
const { legends, hideLegend } = getLegendProps(input.data, input.layout);
|
|
406
|
+
const { legends, hideLegend } = getLegendProps(input.data, input.layout, isMultiPlot);
|
|
407
|
+
let colorScale = undefined;
|
|
408
|
+
const yAxisTickFormat = getYAxisTickFormat(input.data[0], input.layout);
|
|
184
409
|
let yMinValue = 0;
|
|
185
410
|
input.data.forEach((series, index1)=>{
|
|
186
|
-
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _input_layout_template_layout1, _input_layout_template1, _input_layout1, _series_line
|
|
411
|
+
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _input_layout_template_layout1, _input_layout_template1, _input_layout1, _series_line;
|
|
412
|
+
colorScale = createColorScale(input.layout, series, colorScale);
|
|
187
413
|
const isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
|
|
188
414
|
// extract bar colors for each series only once
|
|
189
415
|
const extractedBarColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color, colorMap, isDarkTheme);
|
|
190
416
|
// extract line colors for each series only once
|
|
191
417
|
const extractedLineColors = extractColor((_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_template1 = _input_layout1.template) === null || _input_layout_template1 === void 0 ? void 0 : (_input_layout_template_layout1 = _input_layout_template1.layout) === null || _input_layout_template_layout1 === void 0 ? void 0 : _input_layout_template_layout1.colorway, colorwayType, (_series_line = series.line) === null || _series_line === void 0 ? void 0 : _series_line.color, colorMap, isDarkTheme);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
legend,
|
|
209
|
-
data: yVal,
|
|
210
|
-
color
|
|
211
|
-
});
|
|
212
|
-
yMaxValue = Math.max(yMaxValue, yVal);
|
|
213
|
-
} else if (series.type === 'scatter' || !!fallbackVSBC) {
|
|
214
|
-
var _series_line;
|
|
215
|
-
const lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
|
|
216
|
-
const lineOptions = getLineOptions(series.line);
|
|
217
|
-
const dashType = ((_series_line = series.line) === null || _series_line === void 0 ? void 0 : _series_line.dash) || 'solid';
|
|
218
|
-
const legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
|
|
219
|
-
mapXToDataPoints[x].lineData.push({
|
|
220
|
-
legend,
|
|
221
|
-
legendShape,
|
|
222
|
-
y: yVal,
|
|
223
|
-
color: lineColor,
|
|
224
|
-
...lineOptions ? {
|
|
225
|
-
lineOptions
|
|
226
|
-
} : {},
|
|
227
|
-
useSecondaryYScale: usesSecondaryYScale(series)
|
|
228
|
-
});
|
|
229
|
-
if (!usesSecondaryYScale(series)) {
|
|
230
|
-
yMaxValue = Math.max(yMaxValue, yVal);
|
|
418
|
+
const xValues = series.x;
|
|
419
|
+
const isXDate = isDateArray(xValues);
|
|
420
|
+
const isXString = isStringArray(xValues);
|
|
421
|
+
const isXNumber = isNumberArray(xValues);
|
|
422
|
+
const validXYRanges = getValidXYRanges(series);
|
|
423
|
+
validXYRanges.forEach(([rangeStart, rangeEnd], rangeIdx)=>{
|
|
424
|
+
const rangeXValues = series.x.slice(rangeStart, rangeEnd);
|
|
425
|
+
const rangeYValues = series.y.slice(rangeStart, rangeEnd);
|
|
426
|
+
rangeXValues.forEach((x, index2)=>{
|
|
427
|
+
var _series_marker, _series_marker1, _series_marker_color, _series_marker2;
|
|
428
|
+
if (!mapXToDataPoints[x]) {
|
|
429
|
+
mapXToDataPoints[x] = {
|
|
430
|
+
xAxisPoint: resolveXAxisPoint(x, isXYearCategory, isXString, isXDate, isXNumber),
|
|
431
|
+
chartData: [],
|
|
432
|
+
lineData: []
|
|
433
|
+
};
|
|
231
434
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
435
|
+
const legend = legends[index1];
|
|
436
|
+
// resolve color for each legend's bars from the colorscale or extracted colors
|
|
437
|
+
const color = colorScale ? colorScale(isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color) ? (_series_marker2 = series.marker) === null || _series_marker2 === void 0 ? void 0 : (_series_marker_color = _series_marker2.color) === null || _series_marker_color === void 0 ? void 0 : _series_marker_color[index2 % ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color).length] : 0) : resolveColor(extractedBarColors, index2, legend, colorMap, isDarkTheme);
|
|
438
|
+
const opacity = getOpacity(series, index2);
|
|
439
|
+
const yVal = rangeYValues[index2];
|
|
440
|
+
const yAxisCalloutData = getFormattedCalloutYData(yVal, yAxisTickFormat);
|
|
441
|
+
if (series.type === 'bar') {
|
|
442
|
+
var _rgb_copy_formatHex8;
|
|
443
|
+
mapXToDataPoints[x].chartData.push({
|
|
444
|
+
legend,
|
|
445
|
+
data: yVal,
|
|
446
|
+
color: (_rgb_copy_formatHex8 = rgb(color).copy({
|
|
447
|
+
opacity
|
|
448
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : color,
|
|
449
|
+
yAxisCalloutData
|
|
450
|
+
});
|
|
451
|
+
if (typeof yVal === 'number') {
|
|
452
|
+
yMaxValue = Math.max(yMaxValue, yVal);
|
|
453
|
+
}
|
|
454
|
+
} else if (series.type === 'scatter' || !!fallbackVSBC) {
|
|
455
|
+
var _series_mode;
|
|
456
|
+
const lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
|
|
457
|
+
const lineOptions = !((_series_mode = series.mode) === null || _series_mode === void 0 ? void 0 : _series_mode.includes('text')) ? getLineOptions(series.line) : undefined;
|
|
458
|
+
const legendShape = getLegendShape(series);
|
|
459
|
+
var _rgb_copy_formatHex81;
|
|
460
|
+
mapXToDataPoints[x].lineData.push({
|
|
461
|
+
legend: legend + (validXYRanges.length > 1 ? `.${rangeIdx + 1}` : ''),
|
|
462
|
+
legendShape,
|
|
463
|
+
y: yVal,
|
|
464
|
+
color: (_rgb_copy_formatHex81 = rgb(lineColor).copy({
|
|
465
|
+
opacity
|
|
466
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex81 !== void 0 ? _rgb_copy_formatHex81 : color,
|
|
467
|
+
lineOptions: {
|
|
468
|
+
...lineOptions !== null && lineOptions !== void 0 ? lineOptions : {},
|
|
469
|
+
mode: series.mode
|
|
470
|
+
},
|
|
471
|
+
useSecondaryYScale: usesSecondaryYScale(series, input.layout),
|
|
472
|
+
yAxisCalloutData
|
|
473
|
+
});
|
|
474
|
+
if (!usesSecondaryYScale(series, input.layout) && typeof yVal === 'number') {
|
|
475
|
+
yMaxValue = Math.max(yMaxValue, yVal);
|
|
476
|
+
yMinValue = Math.min(yMinValue, yVal);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
yMaxValue = Math.max(yMaxValue, yVal);
|
|
480
|
+
});
|
|
235
481
|
});
|
|
236
482
|
});
|
|
237
|
-
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
|
|
238
483
|
const vsbcData = Object.values(mapXToDataPoints);
|
|
239
484
|
var _input_layout_height;
|
|
240
485
|
return {
|
|
@@ -244,28 +489,70 @@ export const transformPlotlyJsonToVSBCProps = (input, colorMap, colorwayType, is
|
|
|
244
489
|
barWidth: 'auto',
|
|
245
490
|
yMaxValue,
|
|
246
491
|
yMinValue,
|
|
247
|
-
chartTitle,
|
|
248
|
-
xAxisTitle,
|
|
249
|
-
yAxisTitle,
|
|
250
492
|
mode: 'plotly',
|
|
251
493
|
...secondaryYAxisValues,
|
|
252
494
|
wrapXAxisLables: typeof ((_vsbcData_ = vsbcData[0]) === null || _vsbcData_ === void 0 ? void 0 : _vsbcData_.xAxisPoint) === 'string',
|
|
253
495
|
hideTickOverlap: true,
|
|
254
496
|
barGapMax: 2,
|
|
255
497
|
hideLegend,
|
|
256
|
-
roundCorners: true
|
|
498
|
+
roundCorners: true,
|
|
499
|
+
showYAxisLables: true,
|
|
500
|
+
noOfCharsToTruncate: 20,
|
|
501
|
+
showYAxisLablesTooltip: true,
|
|
502
|
+
...getTitles(input.layout),
|
|
503
|
+
...getXAxisTickFormat(input.data[0], input.layout),
|
|
504
|
+
...yAxisTickFormat,
|
|
505
|
+
...getAxisCategoryOrderProps(input.data, input.layout),
|
|
506
|
+
...getBarProps(input.data, input.layout),
|
|
507
|
+
...getYMinMaxValues(input.data[0], input.layout),
|
|
508
|
+
...getAxisTickProps(input.data, input.layout)
|
|
257
509
|
};
|
|
258
510
|
};
|
|
259
|
-
export const transformPlotlyJsonToGVBCProps = (input, colorMap, colorwayType, isDarkTheme)=>{
|
|
260
|
-
var
|
|
511
|
+
export const transformPlotlyJsonToGVBCProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
512
|
+
var _processedInput_layout, _processedInput_layout1, _gvbcData_;
|
|
513
|
+
// Handle object arrays in y values by normalizing the data first
|
|
514
|
+
let processedInput = {
|
|
515
|
+
...input
|
|
516
|
+
};
|
|
517
|
+
// Check if any bar traces have object arrays as y values
|
|
518
|
+
const hasObjectArrayData = input.data.some((series)=>series.type === 'bar' && isObjectArray(series.y));
|
|
519
|
+
if (hasObjectArrayData) {
|
|
520
|
+
// Process each trace that has object array y values
|
|
521
|
+
const processedData = input.data.map((series, index)=>{
|
|
522
|
+
if (series.type === 'bar' && isObjectArray(series.y)) {
|
|
523
|
+
// Normalize the object array to create multiple traces for GVBC
|
|
524
|
+
const { traces } = normalizeObjectArrayForGVBC(series.y, Array.isArray(series.x) ? series.x : undefined);
|
|
525
|
+
// Return all the new traces, each representing a property from the objects
|
|
526
|
+
return traces.map((trace)=>({
|
|
527
|
+
...trace,
|
|
528
|
+
// Copy other properties from the original series if needed
|
|
529
|
+
marker: series.marker
|
|
530
|
+
}));
|
|
531
|
+
}
|
|
532
|
+
return [
|
|
533
|
+
series
|
|
534
|
+
];
|
|
535
|
+
}).flat();
|
|
536
|
+
processedInput = {
|
|
537
|
+
...input,
|
|
538
|
+
data: processedData
|
|
539
|
+
};
|
|
540
|
+
}
|
|
261
541
|
const mapXToDataPoints = {};
|
|
262
|
-
const secondaryYAxisValues = getSecondaryYAxisValues(
|
|
263
|
-
const { legends, hideLegend } = getLegendProps(
|
|
264
|
-
|
|
265
|
-
|
|
542
|
+
const secondaryYAxisValues = getSecondaryYAxisValues(processedInput.data, processedInput.layout, 0, 0);
|
|
543
|
+
const { legends, hideLegend } = getLegendProps(processedInput.data, processedInput.layout, isMultiPlot);
|
|
544
|
+
let colorScale = undefined;
|
|
545
|
+
const yAxisTickFormat = getYAxisTickFormat(processedInput.data[0], processedInput.layout);
|
|
546
|
+
processedInput.data.forEach((series, index1)=>{
|
|
547
|
+
var _processedInput_layout_template_layout, _processedInput_layout_template, _processedInput_layout, _series_marker, _series_x;
|
|
548
|
+
colorScale = createColorScale(processedInput.layout, series, colorScale);
|
|
266
549
|
// extract colors for each series only once
|
|
267
|
-
const extractedColors = extractColor((
|
|
550
|
+
const extractedColors = extractColor((_processedInput_layout = processedInput.layout) === null || _processedInput_layout === void 0 ? void 0 : (_processedInput_layout_template = _processedInput_layout.template) === null || _processedInput_layout_template === void 0 ? void 0 : (_processedInput_layout_template_layout = _processedInput_layout_template.layout) === null || _processedInput_layout_template_layout === void 0 ? void 0 : _processedInput_layout_template_layout.colorway, colorwayType, (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color, colorMap, isDarkTheme);
|
|
268
551
|
(_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x.forEach((x, index2)=>{
|
|
552
|
+
var _series_y;
|
|
553
|
+
if (isInvalidValue(x) || isInvalidValue((_series_y = series.y) === null || _series_y === void 0 ? void 0 : _series_y[index2])) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
269
556
|
if (!mapXToDataPoints[x]) {
|
|
270
557
|
mapXToDataPoints[x] = {
|
|
271
558
|
name: x.toString(),
|
|
@@ -273,64 +560,82 @@ export const transformPlotlyJsonToGVBCProps = (input, colorMap, colorwayType, is
|
|
|
273
560
|
};
|
|
274
561
|
}
|
|
275
562
|
if (series.type === 'bar') {
|
|
276
|
-
var
|
|
563
|
+
var _series_marker, _series_marker1, _series_marker_color, _series_marker2;
|
|
277
564
|
const legend = legends[index1];
|
|
278
|
-
// resolve color for each legend's bars from the extracted colors
|
|
279
|
-
const color = resolveColor(extractedColors,
|
|
280
|
-
|
|
565
|
+
// resolve color for each legend's bars from the colorscale or extracted colors
|
|
566
|
+
const color = colorScale ? colorScale(isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color) ? (_series_marker2 = series.marker) === null || _series_marker2 === void 0 ? void 0 : (_series_marker_color = _series_marker2.color) === null || _series_marker_color === void 0 ? void 0 : _series_marker_color[index2 % ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color).length] : 0) : resolveColor(extractedColors, index2, legend, colorMap, isDarkTheme);
|
|
567
|
+
const opacity = getOpacity(series, index2);
|
|
568
|
+
const yVal = series.y[index2];
|
|
569
|
+
var _rgb_copy_formatHex8;
|
|
281
570
|
mapXToDataPoints[x].series.push({
|
|
282
571
|
key: legend,
|
|
283
|
-
data:
|
|
572
|
+
data: yVal,
|
|
284
573
|
xAxisCalloutData: x,
|
|
285
|
-
color
|
|
574
|
+
color: (_rgb_copy_formatHex8 = rgb(color).copy({
|
|
575
|
+
opacity
|
|
576
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : color,
|
|
286
577
|
legend,
|
|
287
|
-
useSecondaryYScale: usesSecondaryYScale(series)
|
|
578
|
+
useSecondaryYScale: usesSecondaryYScale(series, processedInput.layout),
|
|
579
|
+
yAxisCalloutData: getFormattedCalloutYData(yVal, yAxisTickFormat)
|
|
288
580
|
});
|
|
289
581
|
}
|
|
290
582
|
});
|
|
291
583
|
});
|
|
292
|
-
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
|
|
293
584
|
const gvbcData = Object.values(mapXToDataPoints);
|
|
294
|
-
var
|
|
585
|
+
var _processedInput_layout_height;
|
|
295
586
|
return {
|
|
296
587
|
data: gvbcData,
|
|
297
|
-
width: (
|
|
298
|
-
height: (
|
|
588
|
+
width: (_processedInput_layout = processedInput.layout) === null || _processedInput_layout === void 0 ? void 0 : _processedInput_layout.width,
|
|
589
|
+
height: (_processedInput_layout_height = (_processedInput_layout1 = processedInput.layout) === null || _processedInput_layout1 === void 0 ? void 0 : _processedInput_layout1.height) !== null && _processedInput_layout_height !== void 0 ? _processedInput_layout_height : 350,
|
|
299
590
|
barWidth: 'auto',
|
|
300
|
-
chartTitle,
|
|
301
|
-
xAxisTitle,
|
|
302
|
-
yAxisTitle,
|
|
303
591
|
mode: 'plotly',
|
|
304
592
|
...secondaryYAxisValues,
|
|
305
593
|
hideTickOverlap: true,
|
|
306
594
|
wrapXAxisLables: typeof ((_gvbcData_ = gvbcData[0]) === null || _gvbcData_ === void 0 ? void 0 : _gvbcData_.name) === 'string',
|
|
307
595
|
hideLegend,
|
|
308
|
-
roundCorners: true
|
|
596
|
+
roundCorners: true,
|
|
597
|
+
...getTitles(processedInput.layout),
|
|
598
|
+
...getAxisCategoryOrderProps(processedInput.data, processedInput.layout),
|
|
599
|
+
...getYMinMaxValues(processedInput.data[0], processedInput.layout),
|
|
600
|
+
...getXAxisTickFormat(processedInput.data[0], processedInput.layout),
|
|
601
|
+
...yAxisTickFormat,
|
|
602
|
+
...getBarProps(processedInput.data, processedInput.layout),
|
|
603
|
+
...getAxisTickProps(processedInput.data, processedInput.layout)
|
|
309
604
|
};
|
|
310
605
|
};
|
|
311
|
-
export const transformPlotlyJsonToVBCProps = (input, colorMap, colorwayType, isDarkTheme)=>{
|
|
606
|
+
export const transformPlotlyJsonToVBCProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
312
607
|
var _input_layout, _input_layout1, _vbcData_;
|
|
313
608
|
const vbcData = [];
|
|
314
|
-
const { legends, hideLegend } = getLegendProps(input.data, input.layout);
|
|
609
|
+
const { legends, hideLegend } = getLegendProps(input.data, input.layout, isMultiPlot);
|
|
610
|
+
let colorScale = undefined;
|
|
315
611
|
input.data.forEach((series, seriesIdx)=>{
|
|
316
612
|
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _series_xbins, _series_xbins1, _series_xbins2;
|
|
317
613
|
if (!series.x) {
|
|
318
614
|
return;
|
|
319
615
|
}
|
|
616
|
+
colorScale = createColorScale(input.layout, series, colorScale);
|
|
320
617
|
// extract colors for each series only once
|
|
321
618
|
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color, colorMap, isDarkTheme);
|
|
322
|
-
const
|
|
619
|
+
const xValues = [];
|
|
620
|
+
const yValues = [];
|
|
621
|
+
series.x.forEach((xVal, index)=>{
|
|
622
|
+
const yVal = getNumberAtIndexOrDefault(series.y, index);
|
|
623
|
+
if (isInvalidValue(xVal) || isInvalidValue(yVal)) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
xValues.push(xVal);
|
|
627
|
+
yValues.push(yVal);
|
|
628
|
+
});
|
|
629
|
+
const isXString = isStringArray(xValues);
|
|
323
630
|
// TODO: In case of a single bin, add an empty bin of the same size to prevent the
|
|
324
631
|
// default bar width from being used and ensure the bar spans the full intended range.
|
|
325
|
-
const xBins = createBins(
|
|
632
|
+
const xBins = createBins(xValues, (_series_xbins = series.xbins) === null || _series_xbins === void 0 ? void 0 : _series_xbins.start, (_series_xbins1 = series.xbins) === null || _series_xbins1 === void 0 ? void 0 : _series_xbins1.end, (_series_xbins2 = series.xbins) === null || _series_xbins2 === void 0 ? void 0 : _series_xbins2.size);
|
|
326
633
|
const yBins = xBins.map(()=>[]);
|
|
327
634
|
let total = 0;
|
|
328
|
-
|
|
635
|
+
xValues.forEach((xVal, index)=>{
|
|
329
636
|
const binIdx = findBinIndex(xBins, xVal, isXString);
|
|
330
637
|
if (binIdx !== -1) {
|
|
331
|
-
|
|
332
|
-
var _series_y_index;
|
|
333
|
-
yBins[binIdx].push((_series_y_index = (_series_y = series.y) === null || _series_y === void 0 ? void 0 : _series_y[index]) !== null && _series_y_index !== void 0 ? _series_y_index : 1);
|
|
638
|
+
yBins[binIdx].push(yValues[index]);
|
|
334
639
|
}
|
|
335
640
|
});
|
|
336
641
|
const y = yBins.map((bin)=>{
|
|
@@ -339,141 +644,210 @@ export const transformPlotlyJsonToVBCProps = (input, colorMap, colorwayType, isD
|
|
|
339
644
|
return yVal;
|
|
340
645
|
});
|
|
341
646
|
xBins.forEach((bin, index)=>{
|
|
647
|
+
var _series_marker, _series_marker1, _series_marker_color, _series_marker2;
|
|
342
648
|
const legend = legends[seriesIdx];
|
|
343
|
-
// resolve color for each legend's bars from the extracted colors
|
|
344
|
-
const color = resolveColor(extractedColors,
|
|
649
|
+
// resolve color for each legend's bars from the colorscale or extracted colors
|
|
650
|
+
const color = colorScale ? colorScale(isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color) ? (_series_marker2 = series.marker) === null || _series_marker2 === void 0 ? void 0 : (_series_marker_color = _series_marker2.color) === null || _series_marker_color === void 0 ? void 0 : _series_marker_color[index % ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color).length] : 0) : resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
|
|
651
|
+
const opacity = getOpacity(series, index);
|
|
345
652
|
const yVal = calculateHistNorm(series.histnorm, y[index], total, isXString ? bin.length : getBinSize(bin));
|
|
653
|
+
var _rgb_copy_formatHex8;
|
|
346
654
|
vbcData.push({
|
|
347
655
|
x: isXString ? bin.join(', ') : getBinCenter(bin),
|
|
348
656
|
y: yVal,
|
|
349
657
|
legend,
|
|
350
|
-
color
|
|
658
|
+
color: (_rgb_copy_formatHex8 = rgb(color).copy({
|
|
659
|
+
opacity
|
|
660
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : color,
|
|
351
661
|
...isXString ? {} : {
|
|
352
662
|
xAxisCalloutData: `[${bin.x0} - ${bin.x1})`
|
|
353
663
|
}
|
|
354
664
|
});
|
|
355
665
|
});
|
|
356
666
|
});
|
|
357
|
-
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
|
|
358
667
|
var _input_layout_height;
|
|
359
668
|
return {
|
|
360
669
|
data: vbcData,
|
|
361
670
|
width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
|
|
362
671
|
height: (_input_layout_height = (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 350,
|
|
363
|
-
chartTitle,
|
|
364
|
-
xAxisTitle,
|
|
365
|
-
yAxisTitle,
|
|
366
672
|
mode: 'histogram',
|
|
367
673
|
hideTickOverlap: true,
|
|
368
674
|
wrapXAxisLables: typeof ((_vbcData_ = vbcData[0]) === null || _vbcData_ === void 0 ? void 0 : _vbcData_.x) === 'string',
|
|
369
675
|
maxBarWidth: 50,
|
|
370
676
|
hideLegend,
|
|
371
|
-
roundCorners: true
|
|
677
|
+
roundCorners: true,
|
|
678
|
+
...getTitles(input.layout),
|
|
679
|
+
...getYMinMaxValues(input.data[0], input.layout),
|
|
680
|
+
...getAxisCategoryOrderProps(input.data, input.layout)
|
|
372
681
|
};
|
|
373
682
|
};
|
|
374
|
-
export const
|
|
683
|
+
export const transformPlotlyJsonToAreaChartProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
684
|
+
return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'area', colorMap, colorwayType, isDarkTheme);
|
|
685
|
+
};
|
|
686
|
+
export const transformPlotlyJsonToLineChartProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
687
|
+
return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'line', colorMap, colorwayType, isDarkTheme);
|
|
688
|
+
};
|
|
689
|
+
export const transformPlotlyJsonToScatterChartProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
690
|
+
return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'scatter', colorMap, colorwayType, isDarkTheme);
|
|
691
|
+
};
|
|
692
|
+
const transformPlotlyJsonToScatterTraceProps = (input, isMultiPlot, chartType, colorMap, colorwayType, isDarkTheme)=>{
|
|
693
|
+
var _input_data_, _input_layout, _input_layout1;
|
|
694
|
+
const isScatterMarkers = [
|
|
695
|
+
'text',
|
|
696
|
+
'markers',
|
|
697
|
+
'text+markers',
|
|
698
|
+
'markers+text',
|
|
699
|
+
'lines+markers',
|
|
700
|
+
'markers+line',
|
|
701
|
+
'text+lines+markers',
|
|
702
|
+
'lines+markers+text'
|
|
703
|
+
].includes((_input_data_ = input.data[0]) === null || _input_data_ === void 0 ? void 0 : _input_data_.mode);
|
|
704
|
+
const isAreaChart = chartType === 'area';
|
|
705
|
+
const isScatterChart = chartType === 'scatter';
|
|
375
706
|
const secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, isAreaChart ? 0 : undefined, isAreaChart ? 0 : undefined);
|
|
376
707
|
let mode = 'tonexty';
|
|
377
|
-
const { legends, hideLegend } = getLegendProps(input.data, input.layout);
|
|
708
|
+
const { legends, hideLegend } = getLegendProps(input.data, input.layout, isMultiPlot);
|
|
709
|
+
const yAxisTickFormat = getYAxisTickFormat(input.data[0], input.layout);
|
|
378
710
|
const chartData = input.data.map((series, index)=>{
|
|
379
|
-
var
|
|
711
|
+
var _series_mode, _series_line, _series_marker, _series_line1, _input_layout_template_layout, _input_layout_template, _input_layout, _series_mode1;
|
|
712
|
+
const colors = isScatterMarkers ? (series === null || series === void 0 ? void 0 : (_series_mode = series.mode) === null || _series_mode === void 0 ? void 0 : _series_mode.includes('line')) ? (_series_line = series.line) === null || _series_line === void 0 ? void 0 : _series_line.color : (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color : (_series_line1 = series.line) === null || _series_line1 === void 0 ? void 0 : _series_line1.color;
|
|
380
713
|
// extract colors for each series only once
|
|
381
|
-
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType,
|
|
714
|
+
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, colors, colorMap, isDarkTheme);
|
|
382
715
|
const xValues = series.x;
|
|
383
|
-
const
|
|
716
|
+
const isXString = isStringArray(xValues);
|
|
384
717
|
const isXDate = isDateArray(xValues);
|
|
385
718
|
const isXNumber = isNumberArray(xValues);
|
|
719
|
+
const isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
|
|
386
720
|
const legend = legends[index];
|
|
387
721
|
// resolve color for each legend's lines from the extracted colors
|
|
388
722
|
const seriesColor = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
|
|
723
|
+
const seriesOpacity = getOpacity(series, index);
|
|
389
724
|
mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
const legendShape =
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
725
|
+
// if mode contains 'text', we prioritize showing the text over curving the line
|
|
726
|
+
const lineOptions = !((_series_mode1 = series.mode) === null || _series_mode1 === void 0 ? void 0 : _series_mode1.includes('text')) && series.type !== 'scatterpolar' ? getLineOptions(series.line) : undefined;
|
|
727
|
+
const legendShape = getLegendShape(series);
|
|
728
|
+
const validXYRanges = getValidXYRanges(series);
|
|
729
|
+
return validXYRanges.map(([rangeStart, rangeEnd], rangeIdx)=>{
|
|
730
|
+
var _series_marker, _input_layout, _input_layout_polar_angularaxis, _input_layout_polar, _input_layout1, _input_layout_polar_angularaxis1, _input_layout_polar1, _input_layout2;
|
|
731
|
+
const rangeXValues = xValues.slice(rangeStart, rangeEnd);
|
|
732
|
+
const rangeYValues = series.y.slice(rangeStart, rangeEnd);
|
|
733
|
+
const markerSizes = isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.size) ? series.marker.size.slice(rangeStart, rangeEnd) : [];
|
|
734
|
+
const textValues = Array.isArray(series.text) ? series.text.slice(rangeStart, rangeEnd) : undefined;
|
|
735
|
+
var _rgb_copy_formatHex8;
|
|
736
|
+
return {
|
|
737
|
+
legend,
|
|
738
|
+
legendShape,
|
|
739
|
+
data: rangeXValues.map((x, i)=>{
|
|
740
|
+
var _series_marker, _series_marker1;
|
|
741
|
+
return {
|
|
742
|
+
x: resolveXAxisPoint(x, isXYearCategory, isXString, isXDate, isXNumber),
|
|
743
|
+
y: rangeYValues[i],
|
|
744
|
+
...Array.isArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.size) ? {
|
|
745
|
+
markerSize: markerSizes[i]
|
|
746
|
+
} : typeof ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.size) === 'number' ? {
|
|
747
|
+
markerSize: series.marker.size
|
|
748
|
+
} : {},
|
|
749
|
+
...textValues ? {
|
|
750
|
+
text: textValues[i]
|
|
751
|
+
} : {},
|
|
752
|
+
yAxisCalloutData: getFormattedCalloutYData(rangeYValues[i], yAxisTickFormat)
|
|
753
|
+
};
|
|
754
|
+
}),
|
|
755
|
+
color: (_rgb_copy_formatHex8 = rgb(seriesColor).copy({
|
|
756
|
+
opacity: seriesOpacity
|
|
757
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : seriesColor,
|
|
758
|
+
lineOptions: {
|
|
759
|
+
...lineOptions !== null && lineOptions !== void 0 ? lineOptions : {},
|
|
760
|
+
mode: series.type !== 'scatterpolar' ? series.mode : 'scatterpolar',
|
|
761
|
+
// originXOffset is not typed on Layout, but may be present in input.layout as a part of projection of
|
|
762
|
+
// scatter polar coordingates to cartesian coordinates
|
|
763
|
+
...series.type === 'scatterpolar' ? {
|
|
764
|
+
originXOffset: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.__polarOriginX,
|
|
765
|
+
direction: (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_polar = _input_layout1.polar) === null || _input_layout_polar === void 0 ? void 0 : (_input_layout_polar_angularaxis = _input_layout_polar.angularaxis) === null || _input_layout_polar_angularaxis === void 0 ? void 0 : _input_layout_polar_angularaxis.direction,
|
|
766
|
+
rotation: (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : (_input_layout_polar1 = _input_layout2.polar) === null || _input_layout_polar1 === void 0 ? void 0 : (_input_layout_polar_angularaxis1 = _input_layout_polar1.angularaxis) === null || _input_layout_polar_angularaxis1 === void 0 ? void 0 : _input_layout_polar_angularaxis1.rotation,
|
|
767
|
+
axisLabel: series.__axisLabel ? series.__axisLabel : {}
|
|
405
768
|
} : {}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
769
|
+
},
|
|
770
|
+
useSecondaryYScale: usesSecondaryYScale(series, input.layout)
|
|
771
|
+
};
|
|
772
|
+
});
|
|
773
|
+
}).flat();
|
|
774
|
+
const yMinMax = getYMinMaxValues(input.data[0], input.layout);
|
|
775
|
+
if (yMinMax.yMinValue === undefined && yMinMax.yMaxValue === undefined) {
|
|
776
|
+
const yMinMaxValues = findNumericMinMaxOfY(chartData);
|
|
777
|
+
yMinMax.yMinValue = yMinMaxValues.startValue;
|
|
778
|
+
yMinMax.yMaxValue = yMinMaxValues.endValue;
|
|
779
|
+
}
|
|
780
|
+
const numDataPoints = chartData.reduce((total, lineChartPoints)=>total + lineChartPoints.data.length, 0);
|
|
417
781
|
const chartProps = {
|
|
418
|
-
chartTitle,
|
|
419
782
|
lineChartData: chartData
|
|
420
783
|
};
|
|
784
|
+
const scatterChartProps = {
|
|
785
|
+
scatterChartData: chartData
|
|
786
|
+
};
|
|
787
|
+
var _input_layout_height;
|
|
788
|
+
const commonProps = {
|
|
789
|
+
supportNegativeData: true,
|
|
790
|
+
...secondaryYAxisValues,
|
|
791
|
+
width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
|
|
792
|
+
height: (_input_layout_height = (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 350,
|
|
793
|
+
hideTickOverlap: true,
|
|
794
|
+
hideLegend,
|
|
795
|
+
useUTC: false,
|
|
796
|
+
optimizeLargeData: numDataPoints > 1000,
|
|
797
|
+
...getTitles(input.layout),
|
|
798
|
+
...getXAxisTickFormat(input.data[0], input.layout),
|
|
799
|
+
...yAxisTickFormat,
|
|
800
|
+
...getAxisScaleTypeProps(input.data, input.layout),
|
|
801
|
+
...getAxisTickProps(input.data, input.layout)
|
|
802
|
+
};
|
|
421
803
|
if (isAreaChart) {
|
|
422
|
-
var _input_layout, _input_layout1;
|
|
423
|
-
var _input_layout_height;
|
|
424
804
|
return {
|
|
425
805
|
data: chartProps,
|
|
426
|
-
supportNegativeData: true,
|
|
427
|
-
xAxisTitle,
|
|
428
|
-
yAxisTitle,
|
|
429
|
-
...secondaryYAxisValues,
|
|
430
806
|
mode,
|
|
431
|
-
|
|
432
|
-
height: (_input_layout_height = (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 350,
|
|
433
|
-
hideTickOverlap: true,
|
|
434
|
-
useUTC: false,
|
|
435
|
-
hideLegend
|
|
807
|
+
...commonProps
|
|
436
808
|
};
|
|
437
809
|
} else {
|
|
438
|
-
var _input_layout2, _input_layout3;
|
|
439
|
-
var _input_layout_height1;
|
|
440
810
|
return {
|
|
441
|
-
data: chartProps,
|
|
442
|
-
supportNegativeData: true,
|
|
443
|
-
xAxisTitle,
|
|
444
|
-
yAxisTitle,
|
|
445
|
-
...secondaryYAxisValues,
|
|
811
|
+
data: isScatterChart ? scatterChartProps : chartProps,
|
|
446
812
|
roundedTicks: true,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
hideLegend
|
|
813
|
+
...commonProps,
|
|
814
|
+
...yMinMax,
|
|
815
|
+
...isScatterChart ? {
|
|
816
|
+
showYAxisLablesTooltip: true,
|
|
817
|
+
...getAxisCategoryOrderProps(input.data, input.layout)
|
|
818
|
+
} : {}
|
|
454
819
|
};
|
|
455
820
|
}
|
|
456
821
|
};
|
|
457
|
-
export const transformPlotlyJsonToHorizontalBarWithAxisProps = (input, colorMap, colorwayType, isDarkTheme)=>{
|
|
822
|
+
export const transformPlotlyJsonToHorizontalBarWithAxisProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
458
823
|
var _input_layout, _input_layout_margin, _input_layout1, _input_layout_margin1, _input_layout2, _input_layout_yaxis2, _input_layout3, _input_layout_yaxis21, _input_layout4, _input_layout_yaxis2_title, _input_layout_yaxis22, _input_layout5, _input_layout6;
|
|
459
|
-
const { legends, hideLegend } = getLegendProps(input.data, input.layout);
|
|
824
|
+
const { legends, hideLegend } = getLegendProps(input.data, input.layout, isMultiPlot);
|
|
825
|
+
let colorScale = undefined;
|
|
460
826
|
const chartData = input.data.map((series, index)=>{
|
|
461
827
|
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker;
|
|
828
|
+
colorScale = createColorScale(input.layout, series, colorScale);
|
|
462
829
|
// extract colors for each series only once
|
|
463
830
|
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color, colorMap, isDarkTheme);
|
|
464
831
|
const legend = legends[index];
|
|
465
|
-
// resolve color for each legend's bars from the extracted colors
|
|
466
|
-
const color = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
|
|
467
832
|
return series.y.map((yValue, i)=>{
|
|
833
|
+
var _series_x, _series_marker, _series_marker1, _series_marker_color, _series_marker2;
|
|
834
|
+
if (isInvalidValue((_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x[i]) || isInvalidValue(yValue)) {
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
// resolve color for each legend's bars from the colorscale or extracted colors
|
|
838
|
+
const color = colorScale ? colorScale(isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color) ? (_series_marker2 = series.marker) === null || _series_marker2 === void 0 ? void 0 : (_series_marker_color = _series_marker2.color) === null || _series_marker_color === void 0 ? void 0 : _series_marker_color[i % ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color).length] : 0) : resolveColor(extractedColors, i, legend, colorMap, isDarkTheme);
|
|
839
|
+
const opacity = getOpacity(series, i);
|
|
840
|
+
var _rgb_copy_formatHex8;
|
|
468
841
|
return {
|
|
469
842
|
x: series.x[i],
|
|
470
843
|
y: yValue,
|
|
471
844
|
legend,
|
|
472
|
-
color
|
|
845
|
+
color: (_rgb_copy_formatHex8 = rgb(color).copy({
|
|
846
|
+
opacity
|
|
847
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : color
|
|
473
848
|
};
|
|
474
|
-
});
|
|
475
|
-
}).
|
|
476
|
-
.reverse();
|
|
849
|
+
}).filter((point)=>point !== null);
|
|
850
|
+
}).flat();
|
|
477
851
|
var _input_layout_height;
|
|
478
852
|
const chartHeight = (_input_layout_height = (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 450;
|
|
479
853
|
var _input_layout_margin_l;
|
|
@@ -485,12 +859,8 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (input, colorMap,
|
|
|
485
859
|
const scalingFactor = 0.01;
|
|
486
860
|
const gapFactor = 1 / (1 + scalingFactor * numberOfRows);
|
|
487
861
|
const barHeight = availableHeight / (numberOfRows * (1 + gapFactor));
|
|
488
|
-
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
|
|
489
862
|
return {
|
|
490
863
|
data: chartData,
|
|
491
|
-
chartTitle,
|
|
492
|
-
xAxisTitle,
|
|
493
|
-
yAxisTitle,
|
|
494
864
|
secondaryYAxistitle: typeof ((_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : (_input_layout_yaxis2 = _input_layout3.yaxis2) === null || _input_layout_yaxis2 === void 0 ? void 0 : _input_layout_yaxis2.title) === 'string' ? (_input_layout4 = input.layout) === null || _input_layout4 === void 0 ? void 0 : (_input_layout_yaxis21 = _input_layout4.yaxis2) === null || _input_layout_yaxis21 === void 0 ? void 0 : _input_layout_yaxis21.title : ((_input_layout5 = input.layout) === null || _input_layout5 === void 0 ? void 0 : (_input_layout_yaxis22 = _input_layout5.yaxis2) === null || _input_layout_yaxis22 === void 0 ? void 0 : (_input_layout_yaxis2_title = _input_layout_yaxis22.title) === null || _input_layout_yaxis2_title === void 0 ? void 0 : _input_layout_yaxis2_title.text) || '',
|
|
495
865
|
barHeight,
|
|
496
866
|
showYAxisLables: true,
|
|
@@ -500,31 +870,102 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (input, colorMap,
|
|
|
500
870
|
noOfCharsToTruncate: 20,
|
|
501
871
|
showYAxisLablesTooltip: true,
|
|
502
872
|
hideLegend,
|
|
503
|
-
roundCorners: true
|
|
873
|
+
roundCorners: true,
|
|
874
|
+
...getTitles(input.layout),
|
|
875
|
+
...getAxisCategoryOrderProps(input.data, input.layout),
|
|
876
|
+
...getBarProps(input.data, input.layout, true),
|
|
877
|
+
...getAxisTickProps(input.data, input.layout)
|
|
504
878
|
};
|
|
505
879
|
};
|
|
506
|
-
export const
|
|
880
|
+
export const transformPlotlyJsonToGanttChartProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
507
881
|
var _input_layout, _input_layout1;
|
|
882
|
+
const { legends, hideLegend } = getLegendProps(input.data, input.layout, isMultiPlot);
|
|
883
|
+
let colorScale = undefined;
|
|
884
|
+
const chartData = input.data.map((series, index)=>{
|
|
885
|
+
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _input_layout_xaxis, _input_layout1;
|
|
886
|
+
colorScale = createColorScale(input.layout, series, colorScale);
|
|
887
|
+
// extract colors for each series only once
|
|
888
|
+
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color, colorMap, isDarkTheme);
|
|
889
|
+
const legend = legends[index];
|
|
890
|
+
const isXDate = ((_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_xaxis = _input_layout1.xaxis) === null || _input_layout_xaxis === void 0 ? void 0 : _input_layout_xaxis.type) === 'date' || isDateArray(series.x);
|
|
891
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
892
|
+
const convertXValueToNumber = (value)=>{
|
|
893
|
+
return isInvalidValue(value) ? 0 : isXDate ? +parseLocalDate(value) : +value;
|
|
894
|
+
};
|
|
895
|
+
return series.y.map((yVal, i)=>{
|
|
896
|
+
var _series_marker, _series_marker1, _series_marker_color, _series_marker2, _series_base, _series_x;
|
|
897
|
+
if (isInvalidValue(yVal)) {
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
// resolve color for each legend's bars from the colorscale or extracted colors
|
|
901
|
+
const color = colorScale ? colorScale(isArrayOrTypedArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.color) ? (_series_marker2 = series.marker) === null || _series_marker2 === void 0 ? void 0 : (_series_marker_color = _series_marker2.color) === null || _series_marker_color === void 0 ? void 0 : _series_marker_color[i % ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color).length] : 0) : resolveColor(extractedColors, i, legend, colorMap, isDarkTheme);
|
|
902
|
+
const opacity = getOpacity(series, i);
|
|
903
|
+
const base = convertXValueToNumber((_series_base = series.base) === null || _series_base === void 0 ? void 0 : _series_base[i]);
|
|
904
|
+
const xVal = convertXValueToNumber((_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x[i]);
|
|
905
|
+
var _rgb_copy_formatHex8;
|
|
906
|
+
return {
|
|
907
|
+
x: {
|
|
908
|
+
start: isXDate ? new Date(base) : base,
|
|
909
|
+
end: isXDate ? new Date(base + xVal) : base + xVal
|
|
910
|
+
},
|
|
911
|
+
y: yVal,
|
|
912
|
+
legend,
|
|
913
|
+
color: (_rgb_copy_formatHex8 = rgb(color).copy({
|
|
914
|
+
opacity
|
|
915
|
+
}).formatHex8()) !== null && _rgb_copy_formatHex8 !== void 0 ? _rgb_copy_formatHex8 : color
|
|
916
|
+
};
|
|
917
|
+
}).filter((point)=>point !== null);
|
|
918
|
+
}).flat();
|
|
919
|
+
var _input_layout_height;
|
|
920
|
+
return {
|
|
921
|
+
data: chartData,
|
|
922
|
+
showYAxisLables: true,
|
|
923
|
+
height: (_input_layout_height = (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 350,
|
|
924
|
+
width: (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.width,
|
|
925
|
+
hideTickOverlap: true,
|
|
926
|
+
hideLegend,
|
|
927
|
+
noOfCharsToTruncate: 20,
|
|
928
|
+
showYAxisLablesTooltip: true,
|
|
929
|
+
roundCorners: true,
|
|
930
|
+
useUTC: false,
|
|
931
|
+
...getTitles(input.layout),
|
|
932
|
+
...getAxisCategoryOrderProps(input.data, input.layout),
|
|
933
|
+
...getBarProps(input.data, input.layout, true),
|
|
934
|
+
...getAxisTickProps(input.data, input.layout)
|
|
935
|
+
};
|
|
936
|
+
};
|
|
937
|
+
export const transformPlotlyJsonToHeatmapProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
938
|
+
var _input_layout, _input_layout_coloraxis, _input_layout1, _input_layout_template_layout, _input_layout_template, _input_layout2, _input_layout_template_data_histogram2d_, _input_layout_template_data_histogram2d, _input_layout_template_data, _input_layout_template1, _input_layout3, _input_layout_template_data_heatmap_, _input_layout_template_data_heatmap, _input_layout_template_data1, _input_layout_template2, _input_layout4, _input_layout5, _input_layout6;
|
|
508
939
|
const firstData = input.data[0];
|
|
509
940
|
const heatmapDataPoints = [];
|
|
510
941
|
let zMin = Number.POSITIVE_INFINITY;
|
|
511
942
|
let zMax = Number.NEGATIVE_INFINITY;
|
|
512
943
|
if (firstData.type === 'histogram2d') {
|
|
513
|
-
var _firstData_xbins, _firstData_xbins1, _firstData_xbins2, _firstData_ybins, _firstData_ybins1, _firstData_ybins2
|
|
514
|
-
const
|
|
515
|
-
const
|
|
516
|
-
const
|
|
517
|
-
const yBins = createBins(firstData.y, (_firstData_ybins = firstData.ybins) === null || _firstData_ybins === void 0 ? void 0 : _firstData_ybins.start, (_firstData_ybins1 = firstData.ybins) === null || _firstData_ybins1 === void 0 ? void 0 : _firstData_ybins1.end, (_firstData_ybins2 = firstData.ybins) === null || _firstData_ybins2 === void 0 ? void 0 : _firstData_ybins2.size);
|
|
518
|
-
const zBins = yBins.map(()=>xBins.map(()=>[]));
|
|
519
|
-
let total = 0;
|
|
944
|
+
var _firstData_x, _firstData_xbins, _firstData_xbins1, _firstData_xbins2, _firstData_ybins, _firstData_ybins1, _firstData_ybins2;
|
|
945
|
+
const xValues = [];
|
|
946
|
+
const yValues = [];
|
|
947
|
+
const zValues = [];
|
|
520
948
|
(_firstData_x = firstData.x) === null || _firstData_x === void 0 ? void 0 : _firstData_x.forEach((xVal, index)=>{
|
|
521
949
|
var _firstData_y;
|
|
950
|
+
const zVal = getNumberAtIndexOrDefault(firstData.z, index);
|
|
951
|
+
if (isInvalidValue(xVal) || isInvalidValue((_firstData_y = firstData.y) === null || _firstData_y === void 0 ? void 0 : _firstData_y[index]) || isInvalidValue(zVal)) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
xValues.push(xVal);
|
|
955
|
+
yValues.push(firstData.y[index]);
|
|
956
|
+
zValues.push(zVal);
|
|
957
|
+
});
|
|
958
|
+
const isXString = isStringArray(xValues);
|
|
959
|
+
const isYString = isStringArray(yValues);
|
|
960
|
+
const xBins = createBins(xValues, (_firstData_xbins = firstData.xbins) === null || _firstData_xbins === void 0 ? void 0 : _firstData_xbins.start, (_firstData_xbins1 = firstData.xbins) === null || _firstData_xbins1 === void 0 ? void 0 : _firstData_xbins1.end, (_firstData_xbins2 = firstData.xbins) === null || _firstData_xbins2 === void 0 ? void 0 : _firstData_xbins2.size);
|
|
961
|
+
const yBins = createBins(yValues, (_firstData_ybins = firstData.ybins) === null || _firstData_ybins === void 0 ? void 0 : _firstData_ybins.start, (_firstData_ybins1 = firstData.ybins) === null || _firstData_ybins1 === void 0 ? void 0 : _firstData_ybins1.end, (_firstData_ybins2 = firstData.ybins) === null || _firstData_ybins2 === void 0 ? void 0 : _firstData_ybins2.size);
|
|
962
|
+
const zBins = yBins.map(()=>xBins.map(()=>[]));
|
|
963
|
+
let total = 0;
|
|
964
|
+
xValues.forEach((xVal, index)=>{
|
|
522
965
|
const xBinIdx = findBinIndex(xBins, xVal, isXString);
|
|
523
|
-
const yBinIdx = findBinIndex(yBins,
|
|
966
|
+
const yBinIdx = findBinIndex(yBins, yValues[index], isYString);
|
|
524
967
|
if (xBinIdx !== -1 && yBinIdx !== -1) {
|
|
525
|
-
|
|
526
|
-
var _firstData_z_index;
|
|
527
|
-
zBins[yBinIdx][xBinIdx].push((_firstData_z_index = (_firstData_z = firstData.z) === null || _firstData_z === void 0 ? void 0 : _firstData_z[index]) !== null && _firstData_z_index !== void 0 ? _firstData_z_index : 1);
|
|
968
|
+
zBins[yBinIdx][xBinIdx].push(zValues[index]);
|
|
528
969
|
}
|
|
529
970
|
});
|
|
530
971
|
const z = zBins.map((row)=>{
|
|
@@ -587,9 +1028,23 @@ export const transformPlotlyJsonToHeatmapProps = (input)=>{
|
|
|
587
1028
|
getColorFromToken(DataVizPalette.color2),
|
|
588
1029
|
getColorFromToken(DataVizPalette.color3)
|
|
589
1030
|
];
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1031
|
+
var _firstData_colorscale, _ref, _ref1, _ref2, _ref3;
|
|
1032
|
+
let colorscale = (_ref3 = (_ref2 = (_ref1 = (_ref = (_firstData_colorscale = firstData === null || firstData === void 0 ? void 0 : firstData.colorscale) !== null && _firstData_colorscale !== void 0 ? _firstData_colorscale : (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.colorscale) !== null && _ref !== void 0 ? _ref : (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_coloraxis = _input_layout1.coloraxis) === null || _input_layout_coloraxis === void 0 ? void 0 : _input_layout_coloraxis.colorscale) !== null && _ref1 !== void 0 ? _ref1 : (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : (_input_layout_template = _input_layout2.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorscale) !== null && _ref2 !== void 0 ? _ref2 : firstData.type === 'histogram2d' && ((_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : (_input_layout_template1 = _input_layout3.template) === null || _input_layout_template1 === void 0 ? void 0 : (_input_layout_template_data = _input_layout_template1.data) === null || _input_layout_template_data === void 0 ? void 0 : (_input_layout_template_data_histogram2d = _input_layout_template_data.histogram2d) === null || _input_layout_template_data_histogram2d === void 0 ? void 0 : (_input_layout_template_data_histogram2d_ = _input_layout_template_data_histogram2d[0]) === null || _input_layout_template_data_histogram2d_ === void 0 ? void 0 : _input_layout_template_data_histogram2d_.colorscale)) !== null && _ref3 !== void 0 ? _ref3 : (_input_layout4 = input.layout) === null || _input_layout4 === void 0 ? void 0 : (_input_layout_template2 = _input_layout4.template) === null || _input_layout_template2 === void 0 ? void 0 : (_input_layout_template_data1 = _input_layout_template2.data) === null || _input_layout_template_data1 === void 0 ? void 0 : (_input_layout_template_data_heatmap = _input_layout_template_data1.heatmap) === null || _input_layout_template_data_heatmap === void 0 ? void 0 : (_input_layout_template_data_heatmap_ = _input_layout_template_data_heatmap[0]) === null || _input_layout_template_data_heatmap_ === void 0 ? void 0 : _input_layout_template_data_heatmap_.colorscale;
|
|
1033
|
+
// determine if the types diverging, sequential or sequentialminus are present in colorscale
|
|
1034
|
+
if (colorscale && typeof colorscale === 'object' && ('diverging' in colorscale || 'sequential' in colorscale || 'sequentialminus' in colorscale)) {
|
|
1035
|
+
const isDivergent = zMin < 0 && zMax > 0; // Data spans both positive and negative values
|
|
1036
|
+
const isSequential = zMin >= 0; // Data is entirely positive
|
|
1037
|
+
const isSequentialMinus = zMax <= 0; // Data is entirely negative
|
|
1038
|
+
if (isDivergent) {
|
|
1039
|
+
colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.diverging;
|
|
1040
|
+
} else if (isSequential) {
|
|
1041
|
+
colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequential;
|
|
1042
|
+
} else if (isSequentialMinus) {
|
|
1043
|
+
colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequentialminus;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
const domainValuesForColorScale = Array.isArray(colorscale) ? colorscale.map((arr)=>arr[0] * (zMax - zMin) + zMin) : defaultDomain;
|
|
1047
|
+
const rangeValuesForColorScale = Array.isArray(colorscale) ? colorscale.map((arr)=>arr[1]) : defaultRange;
|
|
593
1048
|
var _input_layout_height;
|
|
594
1049
|
return {
|
|
595
1050
|
data: [
|
|
@@ -599,28 +1054,36 @@ export const transformPlotlyJsonToHeatmapProps = (input)=>{
|
|
|
599
1054
|
rangeValuesForColorScale,
|
|
600
1055
|
hideLegend: true,
|
|
601
1056
|
showYAxisLables: true,
|
|
602
|
-
chartTitle,
|
|
603
|
-
xAxisTitle,
|
|
604
|
-
yAxisTitle,
|
|
605
1057
|
sortOrder: 'none',
|
|
606
|
-
width: (
|
|
607
|
-
height: (_input_layout_height = (
|
|
1058
|
+
width: (_input_layout5 = input.layout) === null || _input_layout5 === void 0 ? void 0 : _input_layout5.width,
|
|
1059
|
+
height: (_input_layout_height = (_input_layout6 = input.layout) === null || _input_layout6 === void 0 ? void 0 : _input_layout6.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 350,
|
|
608
1060
|
hideTickOverlap: true,
|
|
609
1061
|
noOfCharsToTruncate: 20,
|
|
610
1062
|
showYAxisLablesTooltip: true,
|
|
611
|
-
wrapXAxisLables: true
|
|
1063
|
+
wrapXAxisLables: true,
|
|
1064
|
+
...getTitles(input.layout),
|
|
1065
|
+
...getAxisCategoryOrderProps([
|
|
1066
|
+
firstData
|
|
1067
|
+
], input.layout),
|
|
1068
|
+
...getAxisTickProps(input.data, input.layout)
|
|
612
1069
|
};
|
|
613
1070
|
};
|
|
614
|
-
export const transformPlotlyJsonToSankeyProps = (input, colorMap, colorwayType, isDarkTheme)=>{
|
|
1071
|
+
export const transformPlotlyJsonToSankeyProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
615
1072
|
var _input_layout_template_layout, _input_layout_template, _input_layout, _node_label, _input_layout1, _input_layout2;
|
|
616
1073
|
const { link, node } = input.data[0];
|
|
617
1074
|
var _link_value;
|
|
618
|
-
const validLinks = ((_link_value = link === null || link === void 0 ? void 0 : link.value) !== null && _link_value !== void 0 ? _link_value : []).map((val, index)=>
|
|
1075
|
+
const validLinks = ((_link_value = link === null || link === void 0 ? void 0 : link.value) !== null && _link_value !== void 0 ? _link_value : []).map((val, index)=>{
|
|
1076
|
+
var _link_source, _link_target;
|
|
1077
|
+
if (isInvalidValue(val) || isInvalidValue(link === null || link === void 0 ? void 0 : (_link_source = link.source) === null || _link_source === void 0 ? void 0 : _link_source[index]) || isInvalidValue(link === null || link === void 0 ? void 0 : (_link_target = link.target) === null || _link_target === void 0 ? void 0 : _link_target[index])) {
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
619
1081
|
value: val,
|
|
620
1082
|
source: link === null || link === void 0 ? void 0 : link.source[index],
|
|
621
1083
|
target: link === null || link === void 0 ? void 0 : link.target[index]
|
|
622
|
-
}
|
|
623
|
-
|
|
1084
|
+
};
|
|
1085
|
+
})// Filter out negative nodes, unequal nodes and self-references (circular links)
|
|
1086
|
+
.filter((x)=>x !== null && x.source >= 0 && x.target >= 0 && x.source !== x.target);
|
|
624
1087
|
const extractedNodeColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, node === null || node === void 0 ? void 0 : node.color, colorMap, isDarkTheme);
|
|
625
1088
|
const sankeyChartData = {
|
|
626
1089
|
nodes: (_node_label = node.label) === null || _node_label === void 0 ? void 0 : _node_label.map((label, index)=>{
|
|
@@ -654,7 +1117,7 @@ export const transformPlotlyJsonToSankeyProps = (input, colorMap, colorwayType,
|
|
|
654
1117
|
height: (_input_layout_height = (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.height) !== null && _input_layout_height !== void 0 ? _input_layout_height : 468
|
|
655
1118
|
};
|
|
656
1119
|
};
|
|
657
|
-
export const transformPlotlyJsonToGaugeProps = (input, colorMap, colorwayType, isDarkTheme)=>{
|
|
1120
|
+
export const transformPlotlyJsonToGaugeProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
658
1121
|
var _firstData_gauge, _input_layout_template_layout, _input_layout_template, _input_layout, _firstData_gauge_steps, _firstData_gauge1, _firstData_gauge_axis_range, _firstData_gauge_axis, _firstData_gauge2, _input_layout_template_layout1, _input_layout_template1, _input_layout1, _firstData_gauge_axis1, _firstData_gauge3, _firstData_gauge_axis_range1, _firstData_gauge_axis2, _firstData_gauge4, _firstData_delta, _firstData_gauge_axis_range2, _firstData_gauge_axis3, _firstData_gauge5, _firstData_gauge_axis_range3, _firstData_gauge_axis4, _firstData_gauge6, _firstData_gauge_axis_range4, _firstData_gauge_axis5, _firstData_gauge7, _firstData_gauge_axis_range5, _firstData_gauge_axis6, _firstData_gauge8, _input_layout2, _input_layout3, _firstData_gauge_steps1, _firstData_gauge9;
|
|
659
1122
|
const firstData = input.data[0];
|
|
660
1123
|
const stepsColors = ((_firstData_gauge = firstData.gauge) === null || _firstData_gauge === void 0 ? void 0 : _firstData_gauge.steps) ? firstData.gauge.steps.map((step)=>step.color) : undefined;
|
|
@@ -729,59 +1192,445 @@ export const transformPlotlyJsonToGaugeProps = (input, colorMap, colorwayType, i
|
|
|
729
1192
|
const cleanText = (text)=>{
|
|
730
1193
|
return text.replace(/<[^&]*?>/g, '').replace(/<[^>]*>/g, '').replace(/<br>|\\u003cbr\\u003e|<br>/gi, '').replace(/\$[^$]*\$/g, '$').trim();
|
|
731
1194
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1195
|
+
const formatValue = (value, colIndex, cells)=>{
|
|
1196
|
+
if (value === null || typeof value === 'boolean') {
|
|
1197
|
+
return value;
|
|
1198
|
+
}
|
|
1199
|
+
const formatStr = Array.isArray(cells.format) ? cells.format[colIndex] : cells.format;
|
|
1200
|
+
const prefix = Array.isArray(cells.prefix) ? cells.prefix[colIndex] : cells.prefix;
|
|
1201
|
+
const suffix = Array.isArray(cells.suffix) ? cells.suffix[colIndex] : cells.suffix;
|
|
1202
|
+
let formatted = value;
|
|
1203
|
+
if (typeof value === 'number') {
|
|
1204
|
+
if (typeof formatStr === 'string') {
|
|
1205
|
+
try {
|
|
1206
|
+
formatted = d3Format(formatStr)(value);
|
|
1207
|
+
} catch {
|
|
1208
|
+
formatted = formatScientificLimitWidth(value);
|
|
1209
|
+
}
|
|
1210
|
+
} else {
|
|
1211
|
+
formatted = formatScientificLimitWidth(value);
|
|
739
1212
|
}
|
|
740
|
-
|
|
741
|
-
|
|
1213
|
+
}
|
|
1214
|
+
return `${prefix !== null && prefix !== void 0 ? prefix : ''}${formatted}${suffix !== null && suffix !== void 0 ? suffix : ''}`;
|
|
1215
|
+
};
|
|
1216
|
+
export const transformPlotlyJsonToChartTableProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
1217
|
+
var _tableData_cells, _input_layout_template_data_table_, _input_layout_template_data_table, _input_layout_template_data, _input_layout_template, _input_layout, _input_layout_font, _input_layout1, _tableData_header, _input_layout_template_data1, _input_layout_template1, _input_layout2, _input_layout3, _input_layout4;
|
|
1218
|
+
const tableData = input.data[0];
|
|
1219
|
+
const normalizeHeaders = (values, header)=>{
|
|
1220
|
+
const cleanedValues = Array.isArray(values[0]) ? values.map((row)=>row.map((cell)=>cleanText(cell)).filter(Boolean).join(' ')) : values.map((cell)=>cleanText(cell));
|
|
1221
|
+
return cleanedValues.map((value, colIndex)=>{
|
|
1222
|
+
var _header_font, _header_font1, _header_fill;
|
|
1223
|
+
const fontColorRaw = header === null || header === void 0 ? void 0 : (_header_font = header.font) === null || _header_font === void 0 ? void 0 : _header_font.color;
|
|
1224
|
+
let fontColor;
|
|
1225
|
+
if (Array.isArray(fontColorRaw)) {
|
|
1226
|
+
var _fontColorRaw_colIndex;
|
|
1227
|
+
const colorEntry = (_fontColorRaw_colIndex = fontColorRaw[colIndex]) !== null && _fontColorRaw_colIndex !== void 0 ? _fontColorRaw_colIndex : fontColorRaw[0];
|
|
1228
|
+
if (Array.isArray(colorEntry)) {
|
|
1229
|
+
fontColor = typeof colorEntry[0] === 'string' ? colorEntry[0] : undefined;
|
|
1230
|
+
} else if (typeof colorEntry === 'string') {
|
|
1231
|
+
fontColor = colorEntry;
|
|
1232
|
+
}
|
|
1233
|
+
} else if (typeof fontColorRaw === 'string') {
|
|
1234
|
+
fontColor = fontColorRaw;
|
|
1235
|
+
}
|
|
1236
|
+
const fontSizeRaw = header === null || header === void 0 ? void 0 : (_header_font1 = header.font) === null || _header_font1 === void 0 ? void 0 : _header_font1.size;
|
|
1237
|
+
let fontSize;
|
|
1238
|
+
if (Array.isArray(fontSizeRaw)) {
|
|
1239
|
+
var _fontSizeRaw_colIndex;
|
|
1240
|
+
const fontSizeEntry = (_fontSizeRaw_colIndex = fontSizeRaw[colIndex]) !== null && _fontSizeRaw_colIndex !== void 0 ? _fontSizeRaw_colIndex : fontSizeRaw[0];
|
|
1241
|
+
var _fontSizeRaw__colIndex;
|
|
1242
|
+
fontSize = Array.isArray(fontSizeRaw[0]) ? (_fontSizeRaw__colIndex = fontSizeRaw[0][colIndex]) !== null && _fontSizeRaw__colIndex !== void 0 ? _fontSizeRaw__colIndex : fontSizeRaw[0][0] : typeof fontSizeEntry === 'number' ? fontSizeEntry : undefined;
|
|
1243
|
+
} else if (typeof fontSizeRaw === 'number') {
|
|
1244
|
+
fontSize = fontSizeRaw;
|
|
1245
|
+
}
|
|
1246
|
+
const updatedColIndex = colIndex >= 1 ? 1 : 0;
|
|
1247
|
+
const fillColorRaw = header === null || header === void 0 ? void 0 : (_header_fill = header.fill) === null || _header_fill === void 0 ? void 0 : _header_fill.color;
|
|
1248
|
+
var _fillColorRaw_updatedColIndex;
|
|
1249
|
+
const backgroundColor = Array.isArray(fillColorRaw) ? (_fillColorRaw_updatedColIndex = fillColorRaw[updatedColIndex]) !== null && _fillColorRaw_updatedColIndex !== void 0 ? _fillColorRaw_updatedColIndex : fillColorRaw[0] : fillColorRaw;
|
|
1250
|
+
const textAlignRaw = header === null || header === void 0 ? void 0 : header.align;
|
|
1251
|
+
var _textAlignRaw_colIndex;
|
|
1252
|
+
const textAlign = Array.isArray(textAlignRaw) ? (_textAlignRaw_colIndex = textAlignRaw[colIndex]) !== null && _textAlignRaw_colIndex !== void 0 ? _textAlignRaw_colIndex : textAlignRaw[0] : textAlignRaw;
|
|
1253
|
+
const style = {
|
|
1254
|
+
...typeof fontColor === 'string' ? {
|
|
1255
|
+
color: fontColor
|
|
1256
|
+
} : {},
|
|
1257
|
+
...typeof fontSize === 'number' ? {
|
|
1258
|
+
fontSize
|
|
1259
|
+
} : {},
|
|
1260
|
+
...typeof backgroundColor === 'string' ? {
|
|
1261
|
+
backgroundColor
|
|
1262
|
+
} : {},
|
|
1263
|
+
...textAlign ? {
|
|
1264
|
+
textAlign
|
|
1265
|
+
} : {}
|
|
1266
|
+
};
|
|
1267
|
+
return {
|
|
1268
|
+
value,
|
|
1269
|
+
style
|
|
1270
|
+
};
|
|
1271
|
+
});
|
|
742
1272
|
};
|
|
743
1273
|
var _tableData_cells_values;
|
|
744
1274
|
const columns = (_tableData_cells_values = (_tableData_cells = tableData.cells) === null || _tableData_cells === void 0 ? void 0 : _tableData_cells.values) !== null && _tableData_cells_values !== void 0 ? _tableData_cells_values : [];
|
|
745
|
-
const
|
|
746
|
-
|
|
1275
|
+
const cells = tableData.cells && Object.keys(tableData.cells).length > 0 ? tableData.cells : (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_data = _input_layout_template.data) === null || _input_layout_template_data === void 0 ? void 0 : (_input_layout_template_data_table = _input_layout_template_data.table) === null || _input_layout_template_data_table === void 0 ? void 0 : (_input_layout_template_data_table_ = _input_layout_template_data_table[0]) === null || _input_layout_template_data_table_ === void 0 ? void 0 : _input_layout_template_data_table_.cells;
|
|
1276
|
+
const rows = columns[0].map((_, rowIndex)=>columns.map((col, colIndex)=>{
|
|
1277
|
+
var _cells_font, _cells_font1, _cells_fill;
|
|
1278
|
+
const cellValue = col[rowIndex];
|
|
1279
|
+
const cleanValue = typeof cellValue === 'string' ? cleanText(cellValue) : cellValue;
|
|
1280
|
+
const formattedValue = typeof cleanValue === 'string' || typeof cleanValue === 'number' ? formatValue(cleanValue, colIndex, cells) : cleanValue;
|
|
1281
|
+
const rawFontColor = cells === null || cells === void 0 ? void 0 : (_cells_font = cells.font) === null || _cells_font === void 0 ? void 0 : _cells_font.color;
|
|
1282
|
+
let fontColor;
|
|
1283
|
+
if (Array.isArray(rawFontColor)) {
|
|
1284
|
+
var _rawFontColor_colIndex;
|
|
1285
|
+
const entry = (_rawFontColor_colIndex = rawFontColor[colIndex]) !== null && _rawFontColor_colIndex !== void 0 ? _rawFontColor_colIndex : rawFontColor[0];
|
|
1286
|
+
const colorValue = Array.isArray(entry) ? entry[rowIndex] : entry;
|
|
1287
|
+
fontColor = typeof colorValue === 'string' ? colorValue : undefined;
|
|
1288
|
+
} else if (typeof rawFontColor === 'string') {
|
|
1289
|
+
fontColor = rawFontColor;
|
|
1290
|
+
}
|
|
1291
|
+
const rawFontSize = cells === null || cells === void 0 ? void 0 : (_cells_font1 = cells.font) === null || _cells_font1 === void 0 ? void 0 : _cells_font1.size;
|
|
1292
|
+
let fontSize;
|
|
1293
|
+
if (Array.isArray(rawFontSize)) {
|
|
1294
|
+
var _rawFontSize_colIndex;
|
|
1295
|
+
const entry = (_rawFontSize_colIndex = rawFontSize[colIndex]) !== null && _rawFontSize_colIndex !== void 0 ? _rawFontSize_colIndex : rawFontSize[0];
|
|
1296
|
+
const fontSizeValue = Array.isArray(entry) ? entry[rowIndex] : entry;
|
|
1297
|
+
fontSize = typeof fontSizeValue === 'number' ? fontSizeValue : undefined;
|
|
1298
|
+
} else if (typeof rawFontSize === 'number') {
|
|
1299
|
+
fontSize = rawFontSize;
|
|
1300
|
+
}
|
|
1301
|
+
const updatedColIndex = colIndex >= 1 ? 1 : 0;
|
|
1302
|
+
const rawBackgroundColor = cells === null || cells === void 0 ? void 0 : (_cells_fill = cells.fill) === null || _cells_fill === void 0 ? void 0 : _cells_fill.color;
|
|
1303
|
+
let backgroundColor;
|
|
1304
|
+
if (Array.isArray(rawBackgroundColor)) {
|
|
1305
|
+
var _rawBackgroundColor_updatedColIndex;
|
|
1306
|
+
const entry = (_rawBackgroundColor_updatedColIndex = rawBackgroundColor[updatedColIndex]) !== null && _rawBackgroundColor_updatedColIndex !== void 0 ? _rawBackgroundColor_updatedColIndex : rawBackgroundColor[0];
|
|
1307
|
+
const colorValue = Array.isArray(entry) ? entry[rowIndex] : entry;
|
|
1308
|
+
backgroundColor = typeof colorValue === 'string' ? colorValue : undefined;
|
|
1309
|
+
} else if (typeof rawBackgroundColor === 'string') {
|
|
1310
|
+
backgroundColor = rawBackgroundColor;
|
|
1311
|
+
}
|
|
1312
|
+
var _cells_align_colIndex;
|
|
1313
|
+
const rawTextAlign = Array.isArray(cells === null || cells === void 0 ? void 0 : cells.align) ? (_cells_align_colIndex = cells.align[colIndex]) !== null && _cells_align_colIndex !== void 0 ? _cells_align_colIndex : cells.align[0] : cells === null || cells === void 0 ? void 0 : cells.align;
|
|
1314
|
+
const textAlign = rawTextAlign;
|
|
1315
|
+
const style = {
|
|
1316
|
+
...fontColor ? {
|
|
1317
|
+
color: fontColor
|
|
1318
|
+
} : {},
|
|
1319
|
+
...typeof fontSize === 'number' ? {
|
|
1320
|
+
fontSize
|
|
1321
|
+
} : {},
|
|
1322
|
+
...backgroundColor ? {
|
|
1323
|
+
backgroundColor
|
|
1324
|
+
} : {},
|
|
1325
|
+
...textAlign ? {
|
|
1326
|
+
textAlign
|
|
1327
|
+
} : {}
|
|
1328
|
+
};
|
|
747
1329
|
return {
|
|
748
|
-
value:
|
|
1330
|
+
value: formattedValue,
|
|
1331
|
+
style
|
|
749
1332
|
};
|
|
750
1333
|
}));
|
|
751
1334
|
const styles = {
|
|
752
1335
|
root: {
|
|
753
|
-
...((
|
|
1336
|
+
...((_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_font = _input_layout1.font) === null || _input_layout_font === void 0 ? void 0 : _input_layout_font.size) ? {
|
|
754
1337
|
fontSize: input.layout.font.size
|
|
755
1338
|
} : {}
|
|
756
1339
|
}
|
|
757
1340
|
};
|
|
758
1341
|
var _tableData_header_values;
|
|
759
1342
|
return {
|
|
760
|
-
headers: normalizeHeaders((_tableData_header_values = (_tableData_header = tableData.header) === null || _tableData_header === void 0 ? void 0 : _tableData_header.values) !== null && _tableData_header_values !== void 0 ? _tableData_header_values : []).
|
|
761
|
-
value
|
|
762
|
-
})),
|
|
1343
|
+
headers: normalizeHeaders((_tableData_header_values = (_tableData_header = tableData.header) === null || _tableData_header === void 0 ? void 0 : _tableData_header.values) !== null && _tableData_header_values !== void 0 ? _tableData_header_values : [], tableData.header && Object.keys(tableData.header).length > 0 ? tableData.header : (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : (_input_layout_template1 = _input_layout2.template) === null || _input_layout_template1 === void 0 ? void 0 : (_input_layout_template_data1 = _input_layout_template1.data) === null || _input_layout_template_data1 === void 0 ? void 0 : _input_layout_template_data1.table[0].header),
|
|
763
1344
|
rows,
|
|
764
|
-
width: (
|
|
765
|
-
height: (
|
|
1345
|
+
width: (_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : _input_layout3.width,
|
|
1346
|
+
height: (_input_layout4 = input.layout) === null || _input_layout4 === void 0 ? void 0 : _input_layout4.height,
|
|
766
1347
|
styles
|
|
767
1348
|
};
|
|
768
1349
|
};
|
|
1350
|
+
function getCategoriesAndValues(series) {
|
|
1351
|
+
const orientation = series.orientation || 'h';
|
|
1352
|
+
var _series_labels, _ref;
|
|
1353
|
+
const y = (_ref = (_series_labels = series.labels) !== null && _series_labels !== void 0 ? _series_labels : series.y) !== null && _ref !== void 0 ? _ref : series.stage;
|
|
1354
|
+
var _series_values, _ref1;
|
|
1355
|
+
const x = (_ref1 = (_series_values = series.values) !== null && _series_values !== void 0 ? _series_values : series.x) !== null && _ref1 !== void 0 ? _ref1 : series.value;
|
|
1356
|
+
const xIsString = isStringArray(x);
|
|
1357
|
+
const yIsString = isStringArray(y);
|
|
1358
|
+
const xIsNumber = isNumberArray(x);
|
|
1359
|
+
const yIsNumber = isNumberArray(y);
|
|
1360
|
+
// Helper to ensure array of (string | number)
|
|
1361
|
+
const toArray = (arr)=>{
|
|
1362
|
+
if (Array.isArray(arr)) {
|
|
1363
|
+
return arr;
|
|
1364
|
+
}
|
|
1365
|
+
if (typeof arr === 'string' || typeof arr === 'number') {
|
|
1366
|
+
return [
|
|
1367
|
+
arr
|
|
1368
|
+
];
|
|
1369
|
+
}
|
|
1370
|
+
return [];
|
|
1371
|
+
};
|
|
1372
|
+
if (orientation === 'h') {
|
|
1373
|
+
if (yIsString && xIsNumber) {
|
|
1374
|
+
return {
|
|
1375
|
+
categories: toArray(y),
|
|
1376
|
+
values: toArray(x)
|
|
1377
|
+
};
|
|
1378
|
+
} else if (xIsString && yIsNumber) {
|
|
1379
|
+
return {
|
|
1380
|
+
categories: toArray(x),
|
|
1381
|
+
values: toArray(y)
|
|
1382
|
+
};
|
|
1383
|
+
} else {
|
|
1384
|
+
return {
|
|
1385
|
+
categories: yIsString ? toArray(y) : toArray(x),
|
|
1386
|
+
values: yIsString ? toArray(x) : toArray(y)
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
} else {
|
|
1390
|
+
if (xIsString && yIsNumber) {
|
|
1391
|
+
return {
|
|
1392
|
+
categories: toArray(x),
|
|
1393
|
+
values: toArray(y)
|
|
1394
|
+
};
|
|
1395
|
+
} else if (yIsString && xIsNumber) {
|
|
1396
|
+
return {
|
|
1397
|
+
categories: toArray(y),
|
|
1398
|
+
values: toArray(x)
|
|
1399
|
+
};
|
|
1400
|
+
} else {
|
|
1401
|
+
return {
|
|
1402
|
+
categories: xIsString ? toArray(x) : toArray(y),
|
|
1403
|
+
values: xIsString ? toArray(y) : toArray(x)
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
export const transformPlotlyJsonToFunnelChartProps = (input, isMultiPlot, colorMap, colorwayType, isDarkTheme)=>{
|
|
1409
|
+
var _input_layout, _input_layout1, _input_data_, _input_layout2;
|
|
1410
|
+
const funnelData = [];
|
|
1411
|
+
// Determine if data is stacked based on multiple series with multiple values per series
|
|
1412
|
+
const isStacked = input.data.length > 1 && input.data.every((series)=>{
|
|
1413
|
+
var _series_values, _ref;
|
|
1414
|
+
const values = (_ref = (_series_values = series.values) !== null && _series_values !== void 0 ? _series_values : series.x) !== null && _ref !== void 0 ? _ref : series.value;
|
|
1415
|
+
var _series_labels, _ref1;
|
|
1416
|
+
const labels = (_ref1 = (_series_labels = series.labels) !== null && _series_labels !== void 0 ? _series_labels : series.y) !== null && _ref1 !== void 0 ? _ref1 : series.stage;
|
|
1417
|
+
return Array.isArray(labels) && Array.isArray(values) && values.length > 1 && labels.length > 1;
|
|
1418
|
+
});
|
|
1419
|
+
if (isStacked) {
|
|
1420
|
+
// Assign a color per series/category and use it for all subValues of that category
|
|
1421
|
+
const seriesColors = {};
|
|
1422
|
+
input.data.forEach((series, seriesIdx)=>{
|
|
1423
|
+
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _series_marker1;
|
|
1424
|
+
const category = series.name || `Category ${seriesIdx + 1}`;
|
|
1425
|
+
var _series_marker_colors;
|
|
1426
|
+
// Use the same color for this category across all stages
|
|
1427
|
+
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker_colors = (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.colors) !== null && _series_marker_colors !== void 0 ? _series_marker_colors : (_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color, colorMap, isDarkTheme);
|
|
1428
|
+
// Always use the first color for the series/category
|
|
1429
|
+
const color = resolveColor(extractedColors, 0, category, colorMap, isDarkTheme);
|
|
1430
|
+
seriesColors[category] = color;
|
|
1431
|
+
var _series_labels, _ref;
|
|
1432
|
+
const labels = (_ref = (_series_labels = series.labels) !== null && _series_labels !== void 0 ? _series_labels : series.y) !== null && _ref !== void 0 ? _ref : series.stage;
|
|
1433
|
+
var _series_values, _ref1;
|
|
1434
|
+
const values = (_ref1 = (_series_values = series.values) !== null && _series_values !== void 0 ? _series_values : series.x) !== null && _ref1 !== void 0 ? _ref1 : series.value;
|
|
1435
|
+
if (!isArrayOrTypedArray(labels) || !isArrayOrTypedArray(values)) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
if (labels && isArrayOrTypedArray(labels) && labels.length > 0) {
|
|
1439
|
+
labels.forEach((label, i)=>{
|
|
1440
|
+
const stageIndex = funnelData.findIndex((stage)=>stage.stage === label);
|
|
1441
|
+
const valueNum = Number(values[i]);
|
|
1442
|
+
if (isNaN(valueNum)) {
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
if (stageIndex === -1) {
|
|
1446
|
+
funnelData.push({
|
|
1447
|
+
stage: label,
|
|
1448
|
+
subValues: [
|
|
1449
|
+
{
|
|
1450
|
+
category,
|
|
1451
|
+
value: valueNum,
|
|
1452
|
+
color
|
|
1453
|
+
}
|
|
1454
|
+
]
|
|
1455
|
+
});
|
|
1456
|
+
} else {
|
|
1457
|
+
funnelData[stageIndex].subValues.push({
|
|
1458
|
+
category,
|
|
1459
|
+
value: valueNum,
|
|
1460
|
+
color
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
} else {
|
|
1467
|
+
// Non-stacked data handling (multiple series with single-value arrays)
|
|
1468
|
+
input.data.forEach((series, seriesIdx)=>{
|
|
1469
|
+
var _input_layout_template_layout, _input_layout_template, _input_layout, _series_marker, _series_marker1;
|
|
1470
|
+
const { categories, values } = getCategoriesAndValues(series);
|
|
1471
|
+
if (!isArrayOrTypedArray(categories) || !isArrayOrTypedArray(values)) {
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
var _series_marker_colors;
|
|
1475
|
+
const extractedColors = extractColor((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_template = _input_layout.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_series_marker_colors = (_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.colors) !== null && _series_marker_colors !== void 0 ? _series_marker_colors : (_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.color, colorMap, isDarkTheme);
|
|
1476
|
+
categories.forEach((label, i)=>{
|
|
1477
|
+
const color = resolveColor(extractedColors, i, label, colorMap, isDarkTheme);
|
|
1478
|
+
const valueNum = Number(values[i]);
|
|
1479
|
+
if (isNaN(valueNum)) {
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
funnelData.push({
|
|
1483
|
+
stage: label,
|
|
1484
|
+
value: valueNum,
|
|
1485
|
+
color
|
|
1486
|
+
});
|
|
1487
|
+
});
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
return {
|
|
1491
|
+
data: funnelData,
|
|
1492
|
+
width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
|
|
1493
|
+
height: (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.height,
|
|
1494
|
+
orientation: ((_input_data_ = input.data[0]) === null || _input_data_ === void 0 ? void 0 : _input_data_.orientation) === 'v' ? 'horizontal' : 'vertical',
|
|
1495
|
+
hideLegend: isMultiPlot || ((_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.showlegend) === false
|
|
1496
|
+
};
|
|
1497
|
+
};
|
|
769
1498
|
export const projectPolarToCartesian = (input)=>{
|
|
1499
|
+
var _input_layout, _input_layout1;
|
|
770
1500
|
const projection = {
|
|
771
1501
|
...input
|
|
772
1502
|
};
|
|
1503
|
+
// Find the global min and max radius across all series
|
|
1504
|
+
let minRadius = 0;
|
|
1505
|
+
let maxRadius = 0;
|
|
773
1506
|
for(let sindex = 0; sindex < input.data.length; sindex++){
|
|
1507
|
+
const rVals = input.data[sindex].r;
|
|
1508
|
+
if (rVals && isArrayOrTypedArray(rVals)) {
|
|
1509
|
+
for(let ptindex = 0; ptindex < rVals.length; ptindex++){
|
|
1510
|
+
if (!isInvalidValue(rVals[ptindex])) {
|
|
1511
|
+
minRadius = Math.min(minRadius, rVals[ptindex]);
|
|
1512
|
+
maxRadius = Math.max(maxRadius, rVals[ptindex]);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
// If there are negative radii, compute the shift
|
|
1518
|
+
const radiusShift = minRadius < 0 ? -minRadius : 0;
|
|
1519
|
+
// Collect all unique theta values from all scatterpolar series for equal spacing
|
|
1520
|
+
const allThetaValues = new Set();
|
|
1521
|
+
for(let sindex = 0; sindex < input.data.length; sindex++){
|
|
1522
|
+
const series = input.data[sindex];
|
|
1523
|
+
if (series.theta && isArrayOrTypedArray(series.theta)) {
|
|
1524
|
+
series.theta.forEach((theta)=>allThetaValues.add(String(theta)));
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
// Project all points and create a perfect square domain
|
|
1528
|
+
const allX = [];
|
|
1529
|
+
const allY = [];
|
|
1530
|
+
let originX = null;
|
|
1531
|
+
for(let sindex = 0; sindex < input.data.length; sindex++){
|
|
1532
|
+
var _input_layout_polar_angularaxis, _input_layout_polar, _input_layout2, _input_layout_polar_angularaxis1, _input_layout_polar1, _input_layout3;
|
|
774
1533
|
const series = input.data[sindex];
|
|
1534
|
+
// If scatterpolar, set __axisLabel to all unique theta values for equal spacing
|
|
1535
|
+
if (isArrayOrTypedArray(series.theta)) {
|
|
1536
|
+
series.__axisLabel = Array.from(allThetaValues);
|
|
1537
|
+
}
|
|
775
1538
|
series.x = [];
|
|
776
1539
|
series.y = [];
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
1540
|
+
const thetas = series.theta;
|
|
1541
|
+
const rVals = series.r;
|
|
1542
|
+
// Skip if rVals or thetas are not arrays
|
|
1543
|
+
if (!isArrayOrTypedArray(rVals) || !isArrayOrTypedArray(thetas)) {
|
|
1544
|
+
projection.data[sindex] = series;
|
|
1545
|
+
continue;
|
|
1546
|
+
}
|
|
1547
|
+
// retrieve polar axis settings
|
|
1548
|
+
const dirMultiplier = ((_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : (_input_layout_polar = _input_layout2.polar) === null || _input_layout_polar === void 0 ? void 0 : (_input_layout_polar_angularaxis = _input_layout_polar.angularaxis) === null || _input_layout_polar_angularaxis === void 0 ? void 0 : _input_layout_polar_angularaxis.direction) === 'clockwise' ? -1 : 1;
|
|
1549
|
+
var _input_layout_polar_angularaxis_rotation;
|
|
1550
|
+
const startAngleInRad = ((_input_layout_polar_angularaxis_rotation = (_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : (_input_layout_polar1 = _input_layout3.polar) === null || _input_layout_polar1 === void 0 ? void 0 : (_input_layout_polar_angularaxis1 = _input_layout_polar1.angularaxis) === null || _input_layout_polar_angularaxis1 === void 0 ? void 0 : _input_layout_polar_angularaxis1.rotation) !== null && _input_layout_polar_angularaxis_rotation !== void 0 ? _input_layout_polar_angularaxis_rotation : 0) * Math.PI / 180;
|
|
1551
|
+
// Compute tick positions if categorical
|
|
1552
|
+
let uniqueTheta = [];
|
|
1553
|
+
let categorical = false;
|
|
1554
|
+
if (!isNumberArray(thetas)) {
|
|
1555
|
+
uniqueTheta = Array.from(new Set(thetas));
|
|
1556
|
+
categorical = true;
|
|
1557
|
+
}
|
|
1558
|
+
for(let ptindex = 0; ptindex < rVals.length; ptindex++){
|
|
1559
|
+
if (isInvalidValue(thetas === null || thetas === void 0 ? void 0 : thetas[ptindex]) || isInvalidValue(rVals === null || rVals === void 0 ? void 0 : rVals[ptindex])) {
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
// Map theta to angle in radians
|
|
1563
|
+
let thetaRad;
|
|
1564
|
+
if (categorical) {
|
|
1565
|
+
const idx = uniqueTheta.indexOf(thetas[ptindex]);
|
|
1566
|
+
const step = 2 * Math.PI / uniqueTheta.length;
|
|
1567
|
+
thetaRad = startAngleInRad + dirMultiplier * idx * step;
|
|
1568
|
+
} else {
|
|
1569
|
+
thetaRad = startAngleInRad + dirMultiplier * (thetas[ptindex] * Math.PI / 180);
|
|
1570
|
+
}
|
|
1571
|
+
// Shift only the polar origin (not the cartesian)
|
|
1572
|
+
const rawRadius = rVals[ptindex];
|
|
1573
|
+
const polarRadius = rawRadius + radiusShift; // Only for projection
|
|
1574
|
+
// Calculate cartesian coordinates (with shifted polar origin)
|
|
1575
|
+
const x = polarRadius * Math.cos(thetaRad);
|
|
1576
|
+
const y = polarRadius * Math.sin(thetaRad);
|
|
1577
|
+
// Calculate the cartesian coordinates of the original polar origin (0,0)
|
|
1578
|
+
// This is the point that should be mapped to (0,0) in cartesian coordinates
|
|
1579
|
+
if (sindex === 0 && ptindex === 0) {
|
|
1580
|
+
// For polar origin (r=0, θ=0), cartesian coordinates are (0,0)
|
|
1581
|
+
// But since we shifted the radius by radiusShift, the cartesian origin is at (radiusShift, 0)
|
|
1582
|
+
originX = radiusShift;
|
|
1583
|
+
}
|
|
1584
|
+
series.x.push(x);
|
|
1585
|
+
series.y.push(y);
|
|
1586
|
+
allX.push(x);
|
|
1587
|
+
allY.push(y);
|
|
1588
|
+
}
|
|
1589
|
+
// Map text to each data point for downstream chart rendering
|
|
1590
|
+
if (series.x && series.y) {
|
|
1591
|
+
series.data = series.x.map((xVal, idx)=>({
|
|
1592
|
+
x: xVal,
|
|
1593
|
+
y: series.y[idx],
|
|
1594
|
+
...series.text ? {
|
|
1595
|
+
text: series.text[idx]
|
|
1596
|
+
} : {}
|
|
1597
|
+
}));
|
|
782
1598
|
}
|
|
783
1599
|
projection.data[sindex] = series;
|
|
784
1600
|
}
|
|
1601
|
+
// 7. Recenter all cartesian coordinates
|
|
1602
|
+
if (originX !== null) {
|
|
1603
|
+
for(let sindex = 0; sindex < projection.data.length; sindex++){
|
|
1604
|
+
const series = projection.data[sindex];
|
|
1605
|
+
if (series.x && series.y) {
|
|
1606
|
+
series.x = series.x.map((v)=>v - originX);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
// Also recenter allX for normalization
|
|
1610
|
+
for(let i = 0; i < allX.length; i++){
|
|
1611
|
+
allX[i] = allX[i] - originX;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
// 8. Find the maximum absolute value among all x and y
|
|
1615
|
+
let maxAbs = Math.max(...allX.map(Math.abs), ...allY.map(Math.abs));
|
|
1616
|
+
maxAbs = maxAbs === 0 ? 1 : maxAbs;
|
|
1617
|
+
// 9. Rescale all points so that the largest |x| or |y| is 0.5
|
|
1618
|
+
for(let sindex = 0; sindex < projection.data.length; sindex++){
|
|
1619
|
+
const series = projection.data[sindex];
|
|
1620
|
+
if (series.x && series.y) {
|
|
1621
|
+
series.x = series.x.map((v)=>v / (2 * maxAbs));
|
|
1622
|
+
series.y = series.y.map((v)=>v / (2 * maxAbs));
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
// 10. Customize layout for perfect square with absolute positioning
|
|
1626
|
+
const size = ((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width) || ((_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : _input_layout1.height) || 500;
|
|
1627
|
+
projection.layout = {
|
|
1628
|
+
...projection.layout,
|
|
1629
|
+
width: size,
|
|
1630
|
+
height: size
|
|
1631
|
+
};
|
|
1632
|
+
// Attach originX as custom properties
|
|
1633
|
+
projection.layout.__polarOriginX = originX !== null && originX !== void 0 ? originX : undefined;
|
|
785
1634
|
return projection;
|
|
786
1635
|
};
|
|
787
1636
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -857,11 +1706,6 @@ function getLineOptions(line) {
|
|
|
857
1706
|
}
|
|
858
1707
|
return Object.keys(lineOptions).length > 0 ? lineOptions : undefined;
|
|
859
1708
|
}
|
|
860
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
861
|
-
const isStringArray = (arr)=>{
|
|
862
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
863
|
-
return isArrayOfType(arr, (value)=>typeof value === 'string');
|
|
864
|
-
};
|
|
865
1709
|
// TODO: Use binary search to find the appropriate bin for numeric value.
|
|
866
1710
|
const findBinIndex = (bins, value, isString)=>{
|
|
867
1711
|
if (typeof value === 'undefined' || value === null) {
|
|
@@ -897,7 +1741,7 @@ const createBins = (data, binStart, binEnd, binSize)=>{
|
|
|
897
1741
|
]);
|
|
898
1742
|
if (typeof binSize === 'number' && binSize > 0) {
|
|
899
1743
|
const thresholds = [];
|
|
900
|
-
const precision = Math.max(
|
|
1744
|
+
const precision = Math.max(calculatePrecision(minVal), calculatePrecision(binSize));
|
|
901
1745
|
let th = precisionRound(minVal, precision);
|
|
902
1746
|
while(th < precisionRound(maxVal + binSize, precision)){
|
|
903
1747
|
thresholds.push(th);
|
|
@@ -947,16 +1791,65 @@ const calculateHistNorm = (histnorm, value, total, dx, dy = 1)=>{
|
|
|
947
1791
|
return value;
|
|
948
1792
|
}
|
|
949
1793
|
};
|
|
950
|
-
const
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
|
|
1794
|
+
const getLegendShape = (series)=>{
|
|
1795
|
+
var _series_line, _series_mode;
|
|
1796
|
+
const dashType = ((_series_line = series.line) === null || _series_line === void 0 ? void 0 : _series_line.dash) || 'solid';
|
|
1797
|
+
if (dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot') {
|
|
1798
|
+
return 'dottedLine';
|
|
1799
|
+
} else if ((_series_mode = series.mode) === null || _series_mode === void 0 ? void 0 : _series_mode.includes('markers')) {
|
|
1800
|
+
return 'circle';
|
|
1801
|
+
}
|
|
1802
|
+
return 'default';
|
|
954
1803
|
};
|
|
955
|
-
const
|
|
956
|
-
const
|
|
957
|
-
|
|
1804
|
+
export const getAllupLegendsProps = (input, colorMap, colorwayType, traceInfo, isDarkTheme)=>{
|
|
1805
|
+
const allupLegends = [];
|
|
1806
|
+
// reduce on showlegend boolean propperty. reduce should return true if at least one series has showlegend true
|
|
1807
|
+
const toShowLegend = input.data.reduce((acc, series)=>{
|
|
1808
|
+
return acc || series.showlegend === true || series.showlegend === undefined;
|
|
1809
|
+
}, false);
|
|
1810
|
+
if (toShowLegend) {
|
|
1811
|
+
input.data.forEach((series, index)=>{
|
|
1812
|
+
if (traceInfo[index].type === 'donut') {
|
|
1813
|
+
var _input_layout, _input_layout_template_layout, _input_layout_template, _input_layout1, _input_layout2, _pieSeries_marker, _pieSeries_labels;
|
|
1814
|
+
const pieSeries = series;
|
|
1815
|
+
var _input_layout_piecolorway, _input_layout_piecolorway1;
|
|
1816
|
+
const colors = extractColor((_input_layout_piecolorway = (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.piecolorway) !== null && _input_layout_piecolorway !== void 0 ? _input_layout_piecolorway : (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_template = _input_layout1.template) === null || _input_layout_template === void 0 ? void 0 : (_input_layout_template_layout = _input_layout_template.layout) === null || _input_layout_template_layout === void 0 ? void 0 : _input_layout_template_layout.colorway, colorwayType, (_input_layout_piecolorway1 = (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.piecolorway) !== null && _input_layout_piecolorway1 !== void 0 ? _input_layout_piecolorway1 : pieSeries === null || pieSeries === void 0 ? void 0 : (_pieSeries_marker = pieSeries.marker) === null || _pieSeries_marker === void 0 ? void 0 : _pieSeries_marker.colors, colorMap, isDarkTheme);
|
|
1817
|
+
(_pieSeries_labels = pieSeries.labels) === null || _pieSeries_labels === void 0 ? void 0 : _pieSeries_labels.forEach((label, labelIndex)=>{
|
|
1818
|
+
const legend = `${label}`;
|
|
1819
|
+
// resolve color for each legend from the extracted colors
|
|
1820
|
+
const color = resolveColor(colors, labelIndex, legend, colorMap, isDarkTheme);
|
|
1821
|
+
if (legend !== '' && allupLegends.some((group)=>group.title === legend) === false) {
|
|
1822
|
+
allupLegends.push({
|
|
1823
|
+
title: legend,
|
|
1824
|
+
color
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
} else if (isNonPlotType(traceInfo[index].type) === false) {
|
|
1829
|
+
var _plotSeries_line, _plotSeries_marker, _input_layout_template_layout1, _input_layout_template1, _input_layout3;
|
|
1830
|
+
const plotSeries = series;
|
|
1831
|
+
const name = plotSeries.legendgroup;
|
|
1832
|
+
const color = ((_plotSeries_line = plotSeries.line) === null || _plotSeries_line === void 0 ? void 0 : _plotSeries_line.color) || ((_plotSeries_marker = plotSeries.marker) === null || _plotSeries_marker === void 0 ? void 0 : _plotSeries_marker.color);
|
|
1833
|
+
const legendShape = getLegendShape(plotSeries);
|
|
1834
|
+
const resolvedColor = extractColor((_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : (_input_layout_template1 = _input_layout3.template) === null || _input_layout_template1 === void 0 ? void 0 : (_input_layout_template_layout1 = _input_layout_template1.layout) === null || _input_layout_template_layout1 === void 0 ? void 0 : _input_layout_template_layout1.colorway, colorwayType, color, colorMap, isDarkTheme);
|
|
1835
|
+
if (name !== undefined && name !== '' && allupLegends.some((group)=>group.title === name) === false) {
|
|
1836
|
+
allupLegends.push({
|
|
1837
|
+
title: name,
|
|
1838
|
+
color: resolvedColor,
|
|
1839
|
+
shape: legendShape
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
return {
|
|
1846
|
+
legends: allupLegends,
|
|
1847
|
+
centerLegends: true,
|
|
1848
|
+
enabledWrapLines: true,
|
|
1849
|
+
canSelectMultipleLegends: true
|
|
1850
|
+
};
|
|
958
1851
|
};
|
|
959
|
-
const getLegendProps = (data, layout)=>{
|
|
1852
|
+
const getLegendProps = (data, layout, isMultiPlot)=>{
|
|
960
1853
|
const legends = [];
|
|
961
1854
|
if (data.length === 1) {
|
|
962
1855
|
legends.push(data[0].name || '');
|
|
@@ -965,9 +1858,475 @@ const getLegendProps = (data, layout)=>{
|
|
|
965
1858
|
legends.push(series.name || `Series ${index + 1}`);
|
|
966
1859
|
});
|
|
967
1860
|
}
|
|
968
|
-
const
|
|
1861
|
+
const hideLegendsData = data.every((series)=>series.showlegend === false);
|
|
1862
|
+
const hideLegendsInferred = (layout === null || layout === void 0 ? void 0 : layout.showlegend) === false || (layout === null || layout === void 0 ? void 0 : layout.showlegend) !== true && legends.length < 2;
|
|
969
1863
|
return {
|
|
970
1864
|
legends,
|
|
971
|
-
hideLegend:
|
|
1865
|
+
hideLegend: isMultiPlot || hideLegendsInferred || hideLegendsData
|
|
972
1866
|
};
|
|
973
1867
|
};
|
|
1868
|
+
export const getNumberAtIndexOrDefault = (data, index)=>{
|
|
1869
|
+
if (isArrayOrTypedArray(data)) {
|
|
1870
|
+
if (typeof data[index] !== 'number' || !isFinite(data[index])) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
return data[index];
|
|
1874
|
+
}
|
|
1875
|
+
return 1;
|
|
1876
|
+
};
|
|
1877
|
+
export const getValidXYRanges = (series)=>{
|
|
1878
|
+
if (!isArrayOrTypedArray(series.x) || !isArrayOrTypedArray(series.y)) {
|
|
1879
|
+
return [];
|
|
1880
|
+
}
|
|
1881
|
+
const ranges = [];
|
|
1882
|
+
let start = 0;
|
|
1883
|
+
let end = 0;
|
|
1884
|
+
for(; end < series.x.length; end++){
|
|
1885
|
+
if (isInvalidValue(series.x[end]) || isInvalidValue(series.y[end])) {
|
|
1886
|
+
if (end - start > 0) {
|
|
1887
|
+
ranges.push([
|
|
1888
|
+
start,
|
|
1889
|
+
end
|
|
1890
|
+
]);
|
|
1891
|
+
}
|
|
1892
|
+
start = end + 1;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
if (end - start > 0) {
|
|
1896
|
+
ranges.push([
|
|
1897
|
+
start,
|
|
1898
|
+
end
|
|
1899
|
+
]);
|
|
1900
|
+
}
|
|
1901
|
+
return ranges;
|
|
1902
|
+
};
|
|
1903
|
+
const getIndexFromKey = (key, pattern)=>{
|
|
1904
|
+
const normalizedKey = key.replace(pattern, '') === '' ? '1' : key.replace(pattern, '');
|
|
1905
|
+
return parseInt(normalizedKey, 10) - 1;
|
|
1906
|
+
};
|
|
1907
|
+
export const isNonPlotType = (chartType)=>{
|
|
1908
|
+
return [
|
|
1909
|
+
'donut',
|
|
1910
|
+
'sankey',
|
|
1911
|
+
'pie'
|
|
1912
|
+
].includes(chartType);
|
|
1913
|
+
};
|
|
1914
|
+
export const getGridProperties = (schema, isMultiPlot, validTracesInfo)=>{
|
|
1915
|
+
const domainX = [];
|
|
1916
|
+
const domainY = [];
|
|
1917
|
+
let cartesianDomains = 0;
|
|
1918
|
+
const annotations = {};
|
|
1919
|
+
let templateRows = '1fr';
|
|
1920
|
+
let templateColumns = '1fr';
|
|
1921
|
+
const gridLayout = {};
|
|
1922
|
+
if (!isMultiPlot) {
|
|
1923
|
+
return {
|
|
1924
|
+
templateRows,
|
|
1925
|
+
templateColumns,
|
|
1926
|
+
layout: gridLayout
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
const layout = schema === null || schema === void 0 ? void 0 : schema.layout;
|
|
1930
|
+
if (layout !== undefined && layout !== null && Object.keys(layout).length > 0) {
|
|
1931
|
+
Object.keys(layout !== null && layout !== void 0 ? layout : {}).forEach((key)=>{
|
|
1932
|
+
if (key.startsWith('xaxis')) {
|
|
1933
|
+
var _layout_key;
|
|
1934
|
+
const index = getIndexFromKey(key, 'xaxis');
|
|
1935
|
+
var _layout_key_anchor;
|
|
1936
|
+
const anchor = (_layout_key_anchor = (_layout_key = layout[key]) === null || _layout_key === void 0 ? void 0 : _layout_key.anchor) !== null && _layout_key_anchor !== void 0 ? _layout_key_anchor : 'y';
|
|
1937
|
+
const anchorIndex = getIndexFromKey(anchor, 'y');
|
|
1938
|
+
if (index !== anchorIndex) {
|
|
1939
|
+
throw new Error(`Invalid layout: xaxis ${index + 1} anchor should be y${anchorIndex + 1}`);
|
|
1940
|
+
}
|
|
1941
|
+
const xAxisLayout = layout[key];
|
|
1942
|
+
const domainXInfo = {
|
|
1943
|
+
start: (xAxisLayout === null || xAxisLayout === void 0 ? void 0 : xAxisLayout.domain) ? xAxisLayout.domain[0] : 0,
|
|
1944
|
+
end: (xAxisLayout === null || xAxisLayout === void 0 ? void 0 : xAxisLayout.domain) ? xAxisLayout.domain[1] : 1
|
|
1945
|
+
};
|
|
1946
|
+
domainX.push(domainXInfo);
|
|
1947
|
+
} else if (key.startsWith('yaxis')) {
|
|
1948
|
+
var _layout_key1;
|
|
1949
|
+
const index = getIndexFromKey(key, 'yaxis');
|
|
1950
|
+
var _layout_key_anchor1;
|
|
1951
|
+
const anchor = (_layout_key_anchor1 = (_layout_key1 = layout[key]) === null || _layout_key1 === void 0 ? void 0 : _layout_key1.anchor) !== null && _layout_key_anchor1 !== void 0 ? _layout_key_anchor1 : 'x';
|
|
1952
|
+
const anchorIndex = getIndexFromKey(anchor, 'x');
|
|
1953
|
+
if (index !== anchorIndex) {
|
|
1954
|
+
var _layout_yaxis2;
|
|
1955
|
+
if (index === 1 && anchorIndex === 0 || ((_layout_yaxis2 = layout.yaxis2) === null || _layout_yaxis2 === void 0 ? void 0 : _layout_yaxis2.side) === 'right') {
|
|
1956
|
+
// Special case for secondary y axis where yaxis2 can anchor to x1
|
|
1957
|
+
return {
|
|
1958
|
+
templateRows,
|
|
1959
|
+
templateColumns
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
throw new Error(`Invalid layout: yaxis ${index + 1} anchor should be x${anchorIndex + 1}`);
|
|
1963
|
+
}
|
|
1964
|
+
const yAxisLayout = layout[key];
|
|
1965
|
+
const domainYInfo = {
|
|
1966
|
+
start: (yAxisLayout === null || yAxisLayout === void 0 ? void 0 : yAxisLayout.domain) ? yAxisLayout.domain[0] : 0,
|
|
1967
|
+
end: (yAxisLayout === null || yAxisLayout === void 0 ? void 0 : yAxisLayout.domain) ? yAxisLayout.domain[1] : 1
|
|
1968
|
+
};
|
|
1969
|
+
domainY.push(domainYInfo);
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
cartesianDomains = domainX.length; // Assuming that the number of x and y axes is the same
|
|
1974
|
+
validTracesInfo.forEach((trace, index)=>{
|
|
1975
|
+
if (isNonPlotType(trace.type)) {
|
|
1976
|
+
var _schema_data, _series_domain, _series_domain1, _series_domain2, _series_domain3;
|
|
1977
|
+
const series = schema === null || schema === void 0 ? void 0 : (_schema_data = schema.data) === null || _schema_data === void 0 ? void 0 : _schema_data[index];
|
|
1978
|
+
const domainXInfo = {
|
|
1979
|
+
start: ((_series_domain = series.domain) === null || _series_domain === void 0 ? void 0 : _series_domain.x) ? series.domain.x[0] : 0,
|
|
1980
|
+
end: ((_series_domain1 = series.domain) === null || _series_domain1 === void 0 ? void 0 : _series_domain1.x) ? series.domain.x[1] : 1
|
|
1981
|
+
};
|
|
1982
|
+
const domainYInfo = {
|
|
1983
|
+
start: ((_series_domain2 = series.domain) === null || _series_domain2 === void 0 ? void 0 : _series_domain2.y) ? series.domain.y[0] : 0,
|
|
1984
|
+
end: ((_series_domain3 = series.domain) === null || _series_domain3 === void 0 ? void 0 : _series_domain3.y) ? series.domain.y[1] : 1
|
|
1985
|
+
};
|
|
1986
|
+
domainX.push(domainXInfo);
|
|
1987
|
+
domainY.push(domainYInfo);
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
if (layout !== undefined && layout !== null && Object.keys(layout).length > 0) {
|
|
1991
|
+
var _layout_annotations;
|
|
1992
|
+
(_layout_annotations = layout.annotations) === null || _layout_annotations === void 0 ? void 0 : _layout_annotations.forEach((annotation)=>{
|
|
1993
|
+
const xMatches = domainX.flatMap((interval, idx)=>(annotation === null || annotation === void 0 ? void 0 : annotation.x) >= interval.start && (annotation === null || annotation === void 0 ? void 0 : annotation.x) <= interval.end ? [
|
|
1994
|
+
idx
|
|
1995
|
+
] : []);
|
|
1996
|
+
const yMatch = domainY.findIndex((interval, yIndex)=>xMatches.includes(yIndex) && (annotation === null || annotation === void 0 ? void 0 : annotation.y) >= interval.start && (annotation === null || annotation === void 0 ? void 0 : annotation.y) <= interval.end);
|
|
1997
|
+
if (yMatch !== -1) {
|
|
1998
|
+
if (annotations[yMatch] === undefined) {
|
|
1999
|
+
annotations[yMatch] = {};
|
|
2000
|
+
}
|
|
2001
|
+
if ((annotation === null || annotation === void 0 ? void 0 : annotation.textangle) === 90) {
|
|
2002
|
+
annotations[yMatch].yAnnotation = annotation.text;
|
|
2003
|
+
} else {
|
|
2004
|
+
annotations[yMatch].xAnnotation = annotation.text;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
if (domainX.length > 0) {
|
|
2010
|
+
const uniqueXIntervals = new Map();
|
|
2011
|
+
domainX.forEach((interval)=>{
|
|
2012
|
+
const key = `${interval.start}-${interval.end}`;
|
|
2013
|
+
if (!uniqueXIntervals.has(key)) {
|
|
2014
|
+
uniqueXIntervals.set(key, interval);
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
2017
|
+
const sortedXStart = Array.from(uniqueXIntervals.values()).map((interval)=>interval.start).sort();
|
|
2018
|
+
templateColumns = `repeat(${sortedXStart.length}, 1fr)`;
|
|
2019
|
+
domainX.forEach((interval, index)=>{
|
|
2020
|
+
const cellName = index >= cartesianDomains ? `${NON_PLOT_KEY_PREFIX}${index - cartesianDomains + 1}` : `x${index === 0 ? '' : index + 1}`;
|
|
2021
|
+
const columnIndex = sortedXStart.findIndex((start)=>start === interval.start);
|
|
2022
|
+
const columnNumber = columnIndex + 1; // Column numbers are 1-based
|
|
2023
|
+
const annotationProps = annotations[index];
|
|
2024
|
+
const xAnnotation = annotationProps === null || annotationProps === void 0 ? void 0 : annotationProps.xAnnotation;
|
|
2025
|
+
const row = {
|
|
2026
|
+
row: -1,
|
|
2027
|
+
column: columnNumber,
|
|
2028
|
+
xAnnotation,
|
|
2029
|
+
xDomain: interval,
|
|
2030
|
+
yDomain: {
|
|
2031
|
+
start: 0,
|
|
2032
|
+
end: 1
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
gridLayout[cellName] = row;
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
if (domainY.length > 0) {
|
|
2039
|
+
const uniqueYIntervals = new Map();
|
|
2040
|
+
domainY.forEach((interval)=>{
|
|
2041
|
+
const key = `${interval.start}-${interval.end}`;
|
|
2042
|
+
if (!uniqueYIntervals.has(key)) {
|
|
2043
|
+
uniqueYIntervals.set(key, interval);
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
const sortedYStart = Array.from(uniqueYIntervals.values()).map((interval)=>interval.start).sort();
|
|
2047
|
+
const numberOfRows = sortedYStart.length;
|
|
2048
|
+
templateRows = `repeat(${numberOfRows}, 1fr)`;
|
|
2049
|
+
domainY.forEach((interval, index)=>{
|
|
2050
|
+
const cellName = index >= cartesianDomains ? `${NON_PLOT_KEY_PREFIX}${index - cartesianDomains + 1}` : `x${index === 0 ? '' : index + 1}`;
|
|
2051
|
+
const rowIndex = sortedYStart.findIndex((start)=>start === interval.start);
|
|
2052
|
+
const rowNumber = numberOfRows - rowIndex; // Rows are 1-based and we need to reverse the order for CSS grid
|
|
2053
|
+
const annotationProps = annotations[index];
|
|
2054
|
+
const yAnnotation = annotationProps === null || annotationProps === void 0 ? void 0 : annotationProps.yAnnotation;
|
|
2055
|
+
const cell = gridLayout[cellName];
|
|
2056
|
+
if (cell !== undefined) {
|
|
2057
|
+
cell.row = rowNumber;
|
|
2058
|
+
cell.yAnnotation = yAnnotation;
|
|
2059
|
+
cell.yDomain = interval;
|
|
2060
|
+
}
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
return {
|
|
2064
|
+
templateRows,
|
|
2065
|
+
templateColumns,
|
|
2066
|
+
layout: gridLayout
|
|
2067
|
+
};
|
|
2068
|
+
};
|
|
2069
|
+
/**
|
|
2070
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/category_order_defaults.js#L50}
|
|
2071
|
+
*/ const getAxisCategoryOrderProps = (data, layout)=>{
|
|
2072
|
+
const result = {};
|
|
2073
|
+
const axesById = {
|
|
2074
|
+
x: layout === null || layout === void 0 ? void 0 : layout.xaxis,
|
|
2075
|
+
y: layout === null || layout === void 0 ? void 0 : layout.yaxis
|
|
2076
|
+
};
|
|
2077
|
+
Object.keys(axesById).forEach((axId)=>{
|
|
2078
|
+
const ax = axesById[axId];
|
|
2079
|
+
const axLetter = axId[0];
|
|
2080
|
+
const propName = `${axLetter}AxisCategoryOrder`;
|
|
2081
|
+
const values = [];
|
|
2082
|
+
data.forEach((series)=>{
|
|
2083
|
+
var _series_axLetter;
|
|
2084
|
+
(_series_axLetter = series[axLetter]) === null || _series_axLetter === void 0 ? void 0 : _series_axLetter.forEach((val)=>{
|
|
2085
|
+
if (!isInvalidValue(val)) {
|
|
2086
|
+
values.push(val);
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
});
|
|
2090
|
+
const isAxisTypeCategory = (ax === null || ax === void 0 ? void 0 : ax.type) === 'category' || isStringArray(values) && !isNumberArray(values) && !isDateArray(values);
|
|
2091
|
+
if (!isAxisTypeCategory) {
|
|
2092
|
+
return;
|
|
2093
|
+
}
|
|
2094
|
+
const isValidArray = isArrayOrTypedArray(ax === null || ax === void 0 ? void 0 : ax.categoryarray) && ax.categoryarray.length > 0;
|
|
2095
|
+
if (isValidArray && (!(ax === null || ax === void 0 ? void 0 : ax.categoryorder) || ax.categoryorder === 'array')) {
|
|
2096
|
+
result[propName] = ax.categoryarray;
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
if (!(ax === null || ax === void 0 ? void 0 : ax.categoryorder) || ax.categoryorder === 'trace' || ax.categoryorder === 'array') {
|
|
2100
|
+
const categoriesInTraceOrder = Array.from(new Set(values));
|
|
2101
|
+
result[propName] = categoriesInTraceOrder;
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
result[propName] = ax.categoryorder;
|
|
2105
|
+
});
|
|
2106
|
+
return result;
|
|
2107
|
+
};
|
|
2108
|
+
const getBarProps = (data, layout, isHorizontal)=>{
|
|
2109
|
+
let padding;
|
|
2110
|
+
if (typeof (layout === null || layout === void 0 ? void 0 : layout.bargap) === 'number') {
|
|
2111
|
+
if (layout.bargap >= 0 && layout.bargap <= 1) {
|
|
2112
|
+
padding = layout.bargap;
|
|
2113
|
+
} else {
|
|
2114
|
+
// Plotly uses a default bargap of 0.2, as noted here: https://github.com/plotly/plotly.js/blob/1d5a249e43dd31ae50acf02117a19e5ac97387e9/src/traces/bar/layout_defaults.js#L58.
|
|
2115
|
+
// However, we don't use this value as our default padding because it causes the bars to
|
|
2116
|
+
// appear disproportionately wide in large containers.
|
|
2117
|
+
padding = 0.2;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
const plotlyBarWidths = data.map((series)=>{
|
|
2121
|
+
if (series.type === 'bar' && (isArrayOrTypedArray(series.width) || typeof series.width === 'number')) {
|
|
2122
|
+
return series.width;
|
|
2123
|
+
}
|
|
2124
|
+
return [];
|
|
2125
|
+
}).flat();
|
|
2126
|
+
const maxPlotlyBarWidth = d3Max(plotlyBarWidths);
|
|
2127
|
+
if (typeof maxPlotlyBarWidth === 'number') {
|
|
2128
|
+
padding = 1 - maxPlotlyBarWidth;
|
|
2129
|
+
padding = Math.max(0, Math.min(padding, 1));
|
|
2130
|
+
}
|
|
2131
|
+
if (typeof padding === 'undefined') {
|
|
2132
|
+
return {};
|
|
2133
|
+
}
|
|
2134
|
+
if (isHorizontal) {
|
|
2135
|
+
return {
|
|
2136
|
+
maxBarHeight: 1000,
|
|
2137
|
+
yAxisPadding: padding
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
return {
|
|
2141
|
+
barWidth: 'auto',
|
|
2142
|
+
maxBarWidth: 1000,
|
|
2143
|
+
xAxisInnerPadding: padding,
|
|
2144
|
+
xAxisOuterPadding: padding / 2
|
|
2145
|
+
};
|
|
2146
|
+
};
|
|
2147
|
+
const getAxisScaleTypeProps = (data, layout)=>{
|
|
2148
|
+
var _axisObjects_x, _axisObjects_y, _axisObjects_y2;
|
|
2149
|
+
const result = {};
|
|
2150
|
+
const axisObjects = getAxisObjects(data, layout);
|
|
2151
|
+
if (((_axisObjects_x = axisObjects.x) === null || _axisObjects_x === void 0 ? void 0 : _axisObjects_x.type) === 'log') {
|
|
2152
|
+
result.xScaleType = 'log';
|
|
2153
|
+
}
|
|
2154
|
+
if (((_axisObjects_y = axisObjects.y) === null || _axisObjects_y === void 0 ? void 0 : _axisObjects_y.type) === 'log') {
|
|
2155
|
+
result.yScaleType = 'log';
|
|
2156
|
+
}
|
|
2157
|
+
if (((_axisObjects_y2 = axisObjects.y2) === null || _axisObjects_y2 === void 0 ? void 0 : _axisObjects_y2.type) === 'log') {
|
|
2158
|
+
result.secondaryYScaleType = 'log';
|
|
2159
|
+
}
|
|
2160
|
+
return result;
|
|
2161
|
+
};
|
|
2162
|
+
/**
|
|
2163
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/tick_value_defaults.js#L8}
|
|
2164
|
+
*/ const getAxisTickProps = (data, layout)=>{
|
|
2165
|
+
const props = {};
|
|
2166
|
+
const axisObjects = getAxisObjects(data, layout);
|
|
2167
|
+
Object.keys(axisObjects).forEach((axId)=>{
|
|
2168
|
+
const ax = axisObjects[axId];
|
|
2169
|
+
if (!ax) {
|
|
2170
|
+
return;
|
|
2171
|
+
}
|
|
2172
|
+
const axType = getAxisType(data, axId[0], ax);
|
|
2173
|
+
if ((!ax.tickmode || ax.tickmode === 'array') && isArrayOrTypedArray(ax.tickvals)) {
|
|
2174
|
+
const tickValues = axType === 'date' ? ax.tickvals.map((v)=>new Date(v)) : ax.tickvals;
|
|
2175
|
+
if (axId === 'x') {
|
|
2176
|
+
props.tickValues = tickValues;
|
|
2177
|
+
} else if (axId === 'y') {
|
|
2178
|
+
props.yAxisTickValues = tickValues;
|
|
2179
|
+
}
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2182
|
+
if ((!ax.tickmode || ax.tickmode === 'linear') && ax.dtick) {
|
|
2183
|
+
const dtick = plotlyDtick(ax.dtick, axType);
|
|
2184
|
+
const tick0 = plotlyTick0(ax.tick0, axType, dtick);
|
|
2185
|
+
if (axId === 'x') {
|
|
2186
|
+
props.xAxis = {
|
|
2187
|
+
tickStep: dtick,
|
|
2188
|
+
tick0: tick0
|
|
2189
|
+
};
|
|
2190
|
+
} else if (axId === 'y') {
|
|
2191
|
+
props.yAxis = {
|
|
2192
|
+
tickStep: dtick,
|
|
2193
|
+
tick0: tick0
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
if ((!ax.tickmode || ax.tickmode === 'auto') && typeof ax.nticks === 'number' && ax.nticks >= 0) {
|
|
2199
|
+
if (axId === 'x') {
|
|
2200
|
+
props.xAxisTickCount = ax.nticks;
|
|
2201
|
+
} else if (axId === 'y') {
|
|
2202
|
+
props.yAxisTickCount = ax.nticks;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
});
|
|
2206
|
+
return props;
|
|
2207
|
+
};
|
|
2208
|
+
/**
|
|
2209
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L16}
|
|
2210
|
+
*/ const plotlyDtick = (dtick, axType)=>{
|
|
2211
|
+
const isLogAx = axType === 'log';
|
|
2212
|
+
const isDateAx = axType === 'date';
|
|
2213
|
+
const isCatAx = axType === 'category';
|
|
2214
|
+
const dtickDflt = isDateAx ? 86400000 : 1;
|
|
2215
|
+
if (!dtick) {
|
|
2216
|
+
return dtickDflt;
|
|
2217
|
+
}
|
|
2218
|
+
if (isNumber(dtick)) {
|
|
2219
|
+
dtick = Number(dtick);
|
|
2220
|
+
if (dtick <= 0) {
|
|
2221
|
+
return dtickDflt;
|
|
2222
|
+
}
|
|
2223
|
+
if (isCatAx) {
|
|
2224
|
+
// category dtick must be positive integers
|
|
2225
|
+
return Math.max(1, Math.round(dtick));
|
|
2226
|
+
}
|
|
2227
|
+
if (isDateAx) {
|
|
2228
|
+
// date dtick must be at least 0.1ms (our current precision)
|
|
2229
|
+
return Math.max(0.1, dtick);
|
|
2230
|
+
}
|
|
2231
|
+
return dtick;
|
|
2232
|
+
}
|
|
2233
|
+
if (typeof dtick !== 'string' || !(isDateAx || isLogAx)) {
|
|
2234
|
+
return dtickDflt;
|
|
2235
|
+
}
|
|
2236
|
+
const prefix = dtick.charAt(0);
|
|
2237
|
+
const dtickNum = isNumber(dtick.slice(1)) ? Number(dtick.slice(1)) : 0;
|
|
2238
|
+
if (dtickNum <= 0 || !// "M<n>" gives ticks every (integer) n months
|
|
2239
|
+
(isDateAx && prefix === 'M' && dtickNum === Math.round(dtickNum) || // "L<f>" gives ticks linearly spaced in data (not in position) every (float) f
|
|
2240
|
+
isLogAx && prefix === 'L' || // "D1" gives powers of 10 with all small digits between, "D2" gives only 2 and 5
|
|
2241
|
+
isLogAx && prefix === 'D' && (dtickNum === 1 || dtickNum === 2))) {
|
|
2242
|
+
return dtickDflt;
|
|
2243
|
+
}
|
|
2244
|
+
return dtick;
|
|
2245
|
+
};
|
|
2246
|
+
/**
|
|
2247
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L70}
|
|
2248
|
+
*/ const plotlyTick0 = (tick0, axType, dtick)=>{
|
|
2249
|
+
if (axType === 'date') {
|
|
2250
|
+
return isDate(tick0) ? new Date(tick0) : new Date(DEFAULT_DATE_STRING);
|
|
2251
|
+
}
|
|
2252
|
+
if (dtick === 'D1' || dtick === 'D2') {
|
|
2253
|
+
// D1 and D2 modes ignore tick0 entirely
|
|
2254
|
+
return undefined;
|
|
2255
|
+
}
|
|
2256
|
+
// Aside from date axes, tick0 must be numeric
|
|
2257
|
+
return isNumber(tick0) ? Number(tick0) : 0;
|
|
2258
|
+
};
|
|
2259
|
+
const getAxisObjects = (data, layout)=>{
|
|
2260
|
+
// Traces are grouped by their xaxis property, and for each group/subplot, the adapter functions
|
|
2261
|
+
// are called with the corresponding filtered data. As a result, all traces passed to an adapter
|
|
2262
|
+
// function share the same xaxis.
|
|
2263
|
+
let xAxisId;
|
|
2264
|
+
const yAxisIds = new Set();
|
|
2265
|
+
data.forEach((series)=>{
|
|
2266
|
+
const axisIds = getAxisIds(series);
|
|
2267
|
+
xAxisId = axisIds.x;
|
|
2268
|
+
yAxisIds.add(axisIds.y);
|
|
2269
|
+
});
|
|
2270
|
+
const axisObjects = {};
|
|
2271
|
+
if (typeof xAxisId === 'number') {
|
|
2272
|
+
axisObjects.x = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('x', xAxisId)];
|
|
2273
|
+
}
|
|
2274
|
+
const sortedYAxisIds = Array.from(yAxisIds).sort();
|
|
2275
|
+
if (sortedYAxisIds.length > 0) {
|
|
2276
|
+
axisObjects.y = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('y', sortedYAxisIds[0])];
|
|
2277
|
+
}
|
|
2278
|
+
if (sortedYAxisIds.length > 1) {
|
|
2279
|
+
axisObjects.y2 = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('y', sortedYAxisIds[1])];
|
|
2280
|
+
}
|
|
2281
|
+
return axisObjects;
|
|
2282
|
+
};
|
|
2283
|
+
const getAxisType = (data, axLetter, ax)=>{
|
|
2284
|
+
const values = [];
|
|
2285
|
+
data.forEach((series)=>{
|
|
2286
|
+
var _series_axLetter;
|
|
2287
|
+
(_series_axLetter = series[axLetter]) === null || _series_axLetter === void 0 ? void 0 : _series_axLetter.forEach((val)=>{
|
|
2288
|
+
if (!isInvalidValue(val)) {
|
|
2289
|
+
values.push(val);
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
});
|
|
2293
|
+
// Note: When ax.type is explicitly specified, Plotly casts the values to match that type.
|
|
2294
|
+
// Therefore, simply checking the type of the values may not be sufficient. At the moment,
|
|
2295
|
+
// we don’t always perform this casting ourselves and instead use the values as provided.
|
|
2296
|
+
if (isNumberArray(values)) {
|
|
2297
|
+
if ((ax === null || ax === void 0 ? void 0 : ax.type) === 'log') {
|
|
2298
|
+
return 'log';
|
|
2299
|
+
}
|
|
2300
|
+
return 'linear';
|
|
2301
|
+
}
|
|
2302
|
+
if (isDateArray(values)) {
|
|
2303
|
+
return 'date';
|
|
2304
|
+
}
|
|
2305
|
+
if (isStringArray(values)) {
|
|
2306
|
+
return 'category';
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
/**
|
|
2310
|
+
* This is experimental. Use it only with valid datetime strings to verify if they conform to the ISO 8601 format.
|
|
2311
|
+
*/ const isoDateRegex = /^\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z)?)?$/;
|
|
2312
|
+
/**
|
|
2313
|
+
* We want to display localized date and time in the charts, so the useUTC prop is set to false.
|
|
2314
|
+
* But this can sometimes cause the formatters to display the datetime incorrectly.
|
|
2315
|
+
* To work around this issue, we use this function to adjust datetime strings so that they are always interpreted
|
|
2316
|
+
* as local time, allowing the formatters to produce the correct output.
|
|
2317
|
+
*
|
|
2318
|
+
* FIXME: The formatters should always produce a clear and accurate localized output, regardless of the
|
|
2319
|
+
* format used to create the date object.
|
|
2320
|
+
*/ const parseLocalDate = (value)=>{
|
|
2321
|
+
if (typeof value === 'string') {
|
|
2322
|
+
const match = value.match(isoDateRegex);
|
|
2323
|
+
if (match) {
|
|
2324
|
+
if (!match[3]) {
|
|
2325
|
+
value += 'T00:00';
|
|
2326
|
+
} else if (match[6]) {
|
|
2327
|
+
value = value.replace('Z', '');
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
return new Date(value);
|
|
2332
|
+
};
|