@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,7 +1,7 @@
1
1
  define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/colors", "../GaugeChart/index", "../../utilities/utilities", "@fluentui/chart-utilities", "d3-time-format", "d3-shape", "d3-color"], function (require, exports, tslib_1, d3_array_1, d3_scale_1, colors_1, index_1, utilities_1, chart_utilities_1, d3_time_format_1, d3_shape_1, d3_color_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- 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;
4
+ 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;
5
5
  var dashOptions = {
6
6
  dot: {
7
7
  strokeDasharray: '1, 5',
@@ -162,26 +162,34 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
162
162
  return hexColors;
163
163
  };
164
164
  exports.getSchemaColors = getSchemaColors;
165
+ var _extractColor = function (useFluentVizColorPalette, colors, colorMap, isDarkTheme) {
166
+ return !useFluentVizColorPalette && colors ? (0, exports.getSchemaColors)(colors, colorMap, isDarkTheme) : undefined;
167
+ };
168
+ exports._extractColor = _extractColor;
169
+ var _resolveColor = function (extractedColors, index, legend, colorMap, isDarkTheme) {
170
+ var color = '';
171
+ if (extractedColors && (0, chart_utilities_1.isArrayOrTypedArray)(extractedColors) && extractedColors[index]) {
172
+ color = extractedColors[index % extractedColors.length];
173
+ }
174
+ else if (typeof extractedColors === 'string') {
175
+ color = extractedColors;
176
+ }
177
+ else {
178
+ color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
179
+ }
180
+ return color;
181
+ };
182
+ exports._resolveColor = _resolveColor;
165
183
  var transformPlotlyJsonToDonutProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
166
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
184
+ var _a, _b, _c, _d, _e, _f, _g, _h;
167
185
  var firstData = input.data[0];
168
- var colors = undefined;
169
- if (!useFluentVizColorPalette) {
170
- 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;
171
- }
186
+ // extract colors for each series only once
187
+ 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);
172
188
  var mapLegendToDataPoint = {};
173
- (_c = firstData.labels) === null || _c === void 0 ? void 0 : _c.forEach(function (label, index) {
189
+ (_b = firstData.labels) === null || _b === void 0 ? void 0 : _b.forEach(function (label, index) {
174
190
  var _a;
175
- var color = '';
176
- if (colors && isStringArray(colors)) {
177
- color = colors[index % colors.length];
178
- }
179
- else if (typeof colors === 'string') {
180
- color = colors;
181
- }
182
- else {
183
- color = (0, exports.getColor)(label, colorMap, isDarkTheme);
184
- }
191
+ // resolve color for each legend from the extracted colors
192
+ var color = (0, exports._resolveColor)(colors, index, label, colorMap, isDarkTheme);
185
193
  //ToDo how to handle string data?
186
194
  var value = typeof ((_a = firstData.values) === null || _a === void 0 ? void 0 : _a[index]) === 'number' ? firstData.values[index] : 1;
187
195
  if (!mapLegendToDataPoint[label]) {
@@ -195,8 +203,8 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
195
203
  mapLegendToDataPoint[label].data += value;
196
204
  }
197
205
  });
198
- var width = (_e = (_d = input.layout) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : 440;
199
- var height = (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : 220;
206
+ var width = (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : 440;
207
+ var height = (_f = (_e = input.layout) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 220;
200
208
  var hideLabels = firstData.textinfo
201
209
  ? !['value', 'percent', 'label+percent'].includes(firstData.textinfo)
202
210
  : false;
@@ -211,8 +219,8 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
211
219
  chartTitle: chartTitle,
212
220
  chartData: Object.values(mapLegendToDataPoint),
213
221
  },
214
- hideLegend: ((_h = input.layout) === null || _h === void 0 ? void 0 : _h.showlegend) === false ? true : false,
215
- width: (_j = input.layout) === null || _j === void 0 ? void 0 : _j.width,
222
+ hideLegend: ((_g = input.layout) === null || _g === void 0 ? void 0 : _g.showlegend) === false ? true : false,
223
+ width: (_h = input.layout) === null || _h === void 0 ? void 0 : _h.width,
216
224
  height: height,
217
225
  innerRadius: innerRadius,
218
226
  hideLabels: hideLabels,
@@ -220,24 +228,29 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
220
228
  };
221
229
  };
222
230
  exports.transformPlotlyJsonToDonutProps = transformPlotlyJsonToDonutProps;
223
- var transformPlotlyJsonToVSBCProps = function (input, colorMap, isDarkTheme, fallbackVSBC) {
231
+ var transformPlotlyJsonToVSBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme, fallbackVSBC) {
224
232
  var _a, _b, _c;
225
233
  var mapXToDataPoints = {};
226
234
  var yMaxValue = 0;
227
235
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout);
228
236
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
229
237
  input.data.forEach(function (series, index1) {
230
- var _a;
238
+ var _a, _b, _c;
231
239
  var isXYearCategory = (0, chart_utilities_1.isYearArray)(series.x); // Consider year as categorical not numeric continuous axis
232
- (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, index2) {
240
+ // extract bar colors for each series only once
241
+ var extractedBarColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
242
+ // extract line colors for each series only once
243
+ var extractedLineColors = (0, exports._extractColor)(useFluentVizColorPalette, (_b = series.line) === null || _b === void 0 ? void 0 : _b.color, colorMap, isDarkTheme);
244
+ (_c = series.x) === null || _c === void 0 ? void 0 : _c.forEach(function (x, index2) {
233
245
  var _a, _b, _c;
234
246
  if (!mapXToDataPoints[x]) {
235
247
  mapXToDataPoints[x] = { xAxisPoint: isXYearCategory ? x.toString() : x, chartData: [], lineData: [] };
236
248
  }
237
249
  var legend = legends[index1];
250
+ // resolve color for each legend's bars from the extracted colors
251
+ var color = (0, exports._resolveColor)(extractedBarColors, index1, legend, colorMap, isDarkTheme);
238
252
  var yVal = (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[index2]) !== null && _b !== void 0 ? _b : 0;
239
253
  if (series.type === 'bar') {
240
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
241
254
  mapXToDataPoints[x].chartData.push({
242
255
  legend: legend,
243
256
  data: yVal,
@@ -246,11 +259,11 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
246
259
  yMaxValue = Math.max(yMaxValue, yVal);
247
260
  }
248
261
  else if (series.type === 'scatter' || !!fallbackVSBC) {
249
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
262
+ var lineColor = (0, exports._resolveColor)(extractedLineColors, index1, legend, colorMap, isDarkTheme);
250
263
  var lineOptions = getLineOptions(series.line);
251
264
  var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
252
265
  var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
253
- mapXToDataPoints[x].lineData.push(tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, y: yVal, color: color }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
266
+ mapXToDataPoints[x].lineData.push(tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, y: yVal, color: lineColor }, (lineOptions ? { lineOptions: lineOptions } : {})), { useSecondaryYScale: usesSecondaryYScale(series) }));
254
267
  if (!usesSecondaryYScale(series)) {
255
268
  yMaxValue = Math.max(yMaxValue, yVal);
256
269
  }
@@ -261,21 +274,24 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
261
274
  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 });
262
275
  };
263
276
  exports.transformPlotlyJsonToVSBCProps = transformPlotlyJsonToVSBCProps;
264
- var transformPlotlyJsonToGVBCProps = function (input, colorMap, isDarkTheme) {
277
+ var transformPlotlyJsonToGVBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
265
278
  var _a, _b, _c;
266
279
  var mapXToDataPoints = {};
267
280
  var secondaryYAxisValues = getSecondaryYAxisValues(input.data, input.layout, 0, 0);
268
281
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
269
282
  input.data.forEach(function (series, index1) {
270
- var _a;
271
- (_a = series.x) === null || _a === void 0 ? void 0 : _a.forEach(function (x, xIndex) {
283
+ var _a, _b;
284
+ // extract colors for each series only once
285
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
286
+ (_b = series.x) === null || _b === void 0 ? void 0 : _b.forEach(function (x, xIndex) {
272
287
  var _a, _b;
273
288
  if (!mapXToDataPoints[x]) {
274
289
  mapXToDataPoints[x] = { name: x.toString(), series: [] };
275
290
  }
276
291
  if (series.type === 'bar') {
277
292
  var legend = legends[index1];
278
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
293
+ // resolve color for each legend's bars from the extracted colors
294
+ var color = (0, exports._resolveColor)(extractedColors, index1, legend, colorMap, isDarkTheme);
279
295
  mapXToDataPoints[x].series.push({
280
296
  key: legend,
281
297
  data: (_b = (_a = series.y) === null || _a === void 0 ? void 0 : _a[xIndex]) !== null && _b !== void 0 ? _b : 0,
@@ -291,19 +307,21 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
291
307
  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 });
292
308
  };
293
309
  exports.transformPlotlyJsonToGVBCProps = transformPlotlyJsonToGVBCProps;
294
- var transformPlotlyJsonToVBCProps = function (input, colorMap, isDarkTheme) {
310
+ var transformPlotlyJsonToVBCProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
295
311
  var _a, _b, _c;
296
312
  var vbcData = [];
297
313
  var _d = getLegendProps(input.data, input.layout), legends = _d.legends, hideLegend = _d.hideLegend;
298
314
  input.data.forEach(function (series, seriesIdx) {
299
- var _a, _b, _c;
315
+ var _a, _b, _c, _d;
300
316
  if (!series.x) {
301
317
  return;
302
318
  }
319
+ // extract colors for each series only once
320
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
303
321
  var isXString = isStringArray(series.x);
304
322
  // TODO: In case of a single bin, add an empty bin of the same size to prevent the
305
323
  // default bar width from being used and ensure the bar spans the full intended range.
306
- 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);
324
+ 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);
307
325
  var yBins = xBins.map(function () { return []; });
308
326
  var total = 0;
309
327
  series.x.forEach(function (xVal, index) {
@@ -320,7 +338,8 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
320
338
  });
321
339
  xBins.forEach(function (bin, index) {
322
340
  var legend = legends[seriesIdx];
323
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
341
+ // resolve color for each legend's bars from the extracted colors
342
+ var color = (0, exports._resolveColor)(extractedColors, seriesIdx, legend, colorMap, isDarkTheme);
324
343
  var yVal = calculateHistNorm(series.histnorm, y[index], total, isXString ? bin.length : getBinSize(bin));
325
344
  vbcData.push(tslib_1.__assign({ x: isXString ? bin.join(', ') : getBinCenter(bin), y: yVal, legend: legend, color: color }, (isXString
326
345
  ? {}
@@ -349,18 +368,19 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
349
368
  var mode = 'tonexty';
350
369
  var _g = getLegendProps(input.data, input.layout), legends = _g.legends, hideLegend = _g.hideLegend;
351
370
  var chartData = input.data.map(function (series, index) {
352
- var _a, _b, _c;
371
+ var _a, _b;
372
+ // extract colors for each series only once
373
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.line) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
353
374
  var xValues = series.x;
354
375
  var isString = typeof xValues[0] === 'string';
355
376
  var isXDate = (0, chart_utilities_1.isDateArray)(xValues);
356
377
  var isXNumber = (0, chart_utilities_1.isNumberArray)(xValues);
357
378
  var legend = legends[index];
358
- var lineColor = !useFluentVizColorPalette && ((_a = series.line) === null || _a === void 0 ? void 0 : _a.color)
359
- ? (0, exports.getSchemaColors)((_b = series.line) === null || _b === void 0 ? void 0 : _b.color, colorMap, isDarkTheme)
360
- : (0, exports.getColor)(legend, colorMap, isDarkTheme);
379
+ // resolve color for each legend's lines from the extracted colors
380
+ var lineColor = (0, exports._resolveColor)(extractedColors, index, legend, colorMap, isDarkTheme);
361
381
  mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
362
382
  var lineOptions = getLineOptions(series.line);
363
- var dashType = ((_c = series.line) === null || _c === void 0 ? void 0 : _c.dash) || 'solid';
383
+ var dashType = ((_b = series.line) === null || _b === void 0 ? void 0 : _b.dash) || 'solid';
364
384
  var legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
365
385
  return tslib_1.__assign(tslib_1.__assign({ legend: legend, legendShape: legendShape, data: xValues.map(function (x, i) {
366
386
  var _a, _b;
@@ -385,13 +405,17 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
385
405
  }
386
406
  };
387
407
  exports.transformPlotlyJsonToScatterChartProps = transformPlotlyJsonToScatterChartProps;
388
- var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, isDarkTheme) {
408
+ var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, colorMap, useFluentVizColorPalette, isDarkTheme) {
389
409
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
390
410
  var _s = getLegendProps(input.data, input.layout), legends = _s.legends, hideLegend = _s.hideLegend;
391
411
  var chartData = input.data
392
412
  .map(function (series, index) {
413
+ var _a;
414
+ // extract colors for each series only once
415
+ var extractedColors = (0, exports._extractColor)(useFluentVizColorPalette, (_a = series.marker) === null || _a === void 0 ? void 0 : _a.color, colorMap, isDarkTheme);
393
416
  var legend = legends[index];
394
- var color = (0, exports.getColor)(legend, colorMap, isDarkTheme);
417
+ // resolve color for each legend's bars from the extracted colors
418
+ var color = (0, exports._resolveColor)(extractedColors, index, legend, colorMap, isDarkTheme);
395
419
  return series.y.map(function (yValue, i) {
396
420
  return {
397
421
  x: series.x[i],
@@ -545,7 +569,6 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "../../utilities/
545
569
  source: link === null || link === void 0 ? void 0 : link.source[index],
546
570
  target: link === null || link === void 0 ? void 0 : link.target[index],
547
571
  }); })
548
- // eslint-disable-next-line @typescript-eslint/no-shadow
549
572
  // Filter out negative nodes, unequal nodes and self-references (circular links)
550
573
  .filter(function (x) { return x.source >= 0 && x.target >= 0 && x.source !== x.target; });
551
574
  var sankeyChartData = {