@fluentui/react-charting 5.23.91 → 5.23.93

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 (50) hide show
  1. package/CHANGELOG.json +61 -1
  2. package/CHANGELOG.md +25 -2
  3. package/dist/react-charting.d.ts +5 -1
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +2 -0
  7. package/lib/components/DeclarativeChart/DeclarativeChart.js +9 -2
  8. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  9. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +4 -1
  10. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +239 -94
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  12. package/lib/components/LineChart/LineChart.base.d.ts +2 -0
  13. package/lib/components/LineChart/LineChart.base.js +58 -17
  14. package/lib/components/LineChart/LineChart.base.js.map +1 -1
  15. package/lib/components/LineChart/LineChart.types.d.ts +1 -1
  16. package/lib/components/LineChart/LineChart.types.js.map +1 -1
  17. package/lib/types/IDataPoint.d.ts +4 -0
  18. package/lib/types/IDataPoint.js.map +1 -1
  19. package/lib/utilities/image-export-utils.js +18 -1
  20. package/lib/utilities/image-export-utils.js.map +1 -1
  21. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +9 -2
  22. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  23. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +4 -1
  24. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +243 -95
  25. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  26. package/lib-amd/components/LineChart/LineChart.base.d.ts +2 -0
  27. package/lib-amd/components/LineChart/LineChart.base.js +58 -17
  28. package/lib-amd/components/LineChart/LineChart.base.js.map +1 -1
  29. package/lib-amd/components/LineChart/LineChart.types.d.ts +1 -1
  30. package/lib-amd/components/LineChart/LineChart.types.js.map +1 -1
  31. package/lib-amd/types/IDataPoint.d.ts +4 -0
  32. package/lib-amd/types/IDataPoint.js.map +1 -1
  33. package/lib-amd/utilities/image-export-utils.js +18 -1
  34. package/lib-amd/utilities/image-export-utils.js.map +1 -1
  35. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +9 -2
  36. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  37. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +4 -1
  38. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +243 -95
  39. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  40. package/lib-commonjs/components/LineChart/LineChart.base.d.ts +2 -0
  41. package/lib-commonjs/components/LineChart/LineChart.base.js +58 -17
  42. package/lib-commonjs/components/LineChart/LineChart.base.js.map +1 -1
  43. package/lib-commonjs/components/LineChart/LineChart.types.d.ts +1 -1
  44. package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
  45. package/lib-commonjs/types/IDataPoint.d.ts +4 -0
  46. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  47. package/lib-commonjs/utilities/image-export-utils.js +18 -1
  48. package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/components/LineChart/LineChart.types.ts +1 -1
@@ -53,7 +53,8 @@ var isMonth = function (possiblyMonthValue) {
53
53
  return parseFullMonth(possiblyMonthValue) !== null || parseShortMonth(possiblyMonthValue) !== null;
54
54
  };
55
55
  export var isMonthArray = function (data) {
56
- return isArrayOfType(data, isMonth);
56
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
57
+ return isArrayOfType(data, function (value) { return isMonth(value) || value === null; });
57
58
  };
58
59
  function getTitles(layout) {
59
60
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -74,19 +75,29 @@ export var correctYearMonth = function (xValues) {
74
75
  var parsedDate = "".concat(possiblyMonthValue, " 01, ").concat(presentYear);
75
76
  return isDate(parsedDate) ? new Date(parsedDate) : null;
76
77
  });
77
- for (var i = dates.length - 1; i > 0; i--) {
78
- var currentMonth = dates[i].getMonth();
79
- var previousMonth = dates[i - 1].getMonth();
80
- var currentYear = dates[i].getFullYear();
81
- var previousYear = dates[i - 1].getFullYear();
78
+ var filteredDateIndexPairs = dates.map(function (date, index) { return [date, index]; }).filter(function (_a) {
79
+ var date = _a[0];
80
+ return date !== null;
81
+ });
82
+ for (var i = filteredDateIndexPairs.length - 1; i > 0; i--) {
83
+ var currentDate = filteredDateIndexPairs[i][0];
84
+ var previousDate = filteredDateIndexPairs[i - 1][0];
85
+ var currentMonth = currentDate.getMonth();
86
+ var previousMonth = previousDate.getMonth();
87
+ var currentYear = currentDate.getFullYear();
88
+ var previousYear = previousDate.getFullYear();
82
89
  if (previousMonth >= currentMonth) {
83
- dates[i - 1].setFullYear(dates[i].getFullYear() - 1);
90
+ filteredDateIndexPairs[i - 1][0].setFullYear(currentYear - 1);
84
91
  }
85
92
  else if (previousYear > currentYear) {
86
- dates[i - 1].setFullYear(currentYear);
93
+ filteredDateIndexPairs[i - 1][0].setFullYear(currentYear);
87
94
  }
95
+ dates[filteredDateIndexPairs[i - 1][1]] = filteredDateIndexPairs[i - 1][0];
88
96
  }
89
97
  xValues = xValues.map(function (month, index) {
98
+ if (dates[index] === null) {
99
+ return null;
100
+ }
90
101
  return "".concat(month, " 01, ").concat(dates[index].getFullYear());
91
102
  });
92
103
  return xValues;
@@ -145,20 +156,22 @@ export var transformPlotlyJsonToDonutProps = function (input, colorMap, colorway
145
156
  var colors = 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 = firstData === null || firstData === void 0 ? void 0 : firstData.marker) === null || _d === void 0 ? void 0 : _d.colors, colorMap, isDarkTheme);
146
157
  var mapLegendToDataPoint = {};
147
158
  (_e = firstData.labels) === null || _e === void 0 ? void 0 : _e.forEach(function (label, index) {
148
- var _a;
159
+ var value = getNumberAtIndexOrDefault(firstData.values, index);
160
+ if (isInvalidValue(value) || value < 0) {
161
+ return;
162
+ }
163
+ var legend = "".concat(label);
149
164
  // resolve color for each legend from the extracted colors
150
- var color = resolveColor(colors, index, label, colorMap, isDarkTheme);
151
- //ToDo how to handle string data?
152
- var value = typeof ((_a = firstData.values) === null || _a === void 0 ? void 0 : _a[index]) === 'number' ? firstData.values[index] : 1;
153
- if (!mapLegendToDataPoint[label]) {
154
- mapLegendToDataPoint[label] = {
155
- legend: label,
165
+ var color = resolveColor(colors, index, legend, colorMap, isDarkTheme);
166
+ if (!mapLegendToDataPoint[legend]) {
167
+ mapLegendToDataPoint[legend] = {
168
+ legend: legend,
156
169
  data: value,
157
170
  color: color,
158
171
  };
159
172
  }
160
173
  else {
161
- mapLegendToDataPoint[label].data += value;
174
+ mapLegendToDataPoint[legend].data += value;
162
175
  }
163
176
  });
164
177
  var width = (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.width) !== null && _g !== void 0 ? _g : 440;
@@ -194,44 +207,61 @@ export var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayT
194
207
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
195
208
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
196
209
  input.data.forEach(function (series, index1) {
197
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
210
+ var _a, _b, _c, _d, _e, _f, _g, _h;
198
211
  var isXYearCategory = isYearArray(series.x); // Consider year as categorical not numeric continuous axis
199
212
  // extract bar colors for each series only once
200
213
  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);
201
214
  // extract line colors for each series only once
202
215
  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);
203
- (_j = series.x) === null || _j === void 0 ? void 0 : _j.forEach(function (x, index2) {
204
- var _a, _b, _c;
205
- if (!mapXToDataPoints[x]) {
206
- mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
207
- }
208
- var legend = legends[index1];
209
- // resolve color for each legend's bars from the extracted colors
210
- var color = resolveColor(extractedBarColors, index1, legend, colorMap, isDarkTheme);
211
- var yVal = (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2]) !== null && _b !== void 0 ? _b : 0;
212
- if (series.type === 'bar') {
213
- mapXToDataPoints[x].chartData.push({
214
- legend: legend,
215
- data: yVal,
216
- color: color,
217
- });
218
- yMaxValue = Math.max(yMaxValue, yVal);
219
- }
220
- else if (series.type === 'scatter' || !!fallbackVSBC) {
221
- var lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
222
- var lineOptions = getLineOptions(series.line);
223
- var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
224
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
225
- mapXToDataPoints[x].lineData.push(__assign(__assign({ legend: legend, legendShape: legendShape, y: yVal, color: lineColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
226
- if (!usesSecondaryYScale(series)) {
216
+ var validXYRanges = getValidXYRanges(series);
217
+ validXYRanges.forEach(function (_a, rangeIdx) {
218
+ var rangeStart = _a[0], rangeEnd = _a[1];
219
+ var rangeXValues = series.x.slice(rangeStart, rangeEnd);
220
+ var rangeYValues = series.y.slice(rangeStart, rangeEnd);
221
+ rangeXValues.forEach(function (x, index2) {
222
+ var _a, _b;
223
+ if (!mapXToDataPoints[x]) {
224
+ mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
225
+ }
226
+ var legend = legends[index1];
227
+ // resolve color for each legend's bars from the extracted colors
228
+ var color = resolveColor(extractedBarColors, index1, legend, colorMap, isDarkTheme);
229
+ var yVal = rangeYValues[index2];
230
+ if (series.type === 'bar') {
231
+ mapXToDataPoints[x].chartData.push({
232
+ legend: legend,
233
+ data: yVal,
234
+ color: color,
235
+ });
227
236
  yMaxValue = Math.max(yMaxValue, yVal);
228
- yMinValue = Math.min(yMinValue, yVal);
229
237
  }
230
- }
238
+ else if (series.type === 'scatter' || !!fallbackVSBC) {
239
+ var lineColor = resolveColor(extractedLineColors, index1, legend, colorMap, isDarkTheme);
240
+ var lineOptions = getLineOptions(series.line);
241
+ var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
242
+ var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
243
+ ? 'dottedLine'
244
+ : ((_b = series.mode) === null || _b === void 0 ? void 0 : _b.includes('markers'))
245
+ ? 'circle'
246
+ : 'default';
247
+ mapXToDataPoints[x].lineData.push({
248
+ legend: legend + (validXYRanges.length > 1 ? ".".concat(rangeIdx + 1) : ''),
249
+ legendShape: legendShape,
250
+ y: yVal,
251
+ color: lineColor,
252
+ lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
253
+ useSecondaryYScale: usesSecondaryYScale(series),
254
+ });
255
+ if (!usesSecondaryYScale(series)) {
256
+ yMaxValue = Math.max(yMaxValue, yVal);
257
+ yMinValue = Math.min(yMinValue, yVal);
258
+ }
259
+ }
260
+ });
231
261
  });
232
262
  });
233
263
  var _e = getTitles(input.layout), chartTitle = _e.chartTitle, xAxisTitle = _e.xAxisTitle, yAxisTitle = _e.yAxisTitle;
234
- 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 });
264
+ 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 });
235
265
  };
236
266
  export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
237
267
  var _a, _b, _c;
@@ -243,7 +273,10 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
243
273
  // extract colors for each series only once
244
274
  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);
245
275
  (_e = series.x) === null || _e === void 0 ? void 0 : _e.forEach(function (x, xIndex) {
246
- var _a, _b;
276
+ var _a;
277
+ if (isInvalidValue(x) || isInvalidValue((_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex])) {
278
+ return;
279
+ }
247
280
  if (!mapXToDataPoints[x]) {
248
281
  mapXToDataPoints[x] = { name: x.toString(), series: [] };
249
282
  }
@@ -253,7 +286,7 @@ export var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayT
253
286
  var color = resolveColor(extractedColors, index1, legend, colorMap, isDarkTheme);
254
287
  mapXToDataPoints[x].series.push({
255
288
  key: legend,
256
- data: (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex]) !== null && _b !== void 0 ? _b : 0,
289
+ data: series.y[xIndex],
257
290
  xAxisCalloutData: x,
258
291
  color: color,
259
292
  legend: legend,
@@ -276,17 +309,26 @@ export var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayTy
276
309
  }
277
310
  // extract colors for each series only once
278
311
  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);
279
- var isXString = isStringArray(series.x);
312
+ var xValues = [];
313
+ var yValues = [];
314
+ series.x.forEach(function (xVal, index) {
315
+ var yVal = getNumberAtIndexOrDefault(series.y, index);
316
+ if (isInvalidValue(xVal) || isInvalidValue(yVal)) {
317
+ return;
318
+ }
319
+ xValues.push(xVal);
320
+ yValues.push(yVal);
321
+ });
322
+ var isXString = isStringArray(xValues);
280
323
  // TODO: In case of a single bin, add an empty bin of the same size to prevent the
281
324
  // default bar width from being used and ensure the bar spans the full intended range.
282
- var xBins = createBins(series.x, (_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);
325
+ 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);
283
326
  var yBins = xBins.map(function () { return []; });
284
327
  var total = 0;
285
- series.x.forEach(function (xVal, index) {
286
- var _a, _b;
328
+ xValues.forEach(function (xVal, index) {
287
329
  var binIdx = findBinIndex(xBins, xVal, isXString);
288
330
  if (binIdx !== -1) {
289
- yBins[binIdx].push((_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : 1);
331
+ yBins[binIdx].push(yValues[index]);
290
332
  }
291
333
  });
292
334
  var y = yBins.map(function (bin) {
@@ -325,12 +367,13 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
325
367
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, isAreaChart ? 0 : undefined, isAreaChart ? 0 : undefined);
326
368
  var mode = 'tonexty';
327
369
  var _g = getLegendProps(input.data, input.layout), legends = _g.legends, hideLegend = _g.hideLegend;
328
- var chartData = input.data.map(function (series, index) {
329
- var _a, _b, _c, _d, _e, _f;
370
+ var chartData = input.data
371
+ .map(function (series, index) {
372
+ var _a, _b, _c, _d, _e, _f, _g;
330
373
  // extract colors for each series only once
331
374
  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, isScatterMarkers ? (_d = series.marker) === null || _d === void 0 ? void 0 : _d.color : (_e = series.line) === null || _e === void 0 ? void 0 : _e.color, colorMap, isDarkTheme);
332
375
  var xValues = series.x;
333
- var isString = typeof xValues[0] === 'string';
376
+ var isString = isStringArray(xValues);
334
377
  var isXDate = isDateArray(xValues);
335
378
  var isXNumber = isNumberArray(xValues);
336
379
  var legend = legends[index];
@@ -339,27 +382,50 @@ export var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart
339
382
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
340
383
  var lineOptions = getLineOptions(series.line);
341
384
  var dashType = ((_f = series.line) === null || _f === void 0 ? void 0 : _f.dash) || 'solid';
342
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
343
- return __assign(__assign({ legend: legend, legendShape: legendShape, data: xValues.map(function (x, i) {
344
- var _a, _b;
345
- return (__assign({ x: isString ? (isXDate ? new Date(x) : isXNumber ? parseFloat(x) : x) : x, y: series.y[i] }, (Array.isArray((_a = series.marker) === null || _a === void 0 ? void 0 : _a.size)
346
- ? { markerSize: series.marker.size[i] }
347
- : typeof ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size) === 'number'
348
- ? { markerSize: series.marker.size }
349
- : {})));
350
- }), color: seriesColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) });
351
- });
385
+ var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
386
+ ? 'dottedLine'
387
+ : ((_g = series.mode) === null || _g === void 0 ? void 0 : _g.includes('markers'))
388
+ ? 'circle'
389
+ : 'default';
390
+ var validXYRanges = getValidXYRanges(series);
391
+ return validXYRanges.map(function (_a, rangeIdx) {
392
+ var _b;
393
+ var rangeStart = _a[0], rangeEnd = _a[1];
394
+ var rangeXValues = xValues.slice(rangeStart, rangeEnd);
395
+ var rangeYValues = series.y.slice(rangeStart, rangeEnd);
396
+ var markerSizes = isArrayOrTypedArray((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size)
397
+ ? series.marker.size.slice(rangeStart, rangeEnd)
398
+ : [];
399
+ return {
400
+ legend: legend,
401
+ legendShape: legendShape,
402
+ data: rangeXValues.map(function (x, i) {
403
+ var _a, _b;
404
+ 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)
405
+ ? { markerSize: markerSizes[i] }
406
+ : typeof ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size) === 'number'
407
+ ? { markerSize: series.marker.size }
408
+ : {})));
409
+ }),
410
+ color: seriesColor,
411
+ lineOptions: __assign(__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
412
+ useSecondaryYScale: usesSecondaryYScale(series),
413
+ };
414
+ });
415
+ })
416
+ .flat();
352
417
  var yMinMaxValues = findNumericMinMaxOfY(chartData);
353
418
  var _h = getTitles(input.layout), chartTitle = _h.chartTitle, xAxisTitle = _h.xAxisTitle, yAxisTitle = _h.yAxisTitle;
419
+ var numDataPoints = chartData.reduce(function (total, lineChartPoints) { return total + lineChartPoints.data.length; }, 0);
354
420
  var chartProps = {
355
421
  chartTitle: chartTitle,
356
422
  lineChartData: chartData,
357
423
  };
358
424
  if (isAreaChart) {
359
- 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 });
425
+ 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 });
360
426
  }
361
427
  else {
362
- 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 });
428
+ 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 });
363
429
  }
364
430
  };
365
431
  export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, colorwayType, isDarkTheme) {
@@ -373,14 +439,20 @@ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, co
373
439
  var legend = legends[index];
374
440
  // resolve color for each legend's bars from the extracted colors
375
441
  var color = resolveColor(extractedColors, index, legend, colorMap, isDarkTheme);
376
- return series.y.map(function (yValue, i) {
442
+ return series.y
443
+ .map(function (yValue, i) {
444
+ var _a;
445
+ if (isInvalidValue((_a = series.x) === null || _a === void 0 ? void 0 : _a[i]) || isInvalidValue(yValue)) {
446
+ return null;
447
+ }
377
448
  return {
378
449
  x: series.x[i],
379
450
  y: yValue,
380
451
  legend: legend,
381
452
  color: color,
382
453
  };
383
- });
454
+ })
455
+ .filter(function (point) { return point !== null; });
384
456
  })
385
457
  .reverse()
386
458
  .flat()
@@ -418,24 +490,36 @@ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, co
418
490
  };
419
491
  };
420
492
  export var transformPlotlyJsonToHeatmapProps = function (input) {
421
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
493
+ 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;
422
494
  var firstData = input.data[0];
423
495
  var heatmapDataPoints = [];
424
496
  var zMin = Number.POSITIVE_INFINITY;
425
497
  var zMax = Number.NEGATIVE_INFINITY;
426
498
  if (firstData.type === 'histogram2d') {
427
- var isXString_1 = isStringArray(firstData.x);
428
- var isYString_1 = isStringArray(firstData.y);
429
- var xBins_1 = createBins(firstData.x, (_a = firstData.xbins) === null || _a === void 0 ? void 0 : _a.start, (_b = firstData.xbins) === null || _b === void 0 ? void 0 : _b.end, (_c = firstData.xbins) === null || _c === void 0 ? void 0 : _c.size);
430
- var yBins_1 = createBins(firstData.y, (_d = firstData.ybins) === null || _d === void 0 ? void 0 : _d.start, (_e = firstData.ybins) === null || _e === void 0 ? void 0 : _e.end, (_f = firstData.ybins) === null || _f === void 0 ? void 0 : _f.size);
499
+ var xValues_1 = [];
500
+ var yValues_1 = [];
501
+ var zValues_1 = [];
502
+ (_a = firstData.x) === null || _a === void 0 ? void 0 : _a.forEach(function (xVal, index) {
503
+ var _a;
504
+ var zVal = getNumberAtIndexOrDefault(firstData.z, index);
505
+ if (isInvalidValue(xVal) || isInvalidValue((_a = firstData.y) === null || _a === void 0 ? void 0 : _a[index]) || isInvalidValue(zVal)) {
506
+ return;
507
+ }
508
+ xValues_1.push(xVal);
509
+ yValues_1.push(firstData.y[index]);
510
+ zValues_1.push(zVal);
511
+ });
512
+ var isXString_1 = isStringArray(xValues_1);
513
+ var isYString_1 = isStringArray(yValues_1);
514
+ var xBins_1 = createBins(xValues_1, (_b = firstData.xbins) === null || _b === void 0 ? void 0 : _b.start, (_c = firstData.xbins) === null || _c === void 0 ? void 0 : _c.end, (_d = firstData.xbins) === null || _d === void 0 ? void 0 : _d.size);
515
+ var yBins_1 = createBins(yValues_1, (_e = firstData.ybins) === null || _e === void 0 ? void 0 : _e.start, (_f = firstData.ybins) === null || _f === void 0 ? void 0 : _f.end, (_g = firstData.ybins) === null || _g === void 0 ? void 0 : _g.size);
431
516
  var zBins_1 = yBins_1.map(function () { return xBins_1.map(function () { return []; }); });
432
517
  var total_1 = 0;
433
- (_g = firstData.x) === null || _g === void 0 ? void 0 : _g.forEach(function (xVal, index) {
434
- var _a, _b, _c;
518
+ xValues_1.forEach(function (xVal, index) {
435
519
  var xBinIdx = findBinIndex(xBins_1, xVal, isXString_1);
436
- var yBinIdx = findBinIndex(yBins_1, (_a = firstData.y) === null || _a === void 0 ? void 0 : _a[index], isYString_1);
520
+ var yBinIdx = findBinIndex(yBins_1, yValues_1[index], isYString_1);
437
521
  if (xBinIdx !== -1 && yBinIdx !== -1) {
438
- zBins_1[yBinIdx][xBinIdx].push((_c = (_b = firstData.z) === null || _b === void 0 ? void 0 : _b[index]) !== null && _c !== void 0 ? _c : 1);
522
+ zBins_1[yBinIdx][xBinIdx].push(zValues_1[index]);
439
523
  }
440
524
  });
441
525
  var z_1 = zBins_1.map(function (row) {
@@ -493,13 +577,31 @@ export var transformPlotlyJsonToHeatmapProps = function (input) {
493
577
  getColorFromToken(DataVizPalette.color2),
494
578
  getColorFromToken(DataVizPalette.color3),
495
579
  ];
496
- var domainValuesForColorScale = Array.isArray(firstData.colorscale)
497
- ? firstData.colorscale.map(function (arr) { return arr[0] * (zMax - zMin) + zMin; })
580
+ var colorscale = (_0 = (_u = (_q = (_m = (_k = firstData === null || firstData === void 0 ? void 0 : firstData.colorscale) !== null && _k !== void 0 ? _k : (_l = input.layout) === null || _l === void 0 ? void 0 : _l.colorscale) !== null && _m !== void 0 ? _m : (_p = (_o = input.layout) === null || _o === void 0 ? void 0 : _o.coloraxis) === null || _p === void 0 ? void 0 : _p.colorscale) !== null && _q !== void 0 ? _q : (_t = (_s = (_r = input.layout) === null || _r === void 0 ? void 0 : _r.template) === null || _s === void 0 ? void 0 : _s.layout) === null || _t === void 0 ? void 0 : _t.colorscale) !== null && _u !== void 0 ? _u : (firstData.type === 'histogram2d' && ((_z = (_y = (_x = (_w = (_v = input.layout) === null || _v === void 0 ? void 0 : _v.template) === null || _w === void 0 ? void 0 : _w.data) === null || _x === void 0 ? void 0 : _x.histogram2d) === null || _y === void 0 ? void 0 : _y[0]) === null || _z === void 0 ? void 0 : _z.colorscale))) !== null && _0 !== void 0 ? _0 : (_5 = (_4 = (_3 = (_2 = (_1 = input.layout) === null || _1 === void 0 ? void 0 : _1.template) === null || _2 === void 0 ? void 0 : _2.data) === null || _3 === void 0 ? void 0 : _3.heatmap) === null || _4 === void 0 ? void 0 : _4[0]) === null || _5 === void 0 ? void 0 : _5.colorscale;
581
+ // determine if the types diverging, sequential or sequentialminus are present in colorscale
582
+ if (colorscale &&
583
+ typeof colorscale === 'object' &&
584
+ ('diverging' in colorscale || 'sequential' in colorscale || 'sequentialminus' in colorscale)) {
585
+ var isDivergent = zMin < 0 && zMax > 0; // Data spans both positive and negative values
586
+ var isSequential = zMin >= 0; // Data is entirely positive
587
+ var isSequentialMinus = zMax <= 0; // Data is entirely negative
588
+ if (isDivergent) {
589
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.diverging;
590
+ }
591
+ else if (isSequential) {
592
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequential;
593
+ }
594
+ else if (isSequentialMinus) {
595
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequentialminus;
596
+ }
597
+ }
598
+ var domainValuesForColorScale = Array.isArray(colorscale)
599
+ ? colorscale.map(function (arr) { return arr[0] * (zMax - zMin) + zMin; })
498
600
  : defaultDomain;
499
- var rangeValuesForColorScale = Array.isArray(firstData.colorscale)
500
- ? firstData.colorscale.map(function (arr) { return arr[1]; })
601
+ var rangeValuesForColorScale = Array.isArray(colorscale)
602
+ ? colorscale.map(function (arr) { return arr[1]; })
501
603
  : defaultRange;
502
- var _o = getTitles(input.layout), chartTitle = _o.chartTitle, xAxisTitle = _o.xAxisTitle, yAxisTitle = _o.yAxisTitle;
604
+ var _9 = getTitles(input.layout), chartTitle = _9.chartTitle, xAxisTitle = _9.xAxisTitle, yAxisTitle = _9.yAxisTitle;
503
605
  return {
504
606
  data: [heatmapData],
505
607
  domainValuesForColorScale: domainValuesForColorScale,
@@ -510,8 +612,8 @@ export var transformPlotlyJsonToHeatmapProps = function (input) {
510
612
  xAxisTitle: xAxisTitle,
511
613
  yAxisTitle: yAxisTitle,
512
614
  sortOrder: 'none',
513
- width: (_k = input.layout) === null || _k === void 0 ? void 0 : _k.width,
514
- height: (_m = (_l = input.layout) === null || _l === void 0 ? void 0 : _l.height) !== null && _m !== void 0 ? _m : 350,
615
+ width: (_6 = input.layout) === null || _6 === void 0 ? void 0 : _6.width,
616
+ height: (_8 = (_7 = input.layout) === null || _7 === void 0 ? void 0 : _7.height) !== null && _8 !== void 0 ? _8 : 350,
515
617
  hideTickOverlap: true,
516
618
  noOfCharsToTruncate: 20,
517
619
  showYAxisLablesTooltip: true,
@@ -521,13 +623,19 @@ export var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwa
521
623
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
522
624
  var _m = input.data[0], link = _m.link, node = _m.node;
523
625
  var validLinks = ((_a = link === null || link === void 0 ? void 0 : link.value) !== null && _a !== void 0 ? _a : [])
524
- .map(function (val, index) { return ({
525
- value: val,
526
- source: link === null || link === void 0 ? void 0 : link.source[index],
527
- target: link === null || link === void 0 ? void 0 : link.target[index],
528
- }); })
626
+ .map(function (val, index) {
627
+ var _a, _b;
628
+ if (isInvalidValue(val) || isInvalidValue((_a = link === null || link === void 0 ? void 0 : link.source) === null || _a === void 0 ? void 0 : _a[index]) || isInvalidValue((_b = link === null || link === void 0 ? void 0 : link.target) === null || _b === void 0 ? void 0 : _b[index])) {
629
+ return null;
630
+ }
631
+ return {
632
+ value: val,
633
+ source: link === null || link === void 0 ? void 0 : link.source[index],
634
+ target: link === null || link === void 0 ? void 0 : link.target[index],
635
+ };
636
+ })
529
637
  // Filter out negative nodes, unequal nodes and self-references (circular links)
530
- .filter(function (x) { return x.source >= 0 && x.target >= 0 && x.source !== x.target; });
638
+ .filter(function (x) { return x !== null && x.source >= 0 && x.target >= 0 && x.source !== x.target; });
531
639
  var extractedNodeColors = extractColor((_d = (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.template) === null || _c === void 0 ? void 0 : _c.layout) === null || _d === void 0 ? void 0 : _d.colorway, colorwayType, node === null || node === void 0 ? void 0 : node.color, colorMap, isDarkTheme);
532
640
  var sankeyChartData = {
533
641
  nodes: (_e = node.label) === null || _e === void 0 ? void 0 : _e.map(function (label, index) {
@@ -669,16 +777,20 @@ export var transformPlotlyJsonToChartTableProps = function (input, colorMap, isD
669
777
  };
670
778
  };
671
779
  export var projectPolarToCartesian = function (input) {
780
+ var _a, _b, _c, _d;
672
781
  var projection = __assign({}, input);
673
782
  for (var sindex = 0; sindex < input.data.length; sindex++) {
674
783
  var series = input.data[sindex];
675
784
  series.x = [];
676
785
  series.y = [];
677
- for (var ptindex = 0; ptindex < series.r.length; ptindex++) {
786
+ for (var ptindex = 0; ptindex < ((_b = (_a = series.r) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); ptindex++) {
787
+ if (isInvalidValue((_c = series.theta) === null || _c === void 0 ? void 0 : _c[ptindex]) || isInvalidValue((_d = series.r) === null || _d === void 0 ? void 0 : _d[ptindex])) {
788
+ continue;
789
+ }
678
790
  var thetaRad = (series.theta[ptindex] * Math.PI) / 180;
679
791
  var radius = series.r[ptindex];
680
- series.x[ptindex] = radius * Math.cos(thetaRad);
681
- series.y[ptindex] = radius * Math.sin(thetaRad);
792
+ series.x.push(radius * Math.cos(thetaRad));
793
+ series.y.push(radius * Math.sin(thetaRad));
682
794
  }
683
795
  projection.data[sindex] = series;
684
796
  }
@@ -764,7 +876,7 @@ function getLineOptions(line) {
764
876
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
765
877
  var isStringArray = function (arr) {
766
878
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
767
- return isArrayOfType(arr, function (value) { return typeof value === 'string'; });
879
+ return isArrayOfType(arr, function (value) { return typeof value === 'string' || value === null; });
768
880
  };
769
881
  // TODO: Use binary search to find the appropriate bin for numeric value.
770
882
  var findBinIndex = function (bins, value, isString) {
@@ -876,4 +988,37 @@ var getLegendProps = function (data, layout) {
876
988
  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,
877
989
  };
878
990
  };
991
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
992
+ export var isInvalidValue = function (value) {
993
+ return typeof value === 'undefined' || value === null || (typeof value === 'number' && !isFinite(value));
994
+ };
995
+ export var getNumberAtIndexOrDefault = function (data, index) {
996
+ if (isArrayOrTypedArray(data)) {
997
+ if (typeof data[index] !== 'number' || !isFinite(data[index])) {
998
+ return;
999
+ }
1000
+ return data[index];
1001
+ }
1002
+ return 1;
1003
+ };
1004
+ export var getValidXYRanges = function (series) {
1005
+ if (!isArrayOrTypedArray(series.x) || !isArrayOrTypedArray(series.y)) {
1006
+ return [];
1007
+ }
1008
+ var ranges = [];
1009
+ var start = 0;
1010
+ var end = 0;
1011
+ for (; end < series.x.length; end++) {
1012
+ if (isInvalidValue(series.x[end]) || isInvalidValue(series.y[end])) {
1013
+ if (end - start > 0) {
1014
+ ranges.push([start, end]);
1015
+ }
1016
+ start = end + 1;
1017
+ }
1018
+ }
1019
+ if (end - start > 0) {
1020
+ ranges.push([start, end]);
1021
+ }
1022
+ return ranges;
1023
+ };
879
1024
  //# sourceMappingURL=PlotlySchemaAdapter.js.map