oolib 2.192.0 → 2.192.1
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/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/stories/v2/components/BarGraphCollection.stories.d.ts +1 -0
- package/dist/stories/v2/components/BarGraphCollection.stories.js +1147 -79
- package/dist/v2/components/dataviz/BarGraphCollection/index.d.ts +4 -2
- package/dist/v2/components/dataviz/BarGraphCollection/index.js +9 -18
- package/dist/v2/components/dataviz/BarGraphCollection/styled.js +18 -1
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +20 -18
- 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, totalDataCount, }: {
|
|
4
|
+
export function BarGraphCollection({ data: originalData, valuePath, labelPath, tooltipLabelsMapping, onClick, showCount, showPercent, groupBy, totalDataCount, debug }: {
|
|
5
5
|
data: any;
|
|
6
6
|
valuePath: any;
|
|
7
7
|
labelPath?: string;
|
|
@@ -11,12 +11,14 @@ export function BarGraphCollection({ data: originalData, valuePath, labelPath, t
|
|
|
11
11
|
showPercent?: boolean;
|
|
12
12
|
groupBy: any;
|
|
13
13
|
totalDataCount: any;
|
|
14
|
+
debug: any;
|
|
14
15
|
}): React.JSX.Element;
|
|
15
|
-
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick }: {
|
|
16
|
+
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick, debug }: {
|
|
16
17
|
tagCategory: any;
|
|
17
18
|
index1: any;
|
|
18
19
|
showCount?: boolean;
|
|
19
20
|
showPercent?: boolean;
|
|
20
21
|
onClick: any;
|
|
22
|
+
debug: any;
|
|
21
23
|
}): React.JSX.Element;
|
|
22
24
|
import React from "react";
|
|
@@ -50,7 +50,12 @@ 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, totalDataCount = _a.totalDataCount
|
|
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, debug = _a.debug
|
|
54
|
+
// tooltipLabelsPath,
|
|
55
|
+
// colorIdx = 0,
|
|
56
|
+
// summarizeAfterIdx = 5,
|
|
57
|
+
// breakdownDisplayType = "grouped"
|
|
58
|
+
;
|
|
54
59
|
var containerRef = (0, react_1.useRef)();
|
|
55
60
|
var _f = (0, react_1.useState)(0), containerWidth = _f[0], setContainerWidth = _f[1];
|
|
56
61
|
var highestCount = originalData === null || originalData === void 0 ? void 0 : originalData.reduce(function (highest, item) { return item.value > highest ? item.value : highest; }, 0);
|
|
@@ -58,7 +63,6 @@ var BarGraphCollection = function (_a) {
|
|
|
58
63
|
return (0, usePrepareData_1.usePrepareData)({ data: originalData, valuePath: valuePath, labelPath: labelPath, tooltipLabelsMapping: tooltipLabelsMapping, groupBy: groupBy });
|
|
59
64
|
}, [originalData, valuePath, labelPath, tooltipLabelsMapping, groupBy]);
|
|
60
65
|
var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth, totalDataCount, highestCount);
|
|
61
|
-
// console.log({ total: calculateTotalPercentage(data) })
|
|
62
66
|
(0, react_1.useEffect)(function () {
|
|
63
67
|
var handleResize = function () {
|
|
64
68
|
var _a, _b;
|
|
@@ -86,7 +90,7 @@ var BarGraphCollection = function (_a) {
|
|
|
86
90
|
height: "".concat(exports.BAR_GRAPH_HEIGHT + 50, "px"),
|
|
87
91
|
marginBottom: "0.6rem"
|
|
88
92
|
} },
|
|
89
|
-
react_1.default.createElement(exports.BarGraph, { tagCategory: tagCategory, index1: index1, showCount: showCount, showPercent: showPercent, onClick: onClick }),
|
|
93
|
+
react_1.default.createElement(exports.BarGraph, { tagCategory: tagCategory, index1: index1, showCount: showCount, showPercent: showPercent, onClick: onClick, debug: debug }),
|
|
90
94
|
categoryTitle && react_1.default.createElement("div", { title: categoryTitle, style: {
|
|
91
95
|
width: "".concat(tagCategory === null || tagCategory === void 0 ? void 0 : tagCategory.width, "px"),
|
|
92
96
|
background: grey5,
|
|
@@ -107,7 +111,7 @@ var BarGraphCollection = function (_a) {
|
|
|
107
111
|
exports.BarGraphCollection = BarGraphCollection;
|
|
108
112
|
var BarGraph = function (_a) {
|
|
109
113
|
var _b;
|
|
110
|
-
var tagCategory = _a.tagCategory, index1 = _a.index1, _c = _a.showCount, showCount = _c === void 0 ? true : _c, _d = _a.showPercent, showPercent = _d === void 0 ? true : _d, onClick = _a.onClick;
|
|
114
|
+
var tagCategory = _a.tagCategory, index1 = _a.index1, _c = _a.showCount, showCount = _c === void 0 ? true : _c, _d = _a.showPercent, showPercent = _d === void 0 ? true : _d, onClick = _a.onClick, debug = _a.debug;
|
|
111
115
|
var _e = (0, react_1.useState)({ x: 0, y: 0 }), mousePosition = _e[0], setMousePosition = _e[1];
|
|
112
116
|
var _f = (0, react_1.useState)(null), activeTooltip = _f[0], setActiveTooltip = _f[1];
|
|
113
117
|
(0, react_1.useEffect)(function () {
|
|
@@ -148,7 +152,7 @@ var BarGraph = function (_a) {
|
|
|
148
152
|
tooltipLabel: tag.display
|
|
149
153
|
}];
|
|
150
154
|
return (react_1.default.createElement("div", { key: tag._id || "".concat(index1, "-").concat(index), onMouseEnter: function () { return handleBarMouseEnter(index); }, onMouseLeave: handleBarMouseLeave, onClick: function () { return handleBarClick(tag); }, style: { cursor: onClick ? 'pointer' : 'default' } },
|
|
151
|
-
react_1.default.createElement(styled_1.StyledSingleBarWrapper,
|
|
155
|
+
react_1.default.createElement(styled_1.StyledSingleBarWrapper, { barSections: tag.barSections, debug: debug },
|
|
152
156
|
react_1.default.createElement(styled_1.StyledBar, { style: {
|
|
153
157
|
height: "".concat(tag.height, "px"),
|
|
154
158
|
width: "".concat(tag.width, "px")
|
|
@@ -159,16 +163,3 @@ var BarGraph = function (_a) {
|
|
|
159
163
|
})));
|
|
160
164
|
};
|
|
161
165
|
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
|
-
// }
|
|
@@ -16,7 +16,24 @@ var grey5 = __1.colors2.grey5;
|
|
|
16
16
|
exports.StyledBarGraphContainer = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: ", "px;\n padding-bottom: 0.4rem; // UI scroll bar bottom space \n overflow-x: auto;\n background-color: white;\n border-radius: 8px;\n"], ["\n padding: ", "px;\n padding-bottom: 0.4rem; // UI scroll bar bottom space \n overflow-x: auto;\n background-color: white;\n border-radius: 8px;\n"])), exports.CONTAINER_PADDING);
|
|
17
17
|
exports.StyledBarGraphCollectionWrapper = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n"], ["\n display: flex;\n"])));
|
|
18
18
|
exports.StyledBarGraphWrapper = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n position: relative;\n "], ["\n display: flex;\n position: relative;\n "])));
|
|
19
|
-
|
|
19
|
+
var generateDebugLines = function (barSections, debug) {
|
|
20
|
+
if (!debug)
|
|
21
|
+
return '';
|
|
22
|
+
var lines = [];
|
|
23
|
+
for (var i = 1; i <= barSections; i++) {
|
|
24
|
+
lines.push('linear-gradient(to right, #383838 0%, #383838 100%)');
|
|
25
|
+
}
|
|
26
|
+
var positions = [];
|
|
27
|
+
for (var i = 0; i <= barSections; i++) {
|
|
28
|
+
var position = (100 / barSections) * i;
|
|
29
|
+
positions.push("0 ".concat(position, "%"));
|
|
30
|
+
}
|
|
31
|
+
return "\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-image: ".concat(lines.join(', '), ";\n background-size: ").concat(Array(barSections).fill('100% 1px').join(', '), ";\n background-position: ").concat(positions.join(', '), ";\n background-repeat: no-repeat;\n pointer-events: none;\n z-index: 0;\n }\n ");
|
|
32
|
+
};
|
|
33
|
+
exports.StyledSingleBarWrapper = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n height: 100%;\n display: flex;\n align-items: flex-end;\n position: relative;\n cursor: pointer;\n border-radius: 2px;\n\n &:hover {\n background-color: ", ";\n }\n\n ", "\n \n > * {\n position: relative;\n z-index: 1;\n }\n"], ["\n height: 100%;\n display: flex;\n align-items: flex-end;\n position: relative;\n cursor: pointer;\n border-radius: 2px;\n\n &:hover {\n background-color: ", ";\n }\n\n ", "\n \n > * {\n position: relative;\n z-index: 1;\n }\n"])), grey5, function (_a) {
|
|
34
|
+
var barSections = _a.barSections, debug = _a.debug;
|
|
35
|
+
return generateDebugLines(barSections, debug);
|
|
36
|
+
});
|
|
20
37
|
exports.StyledBar = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n border-radius: 2px;\n background-color: ", ";\n color: ", ";\n position: relative;\n ", ";\n"], ["\n border-radius: 2px;\n background-color: ", ";\n color: ", ";\n position: relative;\n ", ";\n"])), barColor, __1.colors2.onSecondary, (0, __1.transition)("width"));
|
|
21
38
|
exports.StyledLabelWrapper = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n position: absolute;\n transform: rotate(-90deg);\n transform-origin: left top;\n bottom: 0;\n left: calc(50% - 8px); // 10px for font\n text-wrap: nowrap;\n display: flex;\n"], ["\n position: absolute;\n transform: rotate(-90deg);\n transform-origin: left top;\n bottom: 0;\n left: calc(50% - 8px); // 10px for font\n text-wrap: nowrap;\n display: flex;\n"])));
|
|
22
39
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
|
|
@@ -26,25 +26,27 @@ var useGetDimensions = function (data, maxHeight, containerWidth, totalDataCount
|
|
|
26
26
|
var dynamicBarWidth = availableWidthForBars / totalBars;
|
|
27
27
|
singleBarWidth = Math.max(dynamicBarWidth, __1.DEFAULT_SINGLE_BAR_WIDTH);
|
|
28
28
|
// Calculate the ceiling value for the highest count
|
|
29
|
-
var
|
|
30
|
-
if (num
|
|
29
|
+
var divideBarIntoEqualParts = function (num) {
|
|
30
|
+
if (num <= 5)
|
|
31
|
+
return 5;
|
|
32
|
+
if (num <= 10)
|
|
31
33
|
return 10;
|
|
32
|
-
|
|
34
|
+
if (num <= 20)
|
|
35
|
+
return 20;
|
|
36
|
+
if (num <= 50)
|
|
37
|
+
return 50;
|
|
38
|
+
if (num <= 100)
|
|
39
|
+
return 100;
|
|
40
|
+
if (num <= 200)
|
|
41
|
+
return 200;
|
|
42
|
+
if (num <= 500)
|
|
43
|
+
return 500;
|
|
44
|
+
if (num <= 1000)
|
|
45
|
+
return 1000;
|
|
33
46
|
var magnitude = Math.pow(10, Math.floor(Math.log10(num)));
|
|
34
|
-
|
|
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;
|
|
47
|
+
return Math.ceil(num / magnitude) * magnitude;
|
|
46
48
|
};
|
|
47
|
-
var
|
|
49
|
+
var barSections = divideBarIntoEqualParts(highestCount);
|
|
48
50
|
return data === null || data === void 0 ? void 0 : data.map(function (category) {
|
|
49
51
|
// total count for this category
|
|
50
52
|
var total = category.tagSpecificCount.reduce(function (sum, tag) { return sum + tag.count; }, 0);
|
|
@@ -57,8 +59,8 @@ var useGetDimensions = function (data, maxHeight, containerWidth, totalDataCount
|
|
|
57
59
|
var percentage = Number((tag.count / (totalDataCount || total) * 100).toFixed(1));
|
|
58
60
|
// New height calculation relative to highest count and ceiling
|
|
59
61
|
// This creates a "zoomed in" effect where bars are more visible
|
|
60
|
-
var relativeHeight = Math.round((tag.count /
|
|
61
|
-
return __assign({ percentage: percentage, height: relativeHeight, width: singleBarWidth }, tag);
|
|
62
|
+
var relativeHeight = Math.round((tag.count / barSections) * maxHeight);
|
|
63
|
+
return __assign({ percentage: percentage, height: relativeHeight, width: singleBarWidth, barSections: barSections }, tag);
|
|
62
64
|
}) });
|
|
63
65
|
});
|
|
64
66
|
};
|