oolib 2.207.0 → 2.208.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/stories/v2/components/visualization/HeatMapGrid.stories.d.ts +1 -0
- package/dist/stories/v2/components/visualization/HeatMapGrid.stories.js +83 -1
- package/dist/v2/components/TabBar/index.js +1 -2
- package/dist/v2/components/TabBar/index.styled.js +4 -6
- package/dist/v2/components/dataviz/HeatMapGrid/index.js +23 -28
- package/dist/v2/components/dataviz/HeatMapGrid/utils/usePrepareHeatMapData.d.ts +33 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/usePrepareHeatMapData.js +117 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports._HeatMapGrid = void 0;
|
|
17
|
+
exports._HeatMapGridPlayground = exports._HeatMapGrid = void 0;
|
|
18
18
|
var react_1 = __importDefault(require("react"));
|
|
19
19
|
var HeatMapGrid_1 = require("../../../../v2/components/dataviz/HeatMapGrid");
|
|
20
20
|
var props2_1 = require("./configs/props2");
|
|
@@ -120,3 +120,85 @@ var _HeatMapGrid = function (args) {
|
|
|
120
120
|
react_1.default.createElement(HeatMapGrid_1.HeatMapGrid, __assign({}, props2_1.heaMapGridProps2, { style: { height: "300px" } })))));
|
|
121
121
|
};
|
|
122
122
|
exports._HeatMapGrid = _HeatMapGrid;
|
|
123
|
+
var _HeatMapGridPlayground = function (args) {
|
|
124
|
+
var handleCellClick = function (name) {
|
|
125
|
+
console.log("cell clicked: ".concat(name));
|
|
126
|
+
};
|
|
127
|
+
return (react_1.default.createElement("div", { style: { padding: '20px' } },
|
|
128
|
+
react_1.default.createElement(HeatMapGrid_1.HeatMapGrid, { showPercent: args.showPercent, data: [
|
|
129
|
+
{
|
|
130
|
+
display: "Logged",
|
|
131
|
+
stack1: 60,
|
|
132
|
+
stack2: 20,
|
|
133
|
+
stack3: 40,
|
|
134
|
+
stack4: 10,
|
|
135
|
+
stack5: 40,
|
|
136
|
+
stack6: 10,
|
|
137
|
+
stack2Display: 'Labels Path Stack 2 Display'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
display: "Registered Users",
|
|
141
|
+
stack1: 100,
|
|
142
|
+
stack2: 50,
|
|
143
|
+
stack3: 10,
|
|
144
|
+
stack4: 15,
|
|
145
|
+
stack5: 40,
|
|
146
|
+
stack6: 10,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
display: "Created Profile",
|
|
150
|
+
stack1: 20,
|
|
151
|
+
stack2: 5,
|
|
152
|
+
stack3: 10,
|
|
153
|
+
stack4: 15,
|
|
154
|
+
stack5: 40,
|
|
155
|
+
stack6: 10,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
display: "Wrote at least 3 story",
|
|
159
|
+
stack1: 8,
|
|
160
|
+
stack2: 2,
|
|
161
|
+
stack3: 1,
|
|
162
|
+
stack4: 1,
|
|
163
|
+
stack5: 40,
|
|
164
|
+
stack6: 10,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
display: "Created Profile again",
|
|
168
|
+
stack1: 20,
|
|
169
|
+
stack2: 5,
|
|
170
|
+
stack3: 10,
|
|
171
|
+
stack4: 15,
|
|
172
|
+
stack5: 40,
|
|
173
|
+
stack6: 10,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
display: "Wrote at least 1 story",
|
|
177
|
+
stack1: 8,
|
|
178
|
+
stack2: 2,
|
|
179
|
+
stack3: 1,
|
|
180
|
+
stack4: 1,
|
|
181
|
+
stack5: 40,
|
|
182
|
+
stack6: 10,
|
|
183
|
+
},
|
|
184
|
+
], plotDataPoint: "percentage" // This can be changed to count
|
|
185
|
+
, valuePath: [
|
|
186
|
+
"stack1",
|
|
187
|
+
"stack2",
|
|
188
|
+
"stack3",
|
|
189
|
+
"stack4",
|
|
190
|
+
"stack5",
|
|
191
|
+
"stack6",
|
|
192
|
+
], tooltipLabelsMapping: {
|
|
193
|
+
stack1: 'Stack 1',
|
|
194
|
+
stack2: 'Stack 2',
|
|
195
|
+
stack3: 'Stack 3',
|
|
196
|
+
stack4: 'Stack 4',
|
|
197
|
+
stack5: 'Stack 5',
|
|
198
|
+
stack6: 'Stack 6',
|
|
199
|
+
},
|
|
200
|
+
// valuePath="stack1"
|
|
201
|
+
labelPath: "display", title: "This is a Heat Map Grid", onClick: handleCellClick, colorIdx: 2 }),
|
|
202
|
+
react_1.default.createElement(HeatMapGrid_1.HeatMapGrid, __assign({}, props2_1.heaMapGridProps2))));
|
|
203
|
+
};
|
|
204
|
+
exports._HeatMapGridPlayground = _HeatMapGridPlayground;
|
|
@@ -25,7 +25,6 @@ var mixins_1 = require("../../../themes/mixins");
|
|
|
25
25
|
var Typo2_1 = require("../Typo2");
|
|
26
26
|
var colors_1 = require("../../themes/colors");
|
|
27
27
|
var icons_1 = require("../../../icons");
|
|
28
|
-
var __1 = require("../../..");
|
|
29
28
|
var List = icons_1.icons.List;
|
|
30
29
|
var Base = function (_a) {
|
|
31
30
|
var id = _a.id, options = _a.options, valueProp = _a.value, onChange = _a.onChange, style = _a.style, errorTabs = _a.errorTabs, disabledTabs = _a.disabledTabs, _b = _a.tabBarStyle, tabBarStyle = _b === void 0 ? '1' : _b, saveValueAsString = _a.saveValueAsString, _c = _a.black, black = _c === void 0 ? false : _c, M = _a.M, S = _a.S, _size = _a.size //use any one of these 3
|
|
@@ -63,7 +62,7 @@ var Base = function (_a) {
|
|
|
63
62
|
react_1.default.createElement(Typo, { capitalize: true }, op.display),
|
|
64
63
|
op.message && tabBarStyle === '1' ?
|
|
65
64
|
react_1.default.createElement(index_styled_1.StyledMessage1, null,
|
|
66
|
-
react_1.default.createElement(Typo2_1.UI_TAG,
|
|
65
|
+
react_1.default.createElement(Typo2_1.UI_TAG, null, op.message))
|
|
67
66
|
: op.message && tabBarStyle === '2' &&
|
|
68
67
|
react_1.default.createElement(index_styled_1.StyledMessage2, null,
|
|
69
68
|
react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD, { style: { margin: "auto" } }, op.message))),
|
|
@@ -42,9 +42,7 @@ var styled_components_1 = __importStar(require("styled-components"));
|
|
|
42
42
|
var mixins_1 = require("../../../themes/mixins");
|
|
43
43
|
var themes_1 = require("../../themes");
|
|
44
44
|
var getDynamicColors_1 = require("../../themes/utils/getDynamicColors");
|
|
45
|
-
var
|
|
46
|
-
var __1 = require("../../..");
|
|
47
|
-
var secondaryContainer = themes_1.colors.secondaryContainer, onSecondary = themes_1.colors.onSecondary, white = themes_1.colors.white, black = themes_1.colors.black, grey80 = themes_1.colors.grey80, grey40 = themes_1.colors.grey40, grey10 = themes_1.colors.grey10, errorColor = themes_1.colors.error;
|
|
45
|
+
var onSecondary = themes_1.colors.onSecondary, white = themes_1.colors.white, black = themes_1.colors.black, grey80 = themes_1.colors.grey80, grey40 = themes_1.colors.grey40, grey10 = themes_1.colors.grey10, errorColor = themes_1.colors.error, redBG = themes_1.colors.redBG;
|
|
48
46
|
exports.wrapperStyles = {
|
|
49
47
|
style1: (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n :first-of-type {\n border-radius: 1px 0 0 2px;\n }\n :last-of-type {\n border-radius: 0 2px 2px 0;\n }\n\n background-color: white;\n color: ", ";\n \n ", " \n\n ", "\n\n ", "\n\n \n "], ["\n :first-of-type {\n border-radius: 1px 0 0 2px;\n }\n :last-of-type {\n border-radius: 0 2px 2px 0;\n }\n\n background-color: white;\n color: ", ";\n \n ", " \n\n ", "\n\n ", "\n\n \n "])), function (_a) {
|
|
50
48
|
var error = _a.error, active = _a.active, disabled = _a.disabled;
|
|
@@ -98,7 +96,7 @@ exports.tabStyles = {
|
|
|
98
96
|
return message && (0, styled_components_1.css)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n padding-right: 0.8rem;\n "], ["\n padding-right: 0.8rem;\n "])));
|
|
99
97
|
}, function (_a) {
|
|
100
98
|
var error = _a.error;
|
|
101
|
-
return error && (0, styled_components_1.css)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n background-color: ", ";\n "], ["\n background-color: ", ";\n "])),
|
|
99
|
+
return error && (0, styled_components_1.css)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n background-color: ", ";\n "], ["\n background-color: ", ";\n "])), redBG);
|
|
102
100
|
}, function (_a) {
|
|
103
101
|
var disabled = _a.disabled;
|
|
104
102
|
return disabled && (0, styled_components_1.css)(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n cursor: not-allowed; \n color: ", ";\n "], ["\n cursor: not-allowed; \n color: ", ";\n "])), grey40);
|
|
@@ -164,6 +162,6 @@ exports.StyledDot = styled_components_1.default.div(templateObject_21 || (templa
|
|
|
164
162
|
return tabBarStyle === "2" && active ? errorColor : !active && error ? errorColor : errorColor;
|
|
165
163
|
});
|
|
166
164
|
exports.StyledWrapper = styled_components_1.default.div(templateObject_22 || (templateObject_22 = __makeTemplateObject(["\n display: flex;\n /* min-height: 5.6rem; */\n padding: 0.8rem 1.6rem;\n justify-content: space-between;\n align-items: center;\n align-self: stretch;\n border-radius: 1.2rem;\n background: #FFF;\n gap: 0.5rem;\n box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.10);\n cursor: pointer;\n"], ["\n display: flex;\n /* min-height: 5.6rem; */\n padding: 0.8rem 1.6rem;\n justify-content: space-between;\n align-items: center;\n align-self: stretch;\n border-radius: 1.2rem;\n background: #FFF;\n gap: 0.5rem;\n box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.10);\n cursor: pointer;\n"])));
|
|
167
|
-
exports.StyledMessage1 = styled_components_1.default.div(templateObject_23 || (templateObject_23 = __makeTemplateObject(["\n background: ", ";\n padding: 0.3rem 0.5rem;\n border-radius: 2px;\n"], ["\n background: ", ";\n padding: 0.3rem 0.5rem;\n border-radius: 2px;\n"])),
|
|
168
|
-
exports.StyledMessage2 = styled_components_1.default.div(templateObject_24 || (templateObject_24 = __makeTemplateObject(["\n border-radius: 1.2rem;\n background: ", ";\n color: ", ";\n margin: auto;\n min-width: 1.6rem;\n height: 1.6rem;\n padding: 0 0.5rem;\n"], ["\n border-radius: 1.2rem;\n background: ", ";\n color: ", ";\n margin: auto;\n min-width: 1.6rem;\n height: 1.6rem;\n padding: 0 0.5rem;\n"])),
|
|
165
|
+
exports.StyledMessage1 = styled_components_1.default.div(templateObject_23 || (templateObject_23 = __makeTemplateObject(["\n background: ", ";\n color: ", ";\n padding: 0.3rem 0.5rem;\n border-radius: 2px;\n"], ["\n background: ", ";\n color: ", ";\n padding: 0.3rem 0.5rem;\n border-radius: 2px;\n"])), themes_1.colors.black, themes_1.colors.white);
|
|
166
|
+
exports.StyledMessage2 = styled_components_1.default.div(templateObject_24 || (templateObject_24 = __makeTemplateObject(["\n border-radius: 1.2rem;\n background: ", ";\n color: ", ";\n margin: auto;\n min-width: 1.6rem;\n height: 1.6rem;\n padding: 0 0.5rem;\n"], ["\n border-radius: 1.2rem;\n background: ", ";\n color: ", ";\n margin: auto;\n min-width: 1.6rem;\n height: 1.6rem;\n padding: 0 0.5rem;\n"])), themes_1.colors.green, themes_1.colors.white);
|
|
169
167
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24;
|
|
@@ -58,10 +58,10 @@ var __1 = require("../../../..");
|
|
|
58
58
|
var Typo2_1 = require("../../Typo2");
|
|
59
59
|
var BarChart_1 = require("../BarChart");
|
|
60
60
|
var CustomTooltip_1 = __importDefault(require("../BarChart/comps/CustomTooltip"));
|
|
61
|
-
var usePrepareData_1 = require("../utils/usePrepareData");
|
|
62
61
|
var mapValueToColor_1 = require("./utils/mapValueToColor");
|
|
63
62
|
var useAxisMeasure_1 = require("./utils/useAxisMeasure");
|
|
64
63
|
var useFader_1 = require("./utils/useFader");
|
|
64
|
+
var usePrepareHeatMapData_1 = require("./utils/usePrepareHeatMapData");
|
|
65
65
|
var _configs = {
|
|
66
66
|
labelsToGridGap: 4,
|
|
67
67
|
gridGap: 2,
|
|
@@ -101,22 +101,20 @@ var HeatMapCell = function (_a) {
|
|
|
101
101
|
var STYLED_UI_CAPTION_SEMIBOLD_DF = (0, styled_components_1.default)(Typo2_1.UI_CAPTION_SEMIBOLD_DF)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), (0, __1.clampText)(2));
|
|
102
102
|
var HiddenScrollContainer = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n scrollbar-width: none; /* Firefox */\n -ms-overflow-style: none; /* IE and Edge */\n \n &::-webkit-scrollbar {\n display: none; /* Webkit browsers */\n }\n"], ["\n scrollbar-width: none; /* Firefox */\n -ms-overflow-style: none; /* IE and Edge */\n \n &::-webkit-scrollbar {\n display: none; /* Webkit browsers */\n }\n"])));
|
|
103
103
|
var HeatMapGrid = function (_a) {
|
|
104
|
-
var _b;
|
|
105
|
-
var
|
|
106
|
-
var _j = (0, usePrepareData_1.usePrepareData)({
|
|
104
|
+
var _data = _a.data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, _c = _a.showPercent, showPercent = _c === void 0 ? true : _c, _d = _a.colorIdx, colorIdx = _d === void 0 ? 0 : _d, _e = _a.showCount, showCount = _e === void 0 ? true : _e, onClick = _a.onClick, _f = _a.summarizeAfterIdx, summarizeAfterIdx = _f === void 0 ? 5 : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
|
|
105
|
+
var _h = (0, usePrepareHeatMapData_1.usePrepareHeatMapData)({
|
|
107
106
|
_data: _data,
|
|
108
|
-
labelPath: labelPath,
|
|
109
107
|
valuePath: valuePath,
|
|
110
108
|
tooltipLabelsMapping: tooltipLabelsMapping,
|
|
111
109
|
tooltipLabelsPath: tooltipLabelsPath,
|
|
112
|
-
|
|
110
|
+
labelPath: labelPath,
|
|
113
111
|
showPercent: showPercent,
|
|
114
|
-
|
|
115
|
-
}),
|
|
112
|
+
colorIdx: colorIdx
|
|
113
|
+
}), tableData = _h.tableData, columnHeaders = _h.columnHeaders, dataMaxValue = _h.dataMaxValue;
|
|
116
114
|
var scrollableRef = (0, react_1.useRef)(null);
|
|
117
|
-
var
|
|
115
|
+
var _j = (0, useFader_1.useFader)(scrollableRef), setFader = _j.setFader, showFader = _j.showFader, showHorizontalFader = _j.showHorizontalFader;
|
|
118
116
|
// Replace: const { xAxisWidth, yAxisWidth, measurementRef } = useAxisDimensions(data, _configs.axisLabelWidth);
|
|
119
|
-
var
|
|
117
|
+
var _k = (0, useAxisMeasure_1.useAxisMeasure)(_configs.axisLabelWidth), xWidth = _k.xWidth, yWidth = _k.yWidth, setHorizontalRef = _k.setHorizontalRef, setVerticalRef = _k.setVerticalRef;
|
|
120
118
|
return (react_1.default.createElement("div", { style: __assign({ display: "grid", gridTemplateColumns: "".concat(yWidth, "px 1fr"), gridTemplateRows: "".concat(xWidth, "px 1fr"), gap: _configs.labelsToGridGap + 'px', height: '100%', position: 'relative' }, style) },
|
|
121
119
|
react_1.default.createElement("div", { style: { gridRow: 1, gridColumn: 1 } }),
|
|
122
120
|
react_1.default.createElement(HiddenScrollContainer, { style: {
|
|
@@ -137,7 +135,7 @@ var HeatMapGrid = function (_a) {
|
|
|
137
135
|
alignItems: "center",
|
|
138
136
|
gap: _configs.gridGap + "px",
|
|
139
137
|
minWidth: 'max-content',
|
|
140
|
-
} },
|
|
138
|
+
} }, columnHeaders.map(function (header, index) { return (react_1.default.createElement("div", { key: "label-".concat(header.key, "-").concat(index), style: {
|
|
141
139
|
width: _configs.cellSize + "px",
|
|
142
140
|
height: xWidth + "px",
|
|
143
141
|
display: "flex",
|
|
@@ -160,7 +158,7 @@ var HeatMapGrid = function (_a) {
|
|
|
160
158
|
react_1.default.createElement("div", { ref: function (el) { return setHorizontalRef(index, el); } },
|
|
161
159
|
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: {
|
|
162
160
|
whiteSpace: "normal",
|
|
163
|
-
} },
|
|
161
|
+
} }, header.displayLabel))))); }))),
|
|
164
162
|
react_1.default.createElement(HiddenScrollContainer, { style: {
|
|
165
163
|
gridRow: 2,
|
|
166
164
|
gridColumn: 1,
|
|
@@ -174,19 +172,16 @@ var HeatMapGrid = function (_a) {
|
|
|
174
172
|
if (scrollableRef.current) {
|
|
175
173
|
scrollableRef.current.scrollTop = e.target.scrollTop;
|
|
176
174
|
}
|
|
177
|
-
} },
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
} },
|
|
187
|
-
react_1.default.createElement("div", { ref: function (el) { return setVerticalRef(idx, el); } },
|
|
188
|
-
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: { maxWidth: yWidth + "px" } }, (_b = d[0]) === null || _b === void 0 ? void 0 : _b.labels.name))));
|
|
189
|
-
})),
|
|
175
|
+
} }, _data.map(function (row, idx) { return (react_1.default.createElement("div", { key: "name-".concat(row[labelPath], "-").concat(idx), style: {
|
|
176
|
+
height: _configs.cellSize + "px",
|
|
177
|
+
textAlign: "right",
|
|
178
|
+
display: "flex",
|
|
179
|
+
alignItems: "center",
|
|
180
|
+
justifyContent: "flex-end",
|
|
181
|
+
flexShrink: 0,
|
|
182
|
+
} },
|
|
183
|
+
react_1.default.createElement("div", { ref: function (el) { return setVerticalRef(idx, el); } },
|
|
184
|
+
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: { maxWidth: yWidth + "px" } }, row[labelPath])))); })),
|
|
190
185
|
react_1.default.createElement("div", { ref: scrollableRef, style: {
|
|
191
186
|
gridRow: 2,
|
|
192
187
|
gridColumn: 2,
|
|
@@ -208,13 +203,13 @@ var HeatMapGrid = function (_a) {
|
|
|
208
203
|
flexDirection: "column",
|
|
209
204
|
gap: _configs.gridGap + "px",
|
|
210
205
|
minWidth: 'max-content',
|
|
211
|
-
} },
|
|
206
|
+
} }, tableData.map(function (rowCells, rowIdx) { return (react_1.default.createElement("div", { key: rowIdx, style: {
|
|
212
207
|
display: "flex",
|
|
213
208
|
alignItems: "center",
|
|
214
209
|
gap: _configs.gridGap + "px",
|
|
215
210
|
flexShrink: 0,
|
|
216
|
-
} },
|
|
217
|
-
return react_1.default.createElement(HeatMapCell, { key: "".concat(rowIdx, "-").concat(colIdx), showPercent:
|
|
211
|
+
} }, rowCells.map(function (cellData, colIdx) {
|
|
212
|
+
return react_1.default.createElement(HeatMapCell, { key: "".concat(rowIdx, "-").concat(colIdx), showPercent: showPercent, dataMaxValue: dataMaxValue, value: cellData });
|
|
218
213
|
}))); }))),
|
|
219
214
|
showFader && react_1.default.createElement("div", { style: {
|
|
220
215
|
background: "linear-gradient(to top, ".concat(__1.colors2.white, ", hsla(0, 0%, 100%, 0))"),
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface PrepareHeatMapDataParams {
|
|
2
|
+
_data: any[];
|
|
3
|
+
valuePath: string | string[];
|
|
4
|
+
tooltipLabelsMapping?: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
tooltipLabelsPath?: string | string[];
|
|
8
|
+
labelPath: string;
|
|
9
|
+
showPercent: boolean;
|
|
10
|
+
colorIdx: number;
|
|
11
|
+
}
|
|
12
|
+
interface HeatMapCellData {
|
|
13
|
+
labels: {
|
|
14
|
+
count: number;
|
|
15
|
+
percentage?: number;
|
|
16
|
+
name: string;
|
|
17
|
+
tooltipLabel: string;
|
|
18
|
+
dataIndex: number;
|
|
19
|
+
hasData: boolean;
|
|
20
|
+
barColor: string;
|
|
21
|
+
textColor: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface PreparedHeatMapData {
|
|
25
|
+
tableData: HeatMapCellData[][];
|
|
26
|
+
columnHeaders: {
|
|
27
|
+
key: string;
|
|
28
|
+
displayLabel: string;
|
|
29
|
+
}[];
|
|
30
|
+
dataMaxValue: number;
|
|
31
|
+
}
|
|
32
|
+
export declare const usePrepareHeatMapData: ({ _data, valuePath, tooltipLabelsMapping, tooltipLabelsPath, labelPath, showPercent, colorIdx }: PrepareHeatMapDataParams) => PreparedHeatMapData;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePrepareHeatMapData = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var _EXPORTS_1 = require("../../../../../utils/_EXPORTS");
|
|
6
|
+
var colors_1 = require("../../../../themes/colors");
|
|
7
|
+
var usePrepareHeatMapData = function (_a) {
|
|
8
|
+
var _data = _a._data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, labelPath = _a.labelPath, showPercent = _a.showPercent, colorIdx = _a.colorIdx;
|
|
9
|
+
return (0, react_1.useMemo)(function () {
|
|
10
|
+
if (!_data || _data.length === 0) {
|
|
11
|
+
return {
|
|
12
|
+
tableData: [],
|
|
13
|
+
columnHeaders: [],
|
|
14
|
+
dataMaxValue: 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var valuePathArray = Array.isArray(valuePath) ? valuePath : [valuePath];
|
|
18
|
+
// Optimized: Single pass to collect all unique columns and pre-calculate row totals
|
|
19
|
+
var columnMap = new Map(); // columnLabel -> columnIndex
|
|
20
|
+
var rowTotals = [];
|
|
21
|
+
var rowData = [];
|
|
22
|
+
// First pass: collect unique columns and calculate row totals
|
|
23
|
+
_data.forEach(function (row, rowIndex) {
|
|
24
|
+
var rowName = (0, _EXPORTS_1.getVal)(row, labelPath);
|
|
25
|
+
var cellValues = new Map();
|
|
26
|
+
var rowTotal = 0;
|
|
27
|
+
valuePathArray.forEach(function (path, pathIndex) {
|
|
28
|
+
var value = (0, _EXPORTS_1.getVal)(row, path);
|
|
29
|
+
if (value !== undefined && value !== null) {
|
|
30
|
+
// Get column label
|
|
31
|
+
var columnLabel = void 0;
|
|
32
|
+
if (tooltipLabelsPath) {
|
|
33
|
+
if (Array.isArray(tooltipLabelsPath)) {
|
|
34
|
+
var labelPath_1 = tooltipLabelsPath[pathIndex];
|
|
35
|
+
if (labelPath_1) {
|
|
36
|
+
columnLabel = (0, _EXPORTS_1.getVal)(row, labelPath_1) || "Column ".concat(pathIndex);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
columnLabel = "Column ".concat(pathIndex);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
columnLabel = (0, _EXPORTS_1.getVal)(row, tooltipLabelsPath) || "Column ".concat(pathIndex);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (tooltipLabelsMapping) {
|
|
47
|
+
columnLabel = tooltipLabelsMapping[path] || path;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
columnLabel = path;
|
|
51
|
+
}
|
|
52
|
+
// Store cell value and add to column map
|
|
53
|
+
cellValues.set(columnLabel, value);
|
|
54
|
+
if (!columnMap.has(columnLabel)) {
|
|
55
|
+
columnMap.set(columnLabel, columnMap.size);
|
|
56
|
+
}
|
|
57
|
+
rowTotal += value;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
rowTotals.push(rowTotal);
|
|
61
|
+
rowData.push({ rowName: rowName, cellValues: cellValues });
|
|
62
|
+
});
|
|
63
|
+
// Create column headers in order
|
|
64
|
+
var columnHeaders = Array.from(columnMap.entries())
|
|
65
|
+
.sort(function (_a, _b) {
|
|
66
|
+
var a = _a[1];
|
|
67
|
+
var b = _b[1];
|
|
68
|
+
return a - b;
|
|
69
|
+
})
|
|
70
|
+
.map(function (_a) {
|
|
71
|
+
var key = _a[0];
|
|
72
|
+
return ({
|
|
73
|
+
key: key,
|
|
74
|
+
displayLabel: key
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
// Second pass: build table data efficiently
|
|
78
|
+
var tableData = rowData.map(function (_a, rowIndex) {
|
|
79
|
+
var rowName = _a.rowName, cellValues = _a.cellValues;
|
|
80
|
+
var rowTotal = rowTotals[rowIndex];
|
|
81
|
+
return columnHeaders.map(function (header, colIndex) {
|
|
82
|
+
var cellValue = cellValues.get(header.key) || 0;
|
|
83
|
+
var hasData = cellValues.has(header.key);
|
|
84
|
+
var percentage = rowTotal > 0 ? (cellValue / rowTotal) * 100 : 0;
|
|
85
|
+
return {
|
|
86
|
+
labels: {
|
|
87
|
+
count: cellValue,
|
|
88
|
+
percentage: showPercent ? Math.ceil(percentage) : undefined,
|
|
89
|
+
name: rowName,
|
|
90
|
+
tooltipLabel: header.key,
|
|
91
|
+
dataIndex: rowIndex,
|
|
92
|
+
hasData: hasData,
|
|
93
|
+
barColor: colors_1.dataVizColors[(colorIdx + colIndex) % colors_1.dataVizColors.length],
|
|
94
|
+
textColor: colors_1.dataVizColorsText[(colorIdx + colIndex) % colors_1.dataVizColorsText.length]
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
// Calculate max value efficiently
|
|
100
|
+
var dataMaxValue = 1;
|
|
101
|
+
for (var _i = 0, rowData_1 = rowData; _i < rowData_1.length; _i++) {
|
|
102
|
+
var cellValues = rowData_1[_i].cellValues;
|
|
103
|
+
for (var _a = 0, _b = Array.from(cellValues.values()); _a < _b.length; _a++) {
|
|
104
|
+
var value = _b[_a];
|
|
105
|
+
if (value > dataMaxValue) {
|
|
106
|
+
dataMaxValue = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
tableData: tableData,
|
|
112
|
+
columnHeaders: columnHeaders,
|
|
113
|
+
dataMaxValue: dataMaxValue
|
|
114
|
+
};
|
|
115
|
+
}, [_data, valuePath, tooltipLabelsMapping, tooltipLabelsPath, labelPath, showPercent, colorIdx]);
|
|
116
|
+
};
|
|
117
|
+
exports.usePrepareHeatMapData = usePrepareHeatMapData;
|