oolib 2.188.8 → 2.189.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 (31) hide show
  1. package/dist/components/Dropdowns/DropdownMulti/index.js +2 -0
  2. package/dist/components/Dropdowns/DropdownSingle/index.js +6 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/stories/v2/components/Accordion.stories.js +1 -1
  6. package/dist/stories/v2/components/BarChart.stories.js +70 -43
  7. package/dist/stories/v2/components/HeatMapGrid.stories.d.ts +17 -0
  8. package/dist/stories/v2/components/HeatMapGrid.stories.js +107 -0
  9. package/dist/v2/components/DataVizAccordion/index.d.ts +1 -1
  10. package/dist/v2/components/DataVizAccordion/index.js +1 -1
  11. package/dist/v2/components/Dropdowns/DropdownMulti/index.js +2 -0
  12. package/dist/v2/components/Dropdowns/DropdownSingle/index.js +6 -1
  13. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.d.ts +18 -0
  14. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.js +24 -0
  15. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomTooltip/index.d.ts +4 -4
  16. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/index.js +161 -0
  17. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.d.ts +7 -12
  18. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.js +22 -12
  19. package/dist/v2/components/{BarChart → dataviz/BarChart}/index.d.ts +12 -14
  20. package/dist/v2/components/dataviz/BarChart/index.js +276 -0
  21. package/dist/v2/components/dataviz/HeatMapGrid/index.d.ts +21 -0
  22. package/dist/v2/components/dataviz/HeatMapGrid/index.js +230 -0
  23. package/dist/v2/components/dataviz/types.d.ts +12 -0
  24. package/dist/v2/components/dataviz/types.js +2 -0
  25. package/dist/v2/components/dataviz/utils/usePrepareData.d.ts +20 -0
  26. package/dist/v2/components/dataviz/utils/usePrepareData.js +116 -0
  27. package/package.json +1 -1
  28. package/dist/v2/components/BarChart/comps/CustomTooltip/index.js +0 -50
  29. package/dist/v2/components/BarChart/index.js +0 -294
  30. /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.d.ts +0 -0
  31. /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.js +0 -0
@@ -0,0 +1,20 @@
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
+ }
14
+ interface PreparedData {
15
+ data: CountVizData;
16
+ dataToSummarize: CountVizData;
17
+ dataMaxValue: number;
18
+ }
19
+ export declare const usePrepareData: ({ _data, labelPath, valuePath, tooltipLabelsMapping, tooltipLabelsPath, isBreakdown, showPercent, summarizeAfterIdx, }: PrepareDataParams) => PreparedData;
20
+ export {};
@@ -0,0 +1,116 @@
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 usePrepareData = function (_a) {
28
+ 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;
29
+ return (0, react_1.useMemo)(function () {
30
+ var finalData = __spreadArray([], _data, true);
31
+ var totalCount = !isBreakdown
32
+ ? (0, getTotalCount_1.getTotalCount)({ data: finalData, countPath: valuePath })
33
+ : finalData.map(function (d) {
34
+ var valueSum = valuePath
35
+ .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
36
+ .reduce(function (acc, curr) { return acc + curr; }, 0);
37
+ return valueSum;
38
+ });
39
+ finalData = finalData.map(function (d, index) {
40
+ if (!isBreakdown) {
41
+ 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
42
+ return {
43
+ labels: __assign(__assign({}, (showPercent
44
+ ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount) }
45
+ : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
46
+ };
47
+ }
48
+ return valuePath.map(function (path, i) {
49
+ var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
50
+ return {
51
+ labels: __assign(__assign({}, (showPercent
52
+ ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
53
+ : {})), { count: count, tooltipLabel: tooltipLabelsPath
54
+ ? tooltipLabelsPath[i]
55
+ ? (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]
56
+ : path
57
+ : (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
58
+ };
59
+ });
60
+ });
61
+ // Sort by total value
62
+ finalData.sort(function (a, b) {
63
+ if (!isBreakdown) {
64
+ return b.labels.count - a.labels.count;
65
+ }
66
+ else {
67
+ var bTotal = b
68
+ .map(function (bItem) { return bItem.labels.count; })
69
+ .reduce(function (acc, curr) { return acc + curr; }, 0);
70
+ var aTotal = a
71
+ .map(function (aItem) { return aItem.labels.count; })
72
+ .reduce(function (acc, curr) { return acc + curr; }, 0);
73
+ return bTotal - aTotal;
74
+ }
75
+ });
76
+ finalData = isBreakdown
77
+ ? finalData.map(function (d, i) {
78
+ return d.map(function (dd, ii) { return (__assign(__assign({}, dd), { labels: __assign(__assign({}, dd.labels), { dataIndex: i }) })); });
79
+ })
80
+ : finalData.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { dataIndex: i }) })); });
81
+ var mainData = !isBreakdown
82
+ ? finalData.filter(function (_, i) { return i <= summarizeAfterIdx; })
83
+ : finalData;
84
+ var convertDataToSummrizeIntoBreakdownFormat = function (data) {
85
+ var reshaped = data.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { name: "Others", tooltipLabel: d.labels.name, dataIndex: i }) })); });
86
+ return [reshaped];
87
+ };
88
+ var dataToSummarize = !isBreakdown
89
+ ? convertDataToSummrizeIntoBreakdownFormat(finalData.filter(function (_, i) { return i > summarizeAfterIdx; }))
90
+ : undefined;
91
+ var calcDataMaxValue = function (mainData, dataToSummarize, isBreakdown) {
92
+ //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)
93
+ // 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
94
+ if (!dataToSummarize) {
95
+ return !isBreakdown
96
+ ? mainData[0].labels.count
97
+ : mainData[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
98
+ }
99
+ else {
100
+ var totalCountOfSummarizedData = dataToSummarize[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
101
+ var maxCountFromMainData = !isBreakdown
102
+ ? mainData[0].labels.count
103
+ : mainData[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
104
+ return maxCountFromMainData > totalCountOfSummarizedData
105
+ ? maxCountFromMainData
106
+ : totalCountOfSummarizedData;
107
+ }
108
+ };
109
+ return {
110
+ data: mainData,
111
+ dataMaxValue: calcDataMaxValue(mainData, dataToSummarize, isBreakdown),
112
+ dataToSummarize: dataToSummarize,
113
+ };
114
+ }, [_data, labelPath, valuePath, isBreakdown, showPercent]);
115
+ };
116
+ exports.usePrepareData = usePrepareData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.188.8",
3
+ "version": "2.189.0",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var react_1 = __importDefault(require("react"));
7
- var Typo2_1 = require("../../../Typo2");
8
- var __1 = require("../../../../..");
9
- var CustomTooltip = function (props) {
10
- var active = props.active, payload = props.payload, value = props.value, showPercent = props.showPercent, mousePosition = props.mousePosition;
11
- if (!active || !payload || !payload.length)
12
- return null;
13
- // Calculate position - align with the right side of the bars
14
- var style = {
15
- position: 'fixed',
16
- left: "".concat((mousePosition === null || mousePosition === void 0 ? void 0 : mousePosition.x) || 0, "px"),
17
- top: "".concat((mousePosition === null || mousePosition === void 0 ? void 0 : mousePosition.y) || 0, "px"),
18
- transform: 'translate(10px, 10px)', // Offset from cursor and center vertically
19
- backgroundColor: __1.colors2.black,
20
- color: __1.colors2.white,
21
- border: "1px solid ".concat(__1.colors2.grey10),
22
- borderRadius: '6px',
23
- padding: '8px',
24
- boxShadow: '0px 4px 10px 0px rgba(0, 0, 0, 0.12)',
25
- zIndex: 1000,
26
- width: 'max-content',
27
- maxWidth: '200px',
28
- display: 'flex',
29
- flexDirection: 'column',
30
- gap: '1rem',
31
- pointerEvents: 'none', // Add this to prevent tooltip from interfering with mouse events
32
- };
33
- return (react_1.default.createElement("div", { style: style },
34
- react_1.default.createElement("div", { style: {
35
- display: 'grid',
36
- gridTemplateColumns: showPercent ? 'auto auto auto' : 'auto auto',
37
- gap: '0.6rem'
38
- } },
39
- react_1.default.createElement("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' } }, value.map(function (entry, index) { return (react_1.default.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: '0.6rem' } },
40
- react_1.default.createElement("div", { key: index, style: {
41
- width: '1.2rem',
42
- height: '1.2rem',
43
- borderRadius: '50%',
44
- backgroundColor: entry.color
45
- } }),
46
- react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, { key: index }, showPercent ? entry.percentage + '%' : (entry.count || '0')))); })),
47
- showPercent && (react_1.default.createElement("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' } }, value.map(function (entry, index) { return (react_1.default.createElement(Typo2_1.UI_CAPTION_DF, { key: index }, entry.count || '0')); }))),
48
- react_1.default.createElement("div", { style: { paddingLeft: '0.8rem', display: 'flex', flexDirection: 'column', gap: '1rem' } }, value.map(function (entry, index) { return (react_1.default.createElement(Typo2_1.UI_CAPTION_DF, { key: index }, entry.tooltipLabel)); })))));
49
- };
50
- exports.default = CustomTooltip;
@@ -1,294 +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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
47
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
48
- if (ar || !(i in from)) {
49
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
50
- ar[i] = from[i];
51
- }
52
- }
53
- return to.concat(ar || Array.prototype.slice.call(from));
54
- };
55
- var __importDefault = (this && this.__importDefault) || function (mod) {
56
- return (mod && mod.__esModule) ? mod : { "default": mod };
57
- };
58
- Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.BarChart = void 0;
60
- var react_1 = __importStar(require("react"));
61
- var recharts_1 = require("recharts");
62
- var _EXPORTS_1 = require("../../../utils/_EXPORTS");
63
- var getTotalCount_1 = require("../../../utils/getTotalCount");
64
- var CustomizedLabel_1 = require("./comps/CustomizedLabel");
65
- var colors_1 = require("../../themes/colors");
66
- var CustomTooltip_1 = __importDefault(require("./comps/CustomTooltip"));
67
- var usePrepareData = function (_a) {
68
- var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent;
69
- return (0, react_1.useMemo)(function () {
70
- var finalData = __spreadArray([], _data, true);
71
- var totalCount = !isBreakdown
72
- ? (0, getTotalCount_1.getTotalCount)({ data: finalData, countPath: valuePath })
73
- : finalData.map(function (d) {
74
- var valueSum = valuePath
75
- .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
76
- .reduce(function (acc, curr) { return acc + curr; }, 0);
77
- return valueSum;
78
- });
79
- finalData = finalData.map(function (d, index) {
80
- if (!isBreakdown) {
81
- 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
82
- return {
83
- labels: __assign(__assign({}, (showPercent
84
- ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount) }
85
- : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
86
- };
87
- }
88
- return valuePath.map(function (path, i) {
89
- var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
90
- return {
91
- labels: __assign(__assign({}, (showPercent
92
- ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
93
- : {})), { count: count, tooltipLabel: tooltipLabelsPath
94
- ? tooltipLabelsPath[i] ? ((0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]) : path
95
- : ((tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path), name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
96
- };
97
- });
98
- });
99
- // Sort by total value
100
- finalData.sort(function (a, b) {
101
- if (!isBreakdown) {
102
- return b.labels.count - a.labels.count;
103
- }
104
- else {
105
- var bTotal = b
106
- .map(function (bItem) { return bItem.labels.count; })
107
- .reduce(function (acc, curr) { return acc + curr; }, 0);
108
- var aTotal = a
109
- .map(function (aItem) { return aItem.labels.count; })
110
- .reduce(function (acc, curr) { return acc + curr; }, 0);
111
- return bTotal - aTotal;
112
- }
113
- });
114
- return isBreakdown
115
- ? finalData.map(function (d, i) {
116
- return d.map(function (dd, ii) { return (__assign(__assign({}, dd), { labels: __assign(__assign({}, dd.labels), { dataIndex: i }) })); });
117
- })
118
- : finalData.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { dataIndex: i }) })); });
119
- }, [_data, labelPath, valuePath, isBreakdown, showPercent]);
120
- };
121
- /**
122
- * if any changes are being made to the spacing and such of
123
- this comps design, all these properties need to be carefully
124
- observed and tweaked to ensure no ui has gotten warped due to sideeffects
125
- */
126
- var _base_configs = {
127
- //4 of these compose a single bar section
128
- barHeight: 10,
129
- labelToBarGap: 6,
130
- labelHeight: 16.5667,
131
- labelToNextBarGap: 14,
132
- //other bar section related properties
133
- barRadius: 2,
134
- gapBetweenBarSections: 0,
135
- hoverRectStrokeWidth: 1,
136
- //overall chart margin
137
- marginLeft: 6,
138
- marginRight: 6,
139
- //grouped bar chart related properties
140
- gapBetweenBarsInGroup: 3,
141
- };
142
- // CHART_OFFSET_TOP is the y shift on top of the entire chart, because otherwise the chart starts with bar 1 at 0,0 coordinates
143
- var CHART_OFFSET_TOP = _base_configs.labelToBarGap +
144
- _base_configs.labelHeight +
145
- (_base_configs.labelToNextBarGap / 2 - 2); //this minus 2 is just to correct the extra white space that the labelHeight takes on top of the text
146
- var TOT_HEIGHT_SINGLE_BAR_SECTION = _base_configs.barHeight +
147
- _base_configs.labelToBarGap +
148
- _base_configs.labelHeight +
149
- _base_configs.labelToNextBarGap;
150
- var CALC_SINGLE_BAR_SECTION_Y_POS = function (index) {
151
- return (TOT_HEIGHT_SINGLE_BAR_SECTION + _base_configs.gapBetweenBarSections) * index;
152
- };
153
- var CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION = function (noOfBarsInGroup) {
154
- var totalHeightOfAllBars = noOfBarsInGroup * _base_configs.barHeight +
155
- (noOfBarsInGroup - 1) * _base_configs.gapBetweenBarsInGroup;
156
- return (totalHeightOfAllBars +
157
- _base_configs.labelToBarGap +
158
- _base_configs.labelHeight +
159
- _base_configs.labelToNextBarGap);
160
- };
161
- var CALC_GROUPED_BAR_SECTION_Y_POS = function (index, barIndex, noOfBarsInGroup) {
162
- var TOTAL_HEIGHT_GROUPED_BAR_SECTION = CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(noOfBarsInGroup);
163
- var startYPosOfGroup = (TOTAL_HEIGHT_GROUPED_BAR_SECTION + _base_configs.gapBetweenBarSections) *
164
- index;
165
- return (startYPosOfGroup +
166
- barIndex * (_base_configs.barHeight + _base_configs.gapBetweenBarsInGroup));
167
- };
168
- var _debug_controls = {
169
- mouseEventDetectorOpacity: 0, //only increase this for debugging. nothing else.
170
- chartWrapperBgColor: "", //set this to some color value for debugging
171
- };
172
- var barConfigs = {
173
- isBreakdown: {
174
- getBarRadius: function (stackIndex, breakdownDisplayType, //replaced breakdownDisplayType
175
- totalStacks) {
176
- return breakdownDisplayType === "grouped" //replaced breakdownDisplayType
177
- ? _base_configs.barRadius
178
- : stackIndex === totalStacks - 1
179
- ? [0, _base_configs.barRadius, _base_configs.barRadius, 0]
180
- : stackIndex === 0
181
- ? [_base_configs.barRadius, 0, 0, _base_configs.barRadius]
182
- : 0;
183
- },
184
- getDataKey: function (stackIndex) { return "".concat(stackIndex, ".labels.count"); },
185
- getStackId: function (stackIndex, breakdownDisplayType //replaced breakdownDisplayType
186
- ) { return (breakdownDisplayType === "stacked" ? "stack" : "stack-".concat(stackIndex)); },
187
- getCellFill: function (colorIdx, stackIndex, dataVizColors) { return dataVizColors[(colorIdx + stackIndex) % dataVizColors.length]; },
188
- },
189
- isNotBreakdown: {
190
- getBarRadius: function () { return _base_configs.barRadius; },
191
- getDataKey: function () { return "labels.count"; },
192
- getStackId: function () { return undefined; },
193
- getCellFill: function (colorIdx, _stackIndex, dataVizColors) { return dataVizColors[colorIdx]; },
194
- },
195
- };
196
- var BarChart = function (_a) {
197
- var _data = _a.data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, onClick = _a.onClick, _c = _a.breakdownDisplayType, breakdownDisplayType = _c === void 0 ? "grouped" : _c, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, _f = _a.colorIdx, colorIdx = _f === void 0 ? 0 : _f;
198
- var isBreakdown = Array.isArray(valuePath);
199
- var data = usePrepareData({
200
- _data: _data,
201
- labelPath: labelPath,
202
- valuePath: valuePath,
203
- tooltipLabelsMapping: tooltipLabelsMapping,
204
- tooltipLabelsPath: tooltipLabelsPath,
205
- isBreakdown: isBreakdown,
206
- showPercent: showPercent,
207
- });
208
- console.log({ data: data });
209
- var _g = (0, react_1.useState)(undefined), activeBar = _g[0], setActiveBar = _g[1];
210
- var _h = (0, react_1.useState)({ x: 0, y: 0 }), mousePosition = _h[0], setMousePosition = _h[1];
211
- (0, react_1.useEffect)(function () {
212
- var handleMouseMove = function (e) {
213
- setMousePosition({ x: e.clientX, y: e.clientY });
214
- };
215
- window.addEventListener('mousemove', handleMouseMove);
216
- // Clean up
217
- return function () {
218
- window.removeEventListener('mousemove', handleMouseMove);
219
- };
220
- }, []);
221
- // menu options for grouped and stacked
222
- var renderBar = function (stackIndex, lastIndex) {
223
- if (stackIndex === void 0) { stackIndex = 0; }
224
- var activeConfig = isBreakdown
225
- ? barConfigs.isBreakdown
226
- : barConfigs.isNotBreakdown;
227
- var totalStacks = isBreakdown ? data[0].length : 1;
228
- var currentStackId = activeConfig.getStackId(stackIndex, breakdownDisplayType);
229
- return (react_1.default.createElement(react_1.default.Fragment, null,
230
- react_1.default.createElement(recharts_1.Bar, { key: "stack-".concat(stackIndex), radius: activeConfig.getBarRadius(stackIndex, breakdownDisplayType, totalStacks), dataKey: activeConfig.getDataKey(stackIndex), stackId: currentStackId },
231
- (!isBreakdown || stackIndex === 0) && (react_1.default.createElement(recharts_1.LabelList, { dataKey: isBreakdown ? function (dataPoint) { return dataPoint; } : "labels", offset: 0, position: "bottom", content: function (props) { return (react_1.default.createElement(CustomizedLabel_1.CustomizedLabel, __assign({ CALC_SINGLE_BAR_SECTION_Y_POS: CALC_SINGLE_BAR_SECTION_Y_POS, TOT_HEIGHT_SINGLE_BAR_SECTION: TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION: isBreakdown && breakdownDisplayType === "grouped"
232
- ? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(data[0].length)
233
- : undefined, breakdownDisplayType: breakdownDisplayType, y: props.y,
234
- width: props.width,
235
- height: props.height,
236
- value: isBreakdown
237
- ? data[props.index].map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColorsText[(colorIdx + idx) % colors_1.dataVizColorsText.length] })); })
238
- : props.value, showPercent: showPercent, showCount: showCount, opacity: 1, activeBar: activeBar, _base_configs: _base_configs, _debug_controls: _debug_controls }, (onClick
239
- ? {
240
- onMouseOver: function (e, value) {
241
- setActiveBar(isBreakdown
242
- ? data[props.index][0].labels.name
243
- : value.name);
244
- },
245
- onMouseOut: function () { return setActiveBar(undefined); },
246
- onMouseDown: function (e, value) {
247
- var name = isBreakdown
248
- ? data[props.index][0].labels.name
249
- : value.name;
250
- setActiveBar(name);
251
- onClick(name);
252
- },
253
- }
254
- : {})))); } })),
255
- data.map(function (d, index) { return (react_1.default.createElement(recharts_1.Cell, { y: !isBreakdown || breakdownDisplayType === "stacked"
256
- ? CALC_SINGLE_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP
257
- : CALC_GROUPED_BAR_SECTION_Y_POS(index, stackIndex, data[0].length) + CHART_OFFSET_TOP, key: "cell-".concat(index, "-").concat(stackIndex), opacity: 1, height: _base_configs.barHeight, fill: activeConfig.getCellFill(colorIdx, stackIndex, colors_1.dataVizColors) })); }))));
258
- };
259
- return (react_1.default.createElement("div", { style: {
260
- height: "".concat(isBreakdown && breakdownDisplayType === "grouped"
261
- ? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(data[0].length) *
262
- data.length +
263
- _base_configs.gapBetweenBarSections * (data.length - 1) +
264
- _base_configs.hoverRectStrokeWidth * 2
265
- : TOT_HEIGHT_SINGLE_BAR_SECTION * data.length +
266
- _base_configs.gapBetweenBarSections * (data.length - 1) +
267
- _base_configs.hoverRectStrokeWidth * 2, "px"),
268
- width: "100%",
269
- background: _debug_controls.chartWrapperBgColor,
270
- } },
271
- react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: "100%" },
272
- react_1.default.createElement(recharts_1.BarChart, { width: 500, height: 500, data: data, layout: "vertical", margin: {
273
- top: 0,
274
- right: _base_configs.marginRight,
275
- left: _base_configs.marginLeft,
276
- bottom: 0,
277
- } },
278
- react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number" }),
279
- react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
280
- isBreakdown && (react_1.default.createElement(recharts_1.Tooltip, { content: function (props) {
281
- var _a;
282
- return (react_1.default.createElement(CustomTooltip_1.default, __assign({}, props, { mousePosition: mousePosition, showPercent: showPercent,
283
- // god knows why the dataindex gets stored against props.label.
284
- // this is some internal recharts thing for tooltips specifically.
285
- // we dont do this.
286
- value: (_a = data[props.label]) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColors[(colorIdx + idx) % colors_1.dataVizColors.length] })); }) })));
287
- }, cursor: false, allowEscapeViewBox: { x: true, y: true } })),
288
- isBreakdown
289
- ? data[0].map(function (_, stackIndex) {
290
- return renderBar(stackIndex, data[0].length - 1);
291
- })
292
- : renderBar()))));
293
- };
294
- exports.BarChart = BarChart;