blixify-ui-web 1.2.246 → 1.2.249

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 (56) hide show
  1. package/lib/components/advanced/collapse/index.d.ts.map +1 -1
  2. package/lib/components/advanced/collapse/index.js +11 -1
  3. package/lib/components/advanced/collapse/index.js.map +1 -1
  4. package/lib/components/chart/DateRange.js +10 -11
  5. package/lib/components/chart/DateRange.js.map +1 -1
  6. package/lib/components/chart/areaChart/index.js +1 -1
  7. package/lib/components/chart/areaChart/index.js.map +1 -1
  8. package/lib/components/chart/barChart/index.d.ts +139 -0
  9. package/lib/components/chart/barChart/index.d.ts.map +1 -1
  10. package/lib/components/chart/barChart/index.js +520 -106
  11. package/lib/components/chart/barChart/index.js.map +1 -1
  12. package/lib/components/chart/boxPlotChart/index.js +1 -1
  13. package/lib/components/chart/boxPlotChart/index.js.map +1 -1
  14. package/lib/components/chart/bubbleChart/index.js +1 -1
  15. package/lib/components/chart/bubbleChart/index.js.map +1 -1
  16. package/lib/components/chart/card/index.js +1 -1
  17. package/lib/components/chart/card/index.js.map +1 -1
  18. package/lib/components/chart/heatmapChart/index.js +1 -1
  19. package/lib/components/chart/heatmapChart/index.js.map +1 -1
  20. package/lib/components/chart/lineChart/index.js +1 -1
  21. package/lib/components/chart/lineChart/index.js.map +1 -1
  22. package/lib/components/chart/pieChart/index.d.ts +40 -0
  23. package/lib/components/chart/pieChart/index.d.ts.map +1 -1
  24. package/lib/components/chart/pieChart/index.js +184 -44
  25. package/lib/components/chart/pieChart/index.js.map +1 -1
  26. package/lib/components/chart/polarAreaChart/index.js +1 -1
  27. package/lib/components/chart/polarAreaChart/index.js.map +1 -1
  28. package/lib/components/chart/radarChart/index.js +1 -1
  29. package/lib/components/chart/radarChart/index.js.map +1 -1
  30. package/lib/components/chart/radialBar/index.js +1 -1
  31. package/lib/components/chart/radialBar/index.js.map +1 -1
  32. package/lib/components/chart/rangeBarChart/index.js +1 -1
  33. package/lib/components/chart/rangeBarChart/index.js.map +1 -1
  34. package/lib/components/chart/treemapChart/index.js +1 -1
  35. package/lib/components/chart/treemapChart/index.js.map +1 -1
  36. package/lib/components/data/dataGraph/chartResults.d.ts +41 -0
  37. package/lib/components/data/dataGraph/chartResults.d.ts.map +1 -1
  38. package/lib/components/data/dataGraph/chartResults.js +72 -2
  39. package/lib/components/data/dataGraph/chartResults.js.map +1 -1
  40. package/lib/components/data/dataGraph/index.d.ts.map +1 -1
  41. package/lib/components/data/dataGraph/index.js +54 -21
  42. package/lib/components/data/dataGraph/index.js.map +1 -1
  43. package/lib/components/data/dataTemplate/chartBuilder.d.ts +6 -0
  44. package/lib/components/data/dataTemplate/chartBuilder.d.ts.map +1 -1
  45. package/lib/components/data/dataTemplate/chartBuilder.js +19 -10
  46. package/lib/components/data/dataTemplate/chartBuilder.js.map +1 -1
  47. package/lib/components/data/dataTemplate/chartView.d.ts +7 -1
  48. package/lib/components/data/dataTemplate/chartView.d.ts.map +1 -1
  49. package/lib/components/data/dataTemplate/chartView.js +291 -32
  50. package/lib/components/data/dataTemplate/chartView.js.map +1 -1
  51. package/lib/components/data/dataTemplate/spaceModel.d.ts +15 -0
  52. package/lib/components/data/dataTemplate/spaceModel.d.ts.map +1 -1
  53. package/lib/components/data/dataTemplate/spaceModel.js +10 -1
  54. package/lib/components/data/dataTemplate/spaceModel.js.map +1 -1
  55. package/lib/tail.css +2 -2
  56. package/package.json +1 -1
@@ -84,11 +84,303 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
84
84
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
85
  }
86
86
  };
87
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
88
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
89
+ if (ar || !(i in from)) {
90
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
91
+ ar[i] = from[i];
92
+ }
93
+ }
94
+ return to.concat(ar || Array.prototype.slice.call(from));
95
+ };
87
96
  Object.defineProperty(exports, "__esModule", { value: true });
88
- exports.BarChart = void 0;
97
+ exports.BarChart = exports.handleValueAxisMax = exports.handleBarValuePlacement = exports.handleBuildBenchmarkAnnotations = exports.handleBenchmarkLabels = exports.handleStackBenchmarkLabels = exports.handlePackBenchmarkRows = exports.handleBenchmarkTextWidth = exports.BENCHMARK_LABEL_MAX_CHARS = exports.BENCHMARK_LABEL_MAX_ROWS = exports.BENCHMARK_LABEL_ROW_PX = exports.handleBenchmarkLabelTitle = exports.handleBenchmarkLabelText = exports.handleBenchmarkAxisMax = exports.handleNiceCeil = exports.handleBarDataMax = void 0;
89
98
  var react_1 = __importStar(require("react"));
90
99
  var link_1 = require("../../structure/link");
91
100
  var DateRange_1 = require("../DateRange");
101
+ var DEFAULT_BENCHMARK_COLOR = "#8B5CF6";
102
+ var handleBenchmarkValues = function (benchmarkLines) {
103
+ return (benchmarkLines !== null && benchmarkLines !== void 0 ? benchmarkLines : []).filter(function (each) { return typeof each.value === "number" && isFinite(each.value); });
104
+ };
105
+ /** The tallest bar, or the tallest stack when the bars are stacked. */
106
+ var handleBarDataMax = function (seriesData, stackedBarSeries, stacked) {
107
+ if (stackedBarSeries === null || stackedBarSeries === void 0 ? void 0 : stackedBarSeries.length) {
108
+ if (!stacked)
109
+ return Math.max.apply(Math, __spreadArray([0], stackedBarSeries.flatMap(function (each) { return each.data; }), false));
110
+ var length_1 = Math.max.apply(Math, stackedBarSeries.map(function (each) { return each.data.length; }));
111
+ var totals = Array.from({ length: length_1 }, function (_, index) {
112
+ return stackedBarSeries.reduce(function (sum, each) { var _a; return sum + ((_a = each.data[index]) !== null && _a !== void 0 ? _a : 0); }, 0);
113
+ });
114
+ return Math.max.apply(Math, __spreadArray([0], totals, false));
115
+ }
116
+ return Math.max.apply(Math, __spreadArray([0], (seriesData !== null && seriesData !== void 0 ? seriesData : []).map(function (each) { return Number(each.y) || 0; }), false));
117
+ };
118
+ exports.handleBarDataMax = handleBarDataMax;
119
+ /** Rounds up to a tidy axis top: 33 → 35, 47 → 50, 120 → 150. */
120
+ var handleNiceCeil = function (value) {
121
+ if (value <= 0)
122
+ return 0;
123
+ var magnitude = Math.pow(10, Math.floor(Math.log10(value)));
124
+ var step = magnitude / 2;
125
+ return Math.ceil(value / step) * step;
126
+ };
127
+ exports.handleNiceCeil = handleNiceCeil;
128
+ /**
129
+ * The value axis's top when a benchmark sits above every bar, a little past it
130
+ * so its label has room; otherwise undefined, so ApexCharts keeps its own
131
+ * rounded ticks.
132
+ */
133
+ var handleBenchmarkAxisMax = function (benchmarkLines, dataMax) {
134
+ var values = handleBenchmarkValues(benchmarkLines).map(function (each) { return each.value; });
135
+ if (!values.length)
136
+ return undefined;
137
+ var highest = Math.max.apply(Math, values);
138
+ return highest > dataMax ? (0, exports.handleNiceCeil)(highest * 1.1) : undefined;
139
+ };
140
+ exports.handleBenchmarkAxisMax = handleBenchmarkAxisMax;
141
+ // INFO: 11px text at weight 500 runs about this wide per character; close
142
+ // enough to keep labels apart without measuring text in the page
143
+ var BENCHMARK_LABEL_CHAR_PX = 6.2;
144
+ var handleDefaultBenchmarkFormat = function (value) {
145
+ return value.toLocaleString("en-US");
146
+ };
147
+ /**
148
+ * A benchmark's label as printed: its own label, or its value when it has none.
149
+ * The value isn't added to a label, which stays short; hovering shows both.
150
+ */
151
+ var handleBenchmarkLabelText = function (line, formatValue) {
152
+ if (formatValue === void 0) { formatValue = handleDefaultBenchmarkFormat; }
153
+ return line.label || formatValue(line.value);
154
+ };
155
+ exports.handleBenchmarkLabelText = handleBenchmarkLabelText;
156
+ /** A benchmark's hover text, which always names its value: "June Target · 500". */
157
+ var handleBenchmarkLabelTitle = function (line, formatValue) {
158
+ if (formatValue === void 0) { formatValue = handleDefaultBenchmarkFormat; }
159
+ var value = formatValue(line.value);
160
+ return line.label ? "".concat(line.label, " \u00B7 ").concat(value) : value;
161
+ };
162
+ exports.handleBenchmarkLabelTitle = handleBenchmarkLabelTitle;
163
+ // INFO: one row of benchmark labels, tall enough for 11px text
164
+ exports.BENCHMARK_LABEL_ROW_PX = 14;
165
+ // INFO: along the top of a horizontal bar, crowded labels stack this many
166
+ // rows deep at most; any more show as "…" with their text on hover
167
+ exports.BENCHMARK_LABEL_MAX_ROWS = 3;
168
+ var BENCHMARK_LABEL_GAP_PX = 6;
169
+ // INFO: the space between a horizontal bar's line and its label
170
+ var BENCHMARK_LINE_GAP_PX = 4;
171
+ // INFO: a label is cut past this, so one long label can't push all the
172
+ // others into rows
173
+ exports.BENCHMARK_LABEL_MAX_CHARS = 24;
174
+ /** A benchmark's label as printed, cut with "…" past maxChars. */
175
+ var handleCutBenchmarkText = function (text, maxChars) {
176
+ return text.length > maxChars ? "".concat(text.slice(0, maxChars - 1), "\u2026") : text;
177
+ };
178
+ /** The estimated width of a label as printed. */
179
+ var handleBenchmarkTextWidth = function (text) {
180
+ return Math.ceil(text.length * BENCHMARK_LABEL_CHAR_PX) + 4;
181
+ };
182
+ exports.handleBenchmarkTextWidth = handleBenchmarkTextWidth;
183
+ var handleHitsBox = function (boxes, left, right, top, bottom) {
184
+ return boxes.find(function (each) {
185
+ return left < each.right &&
186
+ right > each.left &&
187
+ top < each.bottom &&
188
+ bottom > each.top;
189
+ });
190
+ };
191
+ /**
192
+ * Rows for the labels along the top of a horizontal bar, placed left to
193
+ * right. Each label takes the first row where it fits just right of its line,
194
+ * or else just left of it, touching no label already placed or printed bar
195
+ * value and staying inside the plot. Labels far apart share a row; only
196
+ * crowded ones stack. A label that fits in none of maxRows rows shows as "…"
197
+ * just right of its line, with its text on hover.
198
+ */
199
+ var handlePackBenchmarkRows = function (items, rightEdge, maxRows, leftEdge, valueBoxes, rowTop) {
200
+ if (maxRows === void 0) { maxRows = exports.BENCHMARK_LABEL_MAX_ROWS; }
201
+ if (leftEdge === void 0) { leftEdge = 0; }
202
+ if (valueBoxes === void 0) { valueBoxes = []; }
203
+ if (rowTop === void 0) { rowTop = function (row) { return row * exports.BENCHMARK_LABEL_ROW_PX; }; }
204
+ var rowEnds = [];
205
+ var sorted = __spreadArray([], items, true).sort(function (first, second) { return first.pos - second.pos; });
206
+ var placed = new Map();
207
+ sorted.forEach(function (each) {
208
+ var _a, _b;
209
+ var rightStart = each.pos + BENCHMARK_LINE_GAP_PX;
210
+ var leftStart = each.pos - BENCHMARK_LINE_GAP_PX - each.width;
211
+ var starts = __spreadArray(__spreadArray([], (rightStart + each.width <= rightEdge ? [rightStart] : []), true), (leftStart >= leftEdge ? [leftStart] : []), true);
212
+ if (!starts.length)
213
+ starts.push(Math.max(leftEdge, leftStart));
214
+ var start = starts[0];
215
+ var row = -1;
216
+ var _loop_1 = function (index) {
217
+ var rowEnd = (_a = rowEnds[index]) !== null && _a !== void 0 ? _a : -Infinity;
218
+ var top_1 = rowTop(index);
219
+ var fit_1 = starts.find(function (eachStart) {
220
+ return rowEnd + BENCHMARK_LABEL_GAP_PX <= eachStart &&
221
+ !handleHitsBox(valueBoxes, eachStart, eachStart + each.width, top_1, top_1 + exports.BENCHMARK_LABEL_ROW_PX);
222
+ });
223
+ if (fit_1 !== undefined) {
224
+ row = index;
225
+ start = fit_1;
226
+ }
227
+ };
228
+ for (var index = 0; index < maxRows && row < 0; index += 1) {
229
+ _loop_1(index);
230
+ }
231
+ var overflow = false;
232
+ var width = each.width;
233
+ if (row >= 0) {
234
+ while (rowEnds.length <= row)
235
+ rowEnds.push(-Infinity);
236
+ }
237
+ else {
238
+ // INFO: the full label fits nowhere, so a "…" sits just right of its
239
+ // line in the first row with room for it, its text on hover
240
+ overflow = true;
241
+ width = (0, exports.handleBenchmarkTextWidth)("…");
242
+ start = each.pos + BENCHMARK_LINE_GAP_PX;
243
+ for (var index = 0; index < maxRows && row < 0; index += 1) {
244
+ var top_2 = rowTop(index);
245
+ if (((_b = rowEnds[index]) !== null && _b !== void 0 ? _b : -Infinity) + BENCHMARK_LABEL_GAP_PX <= start &&
246
+ !handleHitsBox(valueBoxes, start, start + width, top_2, top_2 + exports.BENCHMARK_LABEL_ROW_PX))
247
+ row = index;
248
+ }
249
+ if (row < 0) {
250
+ if (!rowEnds.length)
251
+ rowEnds.push(-Infinity);
252
+ row = rowEnds.indexOf(Math.min.apply(Math, rowEnds));
253
+ start = Math.max(start, rowEnds[row] + BENCHMARK_LABEL_GAP_PX);
254
+ }
255
+ while (rowEnds.length <= row)
256
+ rowEnds.push(-Infinity);
257
+ }
258
+ rowEnds[row] = start + width;
259
+ placed.set(each.key, { row: row, start: start, overflow: overflow });
260
+ });
261
+ return placed;
262
+ };
263
+ exports.handlePackBenchmarkRows = handlePackBenchmarkRows;
264
+ /**
265
+ * Where each label on an upright bar sits, bottom to top: just above its
266
+ * line, or just above the label below it or a printed bar value when that
267
+ * spot is taken, so any number of close goals stay readable. One pushed above
268
+ * the chart's top shows as "…".
269
+ */
270
+ var handleStackBenchmarkLabels = function (items, minTop, valueBoxes) {
271
+ if (minTop === void 0) { minTop = 0; }
272
+ if (valueBoxes === void 0) { valueBoxes = []; }
273
+ var half = exports.BENCHMARK_LABEL_ROW_PX / 2;
274
+ var placed = new Map();
275
+ var ceiling = Infinity;
276
+ __spreadArray([], items, true).sort(function (first, second) { return second.pos - first.pos; })
277
+ .forEach(function (each) {
278
+ var _a, _b;
279
+ var center = Math.min(each.pos, ceiling - half - 1);
280
+ var left = (_a = each.left) !== null && _a !== void 0 ? _a : 0;
281
+ var right = left + ((_b = each.width) !== null && _b !== void 0 ? _b : 0);
282
+ // INFO: a bar's value printed where the label would sit pushes it up
283
+ for (var step = 0; step < 20; step += 1) {
284
+ var hit = handleHitsBox(valueBoxes, left, right, center - half, center + half);
285
+ if (!hit)
286
+ break;
287
+ center = hit.top - half - 1;
288
+ }
289
+ var overflow = center - half < minTop;
290
+ if (overflow)
291
+ center = minTop + exports.BENCHMARK_LABEL_ROW_PX / 2;
292
+ ceiling = center - exports.BENCHMARK_LABEL_ROW_PX / 2;
293
+ placed.set(each.key, { center: center, overflow: overflow });
294
+ });
295
+ return placed;
296
+ };
297
+ exports.handleStackBenchmarkLabels = handleStackBenchmarkLabels;
298
+ /**
299
+ * The labels printed over the chart, one per line: the label, or the value
300
+ * when there is none, cut to maxChars, with both on hover.
301
+ */
302
+ var handleBenchmarkLabels = function (benchmarkLines, maxChars, formatValue) {
303
+ return handleBenchmarkValues(benchmarkLines).map(function (each, index) { return ({
304
+ key: "".concat(index),
305
+ value: each.value,
306
+ color: each.color || DEFAULT_BENCHMARK_COLOR,
307
+ text: handleCutBenchmarkText((0, exports.handleBenchmarkLabelText)(each, formatValue), maxChars),
308
+ title: (0, exports.handleBenchmarkLabelTitle)(each, formatValue),
309
+ }); });
310
+ };
311
+ exports.handleBenchmarkLabels = handleBenchmarkLabels;
312
+ /**
313
+ * ApexCharts annotations for the benchmark lines: across the value axis, which
314
+ * is y on an upright bar and x on a horizontal one. Only the lines are drawn
315
+ * here; their labels are printed over the chart once it is drawn.
316
+ */
317
+ var handleBuildBenchmarkAnnotations = function (benchmarkLines, isHorizontal) {
318
+ var annotations = handleBenchmarkValues(benchmarkLines).map(function (each) {
319
+ var _a;
320
+ return (_a = {},
321
+ _a[isHorizontal ? "x" : "y"] = each.value,
322
+ _a.borderColor = each.color || DEFAULT_BENCHMARK_COLOR,
323
+ _a.strokeDashArray = 6,
324
+ _a);
325
+ });
326
+ // INFO: ApexCharts merges new options into the old ones, so both lists are
327
+ // always sent; the unused one empty, or a chart switched between upright
328
+ // and horizontal keeps drawing its old lines the other way
329
+ return isHorizontal
330
+ ? { xaxis: annotations, yaxis: [] }
331
+ : { xaxis: [], yaxis: annotations };
332
+ };
333
+ exports.handleBuildBenchmarkAnnotations = handleBuildBenchmarkAnnotations;
334
+ /**
335
+ * The ApexCharts settings that print each bar's value past its end, in dark
336
+ * text that reads on the chart's background, or inside it. Inside sends
337
+ * ApexCharts' own defaults rather than nothing: options are merged into the
338
+ * old ones, so a chart switched back would otherwise keep its outside look.
339
+ */
340
+ var handleBarValuePlacement = function (outside, isHorizontal, darkMode) {
341
+ return outside
342
+ ? {
343
+ plotBarDataLabels: { position: "top" },
344
+ dataLabels: {
345
+ // INFO: a horizontal value starts 6px past the bar's end, so any
346
+ // length clears it (ApexCharts sets it 12px inside the end); an
347
+ // upright one sits centred above the bar
348
+ textAnchor: isHorizontal ? "start" : "middle",
349
+ offsetX: isHorizontal ? 18 : 0,
350
+ offsetY: isHorizontal ? 0 : -20,
351
+ style: {
352
+ fontSize: "12px",
353
+ fontWeight: 600,
354
+ colors: [darkMode ? "#E5E7EB" : "#374151"],
355
+ },
356
+ },
357
+ }
358
+ : {
359
+ plotBarDataLabels: { position: "center" },
360
+ dataLabels: {
361
+ textAnchor: "middle",
362
+ offsetX: 0,
363
+ offsetY: 0,
364
+ style: { fontSize: "12px", fontWeight: 600, colors: ["#FFFFFF"] },
365
+ },
366
+ };
367
+ };
368
+ exports.handleBarValuePlacement = handleBarValuePlacement;
369
+ /**
370
+ * The value axis's top: past a benchmark above every bar, and, with the
371
+ * values printed outside the bars, a little past the tallest bar so its value
372
+ * has room; undefined when neither applies, so ApexCharts keeps its own
373
+ * rounded ticks.
374
+ */
375
+ var handleValueAxisMax = function (benchmarkAxisMax, dataMax, valuesOutside) {
376
+ var forValues = valuesOutside && dataMax > 0 ? (0, exports.handleNiceCeil)(dataMax * 1.12) : undefined;
377
+ if (benchmarkAxisMax === undefined)
378
+ return forValues;
379
+ if (forValues === undefined)
380
+ return benchmarkAxisMax;
381
+ return Math.max(benchmarkAxisMax, forValues);
382
+ };
383
+ exports.handleValueAxisMax = handleValueAxisMax;
92
384
  var BarChart = /** @class */ (function (_super) {
93
385
  __extends(BarChart, _super);
94
386
  function BarChart() {
@@ -96,6 +388,51 @@ var BarChart = /** @class */ (function (_super) {
96
388
  _this.state = {
97
389
  apexModule: null,
98
390
  colors: [],
391
+ // INFO: where ApexCharts drew the plot, so the benchmark labels line up
392
+ // with their lines
393
+ plot: undefined,
394
+ };
395
+ _this.wrapperRef = react_1.default.createRef();
396
+ // INFO: ApexCharts places a line at min + range across the plot, the value
397
+ // axis being y on an upright bar and, flipped, on a horizontal one too
398
+ _this.handleReadPlot = function (_chartContext, config) {
399
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
400
+ var globals = config === null || config === void 0 ? void 0 : config.globals;
401
+ if (!globals)
402
+ return;
403
+ var isHorizontal = !!globals.isBarHorizontal;
404
+ var plot = {
405
+ top: Math.round((_a = globals.translateY) !== null && _a !== void 0 ? _a : 0),
406
+ height: Math.round((_b = globals.gridHeight) !== null && _b !== void 0 ? _b : 0),
407
+ left: Math.round((_c = globals.translateX) !== null && _c !== void 0 ? _c : 0),
408
+ width: Math.round((_d = globals.gridWidth) !== null && _d !== void 0 ? _d : 0),
409
+ min: isHorizontal
410
+ ? ((_e = globals.minY) !== null && _e !== void 0 ? _e : 0)
411
+ : ((_h = (_g = (_f = globals.minYArr) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : globals.minY) !== null && _h !== void 0 ? _h : 0),
412
+ range: (_k = (_j = globals.yRange) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : ((_l = globals.maxY) !== null && _l !== void 0 ? _l : 0) - ((_m = globals.minY) !== null && _m !== void 0 ? _m : 0),
413
+ valueBoxes: _this.handleReadValueBoxes(),
414
+ };
415
+ var current = _this.state.plot;
416
+ if (current && JSON.stringify(current) === JSON.stringify(plot))
417
+ return;
418
+ _this.setState({ plot: plot });
419
+ };
420
+ // INFO: where the bars' values were printed, read from the page once drawn,
421
+ // so a benchmark label can keep clear of them
422
+ _this.handleReadValueBoxes = function () {
423
+ var wrapper = _this.wrapperRef.current;
424
+ if (!wrapper)
425
+ return [];
426
+ var origin = wrapper.getBoundingClientRect();
427
+ return Array.from(wrapper.querySelectorAll(".apexcharts-datalabel"))
428
+ .map(function (each) { return each.getBoundingClientRect(); })
429
+ .filter(function (each) { return each.width > 0; })
430
+ .map(function (each) { return ({
431
+ left: Math.round(each.left - origin.left) - 2,
432
+ right: Math.round(each.right - origin.left) + 2,
433
+ top: Math.round(each.top - origin.top) - 1,
434
+ bottom: Math.round(each.bottom - origin.top) + 1,
435
+ }); });
99
436
  };
100
437
  _this.componentDidMount = function () { return __awaiter(_this, void 0, void 0, function () {
101
438
  var reactApexChart, colors, propColors, primaryColor;
@@ -196,119 +533,196 @@ var BarChart = /** @class */ (function (_super) {
196
533
  return _this.props.valueFormatter(number);
197
534
  };
198
535
  _this.renderChart = function () {
199
- var _a, _b, _c;
536
+ var _a, _b, _c, _d, _e, _f;
200
537
  var APEXModule = _this.state.apexModule;
201
538
  var isHorizontal = _this.props.orientation === "row";
202
539
  var valueFormatter = _this.props.valueFormatter
203
540
  ? { formatter: _this.handleFormatValue }
204
541
  : {};
205
542
  var borderColor = _this.renderDarkModeSettings().borderColor;
543
+ var dataMax = (0, exports.handleBarDataMax)(_this.props.seriesData, _this.props.stackedBarSeries, _this.props.stackedVertical);
544
+ // INFO: a stacked bar is several values, so it takes no benchmark lines
545
+ var isStacked = !!_this.props.stackedVertical && !!((_a = _this.props.stackedBarSeries) === null || _a === void 0 ? void 0 : _a.length);
546
+ var benchmarkLines = isStacked ? undefined : _this.props.benchmarkLines;
547
+ var benchmarkAxisMax = (0, exports.handleBenchmarkAxisMax)(benchmarkLines, dataMax);
548
+ var benchmarkFormat = function (value) {
549
+ return _this.props.valueFormatter
550
+ ? _this.props.valueFormatter(value)
551
+ : value.toLocaleString("en-US");
552
+ };
206
553
  var xAxisConfig = _this.buildAxisConfig("x", _this.props.xAxisLabels, _this.props.xAxisTitle);
207
554
  var yAxisConfig = _this.buildAxisConfig("y", _this.props.yAxisLabels, _this.props.yAxisTitle);
208
- return (react_1.default.createElement(react_1.default.Fragment, null, APEXModule && (react_1.default.createElement(APEXModule, { options: __assign(__assign({ chart: __assign(__assign({ type: "bar", height: _this.props.chartSize || 280 }, (_this.props.customBackground && {
209
- background: _this.props.customBackground,
210
- })), { foreColor: _this.props.darkMode ? "#FFFFFF" : undefined, toolbar: { show: (_a = _this.props.showToolbar) !== null && _a !== void 0 ? _a : false }, zoom: {
211
- enabled: !_this.props.disableZoom,
212
- type: "x",
213
- autoScaleYaxis: true,
214
- }, stacked: _this.props.stackedVertical, animations: _this.props.customAnimation || {
215
- enabled: true,
216
- easing: "easeout",
217
- speed: 800,
218
- }, events: {
219
- // INFO: the bar under the pointer, read from the bar itself.
220
- // The chart-wide click reads the bar the tooltip last
221
- // tracked — a shared tooltip tracks the nearest series, not
222
- // the segment clicked, and after a drill-down closes it is
223
- // reset until the pointer moves, so a repeat click opened
224
- // nothing
225
- dataPointSelection: function (event, _chartContext, config) { return _this.handleSelectBar(event, config); },
226
- } }), plotOptions: {
227
- bar: __assign(__assign({ horizontal: isHorizontal }, (_this.props.customBackground && { columnWidth: "60%" })), { borderRadius: _this.props.roundedBars ? 8 : 0, borderRadiusApplication: "end", borderRadiusWhenStacked: "last", distributed: (_b = _this.props.distributed) !== null && _b !== void 0 ? _b : false }),
228
- } }, (_this.props.onClick && {
229
- states: { active: { filter: { type: "none" } } },
230
- })), { dataLabels: __assign({ enabled: (_c = _this.props.showDataLabel) !== null && _c !== void 0 ? _c : true }, valueFormatter), grid: {
231
- show: _this.props.hideGrid ? false : true,
232
- borderColor: _this.props.borderColor || borderColor,
233
- }, fill: {
234
- type: _this.props.enableGradient ? "gradient" : "solid",
235
- }, xaxis: __assign({ categories: _this.props.categories || [], labels: __assign(__assign({ style: {
236
- colors: _this.props.darkMode || _this.props.customBackground
237
- ? "rgba(255, 255, 255, 0.7)"
238
- : undefined,
239
- fontSize: "12px",
240
- } }, (isHorizontal ? valueFormatter : {})), xAxisConfig.labels), axisBorder: { show: _this.props.hideAxes ? false : true }, axisTicks: { show: _this.props.hideAxes ? false : true } }, xAxisConfig), yaxis: __assign({ labels: __assign({ show: _this.props.hideAxes ? false : true, style: {
241
- colors: _this.props.darkMode || _this.props.customBackground
242
- ? "rgba(255, 255, 255, 0.7)"
243
- : undefined,
244
- } }, (isHorizontal ? {} : valueFormatter)), axisBorder: { show: _this.props.hideAxes ? false : true }, axisTicks: { show: _this.props.hideAxes ? false : true } }, yAxisConfig), tooltip: __assign(__assign({ enabled: !_this.props.disableTooltip, intersect: _this.props.stackedVertical ? false : true, shared: _this.props.stackedVertical ? true : false }, (_this.props.disableTooltip && { enabled: false })), { y: {
245
- formatter: function (value, _a) {
246
- var _b, _c;
247
- var seriesIndex = _a.seriesIndex;
248
- var defaultUnit = _this.props.seriesUnit || "";
249
- var stackedBarUnit = ((_c = (_b = _this.props.stackedBarSeries) === null || _b === void 0 ? void 0 : _b[seriesIndex]) === null || _c === void 0 ? void 0 : _c.unit) ||
250
- defaultUnit;
251
- var unit = _this.props.stackedVertical
252
- ? stackedBarUnit
253
- : defaultUnit;
254
- // INFO: the bars show a compact value, so the tooltip
255
- // gives the exact one with separators
256
- var shown = _this.props.valueFormatter && typeof value === "number"
257
- ? value.toLocaleString("en", {
258
- maximumFractionDigits: 2,
259
- })
260
- : value;
261
- return "".concat(shown).concat(unit ? " " + unit : "");
262
- },
263
- } }), colors: _this.props.customColors ||
264
- _this.state.colors || [
265
- "#008FFB",
266
- "#00E396",
267
- "#FEB019",
268
- "#FF4560",
269
- "#775DD0",
270
- ], stroke: {
271
- show: false,
272
- },
273
- // INFO: a bar per colour already names itself on its axis
274
- legend: { show: !_this.props.distributed }, annotations: _this.props.dataLabels && _this.props.dataLabels.length > 0
275
- ? {
276
- points: _this.props.dataLabels.map(function (item) {
277
- var _a, _b, _c, _d, _e, _f;
278
- var point = {
279
- x: item.x,
280
- y: item.y,
281
- marker: {
282
- size: 0,
283
- },
284
- label: {
285
- text: item.name,
286
- borderColor: "transparent",
287
- borderWidth: 0,
288
- offsetY: (_a = item.offsetY) !== null && _a !== void 0 ? _a : -20,
289
- offsetX: (_b = item.offsetX) !== null && _b !== void 0 ? _b : 0,
290
- style: {
291
- color: ((_c = item.style) === null || _c === void 0 ? void 0 : _c.color) || "#ffffff",
292
- background: ((_d = item.style) === null || _d === void 0 ? void 0 : _d.background) || "transparent",
293
- fontSize: ((_e = item.style) === null || _e === void 0 ? void 0 : _e.fontSize) || "14px",
294
- fontWeight: ((_f = item.style) === null || _f === void 0 ? void 0 : _f.fontWeight) || "bold",
555
+ var plot = _this.state.plot;
556
+ var hasBenchmarks = handleBenchmarkValues(benchmarkLines).length > 0;
557
+ var shareOf = function (value) {
558
+ return plot && plot.range ? (value - plot.min) / plot.range : 0;
559
+ };
560
+ // INFO: a stacked bar keeps its values inside its segments; outside, the
561
+ // top segment's value would sit above the bar and read as its total
562
+ var valuesOutside = ((_b = _this.props.showDataLabel) !== null && _b !== void 0 ? _b : true) &&
563
+ !isStacked &&
564
+ (_this.props.dataLabelPosition
565
+ ? _this.props.dataLabelPosition === "outside"
566
+ : hasBenchmarks);
567
+ var valuePlacement = (0, exports.handleBarValuePlacement)(valuesOutside, isHorizontal, _this.props.darkMode);
568
+ var valueAxisMax = (0, exports.handleValueAxisMax)(benchmarkAxisMax, dataMax, valuesOutside);
569
+ // INFO: the labels are printed over the chart once ApexCharts reports
570
+ // where it drew the plot, the way monday.com places them: just above the
571
+ // line at its left end on an upright bar, and along the top just right of
572
+ // the line on a horizontal one. The bars' values move outside the bars
573
+ // so a label can never cover one
574
+ var benchmarkLabels = hasBenchmarks && plot
575
+ ? (0, exports.handleBenchmarkLabels)(benchmarkLines, exports.BENCHMARK_LABEL_MAX_CHARS, benchmarkFormat).map(function (each) { return (__assign(__assign({}, each), { width: (0, exports.handleBenchmarkTextWidth)(each.text), pos: isHorizontal
576
+ ? plot.left + plot.width * shareOf(each.value)
577
+ : plot.top + plot.height * (1 - shareOf(each.value)) })); })
578
+ : [];
579
+ var topRows = isHorizontal
580
+ ? (0, exports.handlePackBenchmarkRows)(benchmarkLabels, plot ? plot.left + plot.width : 0, exports.BENCHMARK_LABEL_MAX_ROWS, (_c = plot === null || plot === void 0 ? void 0 : plot.left) !== null && _c !== void 0 ? _c : 0, plot === null || plot === void 0 ? void 0 : plot.valueBoxes, function (row) { var _a; return ((_a = plot === null || plot === void 0 ? void 0 : plot.top) !== null && _a !== void 0 ? _a : 0) + 2 + row * exports.BENCHMARK_LABEL_ROW_PX; })
581
+ : new Map();
582
+ // INFO: an upright label sits just above its line
583
+ var leftStack = isHorizontal
584
+ ? new Map()
585
+ : (0, exports.handleStackBenchmarkLabels)(benchmarkLabels.map(function (each) {
586
+ var _a;
587
+ return ({
588
+ key: each.key,
589
+ pos: each.pos - exports.BENCHMARK_LABEL_ROW_PX / 2 - 1,
590
+ left: ((_a = plot === null || plot === void 0 ? void 0 : plot.left) !== null && _a !== void 0 ? _a : 0) + 4,
591
+ width: each.width,
592
+ });
593
+ }), 0, plot === null || plot === void 0 ? void 0 : plot.valueBoxes);
594
+ return (react_1.default.createElement("div", { ref: _this.wrapperRef, className: "relative" },
595
+ APEXModule && (react_1.default.createElement(APEXModule, { options: __assign(__assign({ chart: __assign(__assign({ type: "bar", height: _this.props.chartSize || 280 }, (_this.props.customBackground && {
596
+ background: _this.props.customBackground,
597
+ })), { foreColor: _this.props.darkMode ? "#FFFFFF" : undefined, toolbar: { show: (_d = _this.props.showToolbar) !== null && _d !== void 0 ? _d : false }, zoom: {
598
+ enabled: !_this.props.disableZoom,
599
+ type: "x",
600
+ autoScaleYaxis: true,
601
+ }, stacked: _this.props.stackedVertical, animations: _this.props.customAnimation || {
602
+ enabled: true,
603
+ easing: "easeout",
604
+ speed: 800,
605
+ }, events: __assign({
606
+ // INFO: the bar under the pointer, read from the bar itself.
607
+ // The chart-wide click reads the bar the tooltip last
608
+ // tracked — a shared tooltip tracks the nearest series, not
609
+ // the segment clicked, and after a drill-down closes it is
610
+ // reset until the pointer moves, so a repeat click opened
611
+ // nothing
612
+ dataPointSelection: function (event, _chartContext, config) { return _this.handleSelectBar(event, config); } }, (hasBenchmarks && {
613
+ mounted: _this.handleReadPlot,
614
+ updated: _this.handleReadPlot,
615
+ // INFO: the values settle where they're printed only once
616
+ // the bars finish growing
617
+ animationEnd: _this.handleReadPlot,
618
+ })) }), plotOptions: {
619
+ bar: __assign(__assign({ horizontal: isHorizontal }, (_this.props.customBackground && { columnWidth: "60%" })), { borderRadius: _this.props.roundedBars ? 8 : 0, borderRadiusApplication: "end", borderRadiusWhenStacked: "last", dataLabels: valuePlacement.plotBarDataLabels, distributed: (_e = _this.props.distributed) !== null && _e !== void 0 ? _e : false }),
620
+ } }, (_this.props.onClick && {
621
+ states: { active: { filter: { type: "none" } } },
622
+ })), { dataLabels: __assign(__assign({ enabled: (_f = _this.props.showDataLabel) !== null && _f !== void 0 ? _f : true }, valueFormatter), valuePlacement.dataLabels), grid: {
623
+ show: _this.props.hideGrid ? false : true,
624
+ borderColor: _this.props.borderColor || borderColor,
625
+ }, fill: {
626
+ type: _this.props.enableGradient ? "gradient" : "solid",
627
+ }, xaxis: __assign({ categories: _this.props.categories || [], labels: __assign(__assign({ style: {
628
+ colors: _this.props.darkMode || _this.props.customBackground
629
+ ? "rgba(255, 255, 255, 0.7)"
630
+ : undefined,
631
+ fontSize: "12px",
632
+ } }, (isHorizontal ? valueFormatter : {})), xAxisConfig.labels), axisBorder: { show: _this.props.hideAxes ? false : true }, axisTicks: { show: _this.props.hideAxes ? false : true } }, xAxisConfig), yaxis: __assign({ labels: __assign({ show: _this.props.hideAxes ? false : true, style: {
633
+ colors: _this.props.darkMode || _this.props.customBackground
634
+ ? "rgba(255, 255, 255, 0.7)"
635
+ : undefined,
636
+ } }, (isHorizontal ? {} : valueFormatter)), axisBorder: { show: _this.props.hideAxes ? false : true }, axisTicks: { show: _this.props.hideAxes ? false : true },
637
+ // INFO: always sent, empty or not, since ApexCharts merges
638
+ // options and a top dropped later would otherwise stay
639
+ max: valueAxisMax }, yAxisConfig), tooltip: __assign(__assign({ enabled: !_this.props.disableTooltip, intersect: _this.props.stackedVertical ? false : true, shared: _this.props.stackedVertical ? true : false }, (_this.props.disableTooltip && { enabled: false })), { y: {
640
+ formatter: function (value, _a) {
641
+ var _b, _c;
642
+ var seriesIndex = _a.seriesIndex;
643
+ var defaultUnit = _this.props.seriesUnit || "";
644
+ var stackedBarUnit = ((_c = (_b = _this.props.stackedBarSeries) === null || _b === void 0 ? void 0 : _b[seriesIndex]) === null || _c === void 0 ? void 0 : _c.unit) ||
645
+ defaultUnit;
646
+ var unit = _this.props.stackedVertical
647
+ ? stackedBarUnit
648
+ : defaultUnit;
649
+ // INFO: the bars show a compact value, so the tooltip
650
+ // gives the exact one with separators
651
+ var shown = _this.props.valueFormatter && typeof value === "number"
652
+ ? value.toLocaleString("en", {
653
+ maximumFractionDigits: 2,
654
+ })
655
+ : value;
656
+ return "".concat(shown).concat(unit ? " " + unit : "");
657
+ },
658
+ } }), colors: _this.props.customColors ||
659
+ _this.state.colors || [
660
+ "#008FFB",
661
+ "#00E396",
662
+ "#FEB019",
663
+ "#FF4560",
664
+ "#775DD0",
665
+ ], stroke: {
666
+ show: false,
667
+ },
668
+ // INFO: a bar per colour already names itself on its axis
669
+ legend: { show: !_this.props.distributed }, annotations: __assign(__assign({}, (0, exports.handleBuildBenchmarkAnnotations)(benchmarkLines, isHorizontal)), (_this.props.dataLabels && _this.props.dataLabels.length > 0
670
+ ? {
671
+ points: _this.props.dataLabels.map(function (item) {
672
+ var _a, _b, _c, _d, _e, _f;
673
+ var point = {
674
+ x: item.x,
675
+ y: item.y,
676
+ marker: {
677
+ size: 0,
295
678
  },
296
- },
297
- };
298
- if (item.image) {
299
- point.image = item.image;
300
- }
301
- return point;
302
- }),
303
- }
304
- : {} }), series: _this.props.stackedBarSeries
305
- ? _this.props.stackedBarSeries
306
- : [
307
- {
308
- name: _this.props.seriesName,
309
- data: _this.props.seriesData,
310
- },
311
- ], type: "bar", height: _this.props.chartSize || 280 }))));
679
+ label: {
680
+ text: item.name,
681
+ borderColor: "transparent",
682
+ borderWidth: 0,
683
+ offsetY: (_a = item.offsetY) !== null && _a !== void 0 ? _a : -20,
684
+ offsetX: (_b = item.offsetX) !== null && _b !== void 0 ? _b : 0,
685
+ style: {
686
+ color: ((_c = item.style) === null || _c === void 0 ? void 0 : _c.color) || "#ffffff",
687
+ background: ((_d = item.style) === null || _d === void 0 ? void 0 : _d.background) || "transparent",
688
+ fontSize: ((_e = item.style) === null || _e === void 0 ? void 0 : _e.fontSize) || "14px",
689
+ fontWeight: ((_f = item.style) === null || _f === void 0 ? void 0 : _f.fontWeight) || "bold",
690
+ },
691
+ },
692
+ };
693
+ if (item.image) {
694
+ point.image = item.image;
695
+ }
696
+ return point;
697
+ }),
698
+ }
699
+ : // INFO: emptied rather than left out, for the same merge
700
+ { points: [] })) }), series: _this.props.stackedBarSeries
701
+ ? _this.props.stackedBarSeries
702
+ : [
703
+ {
704
+ name: _this.props.seriesName,
705
+ data: _this.props.seriesData,
706
+ },
707
+ ], type: "bar", height: _this.props.chartSize || 280 })),
708
+ benchmarkLabels.map(function (each) {
709
+ var row = topRows.get(each.key);
710
+ var stacked = leftStack.get(each.key);
711
+ if (!plot || (!row && !stacked))
712
+ return null;
713
+ var overflow = row ? row.overflow : stacked.overflow;
714
+ return (react_1.default.createElement("span", { key: each.key, title: each.title, className: "pointer-events-auto absolute whitespace-nowrap text-[11px] font-medium leading-[14px]", style: row
715
+ ? {
716
+ top: plot.top + 2 + row.row * exports.BENCHMARK_LABEL_ROW_PX,
717
+ left: row.start,
718
+ color: each.color,
719
+ }
720
+ : {
721
+ top: stacked.center - exports.BENCHMARK_LABEL_ROW_PX / 2,
722
+ left: plot.left + 4,
723
+ color: each.color,
724
+ } }, overflow ? "…" : each.text));
725
+ })));
312
726
  };
313
727
  _this.renderDarkModeSettings = function () {
314
728
  var _a, _b;
@@ -330,7 +744,7 @@ var BarChart = /** @class */ (function (_super) {
330
744
  return !this.props.chartOnly ? (react_1.default.createElement("div", { className: defaultClass },
331
745
  react_1.default.createElement("div", { className: "ml-2 pr-5 my-4 flex flex-row items-center" },
332
746
  react_1.default.createElement("div", { className: "flex-1 " }, this.props.newTabUrl ? (react_1.default.createElement(link_1.Link, { href: this.props.newTabUrl, linkType: this.props.linkType, custom: this.props.custom },
333
- react_1.default.createElement("h3", { className: "text-lg truncate font-medium ".concat(textColor) }, this.props.title))) : (react_1.default.createElement("h3", { className: "text-lg truncate font-medium ".concat(textColor) }, this.props.title))),
747
+ react_1.default.createElement("h3", { className: "text-base truncate font-medium ".concat(textColor) }, this.props.title))) : (react_1.default.createElement("h3", { className: "text-base truncate font-medium ".concat(textColor) }, this.props.title))),
334
748
  this.props.tool),
335
749
  react_1.default.createElement("div", { className: "mr-4 " }, this.renderChart()),
336
750
  this.props.dateRangeVisible && (react_1.default.createElement(DateRange_1.DateRange, { className: "px-3", customDate: this.props.customDate, onChangeDate: this.props.onChangeDate, darkMode: this.props.darkMode, minInterval: this.props.minInterval })))) : (react_1.default.createElement("div", { className: this.props.containerStyle }, this.renderChart()));