oolib 2.213.4 → 2.214.0

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 (64) hide show
  1. package/dist/components/EmptyStates/config/index.js +12 -0
  2. package/dist/components/LoadersAndProgress/LoaderOverlay/index.js +1 -1
  3. package/dist/index.d.ts +0 -6
  4. package/dist/index.js +2 -14
  5. package/dist/stories/v2/components/Accordion.stories.js +0 -1
  6. package/package.json +1 -1
  7. package/dist/stories/v2/components/DataVizAccordion.stories.d.ts +0 -7
  8. package/dist/stories/v2/components/DataVizAccordion.stories.js +0 -141
  9. package/dist/stories/v2/components/visualization/BarChart.stories.d.ts +0 -23
  10. package/dist/stories/v2/components/visualization/BarChart.stories.js +0 -251
  11. package/dist/stories/v2/components/visualization/BarGraphCollection.stories.d.ts +0 -19
  12. package/dist/stories/v2/components/visualization/BarGraphCollection.stories.js +0 -1190
  13. package/dist/stories/v2/components/visualization/HeatMapGrid.stories.d.ts +0 -18
  14. package/dist/stories/v2/components/visualization/HeatMapGrid.stories.js +0 -204
  15. package/dist/stories/v2/components/visualization/PieChart.stories.d.ts +0 -7
  16. package/dist/stories/v2/components/visualization/PieChart.stories.js +0 -79
  17. package/dist/stories/v2/components/visualization/configs/props1.d.ts +0 -102
  18. package/dist/stories/v2/components/visualization/configs/props1.js +0 -70
  19. package/dist/stories/v2/components/visualization/configs/props2.d.ts +0 -45
  20. package/dist/stories/v2/components/visualization/configs/props2.js +0 -2962
  21. package/dist/stories/v2/components/visualization/vizPlayground.stories.d.ts +0 -7
  22. package/dist/stories/v2/components/visualization/vizPlayground.stories.js +0 -55
  23. package/dist/v2/components/DataVizAccordion/index.d.ts +0 -13
  24. package/dist/v2/components/DataVizAccordion/index.js +0 -60
  25. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.d.ts +0 -19
  26. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.js +0 -25
  27. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/OptimizedTooltip.d.ts +0 -8
  28. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/OptimizedTooltip.js +0 -118
  29. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/index.d.ts +0 -15
  30. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/index.js +0 -120
  31. package/dist/v2/components/dataviz/BarChart/comps/CustomizedLabel/index.d.ts +0 -29
  32. package/dist/v2/components/dataviz/BarChart/comps/CustomizedLabel/index.js +0 -73
  33. package/dist/v2/components/dataviz/BarChart/comps/Legend/index.d.ts +0 -12
  34. package/dist/v2/components/dataviz/BarChart/comps/Legend/index.js +0 -35
  35. package/dist/v2/components/dataviz/BarChart/comps/LegendTooltipGlyph/index.d.ts +0 -7
  36. package/dist/v2/components/dataviz/BarChart/comps/LegendTooltipGlyph/index.js +0 -18
  37. package/dist/v2/components/dataviz/BarChart/comps/TruncatedSVGText/index.d.ts +0 -7
  38. package/dist/v2/components/dataviz/BarChart/comps/TruncatedSVGText/index.js +0 -66
  39. package/dist/v2/components/dataviz/BarChart/index.d.ts +0 -45
  40. package/dist/v2/components/dataviz/BarChart/index.js +0 -383
  41. package/dist/v2/components/dataviz/BarGraphCollection/index.d.ts +0 -24
  42. package/dist/v2/components/dataviz/BarGraphCollection/index.js +0 -162
  43. package/dist/v2/components/dataviz/BarGraphCollection/styled.d.ts +0 -9
  44. package/dist/v2/components/dataviz/BarGraphCollection/styled.js +0 -92
  45. package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.d.ts +0 -2
  46. package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +0 -60
  47. package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.d.ts +0 -11
  48. package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.js +0 -76
  49. package/dist/v2/components/dataviz/HeatMapGrid/index.d.ts +0 -19
  50. package/dist/v2/components/dataviz/HeatMapGrid/index.js +0 -232
  51. package/dist/v2/components/dataviz/HeatMapGrid/utils/mapValueToColor.d.ts +0 -20
  52. package/dist/v2/components/dataviz/HeatMapGrid/utils/mapValueToColor.js +0 -45
  53. package/dist/v2/components/dataviz/HeatMapGrid/utils/useAxisMeasure.d.ts +0 -6
  54. package/dist/v2/components/dataviz/HeatMapGrid/utils/useAxisMeasure.js +0 -53
  55. package/dist/v2/components/dataviz/HeatMapGrid/utils/useFader.d.ts +0 -6
  56. package/dist/v2/components/dataviz/HeatMapGrid/utils/useFader.js +0 -36
  57. package/dist/v2/components/dataviz/HeatMapGrid/utils/usePrepareHeatMapData.d.ts +0 -33
  58. package/dist/v2/components/dataviz/HeatMapGrid/utils/usePrepareHeatMapData.js +0 -122
  59. package/dist/v2/components/dataviz/PieChart/index.d.ts +0 -21
  60. package/dist/v2/components/dataviz/PieChart/index.js +0 -186
  61. package/dist/v2/components/dataviz/types.d.ts +0 -13
  62. package/dist/v2/components/dataviz/types.js +0 -2
  63. package/dist/v2/components/dataviz/utils/usePrepareData.d.ts +0 -21
  64. package/dist/v2/components/dataviz/utils/usePrepareData.js +0 -213
@@ -1,186 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || (function () {
30
- var ownKeys = function(o) {
31
- ownKeys = Object.getOwnPropertyNames || function (o) {
32
- var ar = [];
33
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
- return ar;
35
- };
36
- return ownKeys(o);
37
- };
38
- return function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
45
- })();
46
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.PieChart = void 0;
51
- var react_1 = __importStar(require("react"));
52
- var recharts_1 = require("recharts");
53
- var _EXPORTS_1 = require("../../../../utils/_EXPORTS");
54
- var Legend_1 = require("../BarChart/comps/Legend");
55
- var __1 = require("../../../..");
56
- var BarChart_1 = require("../BarChart");
57
- var usePrepareData_1 = require("../utils/usePrepareData");
58
- var BarChart_2 = require("../BarChart");
59
- var CustomTooltip_1 = __importDefault(require("../BarChart/comps/CustomTooltip"));
60
- var chartColors = [
61
- "#5C80FF",
62
- "#FFA800",
63
- "#00BC8F",
64
- "#FF51CE",
65
- "rgb(173, 89, 108)",
66
- "rgb(114, 190, 244)",
67
- "rgb(255, 178, 122)",
68
- "rgb(14, 126, 161)",
69
- "rgb(60, 169, 116)",
70
- "rgb(254, 187, 178)",
71
- "rgb(204, 128, 217)",
72
- "rgb(91, 184, 175)",
73
- ];
74
- var usePieChartData = function (barChartData, isBreakdown) {
75
- return (0, react_1.useMemo)(function () {
76
- if (!barChartData || barChartData.length === 0) {
77
- return [];
78
- }
79
- if (!isBreakdown) {
80
- // For non-breakdown data, the structure is already compatible
81
- return barChartData.map(function (item) { return ({
82
- labels: {
83
- percentage: item.labels.percentage,
84
- count: item.labels.count,
85
- name: item.labels.name,
86
- tooltipLabel: item.labels.tooltipLabel || item.labels.name,
87
- },
88
- }); });
89
- }
90
- else {
91
- // For breakdown data, sum all values for each main category
92
- return barChartData.map(function (itemArray) {
93
- var totalCount = itemArray.reduce(function (sum, item) { return sum + item.labels.count; }, 0);
94
- var mainItem = itemArray[0]; // Use the first item for the main label
95
- // Calculate total across all items for percentage calculation
96
- var grandTotal = barChartData.reduce(function (total, group) {
97
- return total + group.reduce(function (groupSum, item) { return groupSum + item.labels.count; }, 0);
98
- }, 0);
99
- return {
100
- labels: {
101
- percentage: (0, _EXPORTS_1.getPercentage)(totalCount, grandTotal),
102
- count: totalCount,
103
- name: mainItem.labels.name,
104
- tooltipLabel: mainItem.labels.tooltipLabel || mainItem.labels.name,
105
- },
106
- };
107
- });
108
- }
109
- }, [barChartData, isBreakdown]);
110
- };
111
- var CustomLabel = function (_a) {
112
- var viewBox = _a.viewBox, value = _a.value;
113
- var cx = viewBox.cx, cy = viewBox.cy;
114
- return (react_1.default.createElement("text", { x: cx, y: cy, textAnchor: "middle", dominantBaseline: "central", className: "text-sm font-medium" }, value));
115
- };
116
- var RADIAN = Math.PI / 180;
117
- var renderCustomizedLabel = function (_a) {
118
- var cx = _a.cx, cy = _a.cy, midAngle = _a.midAngle, innerRadius = _a.innerRadius, outerRadius = _a.outerRadius, percent = _a.percent, index = _a.index, payload = _a.payload;
119
- // Only show label if percentage is above a threshold (e.g., 5%)
120
- if (percent < 0.05)
121
- return null;
122
- // Calculate position closer to the center of the slice
123
- var radius = innerRadius + (outerRadius - innerRadius) * 0.5;
124
- var x = cx + radius * Math.cos(-midAngle * RADIAN);
125
- var y = cy + radius * Math.sin(-midAngle * RADIAN);
126
- return (react_1.default.createElement("text", { key: "label-".concat(index), x: x, y: y, fill: __1.colors2.black, textAnchor: "middle", dominantBaseline: "central", className: "UI_CAPTION_SEMIBOLD_DF" }, "".concat((percent * 100).toFixed(0), "%")));
127
- };
128
- var renderActiveShape = function (props) {
129
- var cx = props.cx, cy = props.cy, innerRadius = props.innerRadius, outerRadius = props.outerRadius, startAngle = props.startAngle, endAngle = props.endAngle, fill = props.fill, payload = props.payload, midAngle = props.midAngle;
130
- // const radius = innerRadius + (outerRadius - innerRadius) * 0.45; // Moved closer to center
131
- // const x = cx + radius * Math.cos(-midAngle * RADIAN);
132
- // const y = cy + radius * Math.sin(-midAngle * RADIAN);
133
- return (react_1.default.createElement("g", null,
134
- react_1.default.createElement(recharts_1.Sector, { cx: cx, cy: cy, innerRadius: innerRadius, outerRadius: outerRadius + 6, startAngle: startAngle, endAngle: endAngle, fill: fill })));
135
- };
136
- var PieChart = function (_a) {
137
- var _data = _a.data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, breakdownCategoryName = _a.breakdownCategoryName, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, onClick = _a.onClick, _c = _a.colors, colors = _c === void 0 ? chartColors : _c, _d = _a.colorIdx, colorIdx = _d === void 0 ? 0 : _d, _e = _a.plotDataPoint, plotDataPoint = _e === void 0 ? "percentage" : _e, _f = _a.showPercent, showPercent = _f === void 0 ? true : _f, _g = _a.showCount, showCount = _g === void 0 ? false : _g, innerLabel = _a.innerLabel, style = _a.style;
138
- var _h = (0, react_1.useState)(null), tooltipData = _h[0], setTooltipData = _h[1]; // Add this line
139
- var isBreakdown = Array.isArray(valuePath);
140
- var barChartData = (0, usePrepareData_1.usePrepareData)({
141
- _data: _data,
142
- labelPath: labelPath,
143
- valuePath: valuePath,
144
- tooltipLabelsMapping: tooltipLabelsMapping,
145
- tooltipLabelsPath: tooltipLabelsPath,
146
- isBreakdown: isBreakdown,
147
- showPercent: showPercent,
148
- summarizeAfterIdx: undefined, // PieChart doesn't use summarization
149
- colorIdx: colorIdx
150
- }).data;
151
- // Adapt the BarChart data format to PieChart format
152
- var data = usePieChartData(barChartData, isBreakdown);
153
- var _j = (0, BarChart_1.useDecideLegendOrientation)({
154
- widthThreshold: 500
155
- }), vizWrapperRef = _j.vizWrapperRef, orientation = _j.orientation;
156
- var _k = (0, BarChart_2.useTrackMousePosition)({ containerRef: vizWrapperRef }), mousePosition = _k.mousePosition, isHovering = _k.isHovering;
157
- var _l = (0, react_1.useState)(), activeIndex = _l[0], setActiveIndex = _l[1];
158
- var onPieEnter = function (data, index) {
159
- setActiveIndex(index);
160
- setTooltipData(data.payload);
161
- };
162
- var onPieLeave = function () {
163
- setActiveIndex(undefined);
164
- setTooltipData(null);
165
- };
166
- var onPieClick = function (_, index) {
167
- if (onClick) {
168
- onClick(data[index].labels.name);
169
- }
170
- };
171
- if (data.length === 0)
172
- return react_1.default.createElement("div", null, "No data available");
173
- return (react_1.default.createElement("div", { ref: vizWrapperRef, style: __assign(__assign({}, style), { width: "100%", display: 'flex', gap: '8px', flexDirection: orientation === 'vertical' ? 'row' : 'column', position: 'relative' }) },
174
- (isHovering && tooltipData) && (react_1.default.createElement(CustomTooltip_1.default, { active: true, value: [tooltipData.labels], showPercent: showPercent, mousePosition: mousePosition })),
175
- react_1.default.createElement("div", { style: { flexGrow: 1, position: 'relative' } },
176
- react_1.default.createElement("div", { className: "w-full", style: { height: "100%" } },
177
- react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: "100%" },
178
- react_1.default.createElement(recharts_1.PieChart, null,
179
- react_1.default.createElement(recharts_1.Pie, { data: data, cx: "50%", cy: "50%", label: renderCustomizedLabel, fill: "#8884d8", dataKey: "labels.count", nameKey: "labels.name", innerRadius: 70, outerRadius: 140, labelLine: false, activeShape: renderActiveShape, onMouseEnter: onPieEnter, onMouseLeave: onPieLeave, onClick: onClick ? onPieClick : undefined, style: { cursor: "pointer" }, activeIndex: activeIndex }, data.map(function (entry, index) { return (react_1.default.createElement(recharts_1.Cell, { key: "cell-".concat(index), fill: colors[(index + colorIdx) % colors.length] })); })))))),
180
- react_1.default.createElement("div", { style: __assign({ position: 'sticky' }, (orientation === 'vertical' ? { top: 0 } : { bottom: 0, background: __1.colors2.white })) },
181
- react_1.default.createElement(Legend_1.Legend, { orientation: orientation, label: breakdownCategoryName || "Categories", data: data.map(function (d, index) { return ({
182
- text: d.labels.tooltipLabel || d.labels.name,
183
- color: colors[(index + colorIdx) % colors.length]
184
- }); }) }))));
185
- };
186
- exports.PieChart = PieChart;
@@ -1,13 +0,0 @@
1
- export interface CountVizLabels {
2
- percentage?: number;
3
- count: number;
4
- name: string;
5
- dataIndex: number;
6
- barColor: string;
7
- textColor: string;
8
- tooltipLabel?: string;
9
- }
10
- export interface CountVizDatum {
11
- labels: CountVizLabels;
12
- }
13
- export type CountVizData = (CountVizDatum | CountVizDatum[])[];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,21 +0,0 @@
1
- import { CountVizData } from "../types";
2
- interface PrepareDataParams {
3
- _data: any;
4
- labelPath: string;
5
- valuePath: string | string[];
6
- isBreakdown: boolean;
7
- showPercent: boolean;
8
- tooltipLabelsMapping?: {
9
- [key: string]: string;
10
- };
11
- tooltipLabelsPath: string | string[];
12
- summarizeAfterIdx?: number;
13
- colorIdx?: number;
14
- }
15
- interface PreparedData {
16
- data: CountVizData;
17
- dataToSummarize: CountVizData;
18
- dataMaxValue: number;
19
- }
20
- export declare const usePrepareData: ({ _data, labelPath, valuePath, tooltipLabelsMapping, tooltipLabelsPath, isBreakdown, showPercent, summarizeAfterIdx, colorIdx }: PrepareDataParams) => PreparedData;
21
- export {};
@@ -1,213 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.usePrepareData = void 0;
24
- var react_1 = require("react");
25
- var _EXPORTS_1 = require("../../../../utils/_EXPORTS");
26
- var getTotalCount_1 = require("../../../../utils/getTotalCount");
27
- var colors_1 = require("../../../themes/colors");
28
- var getBarColorForBreakdownData = function (_a) {
29
- var colorIdx = _a.colorIdx, index = _a.index;
30
- return colors_1.dataVizColors[(colorIdx + index) % colors_1.dataVizColors.length];
31
- };
32
- var getTextColorForBreakdownData = function (_a) {
33
- var colorIdx = _a.colorIdx, index = _a.index;
34
- return colors_1.dataVizColorsText[(colorIdx + index) % colors_1.dataVizColorsText.length];
35
- };
36
- // Helper function to get identifier using tooltipLabel logic - reused in mapping and final step
37
- var getIdentifierFromPath = function (d, path, i, tooltipLabelsPath, tooltipLabelsMapping) {
38
- var identifier;
39
- if (tooltipLabelsPath) {
40
- // Use tooltipLabelsPath logic to get the identifier - matches original logic exactly
41
- if (Array.isArray(tooltipLabelsPath)) {
42
- // Check if tooltipLabelsPath[i] exists before using it
43
- identifier = tooltipLabelsPath[i]
44
- ? (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]
45
- : path; // fallback to path if tooltipLabelsPath[i] doesn't exist
46
- }
47
- else if (typeof tooltipLabelsPath === 'string') {
48
- identifier = (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath) || tooltipLabelsPath;
49
- }
50
- else {
51
- identifier = path;
52
- }
53
- }
54
- else if (tooltipLabelsMapping) {
55
- identifier = tooltipLabelsMapping[path] || path;
56
- }
57
- else {
58
- identifier = path;
59
- }
60
- return identifier;
61
- };
62
- // Create a consistent mapping of unique identifiers to color indices for breakdown data
63
- var createValueToColorMapping = function (data, tooltipLabelsPath, valuePath, tooltipLabelsMapping) {
64
- var uniqueValues = new Set();
65
- // Find the longest children array to use as template
66
- var longestChildrenArray = [];
67
- var longestLength = 0;
68
- data.forEach(function (d) {
69
- if (d.children && d.children.length > longestLength) {
70
- longestLength = d.children.length;
71
- longestChildrenArray = d.children;
72
- }
73
- });
74
- // Use the longest children array as template to collect unique identifiers
75
- valuePath.forEach(function (path, i) {
76
- var identifier = getIdentifierFromPath({ children: longestChildrenArray }, path, i, tooltipLabelsPath, tooltipLabelsMapping);
77
- uniqueValues.add(identifier);
78
- });
79
- // Create consistent mapping
80
- var valueToColorIndex = {};
81
- Array.from(uniqueValues).sort().forEach(function (value, index) {
82
- valueToColorIndex[value] = index;
83
- });
84
- return valueToColorIndex;
85
- };
86
- var usePrepareData = function (_a) {
87
- var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent, summarizeAfterIdx = _a.summarizeAfterIdx, colorIdx = _a.colorIdx;
88
- return (0, react_1.useMemo)(function () {
89
- var finalData = __spreadArray([], _data, true);
90
- if (finalData.length === 0)
91
- return ({ data: finalData, dataToSummarize: [], dataMaxValue: 0 });
92
- var valueToColorMapping = isBreakdown ? createValueToColorMapping(finalData, tooltipLabelsPath, valuePath, tooltipLabelsMapping) : {};
93
- var totalCount = !isBreakdown
94
- ? (0, getTotalCount_1.getTotalCount)({ data: finalData, countPath: valuePath })
95
- : finalData.map(function (d) {
96
- var valueSum = valuePath
97
- .map(function (path) { return (0, _EXPORTS_1.getVal)(d, path) || 0; }) // fallback to 0, cuz sometimes backend systems return 'undefined' if the count of data against a field is non-existent / zero
98
- .reduce(function (acc, curr) { return acc + curr; }, 0);
99
- return valueSum;
100
- });
101
- finalData = finalData.map(function (d, index) {
102
- if (!isBreakdown) {
103
- var count = (0, _EXPORTS_1.getVal)(d, valuePath) || 0; // fallback to 0, cuz sometimes backend systems return 'undefined' if the count of data against a field is non-existent / zero
104
- return {
105
- labels: __assign(__assign({}, (showPercent
106
- ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount) }
107
- : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: colors_1.dataVizColors[colorIdx], textColor: colors_1.dataVizColorsText[colorIdx] }),
108
- };
109
- }
110
- return valuePath.map(function (path, i) {
111
- var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
112
- // Get the identifier using the same logic as tooltipLabel for consistent coloring
113
- var identifier = getIdentifierFromPath(d, path, i, tooltipLabelsPath, tooltipLabelsMapping);
114
- // Use the consistent color mapping instead of array index
115
- var colorIndex = valueToColorMapping[identifier] !== undefined
116
- ? valueToColorMapping[identifier]
117
- : i; // fallback to index if identifier not found
118
- /**
119
- * for breakdown first we assign a color to each valuepath.
120
- * and then that color stays consistent for that valuepath across different breakdown groups
121
- */
122
- var barColor = getBarColorForBreakdownData({ colorIdx: colorIdx, index: colorIndex });
123
- var textColor = getTextColorForBreakdownData({ colorIdx: colorIdx, index: colorIndex });
124
- return {
125
- labels: __assign(__assign({}, (showPercent
126
- ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
127
- : {})), { count: count, tooltipLabel: identifier, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: barColor, textColor: textColor }),
128
- };
129
- });
130
- });
131
- // Sort by total value
132
- finalData.sort(function (a, b) {
133
- if (!isBreakdown) {
134
- return b.labels.count - a.labels.count;
135
- }
136
- else {
137
- /**
138
- * this sorts the order of the entire breakdown group/stack
139
- * putting the one with the total largest count first all the way to the least
140
- */
141
- var bTotal = b
142
- .map(function (bItem) { return bItem.labels.count; })
143
- .reduce(function (acc, curr) { return acc + curr; }, 0);
144
- var aTotal = a
145
- .map(function (aItem) { return aItem.labels.count; })
146
- .reduce(function (acc, curr) { return acc + curr; }, 0);
147
- return bTotal - aTotal;
148
- }
149
- });
150
- // Sort inner arrays from largest to smallest when it's a breakdown
151
- if (isBreakdown) {
152
- finalData.forEach(function (innerArray) {
153
- innerArray.sort(function (a, b) {
154
- return b.labels.count - a.labels.count;
155
- });
156
- });
157
- }
158
- finalData = isBreakdown
159
- ? finalData.map(function (d, i) {
160
- return d.map(function (dd, ii) { return (__assign(__assign({}, dd), { labels: __assign(__assign({}, dd.labels), { dataIndex: i }) })); });
161
- })
162
- : finalData.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { dataIndex: i }) })); });
163
- var mainData = !isBreakdown
164
- ? (summarizeAfterIdx ? finalData.filter(function (_, i) { return i <= summarizeAfterIdx; }) : finalData)
165
- : finalData;
166
- var convertDataToSummrizeIntoBreakdownFormat = function (data) {
167
- var reshaped = data.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { name: "Others", tooltipLabel: d.labels.name, dataIndex: i, barColor: getBarColorForBreakdownData({ colorIdx: colorIdx + 1, index: i }), textColor: getTextColorForBreakdownData({ colorIdx: colorIdx + 1, index: i }) }) })); });
168
- return [reshaped];
169
- };
170
- var dataToSummarize = (!isBreakdown && summarizeAfterIdx)
171
- ? convertDataToSummrizeIntoBreakdownFormat(finalData.filter(function (_, i) { return i > summarizeAfterIdx; }))
172
- : undefined;
173
- var calcDataMaxValue = function (mainData, dataToSummarize, isBreakdown) {
174
- //now if there is no data to summarize its simple. take the first element and get its count (for !isBreakdown) or accumulate to count for first element (isBreakdown)
175
- // with dataToSummarize, its interesting, because a summarized bar is a 'summation' of everything it is summarizing. sooo.. the summation (and not the individual values) should be taken into consideration while figuring out maxValue
176
- var getHighestNumInArray = function (ary) {
177
- var highest = 0;
178
- ary.forEach(function (item) { if (item.labels.count > highest)
179
- highest = item.labels.count; });
180
- return highest;
181
- };
182
- var getHighestNumInArrayOfArrays = function (ary) {
183
- var highest = 0;
184
- ary.forEach(function (subAry) {
185
- var subHighest = getHighestNumInArray(subAry);
186
- if (subHighest > highest)
187
- highest = subHighest;
188
- });
189
- return highest;
190
- };
191
- if (!dataToSummarize) {
192
- return !isBreakdown
193
- ? getHighestNumInArray(mainData) //if not breakdown, simply get the highest count in this single level array structre : [ { labels: { count: <>, ... }}, ... ]
194
- : getHighestNumInArrayOfArrays(mainData); // if breakdown, get the highest count across all the nested arrays in this structure : [ [ { labels: { count: <>, ... }}, ... ], ... ]
195
- }
196
- else {
197
- var totalCountOfSummarizedData = dataToSummarize[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
198
- var maxCountFromMainData = !isBreakdown
199
- ? getHighestNumInArray(mainData)
200
- : getHighestNumInArrayOfArrays(mainData);
201
- return maxCountFromMainData > totalCountOfSummarizedData
202
- ? maxCountFromMainData
203
- : totalCountOfSummarizedData;
204
- }
205
- };
206
- return {
207
- data: mainData,
208
- dataMaxValue: calcDataMaxValue(mainData, dataToSummarize, isBreakdown),
209
- dataToSummarize: dataToSummarize,
210
- };
211
- }, [_data, labelPath, valuePath, isBreakdown, showPercent]);
212
- };
213
- exports.usePrepareData = usePrepareData;