@fluentui/react-charting 5.23.91 → 5.23.92

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 +40 -1
  2. package/CHANGELOG.md +15 -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 +213 -86
  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 +217 -87
  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 +217 -87
  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()
@@ -436,18 +508,30 @@ var transformPlotlyJsonToHeatmapProps = function (input) {
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) {
@@ -534,13 +618,19 @@ var transformPlotlyJsonToSankeyProps = function (input, colorMap, colorwayType,
534
618
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
535
619
  var _m = input.data[0], link = _m.link, node = _m.node;
536
620
  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
- }); })
621
+ .map(function (val, index) {
622
+ var _a, _b;
623
+ 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])) {
624
+ return null;
625
+ }
626
+ return {
627
+ value: val,
628
+ source: link === null || link === void 0 ? void 0 : link.source[index],
629
+ target: link === null || link === void 0 ? void 0 : link.target[index],
630
+ };
631
+ })
542
632
  // 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; });
633
+ .filter(function (x) { return x !== null && x.source >= 0 && x.target >= 0 && x.source !== x.target; });
544
634
  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
635
  var sankeyChartData = {
546
636
  nodes: (_e = node.label) === null || _e === void 0 ? void 0 : _e.map(function (label, index) {
@@ -685,16 +775,20 @@ var transformPlotlyJsonToChartTableProps = function (input, colorMap, isDarkThem
685
775
  };
686
776
  exports.transformPlotlyJsonToChartTableProps = transformPlotlyJsonToChartTableProps;
687
777
  var projectPolarToCartesian = function (input) {
778
+ var _a, _b, _c, _d;
688
779
  var projection = tslib_1.__assign({}, input);
689
780
  for (var sindex = 0; sindex < input.data.length; sindex++) {
690
781
  var series = input.data[sindex];
691
782
  series.x = [];
692
783
  series.y = [];
693
- for (var ptindex = 0; ptindex < series.r.length; ptindex++) {
784
+ for (var ptindex = 0; ptindex < ((_b = (_a = series.r) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); ptindex++) {
785
+ 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])) {
786
+ continue;
787
+ }
694
788
  var thetaRad = (series.theta[ptindex] * Math.PI) / 180;
695
789
  var radius = series.r[ptindex];
696
- series.x[ptindex] = radius * Math.cos(thetaRad);
697
- series.y[ptindex] = radius * Math.sin(thetaRad);
790
+ series.x.push(radius * Math.cos(thetaRad));
791
+ series.y.push(radius * Math.sin(thetaRad));
698
792
  }
699
793
  projection.data[sindex] = series;
700
794
  }
@@ -782,7 +876,7 @@ function getLineOptions(line) {
782
876
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
783
877
  var isStringArray = function (arr) {
784
878
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
785
- return (0, chart_utilities_1.isArrayOfType)(arr, function (value) { return typeof value === 'string'; });
879
+ return (0, chart_utilities_1.isArrayOfType)(arr, function (value) { return typeof value === 'string' || value === null; });
786
880
  };
787
881
  // TODO: Use binary search to find the appropriate bin for numeric value.
788
882
  var findBinIndex = function (bins, value, isString) {
@@ -894,4 +988,40 @@ var getLegendProps = function (data, layout) {
894
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,
895
989
  };
896
990
  };
991
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
992
+ var isInvalidValue = function (value) {
993
+ return typeof value === 'undefined' || value === null || (typeof value === 'number' && !isFinite(value));
994
+ };
995
+ exports.isInvalidValue = isInvalidValue;
996
+ var getNumberAtIndexOrDefault = function (data, index) {
997
+ if ((0, chart_utilities_1.isArrayOrTypedArray)(data)) {
998
+ if (typeof data[index] !== 'number' || !isFinite(data[index])) {
999
+ return;
1000
+ }
1001
+ return data[index];
1002
+ }
1003
+ return 1;
1004
+ };
1005
+ exports.getNumberAtIndexOrDefault = getNumberAtIndexOrDefault;
1006
+ var getValidXYRanges = function (series) {
1007
+ if (!(0, chart_utilities_1.isArrayOrTypedArray)(series.x) || !(0, chart_utilities_1.isArrayOrTypedArray)(series.y)) {
1008
+ return [];
1009
+ }
1010
+ var ranges = [];
1011
+ var start = 0;
1012
+ var end = 0;
1013
+ for (; end < series.x.length; end++) {
1014
+ if ((0, exports.isInvalidValue)(series.x[end]) || (0, exports.isInvalidValue)(series.y[end])) {
1015
+ if (end - start > 0) {
1016
+ ranges.push([start, end]);
1017
+ }
1018
+ start = end + 1;
1019
+ }
1020
+ }
1021
+ if (end - start > 0) {
1022
+ ranges.push([start, end]);
1023
+ }
1024
+ return ranges;
1025
+ };
1026
+ exports.getValidXYRanges = getValidXYRanges;
897
1027
  //# sourceMappingURL=PlotlySchemaAdapter.js.map