oolib 2.191.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 +5 -2
- package/dist/v2/components/dataviz/BarGraphCollection/index.js +11 -5
- package/dist/v2/components/dataviz/BarGraphCollection/styled.js +18 -1
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.d.ts +1 -1
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +29 -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, debug }: {
|
|
5
5
|
data: any;
|
|
6
6
|
valuePath: any;
|
|
7
7
|
labelPath?: string;
|
|
@@ -10,12 +10,15 @@ export function BarGraphCollection({ data: originalData, valuePath, labelPath, t
|
|
|
10
10
|
showCount?: boolean;
|
|
11
11
|
showPercent?: boolean;
|
|
12
12
|
groupBy: any;
|
|
13
|
+
totalDataCount: any;
|
|
14
|
+
debug: any;
|
|
13
15
|
}): React.JSX.Element;
|
|
14
|
-
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick }: {
|
|
16
|
+
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick, debug }: {
|
|
15
17
|
tagCategory: any;
|
|
16
18
|
index1: any;
|
|
17
19
|
showCount?: boolean;
|
|
18
20
|
showPercent?: boolean;
|
|
19
21
|
onClick: any;
|
|
22
|
+
debug: any;
|
|
20
23
|
}): React.JSX.Element;
|
|
21
24
|
import React from "react";
|
|
@@ -50,13 +50,19 @@ 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, 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];
|
|
61
|
+
var highestCount = originalData === null || originalData === void 0 ? void 0 : originalData.reduce(function (highest, item) { return item.value > highest ? item.value : highest; }, 0);
|
|
56
62
|
var transformedData = (0, react_1.useMemo)(function () {
|
|
57
63
|
return (0, usePrepareData_1.usePrepareData)({ data: originalData, valuePath: valuePath, labelPath: labelPath, tooltipLabelsMapping: tooltipLabelsMapping, groupBy: groupBy });
|
|
58
64
|
}, [originalData, valuePath, labelPath, tooltipLabelsMapping, groupBy]);
|
|
59
|
-
var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth);
|
|
65
|
+
var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth, totalDataCount, highestCount);
|
|
60
66
|
(0, react_1.useEffect)(function () {
|
|
61
67
|
var handleResize = function () {
|
|
62
68
|
var _a, _b;
|
|
@@ -84,7 +90,7 @@ var BarGraphCollection = function (_a) {
|
|
|
84
90
|
height: "".concat(exports.BAR_GRAPH_HEIGHT + 50, "px"),
|
|
85
91
|
marginBottom: "0.6rem"
|
|
86
92
|
} },
|
|
87
|
-
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 }),
|
|
88
94
|
categoryTitle && react_1.default.createElement("div", { title: categoryTitle, style: {
|
|
89
95
|
width: "".concat(tagCategory === null || tagCategory === void 0 ? void 0 : tagCategory.width, "px"),
|
|
90
96
|
background: grey5,
|
|
@@ -105,7 +111,7 @@ var BarGraphCollection = function (_a) {
|
|
|
105
111
|
exports.BarGraphCollection = BarGraphCollection;
|
|
106
112
|
var BarGraph = function (_a) {
|
|
107
113
|
var _b;
|
|
108
|
-
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;
|
|
109
115
|
var _e = (0, react_1.useState)({ x: 0, y: 0 }), mousePosition = _e[0], setMousePosition = _e[1];
|
|
110
116
|
var _f = (0, react_1.useState)(null), activeTooltip = _f[0], setActiveTooltip = _f[1];
|
|
111
117
|
(0, react_1.useEffect)(function () {
|
|
@@ -146,7 +152,7 @@ var BarGraph = function (_a) {
|
|
|
146
152
|
tooltipLabel: tag.display
|
|
147
153
|
}];
|
|
148
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' } },
|
|
149
|
-
react_1.default.createElement(styled_1.StyledSingleBarWrapper,
|
|
155
|
+
react_1.default.createElement(styled_1.StyledSingleBarWrapper, { barSections: tag.barSections, debug: debug },
|
|
150
156
|
react_1.default.createElement(styled_1.StyledBar, { style: {
|
|
151
157
|
height: "".concat(tag.height, "px"),
|
|
152
158
|
width: "".concat(tag.width, "px")
|
|
@@ -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;
|
|
@@ -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,28 @@ 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 divideBarIntoEqualParts = function (num) {
|
|
30
|
+
if (num <= 5)
|
|
31
|
+
return 5;
|
|
32
|
+
if (num <= 10)
|
|
33
|
+
return 10;
|
|
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;
|
|
46
|
+
var magnitude = Math.pow(10, Math.floor(Math.log10(num)));
|
|
47
|
+
return Math.ceil(num / magnitude) * magnitude;
|
|
48
|
+
};
|
|
49
|
+
var barSections = divideBarIntoEqualParts(highestCount);
|
|
28
50
|
return data === null || data === void 0 ? void 0 : data.map(function (category) {
|
|
29
51
|
// total count for this category
|
|
30
52
|
var total = category.tagSpecificCount.reduce(function (sum, tag) { return sum + tag.count; }, 0);
|
|
@@ -33,8 +55,12 @@ var useGetDimensions = function (data, maxHeight, containerWidth) {
|
|
|
33
55
|
var categoryTotalWidth = (barsInCategory * singleBarWidth) + (gapsInCategory * Math.floor(__1.BAR_GAP * 10));
|
|
34
56
|
// percentage to each tag
|
|
35
57
|
return __assign(__assign({}, category), { width: categoryTotalWidth, tagSpecificCount: category.tagSpecificCount.map(function (tag) {
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
// Original percentage relative to total dataset
|
|
59
|
+
var percentage = Number((tag.count / (totalDataCount || total) * 100).toFixed(1));
|
|
60
|
+
// New height calculation relative to highest count and ceiling
|
|
61
|
+
// This creates a "zoomed in" effect where bars are more visible
|
|
62
|
+
var relativeHeight = Math.round((tag.count / barSections) * maxHeight);
|
|
63
|
+
return __assign({ percentage: percentage, height: relativeHeight, width: singleBarWidth, barSections: barSections }, tag);
|
|
38
64
|
}) });
|
|
39
65
|
});
|
|
40
66
|
};
|