oolib 2.191.0 → 2.192.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.
- package/dist/v2/components/dataviz/BarGraphCollection/index.d.ts +2 -1
- package/dist/v2/components/dataviz/BarGraphCollection/index.js +17 -2
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.d.ts +1 -1
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +27 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const BAR_GRAPH_HEIGHT: 250;
|
|
2
2
|
export const DEFAULT_SINGLE_BAR_WIDTH: 24;
|
|
3
3
|
export const BAR_GAP: 0.3;
|
|
4
|
-
export function BarGraphCollection({ data: originalData, valuePath, labelPath, tooltipLabelsMapping, onClick, showCount, showPercent, groupBy, }: {
|
|
4
|
+
export function BarGraphCollection({ data: originalData, valuePath, labelPath, tooltipLabelsMapping, onClick, showCount, showPercent, groupBy, totalDataCount, }: {
|
|
5
5
|
data: any;
|
|
6
6
|
valuePath: any;
|
|
7
7
|
labelPath?: string;
|
|
@@ -10,6 +10,7 @@ export function BarGraphCollection({ data: originalData, valuePath, labelPath, t
|
|
|
10
10
|
showCount?: boolean;
|
|
11
11
|
showPercent?: boolean;
|
|
12
12
|
groupBy: any;
|
|
13
|
+
totalDataCount: any;
|
|
13
14
|
}): React.JSX.Element;
|
|
14
15
|
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick }: {
|
|
15
16
|
tagCategory: any;
|
|
@@ -50,13 +50,15 @@ exports.BAR_GRAPH_HEIGHT = 250;
|
|
|
50
50
|
exports.DEFAULT_SINGLE_BAR_WIDTH = 24;
|
|
51
51
|
exports.BAR_GAP = 0.3;
|
|
52
52
|
var BarGraphCollection = function (_a) {
|
|
53
|
-
var originalData = _a.data, valuePath = _a.valuePath, _b = _a.labelPath, labelPath = _b === void 0 ? "display" : _b, _c = _a.tooltipLabelsMapping, tooltipLabelsMapping = _c === void 0 ? {} : _c, onClick = _a.onClick, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, groupBy = _a.groupBy;
|
|
53
|
+
var originalData = _a.data, valuePath = _a.valuePath, _b = _a.labelPath, labelPath = _b === void 0 ? "display" : _b, _c = _a.tooltipLabelsMapping, tooltipLabelsMapping = _c === void 0 ? {} : _c, onClick = _a.onClick, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, groupBy = _a.groupBy, totalDataCount = _a.totalDataCount;
|
|
54
54
|
var containerRef = (0, react_1.useRef)();
|
|
55
55
|
var _f = (0, react_1.useState)(0), containerWidth = _f[0], setContainerWidth = _f[1];
|
|
56
|
+
var highestCount = originalData === null || originalData === void 0 ? void 0 : originalData.reduce(function (highest, item) { return item.value > highest ? item.value : highest; }, 0);
|
|
56
57
|
var transformedData = (0, react_1.useMemo)(function () {
|
|
57
58
|
return (0, usePrepareData_1.usePrepareData)({ data: originalData, valuePath: valuePath, labelPath: labelPath, tooltipLabelsMapping: tooltipLabelsMapping, groupBy: groupBy });
|
|
58
59
|
}, [originalData, valuePath, labelPath, tooltipLabelsMapping, groupBy]);
|
|
59
|
-
var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth);
|
|
60
|
+
var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth, totalDataCount, highestCount);
|
|
61
|
+
// console.log({ total: calculateTotalPercentage(data) })
|
|
60
62
|
(0, react_1.useEffect)(function () {
|
|
61
63
|
var handleResize = function () {
|
|
62
64
|
var _a, _b;
|
|
@@ -157,3 +159,16 @@ var BarGraph = function (_a) {
|
|
|
157
159
|
})));
|
|
158
160
|
};
|
|
159
161
|
exports.BarGraph = BarGraph;
|
|
162
|
+
// function calculateTotalPercentage(data) {
|
|
163
|
+
// let totalPercentage = 0;
|
|
164
|
+
// // Iterate through each category
|
|
165
|
+
// data.forEach(category => {
|
|
166
|
+
// // Sum all percentages within tagSpecificCount
|
|
167
|
+
// if (category.tagSpecificCount && Array.isArray(category.tagSpecificCount)) {
|
|
168
|
+
// category.tagSpecificCount.forEach(tag => {
|
|
169
|
+
// totalPercentage += tag.percentage || 0;
|
|
170
|
+
// });
|
|
171
|
+
// }
|
|
172
|
+
// });
|
|
173
|
+
// return totalPercentage;
|
|
174
|
+
// }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function useGetDimensions(data: any, maxHeight: any, containerWidth: any): any;
|
|
1
|
+
export function useGetDimensions(data: any, maxHeight: any, containerWidth: any, totalDataCount: any, highestCount: any): any;
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.useGetDimensions = void 0;
|
|
15
15
|
var __1 = require("..");
|
|
16
16
|
var styled_1 = require("../styled");
|
|
17
|
-
var useGetDimensions = function (data, maxHeight, containerWidth) {
|
|
17
|
+
var useGetDimensions = function (data, maxHeight, containerWidth, totalDataCount, highestCount) {
|
|
18
18
|
var singleBarWidth;
|
|
19
19
|
var totalBars = data === null || data === void 0 ? void 0 : data.reduce(function (total, tagCategory) {
|
|
20
20
|
var _a;
|
|
@@ -25,6 +25,26 @@ var useGetDimensions = function (data, maxHeight, containerWidth) {
|
|
|
25
25
|
// const defaultWidthForBars = (totalBars - 1) * DEFAULT_SINGLE_BAR_WIDTH - (CONTAINER_PADDING * 2);
|
|
26
26
|
var dynamicBarWidth = availableWidthForBars / totalBars;
|
|
27
27
|
singleBarWidth = Math.max(dynamicBarWidth, __1.DEFAULT_SINGLE_BAR_WIDTH);
|
|
28
|
+
// Calculate the ceiling value for the highest count
|
|
29
|
+
var getCeilingValue = function (num) {
|
|
30
|
+
if (num === 0)
|
|
31
|
+
return 10;
|
|
32
|
+
// Find the power of 10 (magnitude)
|
|
33
|
+
var magnitude = Math.pow(10, Math.floor(Math.log10(num)));
|
|
34
|
+
// Round up to the nearest "nice" number
|
|
35
|
+
var normalized = num / magnitude; // This gives us a number between 1-10
|
|
36
|
+
var multiplier;
|
|
37
|
+
if (normalized <= 1)
|
|
38
|
+
multiplier = 1;
|
|
39
|
+
else if (normalized <= 2)
|
|
40
|
+
multiplier = 2;
|
|
41
|
+
else if (normalized <= 5)
|
|
42
|
+
multiplier = 5;
|
|
43
|
+
else
|
|
44
|
+
multiplier = 10;
|
|
45
|
+
return multiplier * magnitude;
|
|
46
|
+
};
|
|
47
|
+
var ceilingValue = getCeilingValue(highestCount);
|
|
28
48
|
return data === null || data === void 0 ? void 0 : data.map(function (category) {
|
|
29
49
|
// total count for this category
|
|
30
50
|
var total = category.tagSpecificCount.reduce(function (sum, tag) { return sum + tag.count; }, 0);
|
|
@@ -33,8 +53,12 @@ var useGetDimensions = function (data, maxHeight, containerWidth) {
|
|
|
33
53
|
var categoryTotalWidth = (barsInCategory * singleBarWidth) + (gapsInCategory * Math.floor(__1.BAR_GAP * 10));
|
|
34
54
|
// percentage to each tag
|
|
35
55
|
return __assign(__assign({}, category), { width: categoryTotalWidth, tagSpecificCount: category.tagSpecificCount.map(function (tag) {
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
// Original percentage relative to total dataset
|
|
57
|
+
var percentage = Number((tag.count / (totalDataCount || total) * 100).toFixed(1));
|
|
58
|
+
// New height calculation relative to highest count and ceiling
|
|
59
|
+
// This creates a "zoomed in" effect where bars are more visible
|
|
60
|
+
var relativeHeight = Math.round((tag.count / ceilingValue) * maxHeight);
|
|
61
|
+
return __assign({ percentage: percentage, height: relativeHeight, width: singleBarWidth }, tag);
|
|
38
62
|
}) });
|
|
39
63
|
});
|
|
40
64
|
};
|