oolib 2.188.8 → 2.190.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 (41) 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 +146 -43
  7. package/dist/stories/v2/components/BarGraphCollection.stories.d.ts +18 -0
  8. package/dist/stories/v2/components/BarGraphCollection.stories.js +122 -0
  9. package/dist/stories/v2/components/HeatMapGrid.stories.d.ts +17 -0
  10. package/dist/stories/v2/components/HeatMapGrid.stories.js +107 -0
  11. package/dist/v2/components/DataVizAccordion/index.d.ts +1 -1
  12. package/dist/v2/components/DataVizAccordion/index.js +1 -1
  13. package/dist/v2/components/Dropdowns/DropdownMulti/index.js +2 -0
  14. package/dist/v2/components/Dropdowns/DropdownSingle/index.js +6 -1
  15. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.d.ts +18 -0
  16. package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.js +24 -0
  17. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomTooltip/index.d.ts +4 -4
  18. package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/index.js +161 -0
  19. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.d.ts +7 -12
  20. package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.js +22 -12
  21. package/dist/v2/components/{BarChart → dataviz/BarChart}/index.d.ts +12 -14
  22. package/dist/v2/components/dataviz/BarChart/index.js +276 -0
  23. package/dist/v2/components/dataviz/BarGraphCollection/index.d.ts +21 -0
  24. package/dist/v2/components/dataviz/BarGraphCollection/index.js +159 -0
  25. package/dist/v2/components/dataviz/BarGraphCollection/styled.d.ts +7 -0
  26. package/dist/v2/components/dataviz/BarGraphCollection/styled.js +22 -0
  27. package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.d.ts +1 -0
  28. package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +41 -0
  29. package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.d.ts +11 -0
  30. package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.js +76 -0
  31. package/dist/v2/components/dataviz/HeatMapGrid/index.d.ts +21 -0
  32. package/dist/v2/components/dataviz/HeatMapGrid/index.js +230 -0
  33. package/dist/v2/components/dataviz/types.d.ts +12 -0
  34. package/dist/v2/components/dataviz/types.js +2 -0
  35. package/dist/v2/components/dataviz/utils/usePrepareData.d.ts +20 -0
  36. package/dist/v2/components/dataviz/utils/usePrepareData.js +116 -0
  37. package/package.json +1 -1
  38. package/dist/v2/components/BarChart/comps/CustomTooltip/index.js +0 -50
  39. package/dist/v2/components/BarChart/index.js +0 -294
  40. /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.d.ts +0 -0
  41. /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.js +0 -0
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BarGraph = exports.BarGraphCollection = exports.BAR_GAP = exports.DEFAULT_SINGLE_BAR_WIDTH = exports.BAR_GRAPH_HEIGHT = void 0;
40
+ var react_1 = __importStar(require("react"));
41
+ var __1 = require("../../../..");
42
+ var __2 = require("../../../..");
43
+ var styled_1 = require("./styled");
44
+ var useGetDimensions_1 = require("./utils/useGetDimensions");
45
+ // import { __GetContentTypeConfigNew } from "../../../../../utils/getters/gettersV2";
46
+ var CustomTooltip_1 = __importDefault(require("../BarChart/comps/CustomTooltip"));
47
+ var usePrepareData_1 = require("./utils/usePrepareData");
48
+ var grey5 = __1.colors2.grey5;
49
+ exports.BAR_GRAPH_HEIGHT = 250;
50
+ exports.DEFAULT_SINGLE_BAR_WIDTH = 24;
51
+ exports.BAR_GAP = 0.3;
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;
54
+ var containerRef = (0, react_1.useRef)();
55
+ var _f = (0, react_1.useState)(0), containerWidth = _f[0], setContainerWidth = _f[1];
56
+ var transformedData = (0, react_1.useMemo)(function () {
57
+ return (0, usePrepareData_1.usePrepareData)({ data: originalData, valuePath: valuePath, labelPath: labelPath, tooltipLabelsMapping: tooltipLabelsMapping, groupBy: groupBy });
58
+ }, [originalData, valuePath, labelPath, tooltipLabelsMapping, groupBy]);
59
+ var data = (0, useGetDimensions_1.useGetDimensions)(transformedData, exports.BAR_GRAPH_HEIGHT, containerWidth);
60
+ (0, react_1.useEffect)(function () {
61
+ var handleResize = function () {
62
+ var _a, _b;
63
+ setContainerWidth((_b = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width);
64
+ };
65
+ handleResize();
66
+ window.addEventListener("resize", handleResize);
67
+ return function () { return window.removeEventListener("resize", handleResize); };
68
+ }, [transformedData]);
69
+ if ((data === null || data === void 0 ? void 0 : data.length) === 0) {
70
+ return null;
71
+ }
72
+ return (react_1.default.createElement(styled_1.StyledBarGraphContainer, { style: { width: "auto" }, ref: containerRef },
73
+ react_1.default.createElement(styled_1.StyledBarGraphCollectionWrapper, { style: {
74
+ width: "auto",
75
+ gap: "".concat(exports.BAR_GAP, "rem"),
76
+ overflowX: "auto"
77
+ } }, data === null || data === void 0 ? void 0 : data.map(function (tagCategory, index1) {
78
+ var categoryTitle = (tagCategory === null || tagCategory === void 0 ? void 0 : tagCategory.tagCategory) ? (tagCategory.tagCategory.charAt(0).toUpperCase() + tagCategory.tagCategory.slice(1)) : undefined;
79
+ // __GetContentTypeConfigNew(tagCategory.tagCategory)?.general?.content?.title ||
80
+ return (react_1.default.createElement("div", { key: "".concat(index1, "-").concat(tagCategory.tagCategory), style: {
81
+ display: "flex",
82
+ flexDirection: "column",
83
+ gap: "".concat(exports.BAR_GAP, "rem"),
84
+ height: "".concat(exports.BAR_GRAPH_HEIGHT + 50, "px"),
85
+ marginBottom: "0.6rem"
86
+ } },
87
+ react_1.default.createElement(exports.BarGraph, { tagCategory: tagCategory, index1: index1, showCount: showCount, showPercent: showPercent, onClick: onClick }),
88
+ categoryTitle && react_1.default.createElement("div", { title: categoryTitle, style: {
89
+ width: "".concat(tagCategory === null || tagCategory === void 0 ? void 0 : tagCategory.width, "px"),
90
+ background: grey5,
91
+ borderRadius: "2px",
92
+ padding: "0.8rem",
93
+ maxHeight: "50px",
94
+ overflow: "hidden"
95
+ } },
96
+ react_1.default.createElement(__2.UI_BODY_SEMIBOLD_SM, null,
97
+ react_1.default.createElement("p", { style: {
98
+ whiteSpace: "nowrap",
99
+ overflow: "hidden",
100
+ textOverflow: "ellipsis",
101
+ maxWidth: "100%"
102
+ } }, categoryTitle)))));
103
+ }))));
104
+ };
105
+ exports.BarGraphCollection = BarGraphCollection;
106
+ var BarGraph = function (_a) {
107
+ 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;
109
+ var _e = (0, react_1.useState)({ x: 0, y: 0 }), mousePosition = _e[0], setMousePosition = _e[1];
110
+ var _f = (0, react_1.useState)(null), activeTooltip = _f[0], setActiveTooltip = _f[1];
111
+ (0, react_1.useEffect)(function () {
112
+ var handleMouseMove = function (e) {
113
+ setMousePosition({ x: e.clientX, y: e.clientY });
114
+ };
115
+ window.addEventListener('mousemove', handleMouseMove);
116
+ return function () {
117
+ window.removeEventListener('mousemove', handleMouseMove);
118
+ };
119
+ }, []);
120
+ var truncateText = function (text, maxLength) {
121
+ if (maxLength === void 0) { maxLength = 30; }
122
+ if (!text)
123
+ return '';
124
+ if (text.length <= maxLength)
125
+ return text;
126
+ return text.slice(0, maxLength) + '...';
127
+ };
128
+ var handleBarMouseEnter = function (index) {
129
+ setActiveTooltip(index);
130
+ };
131
+ var handleBarMouseLeave = function () {
132
+ setActiveTooltip(null);
133
+ };
134
+ var handleBarClick = function (tag) {
135
+ if (onClick) {
136
+ onClick(tag.display);
137
+ }
138
+ };
139
+ return (react_1.default.createElement(styled_1.StyledBarGraphWrapper, { style: {
140
+ height: "".concat(exports.BAR_GRAPH_HEIGHT, "px"),
141
+ gap: "".concat(exports.BAR_GAP, "rem"),
142
+ } }, (_b = tagCategory === null || tagCategory === void 0 ? void 0 : tagCategory.tagSpecificCount) === null || _b === void 0 ? void 0 : _b.map(function (tag, index) {
143
+ var tooltipData = [{
144
+ percentage: showPercent ? tag.percentage : undefined,
145
+ count: showCount ? tag.count : undefined,
146
+ tooltipLabel: tag.display
147
+ }];
148
+ 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, null,
150
+ react_1.default.createElement(styled_1.StyledBar, { style: {
151
+ height: "".concat(tag.height, "px"),
152
+ width: "".concat(tag.width, "px")
153
+ } }),
154
+ react_1.default.createElement(styled_1.StyledLabelWrapper, null,
155
+ react_1.default.createElement(__2.UI_BODY_SM, null, truncateText(tag === null || tag === void 0 ? void 0 : tag.display, 30))),
156
+ activeTooltip === index && (react_1.default.createElement(CustomTooltip_1.default, { active: true, payload: [tag], mousePosition: mousePosition, value: tooltipData, showPercent: showPercent })))));
157
+ })));
158
+ };
159
+ exports.BarGraph = BarGraph;
@@ -0,0 +1,7 @@
1
+ export const CONTAINER_PADDING: 10;
2
+ export const StyledBarGraphContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
3
+ export const StyledBarGraphCollectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
4
+ export const StyledBarGraphWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
5
+ export const StyledSingleBarWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
6
+ export const StyledBar: import("styled-components").StyledComponent<"div", any, {}, never>;
7
+ export const StyledLabelWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.StyledLabelWrapper = exports.StyledBar = exports.StyledSingleBarWrapper = exports.StyledBarGraphWrapper = exports.StyledBarGraphCollectionWrapper = exports.StyledBarGraphContainer = exports.CONTAINER_PADDING = void 0;
11
+ var styled_components_1 = __importDefault(require("styled-components"));
12
+ var __1 = require("../../../..");
13
+ exports.CONTAINER_PADDING = 10;
14
+ var barColor = __1.colors2.secondaryContainer; // temp color
15
+ var grey5 = __1.colors2.grey5;
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
+ exports.StyledBarGraphCollectionWrapper = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n"], ["\n display: flex;\n"])));
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
+ 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 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"])), grey5);
20
+ 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
+ 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
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
@@ -0,0 +1 @@
1
+ export function useGetDimensions(data: any, maxHeight: any, containerWidth: any): any;
@@ -0,0 +1,41 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useGetDimensions = void 0;
15
+ var __1 = require("..");
16
+ var styled_1 = require("../styled");
17
+ var useGetDimensions = function (data, maxHeight, containerWidth) {
18
+ var singleBarWidth;
19
+ var totalBars = data === null || data === void 0 ? void 0 : data.reduce(function (total, tagCategory) {
20
+ var _a;
21
+ return total += (_a = tagCategory.tagSpecificCount) === null || _a === void 0 ? void 0 : _a.length;
22
+ }, 0);
23
+ var totalGapSpace = (totalBars - 1) * Math.floor(__1.BAR_GAP * 10); // BAR GAP, example 0.3 converted 3Px
24
+ var availableWidthForBars = (containerWidth - totalGapSpace) - (styled_1.CONTAINER_PADDING * 2); // CONTAINER_PADDING Left right 10 * 10 = 20
25
+ // const defaultWidthForBars = (totalBars - 1) * DEFAULT_SINGLE_BAR_WIDTH - (CONTAINER_PADDING * 2);
26
+ var dynamicBarWidth = availableWidthForBars / totalBars;
27
+ singleBarWidth = Math.max(dynamicBarWidth, __1.DEFAULT_SINGLE_BAR_WIDTH);
28
+ return data === null || data === void 0 ? void 0 : data.map(function (category) {
29
+ // total count for this category
30
+ var total = category.tagSpecificCount.reduce(function (sum, tag) { return sum + tag.count; }, 0);
31
+ var barsInCategory = category.tagSpecificCount.length;
32
+ var gapsInCategory = Math.max(0, barsInCategory - 1); // One less gap than bars
33
+ var categoryTotalWidth = (barsInCategory * singleBarWidth) + (gapsInCategory * Math.floor(__1.BAR_GAP * 10));
34
+ // percentage to each tag
35
+ return __assign(__assign({}, category), { width: categoryTotalWidth, tagSpecificCount: category.tagSpecificCount.map(function (tag) {
36
+ var percentage = Number((tag.count / total * 100).toFixed(1));
37
+ return __assign({ percentage: percentage, height: Math.round((percentage / 100) * maxHeight), width: singleBarWidth }, tag);
38
+ }) });
39
+ });
40
+ };
41
+ exports.useGetDimensions = useGetDimensions;
@@ -0,0 +1,11 @@
1
+ export function usePrepareData({ data, valuePath, labelPath, tooltipLabelsMapping, groupBy }: {
2
+ data: any;
3
+ valuePath: any;
4
+ labelPath: any;
5
+ tooltipLabelsMapping: any;
6
+ groupBy: any;
7
+ }): {
8
+ tagCategory: any;
9
+ totalCountOfAllTagsWithin: any;
10
+ tagSpecificCount: any;
11
+ }[];
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePrepareData = void 0;
4
+ var _EXPORTS_1 = require("../../../../../utils/_EXPORTS");
5
+ var usePrepareData = function (_a) {
6
+ var data = _a.data, valuePath = _a.valuePath, labelPath = _a.labelPath, tooltipLabelsMapping = _a.tooltipLabelsMapping, groupBy = _a.groupBy;
7
+ // Check if it's breakdown data (array of valuePaths) or simple data
8
+ var isBreakdown = Array.isArray(valuePath);
9
+ if (!isBreakdown) {
10
+ // If groupBy is specified, group the data by that field
11
+ if (groupBy && data.length > 0 && groupBy in data[0]) {
12
+ // Group data by the specified field
13
+ var groupedData_1 = {};
14
+ data.forEach(function (item) {
15
+ var groupKey = (0, _EXPORTS_1.getVal)(item, groupBy) || 'Uncategorized';
16
+ if (!groupedData_1[groupKey]) {
17
+ groupedData_1[groupKey] = {
18
+ items: [],
19
+ totalCount: 0
20
+ };
21
+ }
22
+ var count = (0, _EXPORTS_1.getVal)(item, valuePath) || 0;
23
+ groupedData_1[groupKey].items.push({
24
+ tagId: (0, _EXPORTS_1.getVal)(item, labelPath),
25
+ display: (0, _EXPORTS_1.getVal)(item, labelPath),
26
+ _id: Math.random().toString(36).substr(2, 9),
27
+ count: count
28
+ });
29
+ groupedData_1[groupKey].totalCount += count;
30
+ });
31
+ // Convert grouped data to the expected format
32
+ return Object.entries(groupedData_1).map(function (_a) {
33
+ var key = _a[0], value = _a[1];
34
+ return ({
35
+ tagCategory: key,
36
+ totalCountOfAllTagsWithin: value.totalCount,
37
+ tagSpecificCount: value.items
38
+ });
39
+ });
40
+ }
41
+ else {
42
+ // Simple case - single category with single values
43
+ return [{
44
+ tagCategory: undefined,
45
+ totalCountOfAllTagsWithin: data.reduce(function (sum, item) { return sum + ((0, _EXPORTS_1.getVal)(item, valuePath) || 0); }, 0),
46
+ tagSpecificCount: data.map(function (item) { return ({
47
+ tagId: (0, _EXPORTS_1.getVal)(item, labelPath),
48
+ display: (0, _EXPORTS_1.getVal)(item, labelPath),
49
+ _id: Math.random().toString(36).substr(2, 9),
50
+ count: (0, _EXPORTS_1.getVal)(item, valuePath) || 0
51
+ }); })
52
+ }];
53
+ }
54
+ }
55
+ else {
56
+ // For breakdown case, we'll create categories based on the valuePath items
57
+ // Each valuePath becomes a category
58
+ return valuePath.map(function (path, pathIndex) {
59
+ var categoryName = (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path;
60
+ var totalCount = data.reduce(function (sum, item) { return sum + ((0, _EXPORTS_1.getVal)(item, path) || 0); }, 0);
61
+ return {
62
+ tagCategory: categoryName,
63
+ totalCountOfAllTagsWithin: totalCount,
64
+ tagSpecificCount: data
65
+ .map(function (item) { return ({
66
+ tagId: (0, _EXPORTS_1.getVal)(item, labelPath),
67
+ display: (0, _EXPORTS_1.getVal)(item, labelPath),
68
+ _id: "".concat(pathIndex, "-").concat((0, _EXPORTS_1.getVal)(item, labelPath)),
69
+ count: (0, _EXPORTS_1.getVal)(item, path) || 0
70
+ }); })
71
+ .filter(function (tag) { return tag.count > 0; }) // Only include items with values
72
+ };
73
+ }).filter(function (category) { return category.tagSpecificCount.length > 0; }); // Only include categories with items
74
+ }
75
+ };
76
+ exports.usePrepareData = usePrepareData;
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ export interface HeatMapGridProps {
3
+ data: any;
4
+ valuePath: string | string[];
5
+ tooltipLabelsMapping: {
6
+ [key: string]: string;
7
+ };
8
+ tooltipLabelsPath: string | string[];
9
+ labelPath: string;
10
+ onClick?: (name: string) => void;
11
+ valueSuffix?: string;
12
+ showCount?: boolean;
13
+ showPercent?: boolean;
14
+ breakdownDisplayType?: "grouped" | "stacked";
15
+ colorIdx?: number;
16
+ summarizeAfterIdx?: number;
17
+ }
18
+ /**
19
+ * expects exactly the same data structure as barcharts - breakdown version
20
+ */
21
+ export declare const HeatMapGrid: React.FC<HeatMapGridProps>;
@@ -0,0 +1,230 @@
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.HeatMapGrid = void 0;
51
+ var react_1 = __importStar(require("react"));
52
+ var BarChart_1 = require("../BarChart");
53
+ var Typo2_1 = require("../../Typo2");
54
+ var CustomTooltip_1 = __importDefault(require("../BarChart/comps/CustomTooltip"));
55
+ var usePrepareData_1 = require("../utils/usePrepareData");
56
+ var __1 = require("../../../..");
57
+ /**
58
+ * Maps a value from an input range to a color
59
+ * with the base color at the center point of the range
60
+ * @param {number} value - The value to map
61
+ * @param {number} minValue - The minimum value in the input range
62
+ * @param {number} maxValue - The maximum value in the input range
63
+ * @param {Object} hslColor - The base HSL color object
64
+ * @param {number} hslColor.h - Hue component (0-360)
65
+ * @param {number} hslColor.s - Saturation component (0-100)
66
+ * @param {number} hslColor.l - Lightness component (0-100)
67
+ * @param {number} minLightness - The minimum lightness (0-100) for darkest shade
68
+ * @param {number} maxLightness - The maximum lightness (0-100) for lightest shade
69
+ * @return {string} - A hex color code
70
+ */
71
+ function mapValueToColor(value, minValue, maxValue, hslColor, // Default to #be185d
72
+ minLightness, maxLightness) {
73
+ if (hslColor === void 0) { hslColor = { h: 336, s: 74, l: 42 }; }
74
+ if (minLightness === void 0) { minLightness = 20; }
75
+ if (maxLightness === void 0) { maxLightness = 80; }
76
+ // Ensure value is within range
77
+ value = Math.max(minValue, Math.min(maxValue, value));
78
+ // Calculate the center point of the range
79
+ var centerPoint = (minValue + maxValue) / 2;
80
+ // Extract the hsl components
81
+ var h = hslColor.h, s = hslColor.s, baseLightness = hslColor.l;
82
+ // Determine lightness based on position relative to center point
83
+ var lightness;
84
+ if (value < centerPoint) {
85
+ // Value is below center (smaller) - scale from maxLightness to baseLightness
86
+ var normalizedValue = (value - minValue) / (centerPoint - minValue);
87
+ lightness = maxLightness - normalizedValue * (maxLightness - baseLightness);
88
+ }
89
+ else {
90
+ // Value is above center (larger) - scale from baseLightness to minLightness
91
+ var normalizedValue = (value - centerPoint) / (maxValue - centerPoint);
92
+ lightness = baseLightness - normalizedValue * (baseLightness - minLightness);
93
+ }
94
+ // Convert HSL back to hex
95
+ return "hsl(".concat(h, ", ").concat(s, "%, ").concat(lightness, "%)"); //hslToHex(h, s, lightness);
96
+ }
97
+ /**
98
+ * Convert HSL values to hex color code
99
+ * @param {number} h - Hue (0-360)
100
+ * @param {number} s - Saturation (0-100)
101
+ * @param {number} l - Lightness (0-100)
102
+ * @return {string} - Hex color code
103
+ */
104
+ function hslToHex(h, s, l) {
105
+ l /= 100;
106
+ var a = (s * Math.min(l, 1 - l)) / 100;
107
+ var f = function (n) {
108
+ var k = (n + h / 30) % 12;
109
+ var color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
110
+ return Math.round(255 * color)
111
+ .toString(16)
112
+ .padStart(2, "0");
113
+ };
114
+ return "#".concat(f(0)).concat(f(8)).concat(f(4));
115
+ }
116
+ var _configs = {
117
+ gridGap: 2,
118
+ cellRoundness: 4,
119
+ cellSize: 36,
120
+ axisLabelWidth: 62,
121
+ };
122
+ var HeatMapCell = function (_a) {
123
+ var value = _a.value, dataMaxValue = _a.dataMaxValue, _b = _a.dataMinValue, dataMinValue = _b === void 0 ? 0 : _b, showPercent = _a.showPercent;
124
+ var mousePosition = (0, BarChart_1.useTrackMousePosition)().mousePosition;
125
+ var _c = (0, react_1.useState)(false), showTooltip = _c[0], setShowTooltip = _c[1];
126
+ var cellColor = mapValueToColor(value.labels.count, dataMinValue, dataMaxValue);
127
+ var getCellColorLightness = function () {
128
+ var splitUp = cellColor.trim().replace('hsl(', '');
129
+ splitUp = splitUp.replace(')', '');
130
+ var splitUpAry = splitUp.split(',').map(function (d) { return d.trim(); });
131
+ var toReturn = parseInt(splitUpAry[2].replace('%', ''));
132
+ return toReturn;
133
+ };
134
+ var textColor = getCellColorLightness() > 60 ? __1.colors2.black : __1.colors2.white;
135
+ return (react_1.default.createElement("div", { onMouseOver: function () { return setShowTooltip(true); }, onMouseOut: function () { return setShowTooltip(false); } },
136
+ showTooltip && (react_1.default.createElement(CustomTooltip_1.default, { active: true, value: [__assign(__assign({}, value.labels), { tooltipLabel: value.labels.name + ' | ' + value.labels.tooltipLabel //bit of a hack but will sort later
137
+ })], showPercent: showPercent, mousePosition: mousePosition })),
138
+ react_1.default.createElement("div", { style: {
139
+ height: _configs.cellSize + "px",
140
+ width: _configs.cellSize + "px",
141
+ background: cellColor,
142
+ borderRadius: _configs.cellRoundness + "px",
143
+ display: 'flex',
144
+ justifyContent: 'center',
145
+ alignItems: 'center'
146
+ } },
147
+ react_1.default.createElement(Typo2_1.UI_CAPTION_SEMIBOLD_DF, { style: { color: textColor } }, value.labels.count))));
148
+ };
149
+ /**
150
+ * expects exactly the same data structure as barcharts - breakdown version
151
+ */
152
+ var HeatMapGrid = function (_a) {
153
+ 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.showCount, showCount = _c === void 0 ? true : _c, _d = _a.showPercent, showPercent = _d === void 0 ? true : _d, _e = _a.colorIdx, colorIdx = _e === void 0 ? 0 : _e, _f = _a.summarizeAfterIdx, summarizeAfterIdx = _f === void 0 ? 5 : _f;
154
+ var _g = (0, usePrepareData_1.usePrepareData)({
155
+ _data: _data,
156
+ labelPath: labelPath,
157
+ valuePath: valuePath,
158
+ tooltipLabelsMapping: tooltipLabelsMapping,
159
+ tooltipLabelsPath: tooltipLabelsPath,
160
+ isBreakdown: true,
161
+ showPercent: showPercent,
162
+ summarizeAfterIdx: summarizeAfterIdx,
163
+ }), data = _g.data, dataMaxValue = _g.dataMaxValue, dataToSummarize = _g.dataToSummarize;
164
+ return (react_1.default.createElement("div", null,
165
+ react_1.default.createElement("div", { style: {
166
+ display: "grid",
167
+ gridTemplateColumns: "auto 1fr",
168
+ gap: _configs.gridGap + 'px',
169
+ } },
170
+ react_1.default.createElement("div", { style: {
171
+ display: "flex",
172
+ flexDirection: "column",
173
+ gap: _configs.gridGap + "px",
174
+ } },
175
+ react_1.default.createElement("div", { style: { height: _configs.axisLabelWidth + "px" } }),
176
+ data.map(function (d) { return (react_1.default.createElement("div", { style: {
177
+ height: _configs.cellSize + "px",
178
+ textAlign: "right",
179
+ display: "flex",
180
+ alignItems: "center",
181
+ justifyContent: "flex-end",
182
+ } },
183
+ react_1.default.createElement(Typo2_1.UI_CAPTION_SEMIBOLD_DF, { style: {
184
+ width: _configs.axisLabelWidth + "px",
185
+ textOverflow: "ellipsis",
186
+ overflow: "hidden",
187
+ whiteSpace: "nowrap",
188
+ } }, d[0].labels.name))); })),
189
+ react_1.default.createElement("div", { style: {
190
+ display: "flex",
191
+ flexDirection: "column",
192
+ gap: _configs.gridGap + "px",
193
+ } },
194
+ react_1.default.createElement("div", { style: {
195
+ display: "flex",
196
+ alignItems: "center",
197
+ gap: _configs.gridGap + "px",
198
+ } }, data[0].map(function (dd) { return (react_1.default.createElement("div", { style: {
199
+ width: _configs.cellSize + "px",
200
+ height: _configs.axisLabelWidth + "px",
201
+ display: "flex",
202
+ alignItems: "flex-end",
203
+ textWrap: "nowrap",
204
+ justifyContent: 'center',
205
+ position: "relative", // Add this
206
+ overflow: "visible" // Add this to allow content to overflow
207
+ } },
208
+ react_1.default.createElement(Typo2_1.UI_CAPTION_SEMIBOLD_DF, { style: {
209
+ width: _configs.axisLabelWidth + "px",
210
+ textOverflow: "ellipsis",
211
+ overflow: "hidden",
212
+ whiteSpace: "nowrap",
213
+ position: "absolute", // Add this
214
+ bottom: '-8px', // which is half of the line height of the current text
215
+ left: (_configs.cellSize / 2) + 'px', // Center horizontally
216
+ transformOrigin: "left center", // Change origin to bottom
217
+ transform: "rotate(-90deg)", // Adjust transform
218
+ } }, dd.labels.tooltipLabel))); })),
219
+ data.map(function (d) { return (react_1.default.createElement("div", { style: {
220
+ display: "flex",
221
+ alignItems: "center",
222
+ gap: _configs.gridGap + "px",
223
+ } }, d.map(function (dd) {
224
+ // console.log({
225
+ // color: mapValueToColor(dd.labels.count, 0, dataMaxValue),
226
+ // });
227
+ return react_1.default.createElement(HeatMapCell, { showPercent: false, dataMaxValue: dataMaxValue, value: dd });
228
+ }))); })))));
229
+ };
230
+ exports.HeatMapGrid = HeatMapGrid;
@@ -0,0 +1,12 @@
1
+ export interface CountVizLabels {
2
+ percentage?: number;
3
+ count: number;
4
+ name: string;
5
+ dataIndex: number;
6
+ color: string;
7
+ tooltipLabel?: string;
8
+ }
9
+ export interface CountVizDatum {
10
+ labels: CountVizLabels;
11
+ }
12
+ export type CountVizData = (CountVizDatum | CountVizDatum[])[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 {};