@fluentui/react-charting 5.24.25 → 5.24.26

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.
@@ -327,25 +327,55 @@ define(["require", "exports", "tslib", "d3-array", "d3-scale", "d3-format", "../
327
327
  // otherwise, default to colorway from template
328
328
  var colors = (0, PlotlyColorAdapter_1.extractColor)((_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.piecolorway) !== null && _b !== void 0 ? _b : (_e = (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.template) === null || _d === void 0 ? void 0 : _d.layout) === null || _e === void 0 ? void 0 : _e.colorway, colorwayType, (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.piecolorway) !== null && _g !== void 0 ? _g : (_h = firstData === null || firstData === void 0 ? void 0 : firstData.marker) === null || _h === void 0 ? void 0 : _h.colors, colorMap, isDarkTheme);
329
329
  var mapLegendToDataPoint = {};
330
- (_j = firstData.labels) === null || _j === void 0 ? void 0 : _j.forEach(function (label, index) {
331
- var value = (0, exports.getNumberAtIndexOrDefault)(firstData.values, index);
332
- if ((0, chart_utilities_1.isInvalidValue)(value) || value < 0) {
333
- return;
334
- }
335
- var legend = "".concat(label);
336
- // resolve color for each legend from the extracted colors
337
- var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, legend, colorMap, isDarkTheme);
338
- if (!mapLegendToDataPoint[legend]) {
339
- mapLegendToDataPoint[legend] = {
340
- legend: legend,
341
- data: value,
342
- color: color,
343
- };
344
- }
345
- else {
346
- mapLegendToDataPoint[legend].data += value;
330
+ if (colors) {
331
+ (_j = firstData.labels) === null || _j === void 0 ? void 0 : _j.forEach(function (label, index) {
332
+ var value = (0, exports.getNumberAtIndexOrDefault)(firstData.values, index);
333
+ if ((0, chart_utilities_1.isInvalidValue)(value) || value < 0) {
334
+ return;
335
+ }
336
+ var legend = "".concat(label);
337
+ // resolve color for each legend from the extracted colors
338
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, legend, colorMap, isDarkTheme);
339
+ if (!mapLegendToDataPoint[legend]) {
340
+ mapLegendToDataPoint[legend] = {
341
+ legend: legend,
342
+ data: value,
343
+ color: color,
344
+ };
345
+ }
346
+ else {
347
+ mapLegendToDataPoint[legend].data += value;
348
+ }
349
+ });
350
+ }
351
+ else {
352
+ // Sort labels by value descending before mapping
353
+ if (firstData.labels && firstData.values) {
354
+ var labelValuePairs = firstData.labels.map(function (label, index) { return ({
355
+ label: label,
356
+ value: (0, exports.getNumberAtIndexOrDefault)(firstData.values, index),
357
+ index: index,
358
+ }); });
359
+ // Filter out invalid values
360
+ var validPairs = labelValuePairs.filter(function (pair) { return !(0, chart_utilities_1.isInvalidValue)(pair.value); });
361
+ // Sort descending by value
362
+ validPairs.sort(function (a, b) { return b.value - a.value; });
363
+ validPairs.forEach(function (pair, sortedIdx) {
364
+ var legend = "".concat(pair.label);
365
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, sortedIdx, legend, colorMap, isDarkTheme);
366
+ if (!mapLegendToDataPoint[legend]) {
367
+ mapLegendToDataPoint[legend] = {
368
+ legend: legend,
369
+ data: pair.value,
370
+ color: color,
371
+ };
372
+ }
373
+ else {
374
+ mapLegendToDataPoint[legend].data += pair.value;
375
+ }
376
+ });
347
377
  }
348
- });
378
+ }
349
379
  var width = (_l = (_k = input.layout) === null || _k === void 0 ? void 0 : _k.width) !== null && _l !== void 0 ? _l : 440;
350
380
  var height = (_o = (_m = input.layout) === null || _m === void 0 ? void 0 : _m.height) !== null && _o !== void 0 ? _o : 220;
351
381
  var hideLabels = firstData.textinfo