@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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findArrayAttributes = exports.projectPolarToCartesian = exports.transformPlotlyJsonToChartTableProps = exports.transformPlotlyJsonToGaugeProps = exports.transformPlotlyJsonToSankeyProps = exports.transformPlotlyJsonToHeatmapProps = exports.transformPlotlyJsonToHorizontalBarWithAxisProps = exports.transformPlotlyJsonToScatterChartProps = exports.transformPlotlyJsonToVBCProps = exports.transformPlotlyJsonToGVBCProps = exports.transformPlotlyJsonToVSBCProps = exports.transformPlotlyJsonToDonutProps = exports._getGaugeAxisColor = exports.correctYearMonth = exports.isMonthArray = void 0;
3
+ exports.getValidXYRanges = exports.getNumberAtIndexOrDefault = exports.isInvalidValue = exports.findArrayAttributes = exports.projectPolarToCartesian = exports.transformPlotlyJsonToChartTableProps = exports.transformPlotlyJsonToGaugeProps = exports.transformPlotlyJsonToSankeyProps = exports.transformPlotlyJsonToHeatmapProps = exports.transformPlotlyJsonToHorizontalBarWithAxisProps = exports.transformPlotlyJsonToScatterChartProps = exports.transformPlotlyJsonToVBCProps = exports.transformPlotlyJsonToGVBCProps = exports.transformPlotlyJsonToVSBCProps = exports.transformPlotlyJsonToDonutProps = exports._getGaugeAxisColor = exports.correctYearMonth = exports.isMonthArray = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var d3_array_1 = require("d3-array");
6
6
  var d3_scale_1 = require("d3-scale");
@@ -56,7 +56,8 @@ var isMonth = function (possiblyMonthValue) {
56
56
  return parseFullMonth(possiblyMonthValue) !== null || parseShortMonth(possiblyMonthValue) !== null;
57
57
  };
58
58
  var isMonthArray = function (data) {
59
- return (0, chart_utilities_1.isArrayOfType)(data, isMonth);
59
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
60
+ return (0, chart_utilities_1.isArrayOfType)(data, function (value) { return isMonth(value) || value === null; });
60
61
  };
61
62
  exports.isMonthArray = isMonthArray;
62
63
  function getTitles(layout) {
@@ -78,19 +79,29 @@ var correctYearMonth = function (xValues) {
78
79
  var parsedDate = "".concat(possiblyMonthValue, " 01, ").concat(presentYear);
79
80
  return (0, chart_utilities_1.isDate)(parsedDate) ? new Date(parsedDate) : null;
80
81
  });
81
- for (var i = dates.length - 1; i > 0; i--) {
82
- var currentMonth = dates[i].getMonth();
83
- var previousMonth = dates[i - 1].getMonth();
84
- var currentYear = dates[i].getFullYear();
85
- var previousYear = dates[i - 1].getFullYear();
82
+ var filteredDateIndexPairs = dates.map(function (date, index) { return [date, index]; }).filter(function (_a) {
83
+ var date = _a[0];
84
+ return date !== null;
85
+ });
86
+ for (var i = filteredDateIndexPairs.length - 1; i > 0; i--) {
87
+ var currentDate = filteredDateIndexPairs[i][0];
88
+ var previousDate = filteredDateIndexPairs[i - 1][0];
89
+ var currentMonth = currentDate.getMonth();
90
+ var previousMonth = previousDate.getMonth();
91
+ var currentYear = currentDate.getFullYear();
92
+ var previousYear = previousDate.getFullYear();
86
93
  if (previousMonth >= currentMonth) {
87
- dates[i - 1].setFullYear(dates[i].getFullYear() - 1);
94
+ filteredDateIndexPairs[i - 1][0].setFullYear(currentYear - 1);
88
95
  }
89
96
  else if (previousYear > currentYear) {
90
- dates[i - 1].setFullYear(currentYear);
97
+ filteredDateIndexPairs[i - 1][0].setFullYear(currentYear);
91
98
  }
99
+ dates[filteredDateIndexPairs[i - 1][1]] = filteredDateIndexPairs[i - 1][0];
92
100
  }
93
101
  xValues = xValues.map(function (month, index) {
102
+ if (dates[index] === null) {
103
+ return null;
104
+ }
94
105
  return "".concat(month, " 01, ").concat(dates[index].getFullYear());
95
106
  });
96
107
  return xValues;
@@ -151,20 +162,22 @@ var transformPlotlyJsonToDonutProps = function (input, colorMap, colorwayType, i
151
162
  var colors = (0, PlotlyColorAdapter_1.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);
152
163
  var mapLegendToDataPoint = {};
153
164
  (_e = firstData.labels) === null || _e === void 0 ? void 0 : _e.forEach(function (label, index) {
154
- var _a;
165
+ var value = (0, exports.getNumberAtIndexOrDefault)(firstData.values, index);
166
+ if ((0, exports.isInvalidValue)(value) || value < 0) {
167
+ return;
168
+ }
169
+ var legend = "".concat(label);
155
170
  // resolve color for each legend from the extracted colors
156
- var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, label, colorMap, isDarkTheme);
157
- //ToDo how to handle string data?
158
- var value = typeof ((_a = firstData.values) === null || _a === void 0 ? void 0 : _a[index]) === 'number' ? firstData.values[index] : 1;
159
- if (!mapLegendToDataPoint[label]) {
160
- mapLegendToDataPoint[label] = {
161
- legend: label,
171
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, legend, colorMap, isDarkTheme);
172
+ if (!mapLegendToDataPoint[legend]) {
173
+ mapLegendToDataPoint[legend] = {
174
+ legend: legend,
162
175
  data: value,
163
176
  color: color,
164
177
  };
165
178
  }
166
179
  else {
167
- mapLegendToDataPoint[label].data += value;
180
+ mapLegendToDataPoint[legend].data += value;
168
181
  }
169
182
  });
170
183
  var width = (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.width) !== null && _g !== void 0 ? _g : 440;
@@ -201,44 +214,61 @@ var transformPlotlyJsonToVSBCProps = function (input, colorMap, colorwayType, is
201
214
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
202
215
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
203
216
  input.data.forEach(function (series, index1) {
204
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
217
+ var _a, _b, _c, _d, _e, _f, _g, _h;
205
218
  var isXYearCategory = (0, chart_utilities_1.isYearArray)(series.x); // Consider year as categorical not numeric continuous axis
206
219
  // extract bar colors for each series only once
207
220
  var extractedBarColors = (0, PlotlyColorAdapter_1.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);
208
221
  // extract line colors for each series only once
209
222
  var extractedLineColors = (0, PlotlyColorAdapter_1.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);
210
- (_j = series.x) === null || _j === void 0 ? void 0 : _j.forEach(function (x, index2) {
211
- var _a, _b, _c;
212
- if (!mapXToDataPoints[x]) {
213
- mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
214
- }
215
- var legend = legends[index1];
216
- // resolve color for each legend's bars from the extracted colors
217
- var color = (0, PlotlyColorAdapter_1.resolveColor)(extractedBarColors, index1, legend, colorMap, isDarkTheme);
218
- var yVal = (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2]) !== null && _b !== void 0 ? _b : 0;
219
- if (series.type === 'bar') {
220
- mapXToDataPoints[x].chartData.push({
221
- legend: legend,
222
- data: yVal,
223
- color: color,
224
- });
225
- yMaxValue = Math.max(yMaxValue, yVal);
226
- }
227
- else if (series.type === 'scatter' || !!fallbackVSBC) {
228
- var lineColor = (0, PlotlyColorAdapter_1.resolveColor)(extractedLineColors, index1, legend, colorMap, isDarkTheme);
229
- var lineOptions = getLineOptions(series.line);
230
- var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
231
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
232
- mapXToDataPoints[x].lineData.push(tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, y: yVal, color: lineColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
233
- if (!usesSecondaryYScale(series)) {
223
+ var validXYRanges = (0, exports.getValidXYRanges)(series);
224
+ validXYRanges.forEach(function (_a, rangeIdx) {
225
+ var rangeStart = _a[0], rangeEnd = _a[1];
226
+ var rangeXValues = series.x.slice(rangeStart, rangeEnd);
227
+ var rangeYValues = series.y.slice(rangeStart, rangeEnd);
228
+ rangeXValues.forEach(function (x, index2) {
229
+ var _a, _b;
230
+ if (!mapXToDataPoints[x]) {
231
+ mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
232
+ }
233
+ var legend = legends[index1];
234
+ // resolve color for each legend's bars from the extracted colors
235
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(extractedBarColors, index1, legend, colorMap, isDarkTheme);
236
+ var yVal = rangeYValues[index2];
237
+ if (series.type === 'bar') {
238
+ mapXToDataPoints[x].chartData.push({
239
+ legend: legend,
240
+ data: yVal,
241
+ color: color,
242
+ });
234
243
  yMaxValue = Math.max(yMaxValue, yVal);
235
- yMinValue = Math.min(yMinValue, yVal);
236
244
  }
237
- }
245
+ else if (series.type === 'scatter' || !!fallbackVSBC) {
246
+ var lineColor = (0, PlotlyColorAdapter_1.resolveColor)(extractedLineColors, index1, legend, colorMap, isDarkTheme);
247
+ var lineOptions = getLineOptions(series.line);
248
+ var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
249
+ var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
250
+ ? 'dottedLine'
251
+ : ((_b = series.mode) === null || _b === void 0 ? void 0 : _b.includes('markers'))
252
+ ? 'circle'
253
+ : 'default';
254
+ mapXToDataPoints[x].lineData.push({
255
+ legend: legend + (validXYRanges.length > 1 ? ".".concat(rangeIdx + 1) : ''),
256
+ legendShape: legendShape,
257
+ y: yVal,
258
+ color: lineColor,
259
+ lineOptions: tslib_1.__assign(tslib_1.__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
260
+ useSecondaryYScale: usesSecondaryYScale(series),
261
+ });
262
+ if (!usesSecondaryYScale(series)) {
263
+ yMaxValue = Math.max(yMaxValue, yVal);
264
+ yMinValue = Math.min(yMinValue, yVal);
265
+ }
266
+ }
267
+ });
238
268
  });
239
269
  });
240
270
  var _e = getTitles(input.layout), chartTitle = _e.chartTitle, xAxisTitle = _e.xAxisTitle, yAxisTitle = _e.yAxisTitle;
241
- return tslib_1.__assign(tslib_1.__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 });
271
+ return tslib_1.__assign(tslib_1.__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 });
242
272
  };
243
273
  exports.transformPlotlyJsonToVSBCProps = transformPlotlyJsonToVSBCProps;
244
274
  var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, isDarkTheme) {
@@ -251,7 +281,10 @@ var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, is
251
281
  // extract colors for each series only once
252
282
  var extractedColors = (0, PlotlyColorAdapter_1.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);
253
283
  (_e = series.x) === null || _e === void 0 ? void 0 : _e.forEach(function (x, xIndex) {
254
- var _a, _b;
284
+ var _a;
285
+ if ((0, exports.isInvalidValue)(x) || (0, exports.isInvalidValue)((_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex])) {
286
+ return;
287
+ }
255
288
  if (!mapXToDataPoints[x]) {
256
289
  mapXToDataPoints[x] = { name: x.toString(), series: [] };
257
290
  }
@@ -261,7 +294,7 @@ var transformPlotlyJsonToGVBCProps = function (input, colorMap, colorwayType, is
261
294
  var color = (0, PlotlyColorAdapter_1.resolveColor)(extractedColors, index1, legend, colorMap, isDarkTheme);
262
295
  mapXToDataPoints[x].series.push({
263
296
  key: legend,
264
- data: (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex]) !== null && _b !== void 0 ? _b : 0,
297
+ data: series.y[xIndex],
265
298
  xAxisCalloutData: x,
266
299
  color: color,
267
300
  legend: legend,
@@ -285,17 +318,26 @@ var transformPlotlyJsonToVBCProps = function (input, colorMap, colorwayType, isD
285
318
  }
286
319
  // extract colors for each series only once
287
320
  var extractedColors = (0, PlotlyColorAdapter_1.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);
288
- var isXString = isStringArray(series.x);
321
+ var xValues = [];
322
+ var yValues = [];
323
+ series.x.forEach(function (xVal, index) {
324
+ var yVal = (0, exports.getNumberAtIndexOrDefault)(series.y, index);
325
+ if ((0, exports.isInvalidValue)(xVal) || (0, exports.isInvalidValue)(yVal)) {
326
+ return;
327
+ }
328
+ xValues.push(xVal);
329
+ yValues.push(yVal);
330
+ });
331
+ var isXString = isStringArray(xValues);
289
332
  // TODO: In case of a single bin, add an empty bin of the same size to prevent the
290
333
  // default bar width from being used and ensure the bar spans the full intended range.
291
- 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);
334
+ 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);
292
335
  var yBins = xBins.map(function () { return []; });
293
336
  var total = 0;
294
- series.x.forEach(function (xVal, index) {
295
- var _a, _b;
337
+ xValues.forEach(function (xVal, index) {
296
338
  var binIdx = findBinIndex(xBins, xVal, isXString);
297
339
  if (binIdx !== -1) {
298
- yBins[binIdx].push((_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : 1);
340
+ yBins[binIdx].push(yValues[index]);
299
341
  }
300
342
  });
301
343
  var y = yBins.map(function (bin) {
@@ -335,12 +377,13 @@ var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, isSca
335
377
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, isAreaChart ? 0 : undefined, isAreaChart ? 0 : undefined);
336
378
  var mode = 'tonexty';
337
379
  var _g = getLegendProps(input.data, input.layout), legends = _g.legends, hideLegend = _g.hideLegend;
338
- var chartData = input.data.map(function (series, index) {
339
- var _a, _b, _c, _d, _e, _f;
380
+ var chartData = input.data
381
+ .map(function (series, index) {
382
+ var _a, _b, _c, _d, _e, _f, _g;
340
383
  // extract colors for each series only once
341
384
  var extractedColors = (0, PlotlyColorAdapter_1.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);
342
385
  var xValues = series.x;
343
- var isString = typeof xValues[0] === 'string';
386
+ var isString = isStringArray(xValues);
344
387
  var isXDate = (0, chart_utilities_1.isDateArray)(xValues);
345
388
  var isXNumber = (0, chart_utilities_1.isNumberArray)(xValues);
346
389
  var legend = legends[index];
@@ -349,27 +392,50 @@ var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, isSca
349
392
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
350
393
  var lineOptions = getLineOptions(series.line);
351
394
  var dashType = ((_f = series.line) === null || _f === void 0 ? void 0 : _f.dash) || 'solid';
352
- var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
353
- return tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, data: xValues.map(function (x, i) {
354
- var _a, _b;
355
- return (tslib_1.__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)
356
- ? { markerSize: series.marker.size[i] }
357
- : typeof ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size) === 'number'
358
- ? { markerSize: series.marker.size }
359
- : {})));
360
- }), color: seriesColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) });
361
- });
395
+ var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot'
396
+ ? 'dottedLine'
397
+ : ((_g = series.mode) === null || _g === void 0 ? void 0 : _g.includes('markers'))
398
+ ? 'circle'
399
+ : 'default';
400
+ var validXYRanges = (0, exports.getValidXYRanges)(series);
401
+ return validXYRanges.map(function (_a, rangeIdx) {
402
+ var _b;
403
+ var rangeStart = _a[0], rangeEnd = _a[1];
404
+ var rangeXValues = xValues.slice(rangeStart, rangeEnd);
405
+ var rangeYValues = series.y.slice(rangeStart, rangeEnd);
406
+ var markerSizes = (0, chart_utilities_1.isArrayOrTypedArray)((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size)
407
+ ? series.marker.size.slice(rangeStart, rangeEnd)
408
+ : [];
409
+ return {
410
+ legend: legend,
411
+ legendShape: legendShape,
412
+ data: rangeXValues.map(function (x, i) {
413
+ var _a, _b;
414
+ return (tslib_1.__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)
415
+ ? { markerSize: markerSizes[i] }
416
+ : typeof ((_b = series.marker) === null || _b === void 0 ? void 0 : _b.size) === 'number'
417
+ ? { markerSize: series.marker.size }
418
+ : {})));
419
+ }),
420
+ color: seriesColor,
421
+ lineOptions: tslib_1.__assign(tslib_1.__assign({}, (lineOptions !== null && lineOptions !== void 0 ? lineOptions : {})), { mode: series.mode }),
422
+ useSecondaryYScale: usesSecondaryYScale(series),
423
+ };
424
+ });
425
+ })
426
+ .flat();
362
427
  var yMinMaxValues = (0, utilities_1.findNumericMinMaxOfY)(chartData);
363
428
  var _h = getTitles(input.layout), chartTitle = _h.chartTitle, xAxisTitle = _h.xAxisTitle, yAxisTitle = _h.yAxisTitle;
429
+ var numDataPoints = chartData.reduce(function (total, lineChartPoints) { return total + lineChartPoints.data.length; }, 0);
364
430
  var chartProps = {
365
431
  chartTitle: chartTitle,
366
432
  lineChartData: chartData,
367
433
  };
368
434
  if (isAreaChart) {
369
- return tslib_1.__assign(tslib_1.__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 });
435
+ return tslib_1.__assign(tslib_1.__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 });
370
436
  }
371
437
  else {
372
- return tslib_1.__assign(tslib_1.__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 });
438
+ return tslib_1.__assign(tslib_1.__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 });
373
439
  }
374
440
  };
375
441
  exports.transformPlotlyJsonToScatterChartProps = transformPlotlyJsonToScatterChartProps;
@@ -384,14 +450,20 @@ var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap,
384
450
  var legend = legends[index];
385
451
  // resolve color for each legend's bars from the extracted colors
386
452
  var color = (0, PlotlyColorAdapter_1.resolveColor)(extractedColors, index, legend, colorMap, isDarkTheme);
387
- return series.y.map(function (yValue, i) {
453
+ return series.y
454
+ .map(function (yValue, i) {
455
+ var _a;
456
+ if ((0, exports.isInvalidValue)((_a = series.x) === null || _a === void 0 ? void 0 : _a[i]) || (0, exports.isInvalidValue)(yValue)) {
457
+ return null;
458
+ }
388
459
  return {
389
460
  x: series.x[i],
390
461
  y: yValue,
391
462
  legend: legend,
392
463
  color: color,
393
464
  };
394
- });
465
+ })
466
+ .filter(function (point) { return point !== null; });
395
467
  })
396
468
  .reverse()
397
469
  .flat()
@@ -430,24 +502,36 @@ var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap,
430
502
  };
431
503
  exports.transformPlotlyJsonToHorizontalBarWithAxisProps = transformPlotlyJsonToHorizontalBarWithAxisProps;
432
504
  var transformPlotlyJsonToHeatmapProps = function (input) {
433
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
505
+ 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;
434
506
  var firstData = input.data[0];
435
507
  var heatmapDataPoints = [];
436
508
  var zMin = Number.POSITIVE_INFINITY;
437
509
  var zMax = Number.NEGATIVE_INFINITY;
438
510
  if (firstData.type === 'histogram2d') {
439
- var isXString_1 = isStringArray(firstData.x);
440
- var isYString_1 = isStringArray(firstData.y);
441
- 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);
442
- 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);
511
+ var xValues_1 = [];
512
+ var yValues_1 = [];
513
+ var zValues_1 = [];
514
+ (_a = firstData.x) === null || _a === void 0 ? void 0 : _a.forEach(function (xVal, index) {
515
+ var _a;
516
+ var zVal = (0, exports.getNumberAtIndexOrDefault)(firstData.z, index);
517
+ if ((0, exports.isInvalidValue)(xVal) || (0, exports.isInvalidValue)((_a = firstData.y) === null || _a === void 0 ? void 0 : _a[index]) || (0, exports.isInvalidValue)(zVal)) {
518
+ return;
519
+ }
520
+ xValues_1.push(xVal);
521
+ yValues_1.push(firstData.y[index]);
522
+ zValues_1.push(zVal);
523
+ });
524
+ var isXString_1 = isStringArray(xValues_1);
525
+ var isYString_1 = isStringArray(yValues_1);
526
+ 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);
527
+ 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);
443
528
  var zBins_1 = yBins_1.map(function () { return xBins_1.map(function () { return []; }); });
444
529
  var total_1 = 0;
445
- (_g = firstData.x) === null || _g === void 0 ? void 0 : _g.forEach(function (xVal, index) {
446
- var _a, _b, _c;
530
+ xValues_1.forEach(function (xVal, index) {
447
531
  var xBinIdx = findBinIndex(xBins_1, xVal, isXString_1);
448
- var yBinIdx = findBinIndex(yBins_1, (_a = firstData.y) === null || _a === void 0 ? void 0 : _a[index], isYString_1);
532
+ var yBinIdx = findBinIndex(yBins_1, yValues_1[index], isYString_1);
449
533
  if (xBinIdx !== -1 && yBinIdx !== -1) {
450
- zBins_1[yBinIdx][xBinIdx].push((_c = (_b = firstData.z) === null || _b === void 0 ? void 0 : _b[index]) !== null && _c !== void 0 ? _c : 1);
534
+ zBins_1[yBinIdx][xBinIdx].push(zValues_1[index]);
451
535
  }
452
536
  });
453
537
  var z_1 = zBins_1.map(function (row) {
@@ -505,13 +589,31 @@ var transformPlotlyJsonToHeatmapProps = function (input) {
505
589
  (0, colors_1.getColorFromToken)(colors_1.DataVizPalette.color2),
506
590
  (0, colors_1.getColorFromToken)(colors_1.DataVizPalette.color3),
507
591
  ];
508
- var domainValuesForColorScale = Array.isArray(firstData.colorscale)
509
- ? firstData.colorscale.map(function (arr) { return arr[0] * (zMax - zMin) + zMin; })
592
+ 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;
593
+ // determine if the types diverging, sequential or sequentialminus are present in colorscale
594
+ if (colorscale &&
595
+ typeof colorscale === 'object' &&
596
+ ('diverging' in colorscale || 'sequential' in colorscale || 'sequentialminus' in colorscale)) {
597
+ var isDivergent = zMin < 0 && zMax > 0; // Data spans both positive and negative values
598
+ var isSequential = zMin >= 0; // Data is entirely positive
599
+ var isSequentialMinus = zMax <= 0; // Data is entirely negative
600
+ if (isDivergent) {
601
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.diverging;
602
+ }
603
+ else if (isSequential) {
604
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequential;
605
+ }
606
+ else if (isSequentialMinus) {
607
+ colorscale = colorscale === null || colorscale === void 0 ? void 0 : colorscale.sequentialminus;
608
+ }
609
+ }
610
+ var domainValuesForColorScale = Array.isArray(colorscale)
611
+ ? colorscale.map(function (arr) { return arr[0] * (zMax - zMin) + zMin; })
510
612
  : defaultDomain;
511
- var rangeValuesForColorScale = Array.isArray(firstData.colorscale)
512
- ? firstData.colorscale.map(function (arr) { return arr[1]; })
613
+ var rangeValuesForColorScale = Array.isArray(colorscale)
614
+ ? colorscale.map(function (arr) { return arr[1]; })
513
615
  : defaultRange;
514
- var _o = getTitles(input.layout), chartTitle = _o.chartTitle, xAxisTitle = _o.xAxisTitle, yAxisTitle = _o.yAxisTitle;
616
+ var _9 = getTitles(input.layout), chartTitle = _9.chartTitle, xAxisTitle = _9.xAxisTitle, yAxisTitle = _9.yAxisTitle;
515
617
  return {
516
618
  data: [heatmapData],
517
619
  domainValuesForColorScale: domainValuesForColorScale,
@@ -522,8 +624,8 @@ var transformPlotlyJsonToHeatmapProps = function (input) {
522
624
  xAxisTitle: xAxisTitle,
523
625
  yAxisTitle: yAxisTitle,
524
626
  sortOrder: 'none',
525
- width: (_k = input.layout) === null || _k === void 0 ? void 0 : _k.width,
526
- height: (_m = (_l = input.layout) === null || _l === void 0 ? void 0 : _l.height) !== null && _m !== void 0 ? _m : 350,
627
+ width: (_6 = input.layout) === null || _6 === void 0 ? void 0 : _6.width,
628
+ height: (_8 = (_7 = input.layout) === null || _7 === void 0 ? void 0 : _7.height) !== null && _8 !== void 0 ? _8 : 350,
527
629
  hideTickOverlap: true,
528
630
  noOfCharsToTruncate: 20,
529
631
  showYAxisLablesTooltip: true,
@@ -534,13 +636,19 @@ var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwayType,
534
636
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
535
637
  var _m = input.data[0], link = _m.link, node = _m.node;
536
638
  var validLinks = ((_a = link === null || link === void 0 ? void 0 : link.value) !== null && _a !== void 0 ? _a : [])
537
- .map(function (val, index) { return ({
538
- value: val,
539
- source: link === null || link === void 0 ? void 0 : link.source[index],
540
- target: link === null || link === void 0 ? void 0 : link.target[index],
541
- }); })
639
+ .map(function (val, index) {
640
+ var _a, _b;
641
+ if ((0, exports.isInvalidValue)(val) || (0, exports.isInvalidValue)((_a = link === null || link === void 0 ? void 0 : link.source) === null || _a === void 0 ? void 0 : _a[index]) || (0, exports.isInvalidValue)((_b = link === null || link === void 0 ? void 0 : link.target) === null || _b === void 0 ? void 0 : _b[index])) {
642
+ return null;
643
+ }
644
+ return {
645
+ value: val,
646
+ source: link === null || link === void 0 ? void 0 : link.source[index],
647
+ target: link === null || link === void 0 ? void 0 : link.target[index],
648
+ };
649
+ })
542
650
  // Filter out negative nodes, unequal nodes and self-references (circular links)
543
- .filter(function (x) { return x.source >= 0 && x.target >= 0 && x.source !== x.target; });
651
+ .filter(function (x) { return x !== null && x.source >= 0 && x.target >= 0 && x.source !== x.target; });
544
652
  var extractedNodeColors = (0, PlotlyColorAdapter_1.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);
545
653
  var sankeyChartData = {
546
654
  nodes: (_e = node.label) === null || _e === void 0 ? void 0 : _e.map(function (label, index) {
@@ -685,16 +793,20 @@ var transformPlotlyJsonToChartTableProps = function (input, colorMap, isDarkThem
685
793
  };
686
794
  exports.transformPlotlyJsonToChartTableProps = transformPlotlyJsonToChartTableProps;
687
795
  var projectPolarToCartesian = function (input) {
796
+ var _a, _b, _c, _d;
688
797
  var projection = tslib_1.__assign({}, input);
689
798
  for (var sindex = 0; sindex < input.data.length; sindex++) {
690
799
  var series = input.data[sindex];
691
800
  series.x = [];
692
801
  series.y = [];
693
- for (var ptindex = 0; ptindex < series.r.length; ptindex++) {
802
+ for (var ptindex = 0; ptindex < ((_b = (_a = series.r) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); ptindex++) {
803
+ if ((0, exports.isInvalidValue)((_c = series.theta) === null || _c === void 0 ? void 0 : _c[ptindex]) || (0, exports.isInvalidValue)((_d = series.r) === null || _d === void 0 ? void 0 : _d[ptindex])) {
804
+ continue;
805
+ }
694
806
  var thetaRad = (series.theta[ptindex] * Math.PI) / 180;
695
807
  var radius = series.r[ptindex];
696
- series.x[ptindex] = radius * Math.cos(thetaRad);
697
- series.y[ptindex] = radius * Math.sin(thetaRad);
808
+ series.x.push(radius * Math.cos(thetaRad));
809
+ series.y.push(radius * Math.sin(thetaRad));
698
810
  }
699
811
  projection.data[sindex] = series;
700
812
  }
@@ -782,7 +894,7 @@ function getLineOptions(line) {
782
894
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
783
895
  var isStringArray = function (arr) {
784
896
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
785
- return (0, chart_utilities_1.isArrayOfType)(arr, function (value) { return typeof value === 'string'; });
897
+ return (0, chart_utilities_1.isArrayOfType)(arr, function (value) { return typeof value === 'string' || value === null; });
786
898
  };
787
899
  // TODO: Use binary search to find the appropriate bin for numeric value.
788
900
  var findBinIndex = function (bins, value, isString) {
@@ -894,4 +1006,40 @@ var getLegendProps = function (data, layout) {
894
1006
  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,
895
1007
  };
896
1008
  };
1009
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1010
+ var isInvalidValue = function (value) {
1011
+ return typeof value === 'undefined' || value === null || (typeof value === 'number' && !isFinite(value));
1012
+ };
1013
+ exports.isInvalidValue = isInvalidValue;
1014
+ var getNumberAtIndexOrDefault = function (data, index) {
1015
+ if ((0, chart_utilities_1.isArrayOrTypedArray)(data)) {
1016
+ if (typeof data[index] !== 'number' || !isFinite(data[index])) {
1017
+ return;
1018
+ }
1019
+ return data[index];
1020
+ }
1021
+ return 1;
1022
+ };
1023
+ exports.getNumberAtIndexOrDefault = getNumberAtIndexOrDefault;
1024
+ var getValidXYRanges = function (series) {
1025
+ if (!(0, chart_utilities_1.isArrayOrTypedArray)(series.x) || !(0, chart_utilities_1.isArrayOrTypedArray)(series.y)) {
1026
+ return [];
1027
+ }
1028
+ var ranges = [];
1029
+ var start = 0;
1030
+ var end = 0;
1031
+ for (; end < series.x.length; end++) {
1032
+ if ((0, exports.isInvalidValue)(series.x[end]) || (0, exports.isInvalidValue)(series.y[end])) {
1033
+ if (end - start > 0) {
1034
+ ranges.push([start, end]);
1035
+ }
1036
+ start = end + 1;
1037
+ }
1038
+ }
1039
+ if (end - start > 0) {
1040
+ ranges.push([start, end]);
1041
+ }
1042
+ return ranges;
1043
+ };
1044
+ exports.getValidXYRanges = getValidXYRanges;
897
1045
  //# sourceMappingURL=PlotlySchemaAdapter.js.map