@fluentui/react-charting 5.23.87 → 5.23.88

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 (25) hide show
  1. package/CHANGELOG.json +40 -1
  2. package/CHANGELOG.md +15 -2
  3. package/dist/react-charting.d.ts +6 -3
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +1 -1
  7. package/lib/components/DeclarativeChart/DeclarativeChart.d.ts +6 -3
  8. package/lib/components/DeclarativeChart/DeclarativeChart.js +9 -8
  9. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  10. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +7 -5
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +63 -42
  12. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  13. package/lib-amd/components/DeclarativeChart/DeclarativeChart.d.ts +6 -3
  14. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +9 -8
  15. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  16. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +7 -5
  17. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +66 -43
  18. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  19. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.d.ts +6 -3
  20. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +9 -8
  21. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  22. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.d.ts +7 -5
  23. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +66 -43
  24. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  25. package/package.json +5 -5
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findArrayAttributes = exports.projectPolarToCartesian = exports.transformPlotlyJsonToGaugeProps = exports.transformPlotlyJsonToSankeyProps = exports.transformPlotlyJsonToHeatmapProps = exports.transformPlotlyJsonToHorizontalBarWithAxisProps = exports.transformPlotlyJsonToScatterChartProps = exports.transformPlotlyJsonToVBCProps = exports.transformPlotlyJsonToGVBCProps = exports.transformPlotlyJsonToVSBCProps = exports.transformPlotlyJsonToDonutProps = exports.getSchemaColors = exports.getColor = exports.correctYearMonth = exports.isMonthArray = void 0;
3
+ exports.findArrayAttributes = exports.projectPolarToCartesian = exports.transformPlotlyJsonToGaugeProps = exports.transformPlotlyJsonToSankeyProps = exports.transformPlotlyJsonToHeatmapProps = exports.transformPlotlyJsonToHorizontalBarWithAxisProps = exports.transformPlotlyJsonToScatterChartProps = exports.transformPlotlyJsonToVBCProps = exports.transformPlotlyJsonToGVBCProps = exports.transformPlotlyJsonToVSBCProps = exports.transformPlotlyJsonToDonutProps = exports._resolveColor = exports._extractColor = exports.getSchemaColors = exports.getColor = 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");
@@ -171,26 +171,34 @@ var getSchemaColors = function (colors, colorMap, isDarkTheme) {
171
171
  return hexColors;
172
172
  };
173
173
  exports.getSchemaColors = getSchemaColors;
174
+ var _extractColor = function (useFluentVizColorPalette, colors, colorMap, isDarkTheme) {
175
+ return !useFluentVizColorPalette && colors ? (0, exports.getSchemaColors)(colors, colorMap, isDarkTheme) : undefined;
176
+ };
177
+ exports._extractColor = _extractColor;
178
+ var _resolveColor = function (extractedColors, index, legend, colorMap, isDarkTheme) {
179
+ var color = '';
180
+ if (extractedColors && (0, chart_utilities_1.isArrayOrTypedArray)(extractedColors) && extractedColors[index]) {
181
+ color = extractedColors[index % extractedColors.length];
182
+ }
183
+ else if (typeof extractedColors === 'string') {
184
+ color = extractedColors;
185
+ }
186
+ else {
187
+ color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
188
+ }
189
+ return color;
190
+ };
191
+ exports._resolveColor = _resolveColor;
174
192
  var transformPlotlyJsonToDonutProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
175
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
193
+ var _a, _b, _c, _d, _e, _f, _g, _h;
176
194
  var firstData = input.data[0];
177
- var colors = undefined;
178
- if (!useFluentVizColorPalette) {
179
- colors = ((_a = firstData.marker) === null || _a === void 0 ? void 0 : _a.colors) ? (0, exports.getSchemaColors)((_b = firstData === null || firstData === void 0 ? void 0 : firstData.marker) === null || _b === void 0 ? void 0 : _b.colors, colorMap, isDarkTheme) : undefined;
180
- }
195
+ // extract colors for each series only once
196
+ var colors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = firstData === null || firstData === void 0 ? void 0 : firstData.marker) === null || _a === void 0 ? void 0 : _a.colors, colorMap, isDarkTheme);
181
197
  var mapLegendToDataPoint = {};
182
- (_c = firstData.labels) === null || _c === void 0 ? void 0 : _c.forEach(function (label, index) {
198
+ (_b = firstData.labels) === null || _b === void 0 ? void 0 : _b.forEach(function (label, index) {
183
199
  var _a;
184
- var color = '';
185
- if (colors && isStringArray(colors)) {
186
- color = colors[index % colors.length];
187
- }
188
- else if (typeof colors === 'string') {
189
- color = colors;
190
- }
191
- else {
192
- color = (0, exports.getColor)(label, colorMap, isDarkTheme);
193
- }
200
+ // resolve color for each legend from the extracted colors
201
+ var color = (0, exports._resolveColor)(colors, index, label, colorMap, isDarkTheme);
194
202
  //ToDo how to handle string data?
195
203
  var value = typeof ((_a = firstData.values) === null || _a === void 0 ? void 0 : _a[index]) === 'number' ? firstData.values[index] : 1;
196
204
  if (!mapLegendToDataPoint[label]) {
@@ -204,8 +212,8 @@ var transformPlotlyJsonToDonutProps = function (input, colorMap, useFluentVizCol
204
212
  mapLegendToDataPoint[label].data += value;
205
213
  }
206
214
  });
207
- var width = (_e = (_d = input.layout) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : 440;
208
- var height = (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : 220;
215
+ var width = (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : 440;
216
+ var height = (_f = (_e = input.layout) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 220;
209
217
  var hideLabels = firstData.textinfo
210
218
  ? !['value', 'percent', 'label+percent'].includes(firstData.textinfo)
211
219
  : false;
@@ -220,8 +228,8 @@ var transformPlotlyJsonToDonutProps = function (input, colorMap, useFluentVizCol
220
228
  chartTitle: chartTitle,
221
229
  chartData: Object.values(mapLegendToDataPoint),
222
230
  },
223
- hideLegend: ((_h = input.layout) === null || _h === void 0 ? void 0 : _h.showlegend) === false ? true : false,
224
- width: (_j = input.layout) === null || _j === void 0 ? void 0 : _j.width,
231
+ hideLegend: ((_g = input.layout) === null || _g === void 0 ? void 0 : _g.showlegend) === false ? true : false,
232
+ width: (_h = input.layout) === null || _h === void 0 ? void 0 : _h.width,
225
233
  height: height,
226
234
  innerRadius: innerRadius,
227
235
  hideLabels: hideLabels,
@@ -229,24 +237,29 @@ var transformPlotlyJsonToDonutProps = function (input, colorMap, useFluentVizCol
229
237
  };
230
238
  };
231
239
  exports.transformPlotlyJsonToDonutProps = transformPlotlyJsonToDonutProps;
232
- var transformPlotlyJsonToVSBCProps = function (input, colorMap, isDarkTheme, fallbackVSBC) {
240
+ var transformPlotlyJsonToVSBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme, fallbackVSBC) {
233
241
  var _a, _b, _c;
234
242
  var mapXToDataPoints = {};
235
243
  var yMaxValue = 0;
236
244
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
237
245
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
238
246
  input.data.forEach(function (series, index1) {
239
- var _a;
247
+ var _a, _b, _c;
240
248
  var isXYearCategory = (0, chart_utilities_1.isYearArray)(series.x); // Consider year as categorical not numeric continuous axis
241
- (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, index2) {
249
+ // extract bar colors for each series only once
250
+ var extractedBarColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
251
+ // extract line colors for each series only once
252
+ var extractedLineColors = (0, exports._extractColor)(useFluentVizColorPalette, (_b = series.line) === null || _b === void 0 ? void 0 : _b.color, colorMap, isDarkTheme);
253
+ (_c = series.x) === null || _c === void 0 ? void 0 : _c.forEach(function (x, index2) {
242
254
  var _a, _b, _c;
243
255
  if (!mapXToDataPoints[x]) {
244
256
  mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
245
257
  }
246
258
  var legend = legends[index1];
259
+ // resolve color for each legend's bars from the extracted colors
260
+ var color = (0, exports._resolveColor)(extractedBarColors, index1, legend, colorMap, isDarkTheme);
247
261
  var yVal = (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2]) !== null && _b !== void 0 ? _b : 0;
248
262
  if (series.type === 'bar') {
249
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
250
263
  mapXToDataPoints[x].chartData.push({
251
264
  legend: legend,
252
265
  data: yVal,
@@ -255,11 +268,11 @@ var transformPlotlyJsonToVSBCProps = function (input, colorMap, isDarkTheme, fal
255
268
  yMaxValue = Math.max(yMaxValue, yVal);
256
269
  }
257
270
  else if (series.type === 'scatter' || !!fallbackVSBC) {
258
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
271
+ var lineColor = (0, exports._resolveColor)(extractedLineColors, index1, legend, colorMap, isDarkTheme);
259
272
  var lineOptions = getLineOptions(series.line);
260
273
  var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
261
274
  var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
262
- mapXToDataPoints[x].lineData.push(tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, y: yVal, color: color }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
275
+ mapXToDataPoints[x].lineData.push(tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, y: yVal, color: lineColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
263
276
  if (!usesSecondaryYScale(series)) {
264
277
  yMaxValue = Math.max(yMaxValue, yVal);
265
278
  }
@@ -270,21 +283,24 @@ var transformPlotlyJsonToVSBCProps = function (input, colorMap, isDarkTheme, fal
270
283
  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, chartTitle: chartTitle, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend });
271
284
  };
272
285
  exports.transformPlotlyJsonToVSBCProps = transformPlotlyJsonToVSBCProps;
273
- var transformPlotlyJsonToGVBCProps = function (input, colorMap, isDarkTheme) {
286
+ var transformPlotlyJsonToGVBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
274
287
  var _a, _b, _c;
275
288
  var mapXToDataPoints = {};
276
289
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, 0, 0);
277
290
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
278
291
  input.data.forEach(function (series, index1) {
279
- var _a;
280
- (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, xIndex) {
292
+ var _a, _b;
293
+ // extract colors for each series only once
294
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
295
+ (_b = series.x) === null || _b === void 0 ? void 0 : _b.forEach(function (x, xIndex) {
281
296
  var _a, _b;
282
297
  if (!mapXToDataPoints[x]) {
283
298
  mapXToDataPoints[x] = { name: x.toString(), series: [] };
284
299
  }
285
300
  if (series.type === 'bar') {
286
301
  var legend = legends[index1];
287
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
302
+ // resolve color for each legend's bars from the extracted colors
303
+ var color = (0, exports._resolveColor)(extractedColors, index1, legend, colorMap, isDarkTheme);
288
304
  mapXToDataPoints[x].series.push({
289
305
  key: legend,
290
306
  data: (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex]) !== null && _b !== void 0 ? _b : 0,
@@ -300,19 +316,21 @@ var transformPlotlyJsonToGVBCProps = function (input, colorMap, isDarkTheme) {
300
316
  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', chartTitle: chartTitle, xAxisTitle: xAxisTitle, yAxisTitle: yAxisTitle, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend });
301
317
  };
302
318
  exports.transformPlotlyJsonToGVBCProps = transformPlotlyJsonToGVBCProps;
303
- var transformPlotlyJsonToVBCProps = function (input, colorMap, isDarkTheme) {
319
+ var transformPlotlyJsonToVBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
304
320
  var _a, _b, _c;
305
321
  var vbcData = [];
306
322
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
307
323
  input.data.forEach(function (series, seriesIdx) {
308
- var _a, _b, _c;
324
+ var _a, _b, _c, _d;
309
325
  if (!series.x) {
310
326
  return;
311
327
  }
328
+ // extract colors for each series only once
329
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
312
330
  var isXString = isStringArray(series.x);
313
331
  // TODO: In case of a single bin, add an empty bin of the same size to prevent the
314
332
  // default bar width from being used and ensure the bar spans the full intended range.
315
- var xBins = createBins(series.x, (_a = series.xbins) === null || _a === void 0 ? void 0 : _a.start, (_b = series.xbins) === null || _b === void 0 ? void 0 : _b.end, (_c = series.xbins) === null || _c === void 0 ? void 0 : _c.size);
333
+ var xBins = createBins(series.x, (_b = series.xbins) === null || _b === void 0 ? void 0 : _b.start, (_c = series.xbins) === null || _c === void 0 ? void 0 : _c.end, (_d = series.xbins) === null || _d === void 0 ? void 0 : _d.size);
316
334
  var yBins = xBins.map(function () { return []; });
317
335
  var total = 0;
318
336
  series.x.forEach(function (xVal, index) {
@@ -329,7 +347,8 @@ var transformPlotlyJsonToVBCProps = function (input, colorMap, isDarkTheme) {
329
347
  });
330
348
  xBins.forEach(function (bin, index) {
331
349
  var legend = legends[seriesIdx];
332
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
350
+ // resolve color for each legend's bars from the extracted colors
351
+ var color = (0, exports._resolveColor)(extractedColors, seriesIdx, legend, colorMap, isDarkTheme);
333
352
  var yVal = calculateHistNorm(series.histnorm, y[index], total, isXString ? bin.length : getBinSize(bin));
334
353
  vbcData.push(tslib_1.__assign({ x: isXString ? bin.join(', ') : getBinCenter(bin), y: yVal, legend: legend, color: color }, (isXString
335
354
  ? {}
@@ -358,18 +377,19 @@ var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, color
358
377
  var mode = 'tonexty';
359
378
  var _g = getLegendProps(input.data, input.layout), legends = _g.legends, hideLegend = _g.hideLegend;
360
379
  var chartData = input.data.map(function (series, index) {
361
- var _a, _b, _c;
380
+ var _a, _b;
381
+ // extract colors for each series only once
382
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.line) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
362
383
  var xValues = series.x;
363
384
  var isString = typeof xValues[0] === 'string';
364
385
  var isXDate = (0, chart_utilities_1.isDateArray)(xValues);
365
386
  var isXNumber = (0, chart_utilities_1.isNumberArray)(xValues);
366
387
  var legend = legends[index];
367
- var lineColor = !useFluentVizColorPalette && ((_a = series.line) === null || _a === void 0 ? void 0 : _a.color)
368
- ? (0, exports.getSchemaColors)((_b = series.line) === null || _b === void 0 ? void 0 : _b.color, colorMap, isDarkTheme)
369
- : (0, exports.getColor)(legend, colorMap, isDarkTheme);
388
+ // resolve color for each legend's lines from the extracted colors
389
+ var lineColor = (0, exports._resolveColor)(extractedColors, index, legend, colorMap, isDarkTheme);
370
390
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
371
391
  var lineOptions = getLineOptions(series.line);
372
- var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
392
+ var dashType = ((_b = series.line) === null || _b === void 0 ? void 0 : _b.dash) || 'solid';
373
393
  var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
374
394
  return tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, data: xValues.map(function (x, i) {
375
395
  var _a, _b;
@@ -394,13 +414,17 @@ var transformPlotlyJsonToScatterChartProps = function (input, isAreaChart, color
394
414
  }
395
415
  };
396
416
  exports.transformPlotlyJsonToScatterChartProps = transformPlotlyJsonToScatterChartProps;
397
- var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, isDarkTheme) {
417
+ var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
398
418
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
399
419
  var _s = getLegendProps(input.data, input.layout), legends = _s.legends, hideLegend = _s.hideLegend;
400
420
  var chartData = input.data
401
421
  .map(function (series, index) {
422
+ var _a;
423
+ // extract colors for each series only once
424
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
402
425
  var legend = legends[index];
403
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
426
+ // resolve color for each legend's bars from the extracted colors
427
+ var color = (0, exports._resolveColor)(extractedColors, index, legend, colorMap, isDarkTheme);
404
428
  return series.y.map(function (yValue, i) {
405
429
  return {
406
430
  x: series.x[i],
@@ -554,7 +578,6 @@ var transformPlotlyJsonToSankeyProps = function (input, colorMap, isDarkTheme) {
554
578
  source: link === null || link === void 0 ? void 0 : link.source[index],
555
579
  target: link === null || link === void 0 ? void 0 : link.target[index],
556
580
  }); })
557
- // eslint-disable-next-line @typescript-eslint/no-shadow
558
581
  // Filter out negative nodes, unequal nodes and self-references (circular links)
559
582
  .filter(function (x) { return x.source >= 0 && x.target >= 0 && x.source !== x.target; });
560
583
  var sankeyChartData = {