@fluentui/react-charting 5.24.2 → 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 (129) hide show
  1. package/CHANGELOG.json +34 -1
  2. package/CHANGELOG.md +14 -2
  3. package/dist/react-charting.d.ts +170 -37
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +58 -11
  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 +28 -13
  19. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +252 -62
  20. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  21. package/lib/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  22. package/lib/components/ScatterChart/ScatterChart.base.js +453 -0
  23. package/lib/components/ScatterChart/ScatterChart.base.js.map +1 -0
  24. package/lib/components/ScatterChart/ScatterChart.d.ts +7 -0
  25. package/lib/components/ScatterChart/ScatterChart.js +10 -0
  26. package/lib/components/ScatterChart/ScatterChart.js.map +1 -0
  27. package/lib/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  28. package/lib/components/ScatterChart/ScatterChart.styles.js +7 -0
  29. package/lib/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  30. package/lib/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  31. package/lib/components/ScatterChart/ScatterChart.types.js +2 -0
  32. package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -0
  33. package/lib/components/ScatterChart/index.d.ts +2 -0
  34. package/lib/components/ScatterChart/index.js +3 -0
  35. package/lib/components/ScatterChart/index.js.map +1 -0
  36. package/lib/index.d.ts +3 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/types/IDataPoint.d.ts +73 -11
  40. package/lib/types/IDataPoint.js.map +1 -1
  41. package/lib/utilities/SVGTooltipText.d.ts +4 -0
  42. package/lib/utilities/SVGTooltipText.js +1 -2
  43. package/lib/utilities/SVGTooltipText.js.map +1 -1
  44. package/lib/utilities/utilities.d.ts +27 -3
  45. package/lib/utilities/utilities.js +102 -1
  46. package/lib/utilities/utilities.js.map +1 -1
  47. package/lib-amd/ScatterChart.d.ts +1 -0
  48. package/lib-amd/ScatterChart.js +6 -0
  49. package/lib-amd/ScatterChart.js.map +1 -0
  50. package/lib-amd/components/CommonComponents/CartesianChart.base.js +45 -9
  51. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  52. package/lib-amd/components/CommonComponents/CartesianChart.styles.js +48 -26
  53. package/lib-amd/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  54. package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +21 -1
  55. package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
  56. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +155 -78
  57. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  58. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +28 -13
  59. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +264 -71
  60. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  61. package/lib-amd/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  62. package/lib-amd/components/ScatterChart/ScatterChart.base.js +447 -0
  63. package/lib-amd/components/ScatterChart/ScatterChart.base.js.map +1 -0
  64. package/lib-amd/components/ScatterChart/ScatterChart.d.ts +7 -0
  65. package/lib-amd/components/ScatterChart/ScatterChart.js +12 -0
  66. package/lib-amd/components/ScatterChart/ScatterChart.js.map +1 -0
  67. package/lib-amd/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  68. package/lib-amd/components/ScatterChart/ScatterChart.styles.js +12 -0
  69. package/lib-amd/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  70. package/lib-amd/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  71. package/lib-amd/components/ScatterChart/ScatterChart.types.js +5 -0
  72. package/lib-amd/components/ScatterChart/ScatterChart.types.js.map +1 -0
  73. package/lib-amd/components/ScatterChart/index.d.ts +2 -0
  74. package/lib-amd/components/ScatterChart/index.js +7 -0
  75. package/lib-amd/components/ScatterChart/index.js.map +1 -0
  76. package/lib-amd/index.d.ts +3 -1
  77. package/lib-amd/index.js +3 -2
  78. package/lib-amd/index.js.map +1 -1
  79. package/lib-amd/types/IDataPoint.d.ts +73 -11
  80. package/lib-amd/types/IDataPoint.js.map +1 -1
  81. package/lib-amd/utilities/SVGTooltipText.d.ts +4 -0
  82. package/lib-amd/utilities/SVGTooltipText.js +1 -2
  83. package/lib-amd/utilities/SVGTooltipText.js.map +1 -1
  84. package/lib-amd/utilities/utilities.d.ts +27 -3
  85. package/lib-amd/utilities/utilities.js +106 -2
  86. package/lib-amd/utilities/utilities.js.map +1 -1
  87. package/lib-commonjs/ScatterChart.d.ts +1 -0
  88. package/lib-commonjs/ScatterChart.js +5 -0
  89. package/lib-commonjs/ScatterChart.js.map +1 -0
  90. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +45 -9
  91. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  92. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js +48 -26
  93. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  94. package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +21 -1
  95. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  96. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +157 -78
  97. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  98. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +28 -13
  99. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +263 -71
  100. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  101. package/lib-commonjs/components/ScatterChart/ScatterChart.base.d.ts +7 -0
  102. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js +456 -0
  103. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js.map +1 -0
  104. package/lib-commonjs/components/ScatterChart/ScatterChart.d.ts +7 -0
  105. package/lib-commonjs/components/ScatterChart/ScatterChart.js +13 -0
  106. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -0
  107. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.d.ts +2 -0
  108. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.js +11 -0
  109. package/lib-commonjs/components/ScatterChart/ScatterChart.styles.js.map +1 -0
  110. package/lib-commonjs/components/ScatterChart/ScatterChart.types.d.ts +42 -0
  111. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js +3 -0
  112. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -0
  113. package/lib-commonjs/components/ScatterChart/index.d.ts +2 -0
  114. package/lib-commonjs/components/ScatterChart/index.js +6 -0
  115. package/lib-commonjs/components/ScatterChart/index.js.map +1 -0
  116. package/lib-commonjs/index.d.ts +3 -1
  117. package/lib-commonjs/index.js +3 -1
  118. package/lib-commonjs/index.js.map +1 -1
  119. package/lib-commonjs/types/IDataPoint.d.ts +73 -11
  120. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  121. package/lib-commonjs/utilities/SVGTooltipText.d.ts +4 -0
  122. package/lib-commonjs/utilities/SVGTooltipText.js +1 -2
  123. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
  124. package/lib-commonjs/utilities/utilities.d.ts +27 -3
  125. package/lib-commonjs/utilities/utilities.js +106 -2
  126. package/lib-commonjs/utilities/utilities.js.map +1 -1
  127. package/package.json +2 -2
  128. package/src/components/CommonComponents/CartesianChart.types.ts +25 -1
  129. 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) {
@@ -169,7 +159,7 @@ export var resolveXAxisPoint = function (x, isXYearCategory, isXString, isXDate,
169
159
  }
170
160
  return x;
171
161
  };
172
- export var transformPlotlyJsonToDonutProps = function (input, colorMap, colorwayType, isDarkTheme) {
162
+ export var transformPlotlyJsonToDonutProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
173
163
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
174
164
  var firstData = input.data[0];
175
165
  // extract colors for each series only once
@@ -221,13 +211,13 @@ export var transformPlotlyJsonToDonutProps = function (input, colorMap, colorway
221
211
  roundCorners: true,
222
212
  };
223
213
  };
224
- export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayType, isDarkTheme, fallbackVSBC) {
214
+ export var transformPlotlyJsonToVSBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme, fallbackVSBC) {
225
215
  var _a, _b, _c;
226
216
  var mapXToDataPoints = {};
227
217
  var yMaxValue = 0;
228
218
  var yMinValue = 0;
229
219
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
230
- 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;
231
221
  var colorScale = undefined;
232
222
  input.data.forEach(function (series, index1) {
233
223
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
@@ -252,7 +242,7 @@ export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayT
252
242
  var rangeXValues = series.x.slice(rangeStart, rangeEnd);
253
243
  var rangeYValues = series.y.slice(rangeStart, rangeEnd);
254
244
  rangeXValues.forEach(function (x, index2) {
255
- var _a, _b, _c, _d, _e, _f;
245
+ var _a, _b, _c, _d;
256
246
  if (!mapXToDataPoints[x]) {
257
247
  mapXToDataPoints[x] = {
258
248
  xAxisPoint: resolveXAxisPoint(x, isXYearCategory, isXString, isXDate, isXNumber),
@@ -281,21 +271,16 @@ export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayT
281
271
  else if (series.type === 'scatter' || !!fallbackVSBC) {
282
272
  var lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
283
273
  var lineOptions = getLineOptions(series.line);
284
- var dashType = ((_e = series.line) === null || _e === void 0 ? void 0 : _e.dash) || 'solid';
285
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
286
- ? 'dottedLine'
287
- : ((_f = series.mode) === null || _f === void 0 ? void 0 : _f.includes('markers'))
288
- ? 'circle'
289
- : 'default';
274
+ var legendShape = getLegendShape(series);
290
275
  mapXToDataPoints[x].lineData.push({
291
276
  legend: legend + (validXYRanges.length > 1 ? ".".concat(rangeIdx + 1) : ''),
292
277
  legendShape: legendShape,
293
278
  y: yVal,
294
279
  color: lineColor,
295
280
  lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
296
- useSecondaryYScale: usesSecondaryYScale(series),
281
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
297
282
  });
298
- if (!usesSecondaryYScale(series) && typeof yVal === 'number') {
283
+ if (!usesSecondaryYScale(series, input.layout) && typeof yVal === 'number') {
299
284
  yMaxValue = Math.max(yMaxValue, yVal);
300
285
  yMinValue = Math.min(yMinValue, yVal);
301
286
  }
@@ -322,11 +307,11 @@ var createColorScale = function (layout, series) {
322
307
  var scaleColors = scale.map(function (item) { return item[1]; });
323
308
  return d3ScaleLinear().domain(scaleDomain).range(scaleColors);
324
309
  };
325
- export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
310
+ export var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
326
311
  var _a, _b, _c;
327
312
  var mapXToDataPoints = {};
328
313
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, 0, 0);
329
- 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;
330
315
  var colorScale = undefined;
331
316
  input.data.forEach(function (series, index1) {
332
317
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -360,7 +345,7 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
360
345
  xAxisCalloutData: x,
361
346
  color: color,
362
347
  legend: legend,
363
- useSecondaryYScale: usesSecondaryYScale(series),
348
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
364
349
  });
365
350
  }
366
351
  });
@@ -368,10 +353,10 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
368
353
  var _e = getTitles(input.layout), chartTitle = _e.chartTitle, xAxisTitle = _e.xAxisTitle, yAxisTitle = _e.yAxisTitle;
369
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 });
370
355
  };
371
- export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
356
+ export var transformPlotlyJsonToVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
372
357
  var _a, _b, _c;
373
358
  var vbcData = [];
374
- 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;
375
360
  var colorScale = undefined;
376
361
  input.data.forEach(function (series, seriesIdx) {
377
362
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
@@ -444,14 +429,32 @@ export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayTy
444
429
  roundCorners: true,
445
430
  };
446
431
  };
447
- export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, isScatterMarkers, colorMap, colorwayType, isDarkTheme) {
448
- 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';
449
452
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, isAreaChart ? 0 : undefined, isAreaChart ? 0 : undefined);
450
453
  var mode = 'tonexty';
451
- 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;
452
455
  var chartData = input.data
453
456
  .map(function (series, index) {
454
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
457
+ var _a, _b, _c, _d, _e, _f, _g;
455
458
  var colors = isScatterMarkers
456
459
  ? ((_a = series === null || series === void 0 ? void 0 : series.mode) === null || _a === void 0 ? void 0 : _a.includes('line'))
457
460
  ? (_b = series.line) === null || _b === void 0 ? void 0 : _b.color
@@ -463,19 +466,13 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
463
466
  var isXString = isStringArray(xValues);
464
467
  var isXDate = isDateArray(xValues);
465
468
  var isXNumber = isNumberArray(xValues);
466
- // string case is not possible for scatter chart as it is already filtered out in declarative chart
467
- var isXYearCategory = false;
469
+ var isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
468
470
  var legend = legends[index];
469
471
  // resolve color for each legend's lines from the extracted colors
470
472
  var seriesColor = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
471
473
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
472
474
  var lineOptions = getLineOptions(series.line);
473
- var dashType = ((_h = series.line) === null || _h === void 0 ? void 0 : _h.dash) || 'solid';
474
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
475
- ? 'dottedLine'
476
- : ((_j = series.mode) === null || _j === void 0 ? void 0 : _j.includes('markers'))
477
- ? 'circle'
478
- : 'default';
475
+ var legendShape = getLegendShape(series);
479
476
  var validXYRanges = getValidXYRanges(series);
480
477
  return validXYRanges.map(function (_a, rangeIdx) {
481
478
  var _b;
@@ -499,28 +496,32 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
499
496
  }),
500
497
  color: seriesColor,
501
498
  lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
502
- useSecondaryYScale: usesSecondaryYScale(series),
499
+ useSecondaryYScale: usesSecondaryYScale(series, input.layout),
503
500
  };
504
501
  });
505
502
  })
506
503
  .flat();
507
504
  var yMinMaxValues = findNumericMinMaxOfY(chartData);
508
- 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;
509
506
  var numDataPoints = chartData.reduce(function (total, lineChartPoints) { return total + lineChartPoints.data.length; }, 0);
510
507
  var chartProps = {
511
508
  chartTitle: chartTitle,
512
509
  lineChartData: chartData,
513
510
  };
511
+ var scatterChartProps = {
512
+ chartTitle: chartTitle,
513
+ scatterChartData: chartData,
514
+ };
514
515
  if (isAreaChart) {
515
- 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 });
516
517
  }
517
518
  else {
518
- 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 });
519
520
  }
520
521
  };
521
- export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, colorwayType, isDarkTheme) {
522
+ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
522
523
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
523
- 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;
524
525
  var colorScale = undefined;
525
526
  var chartData = input.data
526
527
  .map(function (series, index) {
@@ -587,7 +588,7 @@ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, co
587
588
  roundCorners: true,
588
589
  };
589
590
  };
590
- export var transformPlotlyJsonToHeatmapProps = function (input) {
591
+ export var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
591
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;
592
593
  var firstData = input.data[0];
593
594
  var heatmapDataPoints = [];
@@ -717,7 +718,7 @@ export var transformPlotlyJsonToHeatmapProps = function (input) {
717
718
  showYAxisLablesTooltip: true,
718
719
  };
719
720
  };
720
- export var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwayType, isDarkTheme) {
721
+ export var transformPlotlyJsonToSankeyProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
721
722
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
722
723
  var _m = input.data[0], link = _m.link, node = _m.node;
723
724
  var validLinks = ((_a = link === null || link === void 0 ? void 0 : link.value) !== null && _a !== void 0 ? _a : [])
@@ -764,7 +765,7 @@ export var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwa
764
765
  enableReflow: true,
765
766
  };
766
767
  };
767
- export var transformPlotlyJsonToGaugeProps = function (input, colorMap, colorwayType, isDarkTheme) {
768
+ export var transformPlotlyJsonToGaugeProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
768
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;
769
770
  var firstData = input.data[0];
770
771
  var stepsColors = ((_a = firstData.gauge) === null || _a === void 0 ? void 0 : _a.steps) ? firstData.gauge.steps.map(function (step) { return step.color; }) : undefined;
@@ -863,7 +864,7 @@ var formatValue = function (value, colIndex, cells) {
863
864
  }
864
865
  return "".concat(prefix !== null && prefix !== void 0 ? prefix : '').concat(formatted).concat(suffix !== null && suffix !== void 0 ? suffix : '');
865
866
  };
866
- export var transformPlotlyJsonToChartTableProps = function (input, colorMap, isDarkTheme) {
867
+ export var transformPlotlyJsonToChartTableProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
867
868
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
868
869
  var tableData = input.data[0];
869
870
  var normalizeHeaders = function (values, header) {
@@ -1066,11 +1067,6 @@ function getLineOptions(line) {
1066
1067
  }
1067
1068
  return Object.keys(lineOptions).length > 0 ? lineOptions : undefined;
1068
1069
  }
1069
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1070
- export var isStringArray = function (arr) {
1071
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1072
- return isArrayOfType(arr, function (value) { return typeof value === 'string' || value === null; });
1073
- };
1074
1070
  // TODO: Use binary search to find the appropriate bin for numeric value.
1075
1071
  var findBinIndex = function (bins, value, isString) {
1076
1072
  if (typeof value === 'undefined' || value === null) {
@@ -1165,7 +1161,47 @@ var precisionRound = function (value, precision) {
1165
1161
  var factor = Math.pow(10, precision);
1166
1162
  return Math.round(value * factor) / factor;
1167
1163
  };
1168
- 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) {
1169
1205
  var legends = [];
1170
1206
  if (data.length === 1) {
1171
1207
  legends.push(data[0].name || '');
@@ -1175,10 +1211,11 @@ var getLegendProps = function (data, layout) {
1175
1211
  legends.push(series.name || "Series ".concat(index + 1));
1176
1212
  });
1177
1213
  }
1178
- 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);
1179
1216
  return {
1180
1217
  legends: legends,
1181
- 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,
1182
1219
  };
1183
1220
  };
1184
1221
  export var getNumberAtIndexOrDefault = function (data, index) {
@@ -1210,4 +1247,157 @@ export var getValidXYRanges = function (series) {
1210
1247
  }
1211
1248
  return ranges;
1212
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
+ };
1213
1403
  //# sourceMappingURL=PlotlySchemaAdapter.js.map