source: node_modules/recharts/es6/state/selectors/combiners/combineDisplayedStackedData.js@ a762898

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

Added visualizations

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