oolib 2.197.1 → 2.197.2
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/HeatMapGrid/index.d.ts +0 -3
- package/dist/v2/components/dataviz/HeatMapGrid/index.js +118 -151
- package/dist/v2/components/dataviz/HeatMapGrid/utils/mapValueToColor.d.ts +20 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/mapValueToColor.js +45 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/useAxisMeasure.d.ts +6 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/useAxisMeasure.js +53 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/useFader.d.ts +6 -0
- package/dist/v2/components/dataviz/HeatMapGrid/utils/useFader.js +36 -0
- package/package.json +1 -1
|
@@ -53,71 +53,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.HeatMapGrid = void 0;
|
|
55
55
|
var react_1 = __importStar(require("react"));
|
|
56
|
-
var
|
|
56
|
+
var styled_components_1 = __importDefault(require("styled-components"));
|
|
57
|
+
var __1 = require("../../../..");
|
|
57
58
|
var Typo2_1 = require("../../Typo2");
|
|
59
|
+
var BarChart_1 = require("../BarChart");
|
|
58
60
|
var CustomTooltip_1 = __importDefault(require("../BarChart/comps/CustomTooltip"));
|
|
59
61
|
var usePrepareData_1 = require("../utils/usePrepareData");
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
* Maps a value from an input range to a color
|
|
64
|
-
* with the base color at the center point of the range
|
|
65
|
-
* @param {number} value - The value to map
|
|
66
|
-
* @param {number} minValue - The minimum value in the input range
|
|
67
|
-
* @param {number} maxValue - The maximum value in the input range
|
|
68
|
-
* @param {Object} hslColor - The base HSL color object
|
|
69
|
-
* @param {number} hslColor.h - Hue component (0-360)
|
|
70
|
-
* @param {number} hslColor.s - Saturation component (0-100)
|
|
71
|
-
* @param {number} hslColor.l - Lightness component (0-100)
|
|
72
|
-
* @param {number} minLightness - The minimum lightness (0-100) for darkest shade
|
|
73
|
-
* @param {number} maxLightness - The maximum lightness (0-100) for lightest shade
|
|
74
|
-
* @return {string} - A hex color code
|
|
75
|
-
*/
|
|
76
|
-
function mapValueToColor(value, minValue, maxValue, hslColor, // Default to #be185d
|
|
77
|
-
minLightness, maxLightness) {
|
|
78
|
-
if (hslColor === void 0) { hslColor = { h: 336, s: 74, l: 42 }; }
|
|
79
|
-
if (minLightness === void 0) { minLightness = 20; }
|
|
80
|
-
if (maxLightness === void 0) { maxLightness = 80; }
|
|
81
|
-
// Ensure value is within range
|
|
82
|
-
value = Math.max(minValue, Math.min(maxValue, value));
|
|
83
|
-
// Calculate the center point of the range
|
|
84
|
-
var centerPoint = (minValue + maxValue) / 2;
|
|
85
|
-
// Extract the hsl components
|
|
86
|
-
var h = hslColor.h, s = hslColor.s, baseLightness = hslColor.l;
|
|
87
|
-
// Determine lightness based on position relative to center point
|
|
88
|
-
var lightness;
|
|
89
|
-
if (value < centerPoint) {
|
|
90
|
-
// Value is below center (smaller) - scale from maxLightness to baseLightness
|
|
91
|
-
var normalizedValue = (value - minValue) / (centerPoint - minValue);
|
|
92
|
-
lightness = maxLightness - normalizedValue * (maxLightness - baseLightness);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// Value is above center (larger) - scale from baseLightness to minLightness
|
|
96
|
-
var normalizedValue = (value - centerPoint) / (maxValue - centerPoint);
|
|
97
|
-
lightness = baseLightness - normalizedValue * (baseLightness - minLightness);
|
|
98
|
-
}
|
|
99
|
-
// Convert HSL back to hex
|
|
100
|
-
return "hsl(".concat(h, ", ").concat(s, "%, ").concat(lightness, "%)"); //hslToHex(h, s, lightness);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Convert HSL values to hex color code
|
|
104
|
-
* @param {number} h - Hue (0-360)
|
|
105
|
-
* @param {number} s - Saturation (0-100)
|
|
106
|
-
* @param {number} l - Lightness (0-100)
|
|
107
|
-
* @return {string} - Hex color code
|
|
108
|
-
*/
|
|
109
|
-
function hslToHex(h, s, l) {
|
|
110
|
-
l /= 100;
|
|
111
|
-
var a = (s * Math.min(l, 1 - l)) / 100;
|
|
112
|
-
var f = function (n) {
|
|
113
|
-
var k = (n + h / 30) % 12;
|
|
114
|
-
var color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
115
|
-
return Math.round(255 * color)
|
|
116
|
-
.toString(16)
|
|
117
|
-
.padStart(2, "0");
|
|
118
|
-
};
|
|
119
|
-
return "#".concat(f(0)).concat(f(8)).concat(f(4));
|
|
120
|
-
}
|
|
62
|
+
var mapValueToColor_1 = require("./utils/mapValueToColor");
|
|
63
|
+
var useAxisMeasure_1 = require("./utils/useAxisMeasure");
|
|
64
|
+
var useFader_1 = require("./utils/useFader");
|
|
121
65
|
var _configs = {
|
|
122
66
|
gridGap: 2,
|
|
123
67
|
cellRoundness: 4,
|
|
@@ -128,7 +72,7 @@ var HeatMapCell = function (_a) {
|
|
|
128
72
|
var value = _a.value, dataMaxValue = _a.dataMaxValue, _b = _a.dataMinValue, dataMinValue = _b === void 0 ? 0 : _b, showPercent = _a.showPercent;
|
|
129
73
|
var mousePosition = (0, BarChart_1.useTrackMousePosition)().mousePosition;
|
|
130
74
|
var _c = (0, react_1.useState)(false), showTooltip = _c[0], setShowTooltip = _c[1];
|
|
131
|
-
var cellColor = mapValueToColor(value.labels.count, dataMinValue, dataMaxValue);
|
|
75
|
+
var cellColor = (0, mapValueToColor_1.mapValueToColor)(value.labels.count, dataMinValue, dataMaxValue);
|
|
132
76
|
var getCellColorLightness = function () {
|
|
133
77
|
var splitUp = cellColor.trim().replace('hsl(', '');
|
|
134
78
|
splitUp = splitUp.replace(')', '');
|
|
@@ -136,7 +80,9 @@ var HeatMapCell = function (_a) {
|
|
|
136
80
|
var toReturn = parseInt(splitUpAry[2].replace('%', ''));
|
|
137
81
|
return toReturn;
|
|
138
82
|
};
|
|
139
|
-
var textColor =
|
|
83
|
+
var textColor = value.labels.count === 0
|
|
84
|
+
? __1.colors2.black
|
|
85
|
+
: getCellColorLightness() > 60 ? __1.colors2.black : __1.colors2.white;
|
|
140
86
|
return (react_1.default.createElement("div", { onMouseOver: function () { return setShowTooltip(true); }, onMouseOut: function () { return setShowTooltip(false); } },
|
|
141
87
|
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
|
|
142
88
|
})], showPercent: showPercent, mousePosition: mousePosition })),
|
|
@@ -149,16 +95,10 @@ var HeatMapCell = function (_a) {
|
|
|
149
95
|
justifyContent: 'center',
|
|
150
96
|
alignItems: 'center'
|
|
151
97
|
} },
|
|
152
|
-
react_1.default.createElement(Typo2_1.UI_CAPTION_SEMIBOLD_DF, { style: { color: textColor } }, value.labels.count))));
|
|
98
|
+
react_1.default.createElement(Typo2_1.UI_CAPTION_SEMIBOLD_DF, { style: { color: textColor } }, "".concat(value.labels.count)))));
|
|
153
99
|
};
|
|
154
|
-
var STYLED_UI_CAPTION_SEMIBOLD_DF = (0, styled_components_1.default)(Typo2_1.UI_CAPTION_SEMIBOLD_DF)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n
|
|
155
|
-
|
|
156
|
-
* expects exactly the same data structure as barcharts - breakdown version
|
|
157
|
-
*/
|
|
158
|
-
])), (0, __1.clampText)(2));
|
|
159
|
-
/**
|
|
160
|
-
* expects exactly the same data structure as barcharts - breakdown version
|
|
161
|
-
*/
|
|
100
|
+
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));
|
|
101
|
+
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"])));
|
|
162
102
|
var HeatMapGrid = function (_a) {
|
|
163
103
|
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, _g = _a.style, style = _g === void 0 ? {} : _g;
|
|
164
104
|
var _h = (0, usePrepareData_1.usePrepareData)({
|
|
@@ -171,69 +111,41 @@ var HeatMapGrid = function (_a) {
|
|
|
171
111
|
showPercent: showPercent,
|
|
172
112
|
summarizeAfterIdx: summarizeAfterIdx,
|
|
173
113
|
}), data = _h.data, dataMaxValue = _h.dataMaxValue, dataToSummarize = _h.dataToSummarize;
|
|
174
|
-
var
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
setShowFader(true);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
setShowFader(false);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var _j = (0, react_1.useState)(false), showFader = _j[0], setShowFader = _j[1];
|
|
188
|
-
(0, react_1.useEffect)(function () {
|
|
189
|
-
setFader();
|
|
190
|
-
}, []);
|
|
191
|
-
(0, __1.useScroll)(setFader);
|
|
192
|
-
return (react_1.default.createElement("div", { ref: wrapperRef, style: __assign({ position: 'relative' }, style) },
|
|
114
|
+
var scrollableRef = (0, react_1.useRef)(null);
|
|
115
|
+
var _j = (0, useFader_1.useFader)(scrollableRef), setFader = _j.setFader, showFader = _j.showFader, showHorizontalFader = _j.showHorizontalFader;
|
|
116
|
+
// Replace: const { xAxisWidth, yAxisWidth, measurementRef } = useAxisDimensions(data, _configs.axisLabelWidth);
|
|
117
|
+
var _k = (0, useAxisMeasure_1.useAxisMeasure)(_configs.axisLabelWidth), xWidth = _k.xWidth, yWidth = _k.yWidth, setHorizontalRef = _k.setHorizontalRef, setVerticalRef = _k.setVerticalRef;
|
|
118
|
+
console.log({ xWidth: xWidth, yWidth: yWidth });
|
|
119
|
+
return (react_1.default.createElement("div", { style: __assign({ position: 'relative' }, style) },
|
|
193
120
|
react_1.default.createElement("div", { style: {
|
|
194
|
-
position: 'relative',
|
|
195
121
|
display: "grid",
|
|
196
|
-
gridTemplateColumns: "
|
|
122
|
+
gridTemplateColumns: "".concat(yWidth, "px 1fr"),
|
|
123
|
+
gridTemplateRows: "".concat(xWidth, "px 1fr"),
|
|
197
124
|
gap: _configs.gridGap + 'px',
|
|
198
|
-
|
|
199
|
-
alignItems: "end",
|
|
200
|
-
height: '100%'
|
|
125
|
+
height: '100%',
|
|
201
126
|
} },
|
|
202
|
-
react_1.default.createElement("div", { style: {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: {
|
|
216
|
-
// width: "fit-content",
|
|
217
|
-
maxWidth: _configs.axisLabelWidth + "px",
|
|
218
|
-
// maxHeight: "2.4em",
|
|
219
|
-
// lineHeight: "1.2em",
|
|
220
|
-
// overflow: "hidden",
|
|
221
|
-
// wordBreak: "break-word",
|
|
222
|
-
} }, d[0].labels.name.length > 50 ? d[0].labels.name.substring(0, 50) + "..." : d[0].labels.name))); })),
|
|
223
|
-
react_1.default.createElement("div", { ref: vizRef, style: {
|
|
224
|
-
display: "flex",
|
|
225
|
-
flexDirection: "column",
|
|
226
|
-
gap: _configs.gridGap + "px",
|
|
227
|
-
overflowX: "auto", //horizontal scroll
|
|
228
|
-
position: 'relative'
|
|
127
|
+
react_1.default.createElement("div", { style: { gridRow: 1, gridColumn: 1 } }),
|
|
128
|
+
react_1.default.createElement(HiddenScrollContainer, { style: {
|
|
129
|
+
gridRow: 1,
|
|
130
|
+
gridColumn: 2,
|
|
131
|
+
overflowX: 'auto',
|
|
132
|
+
overflowY: 'hidden',
|
|
133
|
+
display: 'flex',
|
|
134
|
+
alignItems: 'flex-end',
|
|
135
|
+
}, onScroll: function (e) {
|
|
136
|
+
// Sync horizontal scroll with main content area
|
|
137
|
+
if (scrollableRef.current) {
|
|
138
|
+
scrollableRef.current.scrollLeft = e.target.scrollLeft;
|
|
139
|
+
}
|
|
229
140
|
} },
|
|
230
141
|
react_1.default.createElement("div", { style: {
|
|
231
142
|
display: "flex",
|
|
232
143
|
alignItems: "center",
|
|
233
144
|
gap: _configs.gridGap + "px",
|
|
234
|
-
|
|
145
|
+
minWidth: 'max-content',
|
|
146
|
+
} }, data[0].map(function (dd, index) { return (react_1.default.createElement("div", { key: dd.labels.tooltipLabel, style: {
|
|
235
147
|
width: _configs.cellSize + "px",
|
|
236
|
-
height:
|
|
148
|
+
height: xWidth + "px",
|
|
237
149
|
display: "flex",
|
|
238
150
|
alignItems: "flex-end",
|
|
239
151
|
textWrap: "nowrap",
|
|
@@ -242,34 +154,89 @@ var HeatMapGrid = function (_a) {
|
|
|
242
154
|
overflow: "visible",
|
|
243
155
|
flexShrink: 0,
|
|
244
156
|
} },
|
|
157
|
+
react_1.default.createElement("div", { style: {
|
|
158
|
+
width: xWidth + "px",
|
|
159
|
+
position: "absolute",
|
|
160
|
+
bottom: 0,
|
|
161
|
+
left: '50%',
|
|
162
|
+
transformOrigin: "left bottom",
|
|
163
|
+
transform: "rotate(-90deg) translateY(50%)",
|
|
164
|
+
display: 'flex'
|
|
165
|
+
} },
|
|
166
|
+
react_1.default.createElement("div", { ref: function (el) { return setHorizontalRef(index, el); } },
|
|
167
|
+
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: {
|
|
168
|
+
whiteSpace: "normal",
|
|
169
|
+
} }, dd.labels.tooltipLabel))))); }))),
|
|
170
|
+
react_1.default.createElement(HiddenScrollContainer, { style: {
|
|
171
|
+
gridRow: 2,
|
|
172
|
+
gridColumn: 1,
|
|
173
|
+
overflowY: 'auto',
|
|
174
|
+
overflowX: 'hidden',
|
|
175
|
+
display: 'flex',
|
|
176
|
+
flexDirection: 'column',
|
|
177
|
+
gap: _configs.gridGap + "px",
|
|
178
|
+
}, onScroll: function (e) {
|
|
179
|
+
// Sync vertical scroll with main content area
|
|
180
|
+
if (scrollableRef.current) {
|
|
181
|
+
scrollableRef.current.scrollTop = e.target.scrollTop;
|
|
182
|
+
}
|
|
183
|
+
} }, data.map(function (d, idx) { return (react_1.default.createElement("div", { key: idx, style: {
|
|
184
|
+
height: _configs.cellSize + "px",
|
|
185
|
+
textAlign: "right",
|
|
186
|
+
display: "flex",
|
|
187
|
+
alignItems: "center",
|
|
188
|
+
justifyContent: "flex-end",
|
|
189
|
+
flexShrink: 0,
|
|
190
|
+
} },
|
|
191
|
+
react_1.default.createElement("div", { ref: function (el) { return setVerticalRef(idx, el); } },
|
|
245
192
|
react_1.default.createElement(STYLED_UI_CAPTION_SEMIBOLD_DF, { style: {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
193
|
+
maxWidth: yWidth + "px",
|
|
194
|
+
} }, d[0].labels.name.length > 50 ? d[0].labels.name.substring(0, 50) + "..." : d[0].labels.name)))); })),
|
|
195
|
+
react_1.default.createElement("div", { ref: scrollableRef, style: {
|
|
196
|
+
gridRow: 2,
|
|
197
|
+
gridColumn: 2,
|
|
198
|
+
overflow: 'auto',
|
|
199
|
+
position: 'relative',
|
|
200
|
+
}, onScroll: function (e) {
|
|
201
|
+
// Sync scrolling with headers
|
|
202
|
+
var topHeader = e.target.parentElement.children[1]; // Top-right header
|
|
203
|
+
var leftHeader = e.target.parentElement.children[2]; // Bottom-left header
|
|
204
|
+
if (topHeader)
|
|
205
|
+
topHeader.scrollLeft = e.target.scrollLeft;
|
|
206
|
+
if (leftHeader)
|
|
207
|
+
leftHeader.scrollTop = e.target.scrollTop;
|
|
208
|
+
// Update fader visibility on scroll
|
|
209
|
+
setFader();
|
|
210
|
+
} },
|
|
211
|
+
react_1.default.createElement("div", { style: {
|
|
212
|
+
display: "flex",
|
|
213
|
+
flexDirection: "column",
|
|
214
|
+
gap: _configs.gridGap + "px",
|
|
215
|
+
minWidth: 'max-content',
|
|
216
|
+
} }, data.map(function (d, rowIdx) { return (react_1.default.createElement("div", { key: rowIdx, style: {
|
|
262
217
|
display: "flex",
|
|
263
218
|
alignItems: "center",
|
|
264
219
|
gap: _configs.gridGap + "px",
|
|
265
|
-
|
|
266
|
-
} }, d.map(function (dd) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
220
|
+
flexShrink: 0,
|
|
221
|
+
} }, d.map(function (dd, colIdx) {
|
|
222
|
+
return react_1.default.createElement(HeatMapCell, { key: "".concat(rowIdx, "-").concat(colIdx), showPercent: false, dataMaxValue: dataMaxValue, value: dd });
|
|
223
|
+
}))); })))),
|
|
224
|
+
showFader && react_1.default.createElement("div", { style: {
|
|
225
|
+
background: "linear-gradient(to top, ".concat(__1.colors2.white, ", hsla(0, 0%, 100%, 0))"),
|
|
226
|
+
position: 'absolute',
|
|
227
|
+
bottom: 0,
|
|
228
|
+
left: 0,
|
|
229
|
+
width: '100%',
|
|
230
|
+
height: '40px'
|
|
231
|
+
} }),
|
|
232
|
+
showHorizontalFader && react_1.default.createElement("div", { style: {
|
|
233
|
+
background: "linear-gradient(to left, ".concat(__1.colors2.white, ", hsla(0, 0%, 100%, 0))"),
|
|
234
|
+
position: 'absolute',
|
|
235
|
+
top: 0,
|
|
236
|
+
right: 0,
|
|
237
|
+
height: '100%',
|
|
238
|
+
width: '40px'
|
|
239
|
+
} })));
|
|
273
240
|
};
|
|
274
241
|
exports.HeatMapGrid = HeatMapGrid;
|
|
275
|
-
var templateObject_1;
|
|
242
|
+
var templateObject_1, templateObject_2;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a value from an input range to a color
|
|
3
|
+
* with the base color at the center point of the range
|
|
4
|
+
* @param {number} value - The value to map
|
|
5
|
+
* @param {number} minValue - The minimum value in the input range
|
|
6
|
+
* @param {number} maxValue - The maximum value in the input range
|
|
7
|
+
* @param {Object} hslColor - The base HSL color object
|
|
8
|
+
* @param {number} hslColor.h - Hue component (0-360)
|
|
9
|
+
* @param {number} hslColor.s - Saturation component (0-100)
|
|
10
|
+
* @param {number} hslColor.l - Lightness component (0-100)
|
|
11
|
+
* @param {number} minLightness - The minimum lightness (0-100) for darkest shade
|
|
12
|
+
* @param {number} maxLightness - The maximum lightness (0-100) for lightest shade
|
|
13
|
+
* @return {string} - A hex color code
|
|
14
|
+
*/
|
|
15
|
+
export declare function mapValueToColor(value: any, minValue: any, maxValue: any, hslColor?: {
|
|
16
|
+
h: number;
|
|
17
|
+
s: number;
|
|
18
|
+
l: number;
|
|
19
|
+
}, // Default to #be185d
|
|
20
|
+
minLightness?: number, maxLightness?: number): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapValueToColor = mapValueToColor;
|
|
4
|
+
var __1 = require("../../../../..");
|
|
5
|
+
/**
|
|
6
|
+
* Maps a value from an input range to a color
|
|
7
|
+
* with the base color at the center point of the range
|
|
8
|
+
* @param {number} value - The value to map
|
|
9
|
+
* @param {number} minValue - The minimum value in the input range
|
|
10
|
+
* @param {number} maxValue - The maximum value in the input range
|
|
11
|
+
* @param {Object} hslColor - The base HSL color object
|
|
12
|
+
* @param {number} hslColor.h - Hue component (0-360)
|
|
13
|
+
* @param {number} hslColor.s - Saturation component (0-100)
|
|
14
|
+
* @param {number} hslColor.l - Lightness component (0-100)
|
|
15
|
+
* @param {number} minLightness - The minimum lightness (0-100) for darkest shade
|
|
16
|
+
* @param {number} maxLightness - The maximum lightness (0-100) for lightest shade
|
|
17
|
+
* @return {string} - A hex color code
|
|
18
|
+
*/
|
|
19
|
+
function mapValueToColor(value, minValue, maxValue, hslColor, // Default to #be185d
|
|
20
|
+
minLightness, maxLightness) {
|
|
21
|
+
if (hslColor === void 0) { hslColor = { h: 336, s: 74, l: 42 }; }
|
|
22
|
+
if (minLightness === void 0) { minLightness = 20; }
|
|
23
|
+
if (maxLightness === void 0) { maxLightness = 80; }
|
|
24
|
+
// Ensure value is within range
|
|
25
|
+
value = Math.max(minValue, Math.min(maxValue, value));
|
|
26
|
+
if (value === 0)
|
|
27
|
+
return __1.colors2.grey10;
|
|
28
|
+
// Calculate the center point of the range
|
|
29
|
+
var centerPoint = (minValue + maxValue) / 2;
|
|
30
|
+
// Extract the hsl components
|
|
31
|
+
var h = hslColor.h, s = hslColor.s, baseLightness = hslColor.l;
|
|
32
|
+
// Determine lightness based on position relative to center point
|
|
33
|
+
var lightness;
|
|
34
|
+
if (value < centerPoint) {
|
|
35
|
+
// Value is below center (smaller) - scale from maxLightness to baseLightness
|
|
36
|
+
var normalizedValue = (value - minValue) / (centerPoint - minValue);
|
|
37
|
+
lightness = maxLightness - normalizedValue * (maxLightness - baseLightness);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Value is above center (larger) - scale from baseLightness to minLightness
|
|
41
|
+
var normalizedValue = (value - centerPoint) / (maxValue - centerPoint);
|
|
42
|
+
lightness = baseLightness - normalizedValue * (baseLightness - minLightness);
|
|
43
|
+
}
|
|
44
|
+
return "hsl(".concat(h, ", ").concat(s, "%, ").concat(lightness, "%)");
|
|
45
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAxisMeasure = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var useAxisMeasure = function (defaultAxisLabelWidth) {
|
|
6
|
+
var _a = (0, react_1.useState)(defaultAxisLabelWidth), xWidth = _a[0], setXWidth = _a[1];
|
|
7
|
+
var _b = (0, react_1.useState)(defaultAxisLabelWidth), yWidth = _b[0], setYWidth = _b[1];
|
|
8
|
+
var horizontalRefs = (0, react_1.useRef)([]);
|
|
9
|
+
var verticalRefs = (0, react_1.useRef)([]);
|
|
10
|
+
// Functions to set refs
|
|
11
|
+
var setHorizontalRef = function (index, el) {
|
|
12
|
+
console.log({ horEL: el });
|
|
13
|
+
horizontalRefs.current[index] = el;
|
|
14
|
+
};
|
|
15
|
+
var setVerticalRef = function (index, el) {
|
|
16
|
+
console.log({ verEL: el });
|
|
17
|
+
verticalRefs.current[index] = el;
|
|
18
|
+
};
|
|
19
|
+
console.log({ horizontalRefs: horizontalRefs, verticalRefs: verticalRefs });
|
|
20
|
+
(0, react_1.useEffect)(function () {
|
|
21
|
+
// Measure horizontal labels
|
|
22
|
+
var maxHorizontalWidth = 0;
|
|
23
|
+
horizontalRefs.current.forEach(function (ref) {
|
|
24
|
+
console.log({ ref: ref });
|
|
25
|
+
if (ref) {
|
|
26
|
+
var width = ref.offsetWidth;
|
|
27
|
+
maxHorizontalWidth = Math.max(maxHorizontalWidth, width);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
// Measure vertical labels
|
|
31
|
+
var maxVerticalWidth = 0;
|
|
32
|
+
verticalRefs.current.forEach(function (ref) {
|
|
33
|
+
if (ref) {
|
|
34
|
+
var width = ref.offsetWidth;
|
|
35
|
+
maxVerticalWidth = Math.max(maxVerticalWidth, width);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
// Update state if measured width is less than config
|
|
39
|
+
if (maxHorizontalWidth > 0 && maxHorizontalWidth < defaultAxisLabelWidth) {
|
|
40
|
+
setXWidth(maxHorizontalWidth + 10); // +10 for padding
|
|
41
|
+
}
|
|
42
|
+
if (maxVerticalWidth > 0 && maxVerticalWidth < defaultAxisLabelWidth) {
|
|
43
|
+
setYWidth(maxVerticalWidth + 10); // +10 for padding
|
|
44
|
+
}
|
|
45
|
+
}, []);
|
|
46
|
+
return {
|
|
47
|
+
xWidth: xWidth,
|
|
48
|
+
yWidth: yWidth,
|
|
49
|
+
setHorizontalRef: setHorizontalRef,
|
|
50
|
+
setVerticalRef: setVerticalRef
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.useAxisMeasure = useAxisMeasure;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFader = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var __1 = require("../../../../..");
|
|
6
|
+
var useFader = function (scrollableRef) {
|
|
7
|
+
var _a = (0, react_1.useState)(false), showFader = _a[0], setShowFader = _a[1];
|
|
8
|
+
var _b = (0, react_1.useState)(false), showHorizontalFader = _b[0], setShowHorizontalFader = _b[1];
|
|
9
|
+
var setFader = function () {
|
|
10
|
+
if (scrollableRef.current) {
|
|
11
|
+
var _a = scrollableRef.current, scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight, scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth;
|
|
12
|
+
// Vertical fader logic
|
|
13
|
+
var hasMoreContentToScrollDown = scrollTop + clientHeight < scrollHeight - 5;
|
|
14
|
+
if (hasMoreContentToScrollDown && !showFader) {
|
|
15
|
+
setShowFader(true);
|
|
16
|
+
}
|
|
17
|
+
else if (!hasMoreContentToScrollDown && showFader) {
|
|
18
|
+
setShowFader(false);
|
|
19
|
+
}
|
|
20
|
+
// Horizontal fader logic
|
|
21
|
+
var hasMoreContentToScrollRight = scrollLeft + clientWidth < scrollWidth - 5;
|
|
22
|
+
if (hasMoreContentToScrollRight && !showHorizontalFader) {
|
|
23
|
+
setShowHorizontalFader(true);
|
|
24
|
+
}
|
|
25
|
+
else if (!hasMoreContentToScrollRight && showHorizontalFader) {
|
|
26
|
+
setShowHorizontalFader(false);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
(0, react_1.useEffect)(function () {
|
|
31
|
+
setFader();
|
|
32
|
+
}, []);
|
|
33
|
+
(0, __1.useScroll)(setFader);
|
|
34
|
+
return { showFader: showFader, showHorizontalFader: showHorizontalFader, setFader: setFader };
|
|
35
|
+
};
|
|
36
|
+
exports.useFader = useFader;
|