@fluentui/react-charting 5.24.1 → 5.24.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 (154) hide show
  1. package/CHANGELOG.json +61 -1
  2. package/CHANGELOG.md +25 -2
  3. package/dist/react-charting.d.ts +171 -33
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +60 -10
  7. package/lib/ScatterChart.d.ts +1 -0
  8. package/lib/ScatterChart.js +2 -0
  9. package/lib/ScatterChart.js.map +1 -0
  10. package/lib/components/CommonComponents/CartesianChart.base.js +45 -9
  11. package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
  12. package/lib/components/CommonComponents/CartesianChart.styles.js +48 -26
  13. package/lib/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  14. package/lib/components/CommonComponents/CartesianChart.types.d.ts +21 -1
  15. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  16. package/lib/components/DeclarativeChart/DeclarativeChart.js +157 -78
  17. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  18. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -13
  19. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +351 -95
  20. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  21. package/lib/components/LineChart/LineChart.base.js +23 -17
  22. package/lib/components/LineChart/LineChart.base.js.map +1 -1
  23. package/lib/components/LineChart/LineChart.styles.js +9 -0
  24. package/lib/components/LineChart/LineChart.styles.js.map +1 -1
  25. package/lib/components/LineChart/LineChart.types.d.ts +2 -0
  26. package/lib/components/LineChart/LineChart.types.js.map +1 -1
  27. package/lib/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  28. package/lib/components/ScatterChart/ScatterChart.base.js +453 -0
  29. package/lib/components/ScatterChart/ScatterChart.base.js.map +1 -0
  30. package/lib/components/ScatterChart/ScatterChart.d.ts +7 -0
  31. package/lib/components/ScatterChart/ScatterChart.js +10 -0
  32. package/lib/components/ScatterChart/ScatterChart.js.map +1 -0
  33. package/lib/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  34. package/lib/components/ScatterChart/ScatterChart.styles.js +7 -0
  35. package/lib/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  36. package/lib/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  37. package/lib/components/ScatterChart/ScatterChart.types.js +2 -0
  38. package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -0
  39. package/lib/components/ScatterChart/index.d.ts +2 -0
  40. package/lib/components/ScatterChart/index.js +3 -0
  41. package/lib/components/ScatterChart/index.js.map +1 -0
  42. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +8 -2
  43. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  44. package/lib/index.d.ts +3 -1
  45. package/lib/index.js +1 -0
  46. package/lib/index.js.map +1 -1
  47. package/lib/types/IDataPoint.d.ts +77 -11
  48. package/lib/types/IDataPoint.js.map +1 -1
  49. package/lib/utilities/SVGTooltipText.d.ts +4 -0
  50. package/lib/utilities/SVGTooltipText.js +1 -2
  51. package/lib/utilities/SVGTooltipText.js.map +1 -1
  52. package/lib/utilities/utilities.d.ts +27 -3
  53. package/lib/utilities/utilities.js +102 -1
  54. package/lib/utilities/utilities.js.map +1 -1
  55. package/lib-amd/ScatterChart.d.ts +1 -0
  56. package/lib-amd/ScatterChart.js +6 -0
  57. package/lib-amd/ScatterChart.js.map +1 -0
  58. package/lib-amd/components/CommonComponents/CartesianChart.base.js +45 -9
  59. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  60. package/lib-amd/components/CommonComponents/CartesianChart.styles.js +48 -26
  61. package/lib-amd/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  62. package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +21 -1
  63. package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
  64. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +155 -78
  65. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  66. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -13
  67. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +362 -102
  68. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  69. package/lib-amd/components/LineChart/LineChart.base.js +23 -17
  70. package/lib-amd/components/LineChart/LineChart.base.js.map +1 -1
  71. package/lib-amd/components/LineChart/LineChart.styles.js +9 -1
  72. package/lib-amd/components/LineChart/LineChart.styles.js.map +1 -1
  73. package/lib-amd/components/LineChart/LineChart.types.d.ts +2 -0
  74. package/lib-amd/components/LineChart/LineChart.types.js.map +1 -1
  75. package/lib-amd/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  76. package/lib-amd/components/ScatterChart/ScatterChart.base.js +447 -0
  77. package/lib-amd/components/ScatterChart/ScatterChart.base.js.map +1 -0
  78. package/lib-amd/components/ScatterChart/ScatterChart.d.ts +7 -0
  79. package/lib-amd/components/ScatterChart/ScatterChart.js +12 -0
  80. package/lib-amd/components/ScatterChart/ScatterChart.js.map +1 -0
  81. package/lib-amd/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  82. package/lib-amd/components/ScatterChart/ScatterChart.styles.js +12 -0
  83. package/lib-amd/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  84. package/lib-amd/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  85. package/lib-amd/components/ScatterChart/ScatterChart.types.js +5 -0
  86. package/lib-amd/components/ScatterChart/ScatterChart.types.js.map +1 -0
  87. package/lib-amd/components/ScatterChart/index.d.ts +2 -0
  88. package/lib-amd/components/ScatterChart/index.js +7 -0
  89. package/lib-amd/components/ScatterChart/index.js.map +1 -0
  90. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +8 -2
  91. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  92. package/lib-amd/index.d.ts +3 -1
  93. package/lib-amd/index.js +3 -2
  94. package/lib-amd/index.js.map +1 -1
  95. package/lib-amd/types/IDataPoint.d.ts +77 -11
  96. package/lib-amd/types/IDataPoint.js.map +1 -1
  97. package/lib-amd/utilities/SVGTooltipText.d.ts +4 -0
  98. package/lib-amd/utilities/SVGTooltipText.js +1 -2
  99. package/lib-amd/utilities/SVGTooltipText.js.map +1 -1
  100. package/lib-amd/utilities/utilities.d.ts +27 -3
  101. package/lib-amd/utilities/utilities.js +106 -2
  102. package/lib-amd/utilities/utilities.js.map +1 -1
  103. package/lib-commonjs/ScatterChart.d.ts +1 -0
  104. package/lib-commonjs/ScatterChart.js +5 -0
  105. package/lib-commonjs/ScatterChart.js.map +1 -0
  106. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +45 -9
  107. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  108. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js +48 -26
  109. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  110. package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +21 -1
  111. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  112. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +157 -78
  113. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  114. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +29 -13
  115. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +361 -102
  116. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  117. package/lib-commonjs/components/LineChart/LineChart.base.js +23 -17
  118. package/lib-commonjs/components/LineChart/LineChart.base.js.map +1 -1
  119. package/lib-commonjs/components/LineChart/LineChart.styles.js +9 -0
  120. package/lib-commonjs/components/LineChart/LineChart.styles.js.map +1 -1
  121. package/lib-commonjs/components/LineChart/LineChart.types.d.ts +2 -0
  122. package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
  123. package/lib-commonjs/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  124. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js +456 -0
  125. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js.map +1 -0
  126. package/lib-commonjs/components/ScatterChart/ScatterChart.d.ts +7 -0
  127. package/lib-commonjs/components/ScatterChart/ScatterChart.js +13 -0
  128. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -0
  129. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  130. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.js +11 -0
  131. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  132. package/lib-commonjs/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  133. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js +3 -0
  134. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -0
  135. package/lib-commonjs/components/ScatterChart/index.d.ts +2 -0
  136. package/lib-commonjs/components/ScatterChart/index.js +6 -0
  137. package/lib-commonjs/components/ScatterChart/index.js.map +1 -0
  138. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +8 -2
  139. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  140. package/lib-commonjs/index.d.ts +3 -1
  141. package/lib-commonjs/index.js +3 -1
  142. package/lib-commonjs/index.js.map +1 -1
  143. package/lib-commonjs/types/IDataPoint.d.ts +77 -11
  144. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  145. package/lib-commonjs/utilities/SVGTooltipText.d.ts +4 -0
  146. package/lib-commonjs/utilities/SVGTooltipText.js +1 -2
  147. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
  148. package/lib-commonjs/utilities/utilities.d.ts +27 -3
  149. package/lib-commonjs/utilities/utilities.js +106 -2
  150. package/lib-commonjs/utilities/utilities.js.map +1 -1
  151. package/package.json +2 -2
  152. package/src/components/CommonComponents/CartesianChart.types.ts +25 -1
  153. package/src/components/LineChart/LineChart.types.ts +4 -1
  154. package/src/components/ScatterChart/ScatterChart.types.ts +61 -0
@@ -5,8 +5,7 @@ import { format as d3Format } from 'd3-format';
5
5
  import { DataVizPalette, getColorFromToken } from '../../utilities/colors';
6
6
  import { GaugeChartVariant } from '../GaugeChart/index';
7
7
  import { findNumericMinMaxOfY, formatScientificLimitWidth, MIN_DONUT_RADIUS } from '../../utilities/utilities';
8
- import { isArrayOfType, isArrayOrTypedArray, isDate, isDateArray, isNumberArray, isYearArray, isInvalidValue, } from '@fluentui/chart-utilities';
9
- import { timeParse } from 'd3-time-format';
8
+ import { isArrayOrTypedArray, isDate, isDateArray, isNumberArray, isStringArray, isYearArray, isInvalidValue, } from '@fluentui/chart-utilities';
10
9
  import { curveCardinal as d3CurveCardinal } from 'd3-shape';
11
10
  import { extractColor, resolveColor } from './PlotlyColorAdapter';
12
11
  var dashOptions = {
@@ -47,16 +46,6 @@ var dashOptions = {
47
46
  lineBorderWidth: '4',
48
47
  },
49
48
  };
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- var isMonth = function (possiblyMonthValue) {
52
- var parseFullMonth = timeParse('%B');
53
- var parseShortMonth = timeParse('%b');
54
- return parseFullMonth(possiblyMonthValue) !== null || parseShortMonth(possiblyMonthValue) !== null;
55
- };
56
- export var isMonthArray = function (data) {
57
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
58
- return isArrayOfType(data, function (value) { return isMonth(value) || value === null; });
59
- };
60
49
  function getTitles(layout) {
61
50
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
62
51
  var titles = {
@@ -103,8 +92,9 @@ export var correctYearMonth = function (xValues) {
103
92
  });
104
93
  return xValues;
105
94
  };
106
- var usesSecondaryYScale = function (series) {
107
- return series.yaxis === 'y2';
95
+ var usesSecondaryYScale = function (series, layout) {
96
+ var _a, _b;
97
+ return series.yaxis === 'y2' && (((_a = layout === null || layout === void 0 ? void 0 : layout.yaxis2) === null || _a === void 0 ? void 0 : _a.anchor) === 'x' || ((_b = layout === null || layout === void 0 ? void 0 : layout.yaxis2) === null || _b === void 0 ? void 0 : _b.side) === 'right');
108
98
  };
109
99
  var getSecondaryYAxisValues = function (data, layout, maxAllowedMinY, minAllowedMaxY) {
110
100
  var _a, _b, _c, _d;
@@ -112,7 +102,7 @@ var getSecondaryYAxisValues = function (data, layout, maxAllowedMinY, minAllowed
112
102
  var yMinValue;
113
103
  var yMaxValue;
114
104
  data.forEach(function (series) {
115
- if (usesSecondaryYScale(series)) {
105
+ if (usesSecondaryYScale(series, layout)) {
116
106
  containsSecondaryYAxis = true;
117
107
  var yValues = series.y;
118
108
  if (yValues) {
@@ -150,7 +140,26 @@ export var _getGaugeAxisColor = function (colorway, colorwayType, color, colorMa
150
140
  var extractedColors = extractColor(colorway, colorwayType, color, colorMap, isDarkTheme);
151
141
  return resolveColor(extractedColors, 0, '', colorMap, isDarkTheme);
152
142
  };
153
- export var transformPlotlyJsonToDonutProps = function (input, colorMap, colorwayType, isDarkTheme) {
143
+ export var resolveXAxisPoint = function (x, isXYearCategory, isXString, isXDate, isXNumber) {
144
+ if (x === null || x === undefined) {
145
+ return '';
146
+ }
147
+ if (isXYearCategory) {
148
+ return x.toString();
149
+ }
150
+ if (isXString) {
151
+ if (isXDate) {
152
+ var date = new Date(x);
153
+ return date;
154
+ }
155
+ if (isXNumber) {
156
+ return parseFloat(x);
157
+ }
158
+ return x;
159
+ }
160
+ return x;
161
+ };
162
+ export var transformPlotlyJsonToDonutProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
154
163
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
155
164
  var firstData = input.data[0];
156
165
  // extract colors for each series only once
@@ -202,33 +211,52 @@ export var transformPlotlyJsonToDonutProps = function (input, colorMap, colorway
202
211
  roundCorners: true,
203
212
  };
204
213
  };
205
- export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayType, isDarkTheme, fallbackVSBC) {
214
+ export var transformPlotlyJsonToVSBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme, fallbackVSBC) {
206
215
  var _a, _b, _c;
207
216
  var mapXToDataPoints = {};
208
217
  var yMaxValue = 0;
209
218
  var yMinValue = 0;
210
219
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
211
- var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
220
+ var _d = getLegendProps(input.data, input.layout, isMultiPlot), legends = _d.legends, hideLegend = _d.hideLegend;
221
+ var colorScale = undefined;
212
222
  input.data.forEach(function (series, index1) {
213
- var _a, _b, _c, _d, _e, _f, _g, _h;
223
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
224
+ if (((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.coloraxis) === null || _b === void 0 ? void 0 : _b.colorscale) === null || _c === void 0 ? void 0 : _c.length) &&
225
+ isArrayOrTypedArray((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color) &&
226
+ ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length > 0 &&
227
+ typeof ((_g = (_f = series.marker) === null || _f === void 0 ? void 0 : _f.color) === null || _g === void 0 ? void 0 : _g[0]) === 'number') {
228
+ colorScale = createColorScale(input.layout, series);
229
+ }
214
230
  var isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
215
231
  // extract bar colors for each series only once
216
- var extractedBarColors = extractColor((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.layout) === null || _c === void 0 ? void 0 : _c.colorway, colorwayType, (_d = series.marker) === null || _d === void 0 ? void 0 : _d.color, colorMap, isDarkTheme);
232
+ var extractedBarColors = extractColor((_k = (_j = (_h = input.layout) === null || _h === void 0 ? void 0 : _h.template) === null || _j === void 0 ? void 0 : _j.layout) === null || _k === void 0 ? void 0 : _k.colorway, colorwayType, (_l = series.marker) === null || _l === void 0 ? void 0 : _l.color, colorMap, isDarkTheme);
217
233
  // extract line colors for each series only once
218
- var extractedLineColors = extractColor((_g = (_f = (_e = input.layout) === null || _e === void 0 ? void 0 : _e.template) === null || _f === void 0 ? void 0 : _f.layout) === null || _g === void 0 ? void 0 : _g.colorway, colorwayType, (_h = series.line) === null || _h === void 0 ? void 0 : _h.color, colorMap, isDarkTheme);
234
+ var extractedLineColors = extractColor((_p = (_o = (_m = input.layout) === null || _m === void 0 ? void 0 : _m.template) === null || _o === void 0 ? void 0 : _o.layout) === null || _p === void 0 ? void 0 : _p.colorway, colorwayType, (_q = series.line) === null || _q === void 0 ? void 0 : _q.color, colorMap, isDarkTheme);
235
+ var xValues = series.x;
236
+ var isXDate = isDateArray(xValues);
237
+ var isXString = isStringArray(xValues);
238
+ var isXNumber = isNumberArray(xValues);
219
239
  var validXYRanges = getValidXYRanges(series);
220
240
  validXYRanges.forEach(function (_a, rangeIdx) {
221
241
  var rangeStart = _a[0], rangeEnd = _a[1];
222
242
  var rangeXValues = series.x.slice(rangeStart, rangeEnd);
223
243
  var rangeYValues = series.y.slice(rangeStart, rangeEnd);
224
244
  rangeXValues.forEach(function (x, index2) {
225
- var _a, _b;
245
+ var _a, _b, _c, _d;
226
246
  if (!mapXToDataPoints[x]) {
227
- mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
247
+ mapXToDataPoints[x] = {
248
+ xAxisPoint: resolveXAxisPoint(x, isXYearCategory, isXString, isXDate, isXNumber),
249
+ chartData: [],
250
+ lineData: [],
251
+ };
228
252
  }
229
253
  var legend = legends[index1];
230
- // resolve color for each legend's bars from the extracted colors
231
- var color = resolveColor(extractedBarColors, index1, legend, colorMap, isDarkTheme);
254
+ // resolve color for each legend's bars from the colorscale or extracted colors
255
+ var color = colorScale
256
+ ? colorScale(isArrayOrTypedArray((_a = series.marker) === null || _a === void 0 ? void 0 : _a.color)
257
+ ? (_c = (_b = series.marker) === null || _b === void 0 ? void 0 : _b.color) === null || _c === void 0 ? void 0 : _c[index2 % ((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color).length]
258
+ : 0)
259
+ : resolveColor(extractedBarColors, index2, legend, colorMap, isDarkTheme);
232
260
  var yVal = rangeYValues[index2];
233
261
  if (series.type === 'bar') {
234
262
  mapXToDataPoints[x].chartData.push({
@@ -243,21 +271,16 @@ export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayT
243
271
  else if (series.type === 'scatter' || !!fallbackVSBC) {
244
272
  var lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
245
273
  var lineOptions = getLineOptions(series.line);
246
- var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
247
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
248
- ? 'dottedLine'
249
- : ((_b = series.mode) === null || _b === void 0 ? void 0 : _b.includes('markers'))
250
- ? 'circle'
251
- : 'default';
274
+ var legendShape = getLegendShape(series);
252
275
  mapXToDataPoints[x].lineData.push({
253
276
  legend: legend + (validXYRanges.length > 1 ? ".".concat(rangeIdx + 1) : ''),
254
277
  legendShape: legendShape,
255
278
  y: yVal,
256
279
  color: lineColor,
257
280
  lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
258
- useSecondaryYScale: usesSecondaryYScale(series),
281
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
259
282
  });
260
- if (!usesSecondaryYScale(series) && typeof yVal === 'number') {
283
+ if (!usesSecondaryYScale(series, input.layout) && typeof yVal === 'number') {
261
284
  yMaxValue = Math.max(yMaxValue, yVal);
262
285
  yMinValue = Math.min(yMinValue, yVal);
263
286
  }
@@ -268,40 +291,40 @@ export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayT
268
291
  var _e = getTitles(input.layout), chartTitle = _e.chartTitle, xAxisTitle = _e.xAxisTitle, yAxisTitle = _e.yAxisTitle;
269
292
  return __assign(__assign({ data: Object.values(mapXToDataPoints), width: (_a = input.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barWidth: 'auto', yMaxValue: yMaxValue, yMinValue: yMinValue, chartTitle: chartTitle, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true, supportNegativeData: true, barGapMax: 2, showYAxisLables: true, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true });
270
293
  };
271
- var createColorScale = function (colorscale, domain) {
272
- var dMin = domain[0], dMax = domain[1];
294
+ var createColorScale = function (layout, series) {
295
+ var _a, _b, _c, _d, _e, _f;
296
+ var scale = (_a = layout === null || layout === void 0 ? void 0 : layout.coloraxis) === null || _a === void 0 ? void 0 : _a.colorscale;
297
+ var colorValues = (_b = series.marker) === null || _b === void 0 ? void 0 : _b.color;
298
+ var _g = [
299
+ (_d = (_c = layout === null || layout === void 0 ? void 0 : layout.coloraxis) === null || _c === void 0 ? void 0 : _c.cmin) !== null && _d !== void 0 ? _d : Math.min.apply(Math, colorValues),
300
+ (_f = (_e = layout === null || layout === void 0 ? void 0 : layout.coloraxis) === null || _e === void 0 ? void 0 : _e.cmax) !== null && _f !== void 0 ? _f : Math.max.apply(Math, colorValues),
301
+ ], dMin = _g[0], dMax = _g[1];
273
302
  // Normalize colorscale domain to actual data domain
274
- var scaleDomain = colorscale.map(function (_a) {
303
+ var scaleDomain = scale.map(function (_a) {
275
304
  var pos = _a[0];
276
305
  return dMin + pos * (dMax - dMin);
277
306
  });
278
- var scaleColors = colorscale.map(function (item) { return item[1]; });
307
+ var scaleColors = scale.map(function (item) { return item[1]; });
279
308
  return d3ScaleLinear().domain(scaleDomain).range(scaleColors);
280
309
  };
281
- export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
310
+ export var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
282
311
  var _a, _b, _c;
283
312
  var mapXToDataPoints = {};
284
313
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, 0, 0);
285
- var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
314
+ var _d = getLegendProps(input.data, input.layout, isMultiPlot), legends = _d.legends, hideLegend = _d.hideLegend;
286
315
  var colorScale = undefined;
287
316
  input.data.forEach(function (series, index1) {
288
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
317
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
289
318
  if (((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.coloraxis) === null || _b === void 0 ? void 0 : _b.colorscale) === null || _c === void 0 ? void 0 : _c.length) &&
290
319
  isArrayOrTypedArray((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color) &&
291
320
  ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length > 0 &&
292
321
  typeof ((_g = (_f = series.marker) === null || _f === void 0 ? void 0 : _f.color) === null || _g === void 0 ? void 0 : _g[0]) === 'number') {
293
- var scale = input.layout.coloraxis.colorscale;
294
- var colorValues = (_h = series.marker) === null || _h === void 0 ? void 0 : _h.color;
295
- var _t = [
296
- (_k = (_j = input.layout.coloraxis) === null || _j === void 0 ? void 0 : _j.cmin) !== null && _k !== void 0 ? _k : Math.min.apply(Math, colorValues),
297
- (_m = (_l = input.layout.coloraxis) === null || _l === void 0 ? void 0 : _l.cmax) !== null && _m !== void 0 ? _m : Math.max.apply(Math, colorValues),
298
- ], dMin = _t[0], dMax = _t[1];
299
- colorScale = createColorScale(scale, [dMin, dMax]);
322
+ colorScale = createColorScale(input.layout, series);
300
323
  }
301
324
  // extract colors for each series only once
302
- var extractedColors = extractColor((_q = (_p = (_o = input.layout) === null || _o === void 0 ? void 0 : _o.template) === null || _p === void 0 ? void 0 : _p.layout) === null || _q === void 0 ? void 0 : _q.colorway, colorwayType, (_r = series.marker) === null || _r === void 0 ? void 0 : _r.color, colorMap, isDarkTheme);
303
- (_s = series.x) === null || _s === void 0 ? void 0 : _s.forEach(function (x, xIndex) {
304
- var _a, _b, _c, _d;
325
+ var extractedColors = extractColor((_k = (_j = (_h = input.layout) === null || _h === void 0 ? void 0 : _h.template) === null || _j === void 0 ? void 0 : _j.layout) === null || _k === void 0 ? void 0 : _k.colorway, colorwayType, (_l = series.marker) === null || _l === void 0 ? void 0 : _l.color, colorMap, isDarkTheme);
326
+ (_m = series.x) === null || _m === void 0 ? void 0 : _m.forEach(function (x, xIndex) {
327
+ var _a, _b, _c, _d, _e;
305
328
  if (isInvalidValue(x) || isInvalidValue((_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex])) {
306
329
  return;
307
330
  }
@@ -312,7 +335,9 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
312
335
  var legend = legends[index1];
313
336
  // resolve color for each legend's bars from the colorscale or extracted colors
314
337
  var color = colorScale
315
- ? colorScale(isArrayOrTypedArray((_b = series.marker) === null || _b === void 0 ? void 0 : _b.color) ? (_d = (_c = series.marker) === null || _c === void 0 ? void 0 : _c.color) === null || _d === void 0 ? void 0 : _d[xIndex] : 0)
338
+ ? colorScale(isArrayOrTypedArray((_b = series.marker) === null || _b === void 0 ? void 0 : _b.color)
339
+ ? (_d = (_c = series.marker) === null || _c === void 0 ? void 0 : _c.color) === null || _d === void 0 ? void 0 : _d[xIndex % ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length]
340
+ : 0)
316
341
  : resolveColor(extractedColors, index1, legend, colorMap, isDarkTheme);
317
342
  mapXToDataPoints[x].series.push({
318
343
  key: legend,
@@ -320,7 +345,7 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
320
345
  xAxisCalloutData: x,
321
346
  color: color,
322
347
  legend: legend,
323
- useSecondaryYScale: usesSecondaryYScale(series),
348
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
324
349
  });
325
350
  }
326
351
  });
@@ -328,17 +353,24 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
328
353
  var _e = getTitles(input.layout), chartTitle = _e.chartTitle, xAxisTitle = _e.xAxisTitle, yAxisTitle = _e.yAxisTitle;
329
354
  return __assign(__assign({ data: Object.values(mapXToDataPoints), width: (_a = input.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barwidth: 'auto', chartTitle: chartTitle, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true });
330
355
  };
331
- export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
356
+ export var transformPlotlyJsonToVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
332
357
  var _a, _b, _c;
333
358
  var vbcData = [];
334
- var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
359
+ var _d = getLegendProps(input.data, input.layout, isMultiPlot), legends = _d.legends, hideLegend = _d.hideLegend;
360
+ var colorScale = undefined;
335
361
  input.data.forEach(function (series, seriesIdx) {
336
- var _a, _b, _c, _d, _e, _f, _g;
362
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
337
363
  if (!series.x) {
338
364
  return;
339
365
  }
366
+ if (((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.coloraxis) === null || _b === void 0 ? void 0 : _b.colorscale) === null || _c === void 0 ? void 0 : _c.length) &&
367
+ isArrayOrTypedArray((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color) &&
368
+ ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length > 0 &&
369
+ typeof ((_g = (_f = series.marker) === null || _f === void 0 ? void 0 : _f.color) === null || _g === void 0 ? void 0 : _g[0]) === 'number') {
370
+ colorScale = createColorScale(input.layout, series);
371
+ }
340
372
  // extract colors for each series only once
341
- var extractedColors = extractColor((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.layout) === null || _c === void 0 ? void 0 : _c.colorway, colorwayType, (_d = series.marker) === null || _d === void 0 ? void 0 : _d.color, colorMap, isDarkTheme);
373
+ var extractedColors = extractColor((_k = (_j = (_h = input.layout) === null || _h === void 0 ? void 0 : _h.template) === null || _j === void 0 ? void 0 : _j.layout) === null || _k === void 0 ? void 0 : _k.colorway, colorwayType, (_l = series.marker) === null || _l === void 0 ? void 0 : _l.color, colorMap, isDarkTheme);
342
374
  var xValues = [];
343
375
  var yValues = [];
344
376
  series.x.forEach(function (xVal, index) {
@@ -352,7 +384,7 @@ export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayTy
352
384
  var isXString = isStringArray(xValues);
353
385
  // TODO: In case of a single bin, add an empty bin of the same size to prevent the
354
386
  // default bar width from being used and ensure the bar spans the full intended range.
355
- var xBins = createBins(xValues, (_e = series.xbins) === null || _e === void 0 ? void 0 : _e.start, (_f = series.xbins) === null || _f === void 0 ? void 0 : _f.end, (_g = series.xbins) === null || _g === void 0 ? void 0 : _g.size);
387
+ var xBins = createBins(xValues, (_m = series.xbins) === null || _m === void 0 ? void 0 : _m.start, (_o = series.xbins) === null || _o === void 0 ? void 0 : _o.end, (_p = series.xbins) === null || _p === void 0 ? void 0 : _p.size);
356
388
  var yBins = xBins.map(function () { return []; });
357
389
  var total = 0;
358
390
  xValues.forEach(function (xVal, index) {
@@ -367,9 +399,14 @@ export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayTy
367
399
  return yVal;
368
400
  });
369
401
  xBins.forEach(function (bin, index) {
402
+ var _a, _b, _c, _d;
370
403
  var legend = legends[seriesIdx];
371
- // resolve color for each legend's bars from the extracted colors
372
- var color = resolveColor(extractedColors, seriesIdx, legend, colorMap, isDarkTheme);
404
+ // resolve color for each legend's bars from the colorscale or extracted colors
405
+ var color = colorScale
406
+ ? colorScale(isArrayOrTypedArray((_a = series.marker) === null || _a === void 0 ? void 0 : _a.color)
407
+ ? (_c = (_b = series.marker) === null || _b === void 0 ? void 0 : _b.color) === null || _c === void 0 ? void 0 : _c[index % ((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color).length]
408
+ : 0)
409
+ : resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
373
410
  var yVal = calculateHistNorm(series.histnorm, y[index], total, isXString ? bin.length : getBinSize(bin));
374
411
  vbcData.push(__assign({ x: isXString ? bin.join(', ') : getBinCenter(bin), y: yVal, legend: legend, color: color }, (isXString
375
412
  ? {}
@@ -392,14 +429,32 @@ export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayTy
392
429
  roundCorners: true,
393
430
  };
394
431
  };
395
- export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, isScatterMarkers, colorMap, colorwayType, isDarkTheme) {
396
- var _a, _b, _c, _d, _e, _f;
432
+ export var transformPlotlyJsonToAreaChartProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
433
+ return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'area', colorMap, colorwayType, isDarkTheme);
434
+ };
435
+ export var transformPlotlyJsonToLineChartProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
436
+ return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'line', colorMap, colorwayType, isDarkTheme);
437
+ };
438
+ export var transformPlotlyJsonToScatterChartProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
439
+ return transformPlotlyJsonToScatterTraceProps(input, isMultiPlot, 'scatter', colorMap, colorwayType, isDarkTheme);
440
+ };
441
+ var transformPlotlyJsonToScatterTraceProps = function (input, isMultiPlot, chartType, colorMap, colorwayType, isDarkTheme) {
442
+ var _a, _b, _c, _d, _e, _f, _g;
443
+ var isScatterMarkers = [
444
+ 'text+markers',
445
+ 'markers+text',
446
+ 'lines+markers',
447
+ 'markers+line',
448
+ 'text+lines+markers',
449
+ ].includes((_a = input.data[0]) === null || _a === void 0 ? void 0 : _a.mode);
450
+ var isAreaChart = chartType === 'area';
451
+ var isScatterChart = chartType === 'scatter';
397
452
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, isAreaChart ? 0 : undefined, isAreaChart ? 0 : undefined);
398
453
  var mode = 'tonexty';
399
- var _g = getLegendProps(input.data, input.layout), legends = _g.legends, hideLegend = _g.hideLegend;
454
+ var _h = getLegendProps(input.data, input.layout, isMultiPlot), legends = _h.legends, hideLegend = _h.hideLegend;
400
455
  var chartData = input.data
401
456
  .map(function (series, index) {
402
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
457
+ var _a, _b, _c, _d, _e, _f, _g;
403
458
  var colors = isScatterMarkers
404
459
  ? ((_a = series === null || series === void 0 ? void 0 : series.mode) === null || _a === void 0 ? void 0 : _a.includes('line'))
405
460
  ? (_b = series.line) === null || _b === void 0 ? void 0 : _b.color
@@ -408,20 +463,16 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
408
463
  // extract colors for each series only once
409
464
  var extractedColors = extractColor((_g = (_f = (_e = input.layout) === null || _e === void 0 ? void 0 : _e.template) === null || _f === void 0 ? void 0 : _f.layout) === null || _g === void 0 ? void 0 : _g.colorway, colorwayType, colors, colorMap, isDarkTheme);
410
465
  var xValues = series.x;
411
- var isString = isStringArray(xValues);
466
+ var isXString = isStringArray(xValues);
412
467
  var isXDate = isDateArray(xValues);
413
468
  var isXNumber = isNumberArray(xValues);
469
+ var isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
414
470
  var legend = legends[index];
415
471
  // resolve color for each legend's lines from the extracted colors
416
472
  var seriesColor = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
417
473
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
418
474
  var lineOptions = getLineOptions(series.line);
419
- var dashType = ((_h = series.line) === null || _h === void 0 ? void 0 : _h.dash) || 'solid';
420
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
421
- ? 'dottedLine'
422
- : ((_j = series.mode) === null || _j === void 0 ? void 0 : _j.includes('markers'))
423
- ? 'circle'
424
- : 'default';
475
+ var legendShape = getLegendShape(series);
425
476
  var validXYRanges = getValidXYRanges(series);
426
477
  return validXYRanges.map(function (_a, rangeIdx) {
427
478
  var _b;
@@ -431,55 +482,71 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
431
482
  var markerSizes = isArrayOrTypedArray((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size)
432
483
  ? series.marker.size.slice(rangeStart, rangeEnd)
433
484
  : [];
485
+ var textValues = Array.isArray(series.text) ? series.text.slice(rangeStart, rangeEnd) : undefined;
434
486
  return {
435
487
  legend: legend,
436
488
  legendShape: legendShape,
437
489
  data: rangeXValues.map(function (x, i) {
438
490
  var _a, _b;
439
- return (__assign({ x: isString ? (isXDate ? new Date(x) : isXNumber ? parseFloat(x) : x) : x, y: rangeYValues[i] }, (Array.isArray((_a = series.marker) === null || _a === void 0 ? void 0 : _a.size)
491
+ return (__assign(__assign({ x: resolveXAxisPoint(x, isXYearCategory, isXString, isXDate, isXNumber), y: rangeYValues[i] }, (Array.isArray((_a = series.marker) === null || _a === void 0 ? void 0 : _a.size)
440
492
  ? { markerSize: markerSizes[i] }
441
493
  : typeof ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size) === 'number'
442
494
  ? { markerSize: series.marker.size }
443
- : {})));
495
+ : {})), (textValues ? { text: textValues[i] } : {})));
444
496
  }),
445
497
  color: seriesColor,
446
498
  lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
447
- useSecondaryYScale: usesSecondaryYScale(series),
499
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
448
500
  };
449
501
  });
450
502
  })
451
503
  .flat();
452
504
  var yMinMaxValues = findNumericMinMaxOfY(chartData);
453
- var _h = getTitles(input.layout), chartTitle = _h.chartTitle, xAxisTitle = _h.xAxisTitle, yAxisTitle = _h.yAxisTitle;
505
+ var _j = getTitles(input.layout), chartTitle = _j.chartTitle, xAxisTitle = _j.xAxisTitle, yAxisTitle = _j.yAxisTitle;
454
506
  var numDataPoints = chartData.reduce(function (total, lineChartPoints) { return total + lineChartPoints.data.length; }, 0);
455
507
  var chartProps = {
456
508
  chartTitle: chartTitle,
457
509
  lineChartData: chartData,
458
510
  };
511
+ var scatterChartProps = {
512
+ chartTitle: chartTitle,
513
+ scatterChartData: chartData,
514
+ };
459
515
  if (isAreaChart) {
460
- return __assign(__assign({ data: chartProps, supportNegativeData: true, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle }, secondaryYAxisValues), { mode: mode, width: (_a = input.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, hideTickOverlap: true, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 });
516
+ return __assign(__assign({ data: chartProps, supportNegativeData: true, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle }, secondaryYAxisValues), { mode: mode, width: (_b = input.layout) === null || _b === void 0 ? void 0 : _b.width, height: (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 350, hideTickOverlap: true, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 });
461
517
  }
462
518
  else {
463
- return __assign(__assign({ data: chartProps, supportNegativeData: true, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle }, secondaryYAxisValues), { roundedTicks: true, yMinValue: yMinMaxValues.startValue, yMaxValue: yMinMaxValues.endValue, width: (_d = input.layout) === null || _d === void 0 ? void 0 : _d.width, height: (_f = (_e = input.layout) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 350, hideTickOverlap: true, enableReflow: false, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 });
519
+ return __assign(__assign({ data: isScatterChart ? scatterChartProps : chartProps, supportNegativeData: true, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle }, secondaryYAxisValues), { roundedTicks: true, yMinValue: yMinMaxValues.startValue, yMaxValue: yMinMaxValues.endValue, width: (_e = input.layout) === null || _e === void 0 ? void 0 : _e.width, height: (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : 350, hideTickOverlap: true, enableReflow: false, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 });
464
520
  }
465
521
  };
466
- export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, colorwayType, isDarkTheme) {
522
+ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
467
523
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
468
- var _s = getLegendProps(input.data, input.layout), legends = _s.legends, hideLegend = _s.hideLegend;
524
+ var _s = getLegendProps(input.data, input.layout, isMultiPlot), legends = _s.legends, hideLegend = _s.hideLegend;
525
+ var colorScale = undefined;
469
526
  var chartData = input.data
470
527
  .map(function (series, index) {
471
- var _a, _b, _c, _d;
528
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
529
+ if (((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.coloraxis) === null || _b === void 0 ? void 0 : _b.colorscale) === null || _c === void 0 ? void 0 : _c.length) &&
530
+ isArrayOrTypedArray((_d = series.marker) === null || _d === void 0 ? void 0 : _d.color) &&
531
+ ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length > 0 &&
532
+ typeof ((_g = (_f = series.marker) === null || _f === void 0 ? void 0 : _f.color) === null || _g === void 0 ? void 0 : _g[0]) === 'number') {
533
+ colorScale = createColorScale(input.layout, series);
534
+ }
472
535
  // extract colors for each series only once
473
- var extractedColors = extractColor((_c = (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.layout) === null || _c === void 0 ? void 0 : _c.colorway, colorwayType, (_d = series.marker) === null || _d === void 0 ? void 0 : _d.color, colorMap, isDarkTheme);
536
+ var extractedColors = extractColor((_k = (_j = (_h = input.layout) === null || _h === void 0 ? void 0 : _h.template) === null || _j === void 0 ? void 0 : _j.layout) === null || _k === void 0 ? void 0 : _k.colorway, colorwayType, (_l = series.marker) === null || _l === void 0 ? void 0 : _l.color, colorMap, isDarkTheme);
474
537
  var legend = legends[index];
475
- // resolve color for each legend's bars from the extracted colors
476
- var color = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
477
538
  return series.y
478
539
  .map(function (yValue, i) {
479
- var _a;
540
+ var _a, _b, _c, _d, _e;
480
541
  if (isInvalidValue((_a = series.x) === null || _a === void 0 ? void 0 : _a[i]) || isInvalidValue(yValue)) {
481
542
  return null;
482
543
  }
544
+ // resolve color for each legend's bars from the colorscale or extracted colors
545
+ var color = colorScale
546
+ ? colorScale(isArrayOrTypedArray((_b = series.marker) === null || _b === void 0 ? void 0 : _b.color)
547
+ ? (_d = (_c = series.marker) === null || _c === void 0 ? void 0 : _c.color) === null || _d === void 0 ? void 0 : _d[i % ((_e = series.marker) === null || _e === void 0 ? void 0 : _e.color).length]
548
+ : 0)
549
+ : resolveColor(extractedColors, i, legend, colorMap, isDarkTheme);
483
550
  return {
484
551
  x: series.x[i],
485
552
  y: yValue,
@@ -521,7 +588,7 @@ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, co
521
588
  roundCorners: true,
522
589
  };
523
590
  };
524
- export var transformPlotlyJsonToHeatmapProps = function (input) {
591
+ export var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
525
592
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
526
593
  var firstData = input.data[0];
527
594
  var heatmapDataPoints = [];
@@ -651,7 +718,7 @@ export var transformPlotlyJsonToHeatmapProps = function (input) {
651
718
  showYAxisLablesTooltip: true,
652
719
  };
653
720
  };
654
- export var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwayType, isDarkTheme) {
721
+ export var transformPlotlyJsonToSankeyProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
655
722
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
656
723
  var _m = input.data[0], link = _m.link, node = _m.node;
657
724
  var validLinks = ((_a = link === null || link === void 0 ? void 0 : link.value) !== null && _a !== void 0 ? _a : [])
@@ -698,7 +765,7 @@ export var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwa
698
765
  enableReflow: true,
699
766
  };
700
767
  };
701
- export var transformPlotlyJsonToGaugeProps = function (input, colorMap, colorwayType, isDarkTheme) {
768
+ export var transformPlotlyJsonToGaugeProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
702
769
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
703
770
  var firstData = input.data[0];
704
771
  var stepsColors = ((_a = firstData.gauge) === null || _a === void 0 ? void 0 : _a.steps) ? firstData.gauge.steps.map(function (step) { return step.color; }) : undefined;
@@ -797,7 +864,7 @@ var formatValue = function (value, colIndex, cells) {
797
864
  }
798
865
  return "".concat(prefix !== null && prefix !== void 0 ? prefix : '').concat(formatted).concat(suffix !== null && suffix !== void 0 ? suffix : '');
799
866
  };
800
- export var transformPlotlyJsonToChartTableProps = function (input, colorMap, isDarkTheme) {
867
+ export var transformPlotlyJsonToChartTableProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
801
868
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
802
869
  var tableData = input.data[0];
803
870
  var normalizeHeaders = function (values, header) {
@@ -1000,11 +1067,6 @@ function getLineOptions(line) {
1000
1067
  }
1001
1068
  return Object.keys(lineOptions).length > 0 ? lineOptions : undefined;
1002
1069
  }
1003
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1004
- export var isStringArray = function (arr) {
1005
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1006
- return isArrayOfType(arr, function (value) { return typeof value === 'string' || value === null; });
1007
- };
1008
1070
  // TODO: Use binary search to find the appropriate bin for numeric value.
1009
1071
  var findBinIndex = function (bins, value, isString) {
1010
1072
  if (typeof value === 'undefined' || value === null) {
@@ -1099,7 +1161,47 @@ var precisionRound = function (value, precision) {
1099
1161
  var factor = Math.pow(10, precision);
1100
1162
  return Math.round(value * factor) / factor;
1101
1163
  };
1102
- var getLegendProps = function (data, layout) {
1164
+ var getLegendShape = function (series) {
1165
+ var _a, _b;
1166
+ var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
1167
+ if (dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot') {
1168
+ return 'dottedLine';
1169
+ }
1170
+ else if ((_b = series.mode) === null || _b === void 0 ? void 0 : _b.includes('markers')) {
1171
+ return 'circle';
1172
+ }
1173
+ return 'default';
1174
+ };
1175
+ export var getAllupLegendsProps = function (input, colorMap, colorwayType, isDarkTheme) {
1176
+ var allupLegends = [];
1177
+ // reduce on showlegend boolean propperty. reduce should return true if at least one series has showlegend true
1178
+ var toShowLegend = input.data.reduce(function (acc, series) {
1179
+ return acc || series.showlegend === true;
1180
+ }, false);
1181
+ if (toShowLegend) {
1182
+ input.data.forEach(function (series, index) {
1183
+ var _a, _b, _c, _d, _e;
1184
+ var name = series.legendgroup;
1185
+ var color = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.color) || ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.color);
1186
+ var legendShape = getLegendShape(series);
1187
+ var resolvedColor = extractColor((_e = (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.template) === null || _d === void 0 ? void 0 : _d.layout) === null || _e === void 0 ? void 0 : _e.colorway, colorwayType, color, colorMap, isDarkTheme);
1188
+ if (name !== undefined && allupLegends.some(function (group) { return group.title === name; }) === false) {
1189
+ allupLegends.push({
1190
+ title: name,
1191
+ color: resolvedColor,
1192
+ shape: legendShape,
1193
+ });
1194
+ }
1195
+ });
1196
+ }
1197
+ return {
1198
+ legends: allupLegends,
1199
+ centerLegends: true,
1200
+ enabledWrapLines: true,
1201
+ canSelectMultipleLegends: true,
1202
+ };
1203
+ };
1204
+ var getLegendProps = function (data, layout, isMultiPlot) {
1103
1205
  var legends = [];
1104
1206
  if (data.length === 1) {
1105
1207
  legends.push(data[0].name || '');
@@ -1109,10 +1211,11 @@ var getLegendProps = function (data, layout) {
1109
1211
  legends.push(series.name || "Series ".concat(index + 1));
1110
1212
  });
1111
1213
  }
1112
- var hideLegends = data.every(function (series) { return series.showlegend === false; });
1214
+ var hideLegendsData = data.every(function (series) { return series.showlegend === false; });
1215
+ var hideLegendsInferred = (layout === null || layout === void 0 ? void 0 : layout.showlegend) === false || ((layout === null || layout === void 0 ? void 0 : layout.showlegend) !== true && legends.length < 2);
1113
1216
  return {
1114
1217
  legends: legends,
1115
- hideLegend: (layout === null || layout === void 0 ? void 0 : layout.showlegend) === false || ((layout === null || layout === void 0 ? void 0 : layout.showlegend) !== true && legends.length < 2) ? true : hideLegends,
1218
+ hideLegend: isMultiPlot || hideLegendsInferred || hideLegendsData,
1116
1219
  };
1117
1220
  };
1118
1221
  export var getNumberAtIndexOrDefault = function (data, index) {
@@ -1144,4 +1247,157 @@ export var getValidXYRanges = function (series) {
1144
1247
  }
1145
1248
  return ranges;
1146
1249
  };
1250
+ var getIndexFromKey = function (key, pattern) {
1251
+ var normalizedKey = key.replace(pattern, '') === '' ? '1' : key.replace(pattern, '');
1252
+ return parseInt(normalizedKey, 10) - 1;
1253
+ };
1254
+ export var getGridProperties = function (layout, isMultiPlot) {
1255
+ var _a;
1256
+ var gridX = [];
1257
+ var gridY = [];
1258
+ var annotations = {};
1259
+ var templateRows = '1fr';
1260
+ var templateColumns = '1fr';
1261
+ var gridLayout = {};
1262
+ if (layout === undefined || layout === null || Object.keys(layout).length === 0) {
1263
+ return { templateRows: templateRows, templateColumns: templateColumns, layout: gridLayout };
1264
+ }
1265
+ if (!layout.xaxis || !layout.yaxis) {
1266
+ return { templateRows: templateRows, templateColumns: templateColumns, layout: gridLayout };
1267
+ }
1268
+ if (!isMultiPlot) {
1269
+ return { templateRows: templateRows, templateColumns: templateColumns, layout: gridLayout };
1270
+ }
1271
+ Object.keys(layout).forEach(function (key) {
1272
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1273
+ if (key.startsWith('xaxis')) {
1274
+ var index = getIndexFromKey(key, 'xaxis');
1275
+ var anchor = (_b = (_a = layout[key]) === null || _a === void 0 ? void 0 : _a.anchor) !== null && _b !== void 0 ? _b : 'y';
1276
+ var anchorIndex = getIndexFromKey(anchor, 'y');
1277
+ if (index !== anchorIndex) {
1278
+ throw new Error("Invalid layout: xaxis ".concat(index + 1, " anchor should be y").concat(anchorIndex + 1));
1279
+ }
1280
+ gridX[index] = (_d = (_c = layout[key]) === null || _c === void 0 ? void 0 : _c.domain) !== null && _d !== void 0 ? _d : [];
1281
+ }
1282
+ else if (key.startsWith('yaxis')) {
1283
+ var index = getIndexFromKey(key, 'yaxis');
1284
+ var anchor = (_f = (_e = layout[key]) === null || _e === void 0 ? void 0 : _e.anchor) !== null && _f !== void 0 ? _f : 'x';
1285
+ var anchorIndex = getIndexFromKey(anchor, 'x');
1286
+ if (index !== anchorIndex) {
1287
+ if ((index === 1 && anchorIndex === 0) || ((_g = layout.yaxis2) === null || _g === void 0 ? void 0 : _g.side) === 'right') {
1288
+ // Special case for secondary y axis where yaxis2 can anchor to x1
1289
+ return { templateRows: templateRows, templateColumns: templateColumns };
1290
+ }
1291
+ throw new Error("Invalid layout: yaxis ".concat(index + 1, " anchor should be x").concat(anchorIndex + 1));
1292
+ }
1293
+ gridY[index] = (_j = (_h = layout[key]) === null || _h === void 0 ? void 0 : _h.domain) !== null && _j !== void 0 ? _j : [];
1294
+ }
1295
+ });
1296
+ (_a = layout.annotations) === null || _a === void 0 ? void 0 : _a.forEach(function (annotation) {
1297
+ var xMatches = gridX.flatMap(function (interval, idx) {
1298
+ return (annotation === null || annotation === void 0 ? void 0 : annotation.x) >= interval[0] && (annotation === null || annotation === void 0 ? void 0 : annotation.x) <= interval[1] ? [idx] : [];
1299
+ });
1300
+ var yMatch = gridY.findIndex(function (interval, yIndex) {
1301
+ return xMatches.includes(yIndex) &&
1302
+ (annotation === null || annotation === void 0 ? void 0 : annotation.y) >= interval[0] &&
1303
+ (annotation === null || annotation === void 0 ? void 0 : annotation.y) <= interval[1];
1304
+ });
1305
+ if (yMatch !== -1) {
1306
+ if (annotations[yMatch] === undefined) {
1307
+ annotations[yMatch] = {};
1308
+ }
1309
+ if ((annotation === null || annotation === void 0 ? void 0 : annotation.textangle) === 90) {
1310
+ annotations[yMatch].yAnnotation = annotation.text;
1311
+ }
1312
+ else {
1313
+ annotations[yMatch].xAnnotation = annotation.text;
1314
+ }
1315
+ }
1316
+ });
1317
+ if (gridX.length > 0) {
1318
+ var uniqueXIntervals_1 = new Map();
1319
+ gridX.forEach(function (interval) {
1320
+ var key = "".concat(interval[0], "-").concat(interval[1]);
1321
+ if (!uniqueXIntervals_1.has(key)) {
1322
+ uniqueXIntervals_1.set(key, interval);
1323
+ }
1324
+ });
1325
+ var minXInterval_1 = Math.min.apply(Math, Array.from(uniqueXIntervals_1.values()).map(function (interval) { return interval[1] - interval[0]; }));
1326
+ templateColumns = Array.from(uniqueXIntervals_1.values())
1327
+ .map(function (interval) { return "".concat((interval[1] - interval[0]) / minXInterval_1, "fr"); })
1328
+ .join(' ');
1329
+ var columnNumber_1 = 1;
1330
+ var lastIntervalEnd_1 = 0;
1331
+ gridX.forEach(function (interval, index) {
1332
+ if (interval.length === 0) {
1333
+ return;
1334
+ }
1335
+ var cellName = "x".concat(index === 0 ? '' : index + 1);
1336
+ var annotationProps = annotations[index];
1337
+ var xAnnotation = annotationProps === null || annotationProps === void 0 ? void 0 : annotationProps.xAnnotation;
1338
+ if (interval[0] < lastIntervalEnd_1) {
1339
+ columnNumber_1 = 1;
1340
+ }
1341
+ lastIntervalEnd_1 = interval[1];
1342
+ var row = {
1343
+ row: -1,
1344
+ column: columnNumber_1,
1345
+ xAnnotation: xAnnotation,
1346
+ };
1347
+ gridLayout[cellName] = row;
1348
+ columnNumber_1 += 1;
1349
+ });
1350
+ }
1351
+ var numColumns = Math.max.apply(Math, Object.values(gridLayout).map(function (cell) { var _a; return (_a = cell.column) !== null && _a !== void 0 ? _a : 0; }));
1352
+ var columnFill = {};
1353
+ for (var i = 1; i <= numColumns; i++) {
1354
+ columnFill[i] = { row: 1, fillDomain: 0 };
1355
+ }
1356
+ if (gridY.length > 0) {
1357
+ var uniqueYIntervals_1 = new Map();
1358
+ gridY.forEach(function (interval) {
1359
+ var key = "".concat(interval[0], "-").concat(interval[1]);
1360
+ if (!uniqueYIntervals_1.has(key)) {
1361
+ uniqueYIntervals_1.set(key, interval);
1362
+ }
1363
+ });
1364
+ var minYInterval_1 = Math.min.apply(Math, Array.from(uniqueYIntervals_1.values()).map(function (interval) { return interval[1] - interval[0]; }));
1365
+ templateRows = Array.from(uniqueYIntervals_1.values())
1366
+ .map(function (interval) { return "".concat((interval[1] - interval[0]) / minYInterval_1, "fr"); })
1367
+ .join(' ');
1368
+ gridY.forEach(function (interval, index) {
1369
+ if (interval.length === 0) {
1370
+ return;
1371
+ }
1372
+ var cellName = "x".concat(index === 0 ? '' : index + 1);
1373
+ var annotationProps = annotations[index];
1374
+ var yAnnotation = annotationProps === null || annotationProps === void 0 ? void 0 : annotationProps.yAnnotation;
1375
+ var cell = gridLayout[cellName];
1376
+ if (cell !== undefined) {
1377
+ cell.row = columnFill[cell.column].row;
1378
+ cell.yAnnotation = yAnnotation;
1379
+ }
1380
+ columnFill[cell.column].fillDomain = interval[1];
1381
+ columnFill[cell.column].row += 1;
1382
+ });
1383
+ }
1384
+ // reverse the order of rows in grid layout from bottom-top to top-bottom as required by CSS grid
1385
+ var reversedGridLayout = {};
1386
+ // find the maximum row number
1387
+ var maxRowNumber = Math.max.apply(Math, Object.values(gridLayout).map(function (cell) { var _a; return (_a = cell.row) !== null && _a !== void 0 ? _a : 0; }));
1388
+ // iterate over the gridLayout and reverse the row numbers
1389
+ Object.keys(gridLayout).forEach(function (key) {
1390
+ var cell = gridLayout[key];
1391
+ if (cell.row !== undefined) {
1392
+ // reverse the row number
1393
+ cell.row = maxRowNumber - cell.row + 1;
1394
+ }
1395
+ reversedGridLayout[key] = cell;
1396
+ });
1397
+ return {
1398
+ templateRows: templateRows,
1399
+ templateColumns: templateColumns,
1400
+ layout: reversedGridLayout,
1401
+ };
1402
+ };
1147
1403
  //# sourceMappingURL=PlotlySchemaAdapter.js.map