source: node_modules/recharts/lib/state/selectors/combiners/combineDisplayedStackedData.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.combineDisplayedStackedData = combineDisplayedStackedData;
7var _getStackSeriesIdentifier = require("../../../util/stacks/getStackSeriesIdentifier");
8var _ChartUtils = require("../../../util/ChartUtils");
9/**
10 * In a stacked chart, each graphical item has its own data. That data could be either:
11 * - defined on the chart root, in which case the item gets a unique dataKey
12 * - or defined on the item itself, in which case multiple items can share the same dataKey
13 *
14 * That means we cannot use the dataKey as a unique identifier for the item.
15 *
16 * This type represents a single data point in a stacked chart, where each key is a series identifier
17 * and the value is the numeric value for that series using the numerical axis dataKey.
18 */
19
20function combineDisplayedStackedData(stackedGraphicalItems, _ref, tooltipAxisSettings) {
21 var {
22 chartData = []
23 } = _ref;
24 var {
25 allowDuplicatedCategory,
26 dataKey: tooltipDataKey
27 } = tooltipAxisSettings;
28
29 // A map of tooltip data keys to the stacked data points
30 var knownItemsByDataKey = new Map();
31 stackedGraphicalItems.forEach(item => {
32 var _item$data;
33 // If there is no data on the individual item then we use the root chart data
34 var resolvedData = (_item$data = item.data) !== null && _item$data !== void 0 ? _item$data : chartData;
35 if (resolvedData == null || resolvedData.length === 0) {
36 // if that doesn't work then we skip this item
37 return;
38 }
39 var stackIdentifier = (0, _getStackSeriesIdentifier.getStackSeriesIdentifier)(item);
40 resolvedData.forEach((entry, index) => {
41 var tooltipValue = tooltipDataKey == null || allowDuplicatedCategory ? index : String((0, _ChartUtils.getValueByDataKey)(entry, tooltipDataKey, null));
42 var numericValue = (0, _ChartUtils.getValueByDataKey)(entry, item.dataKey, 0);
43 var curr;
44 if (knownItemsByDataKey.has(tooltipValue)) {
45 curr = knownItemsByDataKey.get(tooltipValue);
46 } else {
47 curr = {};
48 }
49 Object.assign(curr, {
50 [stackIdentifier]: numericValue
51 });
52 knownItemsByDataKey.set(tooltipValue, curr);
53 });
54 });
55 return Array.from(knownItemsByDataKey.values());
56}
Note: See TracBrowser for help on using the repository browser.