@fluentui/react-charts 9.0.2 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.md +48 -7
  2. package/dist/index.d.ts +767 -0
  3. package/lib/AreaChart.js +1 -0
  4. package/lib/AreaChart.js.map +1 -0
  5. package/lib/HeatMapChart.js +1 -0
  6. package/lib/HeatMapChart.js.map +1 -0
  7. package/lib/HorizontalBarChartWithAxis.js +1 -0
  8. package/lib/HorizontalBarChartWithAxis.js.map +1 -0
  9. package/lib/SankeyChart.js +1 -0
  10. package/lib/SankeyChart.js.map +1 -0
  11. package/lib/VerticalStackedBarChart.js +1 -0
  12. package/lib/VerticalStackedBarChart.js.map +1 -0
  13. package/lib/components/AreaChart/AreaChart.js +775 -0
  14. package/lib/components/AreaChart/AreaChart.js.map +1 -0
  15. package/lib/components/AreaChart/AreaChart.types.js +4 -0
  16. package/lib/components/AreaChart/AreaChart.types.js.map +1 -0
  17. package/lib/components/AreaChart/index.js +3 -0
  18. package/lib/components/AreaChart/index.js.map +1 -0
  19. package/lib/components/AreaChart/useAreaChartStyles.styles.js +64 -0
  20. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  21. package/lib/components/CommonComponents/CartesianChart.js +30 -14
  22. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  23. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  24. package/lib/components/DeclarativeChart/DeclarativeChart.js +112 -65
  25. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  26. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +570 -159
  27. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  28. package/lib/components/DonutChart/Arc/Arc.js +1 -1
  29. package/lib/components/DonutChart/Arc/Arc.js.map +1 -1
  30. package/lib/components/DonutChart/DonutChart.js +1 -1
  31. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  32. package/lib/components/GaugeChart/GaugeChart.js +3 -0
  33. package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
  34. package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
  35. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  36. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  37. package/lib/components/HeatMapChart/HeatMapChart.js +588 -0
  38. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -0
  39. package/lib/components/HeatMapChart/HeatMapChart.types.js +4 -0
  40. package/lib/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  41. package/lib/components/HeatMapChart/index.js +3 -0
  42. package/lib/components/HeatMapChart/index.js.map +1 -0
  43. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +46 -0
  44. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  45. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +571 -0
  46. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  47. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +4 -0
  48. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  49. package/lib/components/HorizontalBarChartWithAxis/index.js +3 -0
  50. package/lib/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  51. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +76 -0
  52. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  53. package/lib/components/Legends/Legends.js +38 -37
  54. package/lib/components/Legends/Legends.js.map +1 -1
  55. package/lib/components/LineChart/LineChart.js +43 -35
  56. package/lib/components/LineChart/LineChart.js.map +1 -1
  57. package/lib/components/SankeyChart/SankeyChart.js +1022 -0
  58. package/lib/components/SankeyChart/SankeyChart.js.map +1 -0
  59. package/lib/components/SankeyChart/SankeyChart.types.js +3 -0
  60. package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -0
  61. package/lib/components/SankeyChart/index.js +3 -0
  62. package/lib/components/SankeyChart/index.js.map +1 -0
  63. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +109 -0
  64. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  65. package/lib/components/ScatterChart/ScatterChart.js +46 -59
  66. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  67. package/lib/components/VerticalBarChart/VerticalBarChart.js +165 -88
  68. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  69. package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  70. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +904 -0
  71. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  72. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +1 -0
  73. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  74. package/lib/components/VerticalStackedBarChart/index.js +3 -0
  75. package/lib/components/VerticalStackedBarChart/index.js.map +1 -0
  76. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +73 -0
  77. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  78. package/lib/index.js +5 -0
  79. package/lib/index.js.map +1 -1
  80. package/lib/types/DataPoint.js +1 -3
  81. package/lib/types/DataPoint.js.map +1 -1
  82. package/lib/utilities/SVGTooltipText.js +49 -4
  83. package/lib/utilities/SVGTooltipText.js.map +1 -1
  84. package/lib/utilities/colors.js +20 -0
  85. package/lib/utilities/colors.js.map +1 -1
  86. package/lib/utilities/string.js +32 -0
  87. package/lib/utilities/string.js.map +1 -0
  88. package/lib/utilities/test-data.js +53 -0
  89. package/lib/utilities/test-data.js.map +1 -1
  90. package/lib/utilities/utilities.js +90 -18
  91. package/lib/utilities/utilities.js.map +1 -1
  92. package/lib-commonjs/AreaChart.js +6 -0
  93. package/lib-commonjs/AreaChart.js.map +1 -0
  94. package/lib-commonjs/HeatMapChart.js +6 -0
  95. package/lib-commonjs/HeatMapChart.js.map +1 -0
  96. package/lib-commonjs/HorizontalBarChartWithAxis.js +6 -0
  97. package/lib-commonjs/HorizontalBarChartWithAxis.js.map +1 -0
  98. package/lib-commonjs/SankeyChart.js +6 -0
  99. package/lib-commonjs/SankeyChart.js.map +1 -0
  100. package/lib-commonjs/VerticalStackedBarChart.js +6 -0
  101. package/lib-commonjs/VerticalStackedBarChart.js.map +1 -0
  102. package/lib-commonjs/components/AreaChart/AreaChart.js +781 -0
  103. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -0
  104. package/lib-commonjs/components/AreaChart/AreaChart.types.js +7 -0
  105. package/lib-commonjs/components/AreaChart/AreaChart.types.js.map +1 -0
  106. package/lib-commonjs/components/AreaChart/index.js +8 -0
  107. package/lib-commonjs/components/AreaChart/index.js.map +1 -0
  108. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +104 -0
  109. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  110. package/lib-commonjs/components/CommonComponents/CartesianChart.js +29 -14
  111. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  112. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  113. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +120 -73
  114. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  115. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +592 -178
  116. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  117. package/lib-commonjs/components/DonutChart/Arc/Arc.js +1 -1
  118. package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -1
  119. package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
  120. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  121. package/lib-commonjs/components/GaugeChart/GaugeChart.js +3 -0
  122. package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
  123. package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
  124. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  125. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  126. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +599 -0
  127. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -0
  128. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js +7 -0
  129. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  130. package/lib-commonjs/components/HeatMapChart/index.js +8 -0
  131. package/lib-commonjs/components/HeatMapChart/index.js.map +1 -0
  132. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +68 -0
  133. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  134. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +580 -0
  135. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  136. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +7 -0
  137. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  138. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js +8 -0
  139. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  140. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +116 -0
  141. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  142. package/lib-commonjs/components/Legends/Legends.js +37 -37
  143. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  144. package/lib-commonjs/components/LineChart/LineChart.js +41 -33
  145. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  146. package/lib-commonjs/components/SankeyChart/SankeyChart.js +1038 -0
  147. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -0
  148. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js +6 -0
  149. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -0
  150. package/lib-commonjs/components/SankeyChart/index.js +8 -0
  151. package/lib-commonjs/components/SankeyChart/index.js.map +1 -0
  152. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +179 -0
  153. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  154. package/lib-commonjs/components/ScatterChart/ScatterChart.js +45 -58
  155. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  156. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +164 -87
  157. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  158. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  159. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +915 -0
  160. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  161. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +6 -0
  162. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  163. package/lib-commonjs/components/VerticalStackedBarChart/index.js +8 -0
  164. package/lib-commonjs/components/VerticalStackedBarChart/index.js.map +1 -0
  165. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +120 -0
  166. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  167. package/lib-commonjs/index.js +5 -0
  168. package/lib-commonjs/index.js.map +1 -1
  169. package/lib-commonjs/types/DataPoint.js +1 -3
  170. package/lib-commonjs/types/DataPoint.js.map +1 -1
  171. package/lib-commonjs/utilities/SVGTooltipText.js +49 -4
  172. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
  173. package/lib-commonjs/utilities/colors.js +23 -0
  174. package/lib-commonjs/utilities/colors.js.map +1 -1
  175. package/lib-commonjs/utilities/string.js +29 -0
  176. package/lib-commonjs/utilities/string.js.map +1 -0
  177. package/lib-commonjs/utilities/test-data.js +59 -0
  178. package/lib-commonjs/utilities/test-data.js.map +1 -1
  179. package/lib-commonjs/utilities/utilities.js +94 -17
  180. package/lib-commonjs/utilities/utilities.js.map +1 -1
  181. package/package.json +11 -8
  182. package/lib/components/DeclarativeChart/PlotlySchema.js +0 -7
  183. package/lib/components/DeclarativeChart/PlotlySchema.js.map +0 -1
  184. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +0 -10
  185. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +0 -1
@@ -1,19 +1,11 @@
1
1
  /* eslint-disable one-var */ /* eslint-disable vars-on-top */ /* eslint-disable no-var */ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as React from 'react';
2
- import { bin as d3Bin, extent as d3Extent, sum as d3Sum, min as d3Min, max as d3Max, merge as d3Merge } from 'd3-array';
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, precisionFixed as d3PrecisionFixed } from 'd3-format';
5
- import { getNextColor } from '../../utilities/colors';
4
+ import { DataVizPalette, getColorFromToken, getNextColor } from '../../utilities/colors';
6
5
  import { findNumericMinMaxOfY } from '../../utilities/utilities';
6
+ import { isArrayOfType, isArrayOrTypedArray, isDate, isDateArray, isNumberArray, isLineData } from '@fluentui/chart-utilities';
7
7
  import { timeParse } from 'd3-time-format';
8
- const SUPPORTED_PLOT_TYPES = [
9
- 'pie',
10
- 'bar',
11
- 'scatter',
12
- 'heatmap',
13
- 'sankey',
14
- 'indicator',
15
- 'histogram'
16
- ];
8
+ import { curveCardinal as d3CurveCardinal } from 'd3-shape';
17
9
  const dashOptions = {
18
10
  dot: {
19
11
  strokeDasharray: '1, 5',
@@ -52,60 +44,14 @@ const dashOptions = {
52
44
  lineBorderWidth: '4'
53
45
  }
54
46
  };
55
- const isDate = (value)=>{
56
- const parsedDate = new Date(Date.parse(value));
57
- if (isNaN(parsedDate.getTime())) {
58
- return false;
59
- }
60
- const parsedYear = parsedDate.getFullYear();
61
- const yearInString = /\b\d{4}\b/.test(value);
62
- if (!yearInString && (parsedYear === 2000 || parsedYear === 2001)) {
63
- return false;
64
- }
65
- return true;
66
- };
67
- const isNumber = (value)=>!isNaN(parseFloat(value)) && isFinite(value);
68
47
  const isMonth = (possiblyMonthValue)=>{
69
48
  const parseFullMonth = timeParse('%B');
70
49
  const parseShortMonth = timeParse('%b');
71
50
  return parseFullMonth(possiblyMonthValue) !== null || parseShortMonth(possiblyMonthValue) !== null;
72
51
  };
73
- const isArrayOfType = (plotCoordinates, typeCheck, ...args)=>{
74
- if (!isArrayOrTypedArray(plotCoordinates)) {
75
- return false;
76
- }
77
- if (plotCoordinates.length === 0) {
78
- return false;
79
- }
80
- if (Array.isArray(plotCoordinates[0])) {
81
- // Handle 2D array
82
- return plotCoordinates.every((innerArray)=>innerArray.every((datum)=>typeCheck(datum, ...args)));
83
- } else {
84
- // Handle 1D array
85
- return plotCoordinates.every((datum)=>typeCheck(datum, ...args));
86
- }
87
- };
88
- export const isDateArray = (data)=>{
89
- return isArrayOfType(data, isDate);
90
- };
91
- export const isNumberArray = (data)=>{
92
- return isArrayOfType(data, isNumber);
93
- };
94
52
  export const isMonthArray = (data)=>{
95
53
  return isArrayOfType(data, isMonth);
96
54
  };
97
- export const isLineData = (data)=>{
98
- return !SUPPORTED_PLOT_TYPES.includes(`${data.type}`) && Array.isArray(data.x) && isArrayOfType(data.y, (value)=>typeof value === 'number') && data.x.length > 0 && data.x.length === data.y.length;
99
- };
100
- const invalidate2Dseries = (series, chartType)=>{
101
- var _series_x, _series_y;
102
- if (((_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x.length) > 0 && Array.isArray(series.x[0])) {
103
- throw new Error(`transform to ${chartType}:: 2D x array not supported`);
104
- }
105
- if (((_series_y = series.y) === null || _series_y === void 0 ? void 0 : _series_y.length) > 0 && Array.isArray(series.y[0])) {
106
- throw new Error(`transform to ${chartType}:: 2D y array not supported`);
107
- }
108
- };
109
55
  const getLegend = (series, index)=>{
110
56
  return series.name || `Series ${index + 1}`;
111
57
  };
@@ -119,7 +65,7 @@ function getTitles(layout) {
119
65
  };
120
66
  return titles;
121
67
  }
122
- export const updateXValues = (xValues)=>{
68
+ export const correctYearMonth = (xValues)=>{
123
69
  const presentYear = new Date().getFullYear();
124
70
  if (xValues.length > 0 && Array.isArray(xValues[0])) {
125
71
  throw new Error('updateXValues:: 2D array not supported');
@@ -177,16 +123,23 @@ const getSecondaryYAxisValues = (series, layout)=>{
177
123
  return secondaryYAxisValues;
178
124
  };
179
125
  export const transformPlotlyJsonToDonutProps = (input, colorMap, isDarkTheme)=>{
180
- var _firstData_labels, _input_layout, _input_layout1, _input_layout2;
126
+ var _firstData_labels, _input_layout, _input_layout1, _input_layout2, _input_layout3;
181
127
  const firstData = input.data[0];
182
- const donutData = (_firstData_labels = firstData.labels) === null || _firstData_labels === void 0 ? void 0 : _firstData_labels.map((label, index)=>{
128
+ const mapLegendToDataPoint = {};
129
+ (_firstData_labels = firstData.labels) === null || _firstData_labels === void 0 ? void 0 : _firstData_labels.forEach((label, index)=>{
183
130
  var _firstData_values;
184
131
  const color = getColor(label, colorMap, isDarkTheme);
185
- return {
186
- legend: label,
187
- data: (_firstData_values = firstData.values) === null || _firstData_values === void 0 ? void 0 : _firstData_values[index],
188
- color
189
- };
132
+ //ToDo how to handle string data?
133
+ const value = typeof ((_firstData_values = firstData.values) === null || _firstData_values === void 0 ? void 0 : _firstData_values[index]) === 'number' ? firstData.values[index] : 1;
134
+ if (!mapLegendToDataPoint[label]) {
135
+ mapLegendToDataPoint[label] = {
136
+ legend: label,
137
+ data: value,
138
+ color
139
+ };
140
+ } else {
141
+ mapLegendToDataPoint[label].data += value;
142
+ }
190
143
  });
191
144
  var _input_layout_width;
192
145
  const width = (_input_layout_width = (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width) !== null && _input_layout_width !== void 0 ? _input_layout_width : 440;
@@ -204,10 +157,10 @@ export const transformPlotlyJsonToDonutProps = (input, colorMap, isDarkTheme)=>{
204
157
  return {
205
158
  data: {
206
159
  chartTitle,
207
- chartData: donutData
160
+ chartData: Object.values(mapLegendToDataPoint)
208
161
  },
209
162
  hideLegend: ((_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.showlegend) === false ? true : false,
210
- width,
163
+ width: (_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : _input_layout3.width,
211
164
  height,
212
165
  innerRadius,
213
166
  hideLabels,
@@ -217,87 +170,167 @@ export const transformPlotlyJsonToDonutProps = (input, colorMap, isDarkTheme)=>{
217
170
  ].includes(firstData.textinfo) : true
218
171
  };
219
172
  };
173
+ export const transformPlotlyJsonToVSBCProps = (input, colorMap, isDarkTheme, fallbackVSBC)=>{
174
+ var _input_layout, _input_layout1;
175
+ const mapXToDataPoints = {};
176
+ let yMaxValue = 0;
177
+ let secondaryYAxisValues = {};
178
+ input.data.forEach((series, index1)=>{
179
+ var _series_x;
180
+ (_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x.forEach((x, index2)=>{
181
+ var _series_y;
182
+ if (!mapXToDataPoints[x]) {
183
+ mapXToDataPoints[x] = {
184
+ xAxisPoint: x,
185
+ chartData: [],
186
+ lineData: []
187
+ };
188
+ }
189
+ const legend = getLegend(series, index1);
190
+ var _series_y_index2;
191
+ const yVal = (_series_y_index2 = (_series_y = series.y) === null || _series_y === void 0 ? void 0 : _series_y[index2]) !== null && _series_y_index2 !== void 0 ? _series_y_index2 : 0;
192
+ if (series.type === 'bar') {
193
+ const color = getColor(legend, colorMap, isDarkTheme);
194
+ mapXToDataPoints[x].chartData.push({
195
+ legend,
196
+ data: yVal,
197
+ color
198
+ });
199
+ } else if (series.type === 'scatter' || isLineData(series) || !!fallbackVSBC) {
200
+ const color = getColor(legend, colorMap, isDarkTheme);
201
+ const lineOptions = getLineOptions(series.line);
202
+ mapXToDataPoints[x].lineData.push({
203
+ legend,
204
+ y: yVal,
205
+ color,
206
+ ...lineOptions ? {
207
+ lineOptions
208
+ } : {}
209
+ });
210
+ }
211
+ yMaxValue = Math.max(yMaxValue, yVal);
212
+ });
213
+ secondaryYAxisValues = getSecondaryYAxisValues(series, input.layout);
214
+ });
215
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
216
+ var _input_layout_height;
217
+ return {
218
+ data: Object.values(mapXToDataPoints),
219
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
220
+ 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,
221
+ barWidth: 'auto',
222
+ yMaxValue,
223
+ chartTitle,
224
+ xAxisTitle,
225
+ yAxisTitle,
226
+ mode: 'plotly',
227
+ secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
228
+ secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
229
+ hideTickOverlap: true
230
+ };
231
+ };
232
+ export const transformPlotlyJsonToGVBCProps = (input, colorMap, isDarkTheme)=>{
233
+ var _input_layout, _input_layout1;
234
+ const mapXToDataPoints = {};
235
+ let secondaryYAxisValues = {};
236
+ input.data.forEach((series, index1)=>{
237
+ var _series_x;
238
+ (_series_x = series.x) === null || _series_x === void 0 ? void 0 : _series_x.forEach((x, index2)=>{
239
+ if (!mapXToDataPoints[x]) {
240
+ mapXToDataPoints[x] = {
241
+ name: x.toString(),
242
+ series: []
243
+ };
244
+ }
245
+ if (series.type === 'bar') {
246
+ var _series_y;
247
+ const legend = getLegend(series, index1);
248
+ const color = getColor(legend, colorMap, isDarkTheme);
249
+ var _series_y_index2;
250
+ mapXToDataPoints[x].series.push({
251
+ key: legend,
252
+ data: (_series_y_index2 = (_series_y = series.y) === null || _series_y === void 0 ? void 0 : _series_y[index2]) !== null && _series_y_index2 !== void 0 ? _series_y_index2 : 0,
253
+ xAxisCalloutData: x,
254
+ color,
255
+ legend
256
+ });
257
+ }
258
+ });
259
+ secondaryYAxisValues = getSecondaryYAxisValues(series, input.layout);
260
+ });
261
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
262
+ var _input_layout_height;
263
+ return {
264
+ data: Object.values(mapXToDataPoints),
265
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
266
+ 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,
267
+ barWidth: 'auto',
268
+ chartTitle,
269
+ xAxisTitle,
270
+ yAxisTitle,
271
+ mode: 'plotly',
272
+ secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
273
+ secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
274
+ hideTickOverlap: true
275
+ };
276
+ };
220
277
  export const transformPlotlyJsonToVBCProps = (input, colorMap, isDarkTheme)=>{
278
+ var _input_layout, _input_layout1;
221
279
  const vbcData = [];
222
- input.data.forEach((series, index)=>{
280
+ input.data.forEach((series, seriesIdx)=>{
223
281
  var _series_xbins, _series_xbins1, _series_xbins2;
224
- invalidate2Dseries(series, 'VBC');
225
282
  if (!series.x) {
226
283
  return;
227
284
  }
228
- const scale = d3ScaleLinear().domain(d3Extent(series.x)).nice();
229
- let [xMin, xMax] = scale.domain();
230
- xMin = typeof ((_series_xbins = series.xbins) === null || _series_xbins === void 0 ? void 0 : _series_xbins.start) === 'number' ? series.xbins.start : xMin;
231
- xMax = typeof ((_series_xbins1 = series.xbins) === null || _series_xbins1 === void 0 ? void 0 : _series_xbins1.end) === 'number' ? series.xbins.end : xMax;
232
- const bin = d3Bin().domain([
233
- xMin,
234
- xMax
235
- ]);
236
- if (typeof ((_series_xbins2 = series.xbins) === null || _series_xbins2 === void 0 ? void 0 : _series_xbins2.size) === 'number') {
237
- const thresholds = [];
238
- let th = xMin;
239
- const precision = d3PrecisionFixed(series.xbins.size);
240
- const format = d3Format(`.${precision}f`);
241
- while(th < xMax + series.xbins.size){
242
- thresholds.push(parseFloat(format(th)));
243
- th += series.xbins.size;
285
+ const isXString = isStringArray(series.x);
286
+ const xBins = createBins(series.x, (_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);
287
+ const yBins = xBins.map(()=>[]);
288
+ let total = 0;
289
+ series.x.forEach((xVal, index)=>{
290
+ const binIdx = findBinIndex(xBins, xVal, isXString);
291
+ if (binIdx !== -1) {
292
+ var _series_y;
293
+ var _series_y_index;
294
+ 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);
244
295
  }
245
- xMin = thresholds[0];
246
- xMax = thresholds[thresholds.length - 1];
247
- bin.domain([
248
- xMin,
249
- xMax
250
- ]).thresholds(thresholds);
251
- }
252
- const buckets = bin(series.x);
253
- // If the start or end of xbins is specified, then the number of datapoints may become less than x.length
254
- const totalDataPoints = d3Merge(buckets).length;
255
- buckets.forEach((bucket)=>{
256
- const legend = getLegend(series, index);
296
+ });
297
+ const y = yBins.map((bin)=>{
298
+ const yVal = calculateHistFunc(series.histfunc, bin);
299
+ total += yVal;
300
+ return yVal;
301
+ });
302
+ xBins.forEach((bin, index)=>{
303
+ const legend = getLegend(series, seriesIdx);
257
304
  const color = getColor(legend, colorMap, isDarkTheme);
258
- let y = bucket.length;
259
- if (series.histnorm === 'percent') {
260
- y = bucket.length / totalDataPoints * 100;
261
- } else if (series.histnorm === 'probability') {
262
- y = bucket.length / totalDataPoints;
263
- } else if (series.histnorm === 'density') {
264
- y = bucket.x0 === bucket.x1 ? 0 : bucket.length / (bucket.x1 - bucket.x0);
265
- } else if (series.histnorm === 'probability density') {
266
- y = bucket.x0 === bucket.x1 ? 0 : bucket.length / (totalDataPoints * (bucket.x1 - bucket.x0));
267
- } else if (series.histfunc === 'sum') {
268
- y = d3Sum(bucket);
269
- } else if (series.histfunc === 'avg') {
270
- y = bucket.length === 0 ? 0 : d3Sum(bucket) / bucket.length;
271
- } else if (series.histfunc === 'min') {
272
- y = d3Min(bucket);
273
- } else if (series.histfunc === 'max') {
274
- y = d3Max(bucket);
275
- }
305
+ const yVal = calculateHistNorm(series.histnorm, y[index], total, isXString ? bin.length : getBinSize(bin));
276
306
  vbcData.push({
277
- x: (bucket.x1 + bucket.x0) / 2,
278
- y,
307
+ x: isXString ? bin.join(', ') : getBinCenter(bin),
308
+ y: yVal,
279
309
  legend,
280
310
  color,
281
- xAxisCalloutData: `[${bucket.x0} - ${bucket.x1})`
311
+ ...isXString ? {} : {
312
+ xAxisCalloutData: `[${bin.x0} - ${bin.x1})`
313
+ }
282
314
  });
283
315
  });
284
316
  });
285
317
  const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
318
+ var _input_layout_height;
286
319
  return {
287
320
  data: vbcData,
288
- // width: layout?.width,
289
- // height: layout?.height,
321
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
322
+ 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,
290
323
  chartTitle,
291
324
  xAxisTitle,
292
325
  yAxisTitle,
326
+ mode: 'plotly',
293
327
  hideTickOverlap: true
294
328
  };
295
329
  };
296
330
  export const transformPlotlyJsonToScatterChartProps = (input, isAreaChart, colorMap, isDarkTheme)=>{
297
331
  let secondaryYAxisValues = {};
332
+ let mode = 'tonexty';
298
333
  const chartData = input.data.map((series, index)=>{
299
- var _series_line;
300
- invalidate2Dseries(series, 'Scatter');
301
334
  const xValues = series.x;
302
335
  const isString = typeof xValues[0] === 'string';
303
336
  const isXDate = isDateArray(xValues);
@@ -305,18 +338,26 @@ export const transformPlotlyJsonToScatterChartProps = (input, isAreaChart, color
305
338
  const legend = getLegend(series, index);
306
339
  const lineColor = getColor(legend, colorMap, isDarkTheme);
307
340
  secondaryYAxisValues = getSecondaryYAxisValues(series, input.layout);
341
+ mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
342
+ const lineOptions = getLineOptions(series.line);
308
343
  return {
309
344
  legend,
310
- ...((_series_line = series.line) === null || _series_line === void 0 ? void 0 : _series_line.dash) && dashOptions[series.line.dash] ? {
311
- lineOptions: {
312
- ...dashOptions[series.line.dash]
313
- }
314
- } : {},
315
- data: xValues.map((x, i)=>({
345
+ data: xValues.map((x, i)=>{
346
+ var _series_marker, _series_marker1;
347
+ return {
316
348
  x: isString ? isXDate ? new Date(x) : isXNumber ? parseFloat(x) : x : x,
317
- y: series.y[i]
318
- })),
319
- color: lineColor
349
+ y: series.y[i],
350
+ ...Array.isArray((_series_marker = series.marker) === null || _series_marker === void 0 ? void 0 : _series_marker.size) ? {
351
+ markerSize: series.marker.size[i]
352
+ } : typeof ((_series_marker1 = series.marker) === null || _series_marker1 === void 0 ? void 0 : _series_marker1.size) === 'number' ? {
353
+ markerSize: series.marker.size
354
+ } : {}
355
+ };
356
+ }),
357
+ color: lineColor,
358
+ ...lineOptions ? {
359
+ lineOptions
360
+ } : {}
320
361
  };
321
362
  });
322
363
  const yMinMaxValues = findNumericMinMaxOfY(chartData);
@@ -325,43 +366,296 @@ export const transformPlotlyJsonToScatterChartProps = (input, isAreaChart, color
325
366
  chartTitle,
326
367
  lineChartData: chartData
327
368
  };
369
+ if (isAreaChart) {
370
+ var _input_layout, _input_layout1;
371
+ var _input_layout_height;
372
+ return {
373
+ data: chartProps,
374
+ supportNegativeData: true,
375
+ xAxisTitle,
376
+ yAxisTitle,
377
+ secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
378
+ secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
379
+ mode,
380
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
381
+ 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,
382
+ hideTickOverlap: true
383
+ };
384
+ } else {
385
+ var _input_layout2, _input_layout3;
386
+ var _input_layout_height1;
387
+ return {
388
+ data: chartProps,
389
+ supportNegativeData: true,
390
+ xAxisTitle,
391
+ yAxisTitle,
392
+ secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
393
+ secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
394
+ roundedTicks: true,
395
+ yMinValue: yMinMaxValues.startValue,
396
+ yMaxValue: yMinMaxValues.endValue,
397
+ width: (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : _input_layout2.width,
398
+ height: (_input_layout_height1 = (_input_layout3 = input.layout) === null || _input_layout3 === void 0 ? void 0 : _input_layout3.height) !== null && _input_layout_height1 !== void 0 ? _input_layout_height1 : 350,
399
+ hideTickOverlap: true,
400
+ enableReflow: false
401
+ };
402
+ }
403
+ };
404
+ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (input, colorMap, isDarkTheme)=>{
405
+ 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;
406
+ const chartData = input.data.map((series, index)=>{
407
+ return series.y.map((yValue, i)=>{
408
+ const color = getColor(yValue, colorMap, isDarkTheme);
409
+ return {
410
+ x: series.x[i],
411
+ y: yValue,
412
+ legend: yValue,
413
+ color
414
+ };
415
+ });
416
+ }).flat()//reversing the order to invert the Y bars order as required by plotly.
417
+ .reverse();
418
+ var _input_layout_height;
419
+ 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;
420
+ var _input_layout_margin_l;
421
+ const margin = (_input_layout_margin_l = (_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_margin = _input_layout1.margin) === null || _input_layout_margin === void 0 ? void 0 : _input_layout_margin.l) !== null && _input_layout_margin_l !== void 0 ? _input_layout_margin_l : 0;
422
+ var _input_layout_margin_pad;
423
+ const padding = (_input_layout_margin_pad = (_input_layout2 = input.layout) === null || _input_layout2 === void 0 ? void 0 : (_input_layout_margin1 = _input_layout2.margin) === null || _input_layout_margin1 === void 0 ? void 0 : _input_layout_margin1.pad) !== null && _input_layout_margin_pad !== void 0 ? _input_layout_margin_pad : 0;
424
+ const availableHeight = chartHeight - margin - padding;
425
+ const numberOfBars = input.data[0].y.length;
426
+ const scalingFactor = 0.01;
427
+ const gapFactor = 1 / (1 + scalingFactor * numberOfBars);
428
+ const barHeight = availableHeight / (numberOfBars * (1 + gapFactor));
429
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
328
430
  return {
329
- data: chartProps,
330
- supportNegativeData: true,
431
+ data: chartData,
432
+ chartTitle,
331
433
  xAxisTitle,
332
434
  yAxisTitle,
333
- secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
334
- secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
335
- roundedTicks: true,
336
- yMinValue: yMinMaxValues.startValue,
337
- yMaxValue: yMinMaxValues.endValue,
435
+ 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) || '',
436
+ barHeight,
437
+ showYAxisLables: true,
438
+ height: chartHeight,
439
+ width: (_input_layout6 = input.layout) === null || _input_layout6 === void 0 ? void 0 : _input_layout6.width,
338
440
  hideTickOverlap: true
339
441
  };
340
442
  };
341
- const MAX_DEPTH = 15;
342
- export const sanitizeJson = (jsonObject, depth = 0)=>{
343
- if (depth > MAX_DEPTH) {
344
- throw new Error('Maximum json depth exceeded');
345
- }
346
- if (typeof jsonObject === 'object' && jsonObject !== null) {
347
- for(const key in jsonObject){
348
- if (jsonObject.hasOwnProperty(key)) {
349
- if (typeof jsonObject[key] === 'string') {
350
- jsonObject[key] = jsonObject[key].replace(/</g, '&lt;').replace(/>/g, '&gt;');
351
- } else {
352
- jsonObject[key] = sanitizeJson(jsonObject[key], depth + 1);
353
- }
443
+ export const transformPlotlyJsonToHeatmapProps = (input)=>{
444
+ var _input_layout, _input_layout1;
445
+ const firstData = input.data[0];
446
+ const heatmapDataPoints = [];
447
+ let zMin = Number.POSITIVE_INFINITY;
448
+ let zMax = Number.NEGATIVE_INFINITY;
449
+ if (firstData.type === 'histogram2d') {
450
+ var _firstData_xbins, _firstData_xbins1, _firstData_xbins2, _firstData_ybins, _firstData_ybins1, _firstData_ybins2, _firstData_x;
451
+ const isXString = isStringArray(firstData.x);
452
+ const isYString = isStringArray(firstData.y);
453
+ const xBins = createBins(firstData.x, (_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);
454
+ 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);
455
+ const zBins = yBins.map(()=>xBins.map(()=>[]));
456
+ let total = 0;
457
+ (_firstData_x = firstData.x) === null || _firstData_x === void 0 ? void 0 : _firstData_x.forEach((xVal, index)=>{
458
+ var _firstData_y;
459
+ const xBinIdx = findBinIndex(xBins, xVal, isXString);
460
+ const yBinIdx = findBinIndex(yBins, (_firstData_y = firstData.y) === null || _firstData_y === void 0 ? void 0 : _firstData_y[index], isYString);
461
+ if (xBinIdx !== -1 && yBinIdx !== -1) {
462
+ var _firstData_z;
463
+ var _firstData_z_index;
464
+ 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);
354
465
  }
466
+ });
467
+ const z = zBins.map((row)=>{
468
+ return row.map((bin)=>{
469
+ const zVal = calculateHistFunc(firstData.histfunc, bin);
470
+ total += zVal;
471
+ return zVal;
472
+ });
473
+ });
474
+ xBins.forEach((xBin, xIdx)=>{
475
+ yBins.forEach((yBin, yIdx)=>{
476
+ const zVal = calculateHistNorm(firstData.histnorm, z[yIdx][xIdx], total, isXString ? xBin.length : getBinSize(xBin), isYString ? yBin.length : getBinSize(yBin));
477
+ heatmapDataPoints.push({
478
+ x: isXString ? xBin.join(', ') : getBinCenter(xBin),
479
+ y: isYString ? yBin.join(', ') : getBinCenter(yBin),
480
+ value: zVal,
481
+ rectText: zVal
482
+ });
483
+ if (typeof zVal === 'number') {
484
+ zMin = Math.min(zMin, zVal);
485
+ zMax = Math.max(zMax, zVal);
486
+ }
487
+ });
488
+ });
489
+ } else {
490
+ var _firstData_x1;
491
+ (_firstData_x1 = firstData.x) === null || _firstData_x1 === void 0 ? void 0 : _firstData_x1.forEach((xVal, xIdx)=>{
492
+ var _firstData_y;
493
+ (_firstData_y = firstData.y) === null || _firstData_y === void 0 ? void 0 : _firstData_y.forEach((yVal, yIdx)=>{
494
+ var _firstData_z_yIdx, _firstData_z, _input_layout_xaxis, _input_layout, _input_layout_yaxis, _input_layout1;
495
+ const zVal = (_firstData_z = firstData.z) === null || _firstData_z === void 0 ? void 0 : (_firstData_z_yIdx = _firstData_z[yIdx]) === null || _firstData_z_yIdx === void 0 ? void 0 : _firstData_z_yIdx[xIdx];
496
+ heatmapDataPoints.push({
497
+ x: ((_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : (_input_layout_xaxis = _input_layout.xaxis) === null || _input_layout_xaxis === void 0 ? void 0 : _input_layout_xaxis.type) === 'date' ? xVal : xVal !== null && xVal !== void 0 ? xVal : 0,
498
+ y: ((_input_layout1 = input.layout) === null || _input_layout1 === void 0 ? void 0 : (_input_layout_yaxis = _input_layout1.yaxis) === null || _input_layout_yaxis === void 0 ? void 0 : _input_layout_yaxis.type) === 'date' ? yVal : yVal,
499
+ value: zVal,
500
+ rectText: zVal
501
+ });
502
+ if (typeof zVal === 'number') {
503
+ zMin = Math.min(zMin, zVal);
504
+ zMax = Math.max(zMax, zVal);
505
+ }
506
+ });
507
+ });
508
+ }
509
+ var _firstData_name;
510
+ const heatmapData = {
511
+ legend: (_firstData_name = firstData.name) !== null && _firstData_name !== void 0 ? _firstData_name : '',
512
+ data: heatmapDataPoints,
513
+ value: 0
514
+ };
515
+ // Initialize domain and range to default values
516
+ const defaultDomain = [
517
+ zMin,
518
+ (zMax + zMin) / 2,
519
+ zMax
520
+ ];
521
+ const defaultRange = [
522
+ getColorFromToken(DataVizPalette.color1),
523
+ getColorFromToken(DataVizPalette.color2),
524
+ getColorFromToken(DataVizPalette.color3)
525
+ ];
526
+ const domainValuesForColorScale = Array.isArray(firstData.colorscale) ? firstData.colorscale.map((arr)=>arr[0] * (zMax - zMin) + zMin) : defaultDomain;
527
+ const rangeValuesForColorScale = Array.isArray(firstData.colorscale) ? firstData.colorscale.map((arr)=>arr[1]) : defaultRange;
528
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);
529
+ var _input_layout_height;
530
+ return {
531
+ data: [
532
+ heatmapData
533
+ ],
534
+ domainValuesForColorScale,
535
+ rangeValuesForColorScale,
536
+ hideLegend: true,
537
+ showYAxisLables: true,
538
+ chartTitle,
539
+ xAxisTitle,
540
+ yAxisTitle,
541
+ sortOrder: 'none',
542
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
543
+ 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,
544
+ hideTickOverlap: true
545
+ };
546
+ };
547
+ export const transformPlotlyJsonToSankeyProps = (input, colorMap, isDarkTheme)=>{
548
+ var _node_label, _input_layout, _input_layout1;
549
+ const { link, node } = input.data[0];
550
+ var _link_value;
551
+ const validLinks = ((_link_value = link === null || link === void 0 ? void 0 : link.value) !== null && _link_value !== void 0 ? _link_value : []).map((val, index)=>({
552
+ value: val,
553
+ source: link === null || link === void 0 ? void 0 : link.source[index],
554
+ target: link === null || link === void 0 ? void 0 : link.target[index]
555
+ }))// eslint-disable-next-line @typescript-eslint/no-shadow
556
+ // Filter out negative nodes, unequal nodes and self-references (circular links)
557
+ .filter((x)=>x.source >= 0 && x.target >= 0 && x.source !== x.target);
558
+ const sankeyChartData = {
559
+ nodes: (_node_label = node.label) === null || _node_label === void 0 ? void 0 : _node_label.map((label, index)=>{
560
+ const color = getColor(label, colorMap, isDarkTheme);
561
+ return {
562
+ nodeId: index,
563
+ name: label,
564
+ color
565
+ };
566
+ }),
567
+ links: validLinks.map((validLink, index)=>{
568
+ return {
569
+ ...validLink
570
+ };
571
+ })
572
+ };
573
+ // const styles: SankeyChartProps['styles'] = {
574
+ // root: {
575
+ // ...(input.layout?.font?.size ? { fontSize: input.layout.font?.size } : {}),
576
+ // },
577
+ // };
578
+ const { chartTitle } = getTitles(input.layout);
579
+ var _input_layout_height;
580
+ return {
581
+ data: {
582
+ chartTitle,
583
+ SankeyChartData: sankeyChartData
584
+ },
585
+ width: (_input_layout = input.layout) === null || _input_layout === void 0 ? void 0 : _input_layout.width,
586
+ 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 : 468,
587
+ // TODO
588
+ // styles,
589
+ enableReflow: true
590
+ };
591
+ };
592
+ export const transformPlotlyJsonToGaugeProps = (input, colorMap, isDarkTheme)=>{
593
+ var _firstData_gauge_steps, _firstData_gauge, _firstData_gauge_axis_range, _firstData_gauge_axis, _firstData_gauge1, _firstData_gauge_axis_range1, _firstData_gauge_axis1, _firstData_gauge2, _firstData_delta, _firstData_gauge_axis_range2, _firstData_gauge_axis2, _firstData_gauge3, _firstData_gauge_axis_range3, _firstData_gauge_axis3, _firstData_gauge4, _firstData_gauge_axis_range4, _firstData_gauge_axis4, _firstData_gauge5, _firstData_gauge_axis_range5, _firstData_gauge_axis5, _firstData_gauge6, _firstData_gauge_steps1, _firstData_gauge7;
594
+ const firstData = input.data[0];
595
+ var _firstData_gauge_axis_range_, _firstData_value, _firstData_gauge_axis_range_1, _firstData_value1;
596
+ const segments = ((_firstData_gauge = firstData.gauge) === null || _firstData_gauge === void 0 ? void 0 : (_firstData_gauge_steps = _firstData_gauge.steps) === null || _firstData_gauge_steps === void 0 ? void 0 : _firstData_gauge_steps.length) ? firstData.gauge.steps.map((step, index)=>{
597
+ var _step_range, _step_range1;
598
+ const legend = step.name || `Segment ${index + 1}`;
599
+ const color = getColor(legend, colorMap, isDarkTheme);
600
+ return {
601
+ legend,
602
+ size: ((_step_range = step.range) === null || _step_range === void 0 ? void 0 : _step_range[1]) - ((_step_range1 = step.range) === null || _step_range1 === void 0 ? void 0 : _step_range1[0]),
603
+ color
604
+ };
605
+ }) : [
606
+ {
607
+ legend: 'Current',
608
+ size: (_firstData_value = firstData.value) !== null && _firstData_value !== void 0 ? _firstData_value : 0 - ((_firstData_gauge_axis_range_ = (_firstData_gauge1 = firstData.gauge) === null || _firstData_gauge1 === void 0 ? void 0 : (_firstData_gauge_axis = _firstData_gauge1.axis) === null || _firstData_gauge_axis === void 0 ? void 0 : (_firstData_gauge_axis_range = _firstData_gauge_axis.range) === null || _firstData_gauge_axis_range === void 0 ? void 0 : _firstData_gauge_axis_range[0]) !== null && _firstData_gauge_axis_range_ !== void 0 ? _firstData_gauge_axis_range_ : 0),
609
+ color: getColor('Current', colorMap, isDarkTheme)
610
+ },
611
+ {
612
+ legend: 'Target',
613
+ size: ((_firstData_gauge_axis_range_1 = (_firstData_gauge2 = firstData.gauge) === null || _firstData_gauge2 === void 0 ? void 0 : (_firstData_gauge_axis1 = _firstData_gauge2.axis) === null || _firstData_gauge_axis1 === void 0 ? void 0 : (_firstData_gauge_axis_range1 = _firstData_gauge_axis1.range) === null || _firstData_gauge_axis_range1 === void 0 ? void 0 : _firstData_gauge_axis_range1[1]) !== null && _firstData_gauge_axis_range_1 !== void 0 ? _firstData_gauge_axis_range_1 : 100) - ((_firstData_value1 = firstData.value) !== null && _firstData_value1 !== void 0 ? _firstData_value1 : 0),
614
+ color: DataVizPalette.disabled
615
+ }
616
+ ];
617
+ let sublabel;
618
+ // let sublabelColor: string | undefined;
619
+ if ((_firstData_delta = firstData.delta) === null || _firstData_delta === void 0 ? void 0 : _firstData_delta.reference) {
620
+ const diff = firstData.value - firstData.delta.reference;
621
+ if (diff >= 0) {
622
+ sublabel = `\u25B2 ${diff}`;
623
+ // const color = getColorFromToken(DataVizPalette.success, isDarkTheme);
624
+ // sublabelColor = color;
625
+ } else {
626
+ sublabel = `\u25BC ${Math.abs(diff)}`;
627
+ // const color = getColorFromToken(DataVizPalette.error, isDarkTheme);
628
+ // sublabelColor = color;
355
629
  }
356
630
  }
357
- return jsonObject;
631
+ // const styles: GaugeChartProps['styles'] = {
632
+ // sublabel: {
633
+ // fill: sublabelColor,
634
+ // },
635
+ // };
636
+ const { chartTitle } = getTitles(input.layout);
637
+ var _firstData_value2;
638
+ return {
639
+ segments,
640
+ chartValue: (_firstData_value2 = firstData.value) !== null && _firstData_value2 !== void 0 ? _firstData_value2 : 0,
641
+ chartTitle,
642
+ sublabel,
643
+ // range values can be null
644
+ minValue: typeof ((_firstData_gauge3 = firstData.gauge) === null || _firstData_gauge3 === void 0 ? void 0 : (_firstData_gauge_axis2 = _firstData_gauge3.axis) === null || _firstData_gauge_axis2 === void 0 ? void 0 : (_firstData_gauge_axis_range2 = _firstData_gauge_axis2.range) === null || _firstData_gauge_axis_range2 === void 0 ? void 0 : _firstData_gauge_axis_range2[0]) === 'number' ? (_firstData_gauge4 = firstData.gauge) === null || _firstData_gauge4 === void 0 ? void 0 : (_firstData_gauge_axis3 = _firstData_gauge4.axis) === null || _firstData_gauge_axis3 === void 0 ? void 0 : (_firstData_gauge_axis_range3 = _firstData_gauge_axis3.range) === null || _firstData_gauge_axis_range3 === void 0 ? void 0 : _firstData_gauge_axis_range3[0] : undefined,
645
+ maxValue: typeof ((_firstData_gauge5 = firstData.gauge) === null || _firstData_gauge5 === void 0 ? void 0 : (_firstData_gauge_axis4 = _firstData_gauge5.axis) === null || _firstData_gauge_axis4 === void 0 ? void 0 : (_firstData_gauge_axis_range4 = _firstData_gauge_axis4.range) === null || _firstData_gauge_axis_range4 === void 0 ? void 0 : _firstData_gauge_axis_range4[1]) === 'number' ? (_firstData_gauge6 = firstData.gauge) === null || _firstData_gauge6 === void 0 ? void 0 : (_firstData_gauge_axis5 = _firstData_gauge6.axis) === null || _firstData_gauge_axis5 === void 0 ? void 0 : (_firstData_gauge_axis_range5 = _firstData_gauge_axis5.range) === null || _firstData_gauge_axis_range5 === void 0 ? void 0 : _firstData_gauge_axis_range5[1] : undefined,
646
+ chartValueFormat: ()=>{
647
+ var _firstData_value;
648
+ var _firstData_value_toString;
649
+ return (_firstData_value_toString = (_firstData_value = firstData.value) === null || _firstData_value === void 0 ? void 0 : _firstData_value.toString()) !== null && _firstData_value_toString !== void 0 ? _firstData_value_toString : '';
650
+ },
651
+ // FIXME
652
+ // width: input.layout?.width,
653
+ // height: input.layout?.height ?? 220,
654
+ // TODO
655
+ // styles,
656
+ variant: ((_firstData_gauge7 = firstData.gauge) === null || _firstData_gauge7 === void 0 ? void 0 : (_firstData_gauge_steps1 = _firstData_gauge7.steps) === null || _firstData_gauge_steps1 === void 0 ? void 0 : _firstData_gauge_steps1.length) ? 'multiple-segments' : 'single-segment'
657
+ };
358
658
  };
359
- function isTypedArray(a) {
360
- return ArrayBuffer.isView(a) && !(a instanceof DataView);
361
- }
362
- export function isArrayOrTypedArray(a) {
363
- return Array.isArray(a) || isTypedArray(a);
364
- }
365
659
  function isPlainObject(obj) {
366
660
  return Object.prototype.toString.call(obj) === '[object Object]' && Object.getPrototypeOf(obj).hasOwnProperty('hasOwnProperty');
367
661
  }
@@ -398,3 +692,120 @@ function crawlIntoTrace(container, i, astrPartial) {
398
692
  }
399
693
  }
400
694
  }
695
+ function getLineOptions(line) {
696
+ if (!line) {
697
+ return;
698
+ }
699
+ let lineOptions = {};
700
+ if (line.dash) {
701
+ lineOptions = {
702
+ ...lineOptions,
703
+ ...dashOptions[line.dash]
704
+ };
705
+ }
706
+ switch(line.shape){
707
+ case 'spline':
708
+ const smoothing = typeof line.smoothing === 'number' ? line.smoothing : 1;
709
+ lineOptions.curve = d3CurveCardinal.tension(1 - smoothing / 1.3);
710
+ break;
711
+ case 'hv':
712
+ lineOptions.curve = 'stepAfter';
713
+ break;
714
+ case 'vh':
715
+ lineOptions.curve = 'stepBefore';
716
+ break;
717
+ case 'hvh':
718
+ lineOptions.curve = 'step';
719
+ break;
720
+ default:
721
+ lineOptions.curve = 'linear';
722
+ }
723
+ return Object.keys(lineOptions).length > 0 ? lineOptions : undefined;
724
+ }
725
+ const isStringArray = (arr)=>{
726
+ return isArrayOfType(arr, (value)=>typeof value === 'string');
727
+ };
728
+ // TODO: Use binary search to find the appropriate bin for numeric value.
729
+ const findBinIndex = (bins, value, isString)=>{
730
+ if (typeof value === 'undefined' || value === null) {
731
+ return -1;
732
+ }
733
+ return isString ? bins.findIndex((bin)=>bin.includes(value)) : bins.findIndex((bin)=>value >= bin.x0 && value < bin.x1);
734
+ };
735
+ const getBinSize = (bin)=>{
736
+ return bin.x1 - bin.x0;
737
+ };
738
+ const getBinCenter = (bin)=>{
739
+ return (bin.x1 + bin.x0) / 2;
740
+ };
741
+ // TODO: Add support for date axes
742
+ const createBins = (data, binStart, binEnd, binSize)=>{
743
+ if (!data || data.length === 0) {
744
+ return [];
745
+ }
746
+ if (isStringArray(data)) {
747
+ const categories = Array.from(new Set(data));
748
+ const start = typeof binStart === 'number' ? Math.ceil(binStart) : 0;
749
+ const stop = typeof binEnd === 'number' ? Math.floor(binEnd) + 1 : categories.length;
750
+ const step = typeof binSize === 'number' ? binSize : 1;
751
+ return d3Range(start, stop, step).map((i)=>categories.slice(i, i + step));
752
+ }
753
+ const scale = d3ScaleLinear().domain(d3Extent(data)).nice();
754
+ let [minVal, maxVal] = scale.domain();
755
+ minVal = typeof binStart === 'number' ? binStart : minVal;
756
+ maxVal = typeof binEnd === 'number' ? binEnd : maxVal;
757
+ const binGenerator = d3Bin().domain([
758
+ minVal,
759
+ maxVal
760
+ ]);
761
+ if (typeof binSize === 'number') {
762
+ var _binSize_toString_split_;
763
+ const thresholds = [];
764
+ let th = minVal;
765
+ var _binSize_toString_split__length;
766
+ const tolerance = 1 / Math.pow(10, (_binSize_toString_split__length = (_binSize_toString_split_ = binSize.toString().split('.')[1]) === null || _binSize_toString_split_ === void 0 ? void 0 : _binSize_toString_split_.length) !== null && _binSize_toString_split__length !== void 0 ? _binSize_toString_split__length : 0);
767
+ while(maxVal + binSize - th > tolerance){
768
+ thresholds.push(th);
769
+ th += binSize;
770
+ }
771
+ minVal = thresholds[0];
772
+ maxVal = thresholds[thresholds.length - 1];
773
+ binGenerator.domain([
774
+ minVal,
775
+ maxVal
776
+ ]).thresholds(thresholds);
777
+ }
778
+ // NOTE: The last bin generated by d3Bin often has identical x0 and x1 values (both inclusive) and
779
+ // can be ignored if the highest value is already included in the previous bin.
780
+ return binGenerator(data);
781
+ };
782
+ const calculateHistFunc = (histfunc, bin)=>{
783
+ switch(histfunc){
784
+ case 'sum':
785
+ return d3Sum(bin);
786
+ case 'avg':
787
+ return bin.length === 0 ? 0 : d3Sum(bin) / bin.length;
788
+ case 'min':
789
+ var _d3Min;
790
+ return (_d3Min = d3Min(bin)) !== null && _d3Min !== void 0 ? _d3Min : 0;
791
+ case 'max':
792
+ var _d3Max;
793
+ return (_d3Max = d3Max(bin)) !== null && _d3Max !== void 0 ? _d3Max : 0;
794
+ default:
795
+ return bin.length;
796
+ }
797
+ };
798
+ const calculateHistNorm = (histnorm, value, total, dx, dy = 1)=>{
799
+ switch(histnorm){
800
+ case 'percent':
801
+ return total === 0 ? 0 : value / total * 100;
802
+ case 'probability':
803
+ return total === 0 ? 0 : value / total;
804
+ case 'density':
805
+ return dx * dy === 0 ? 0 : value / (dx * dy);
806
+ case 'probability density':
807
+ return total * dx * dy === 0 ? 0 : value / (total * dx * dy);
808
+ default:
809
+ return value;
810
+ }
811
+ };