@hpcc-js/html 3.3.1 → 3.3.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/index.js CHANGED
@@ -1,864 +1,5 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- import { HTMLWidget, select, format } from "@hpcc-js/common";
6
- import { scopedLogger } from "@hpcc-js/util";
7
- import { React } from "@hpcc-js/react";
8
- const PKG_NAME = "@hpcc-js/html";
9
- const PKG_VERSION = "3.3.1";
10
- const BUILD_VERSION = "3.15.1";
11
- const _HTMLTooltip = class _HTMLTooltip extends HTMLWidget {
12
- _triggerElement;
13
- _contentNode;
14
- _prevContentNode;
15
- _tooltipElement;
16
- _arrowElement;
17
- _tooltipHTMLCallback = /* @__PURE__ */ __name((data) => "<b>_tooltipHTMLCallback is undefined</b>", "_tooltipHTMLCallback");
18
- _logger = scopedLogger("html/HTMLTooltip");
19
- constructor() {
20
- super();
21
- this.visible(false);
22
- }
23
- tooltipHTML(_) {
24
- this._tooltipHTMLCallback = _;
25
- return this;
26
- }
27
- tooltipContent(_) {
28
- if (!arguments.length) return this._contentNode;
29
- this._contentNode = _;
30
- return this;
31
- }
32
- triggerElement(_) {
33
- this._triggerElement = _;
34
- return this;
35
- }
36
- enter(domNode, element) {
37
- super.enter(domNode, element);
38
- const body = select("body");
39
- this._tooltipElement = body.append("div").attr("class", "tooltip-div").style("z-index", "2147483638").style("position", "fixed");
40
- this._arrowElement = body.append("div").attr("class", "arrow-div").style("z-index", "2147483638").style("position", "fixed");
41
- }
42
- update(domNode, element) {
43
- super.update(domNode, element);
44
- if (this._contentNode !== this._prevContentNode) {
45
- const node = this._tooltipElement.node();
46
- [...node.querySelectorAll("*")].map((n) => n.__data__).filter((n) => n).forEach((w) => {
47
- if (typeof w.target === "function") {
48
- w.target(null);
49
- }
50
- if (typeof w.exit === "function") {
51
- w.exit();
52
- }
53
- });
54
- node.innerHTML = "";
55
- node.appendChild(this._contentNode);
56
- this._prevContentNode = this._contentNode;
57
- }
58
- if (this._contentNode) {
59
- this.onShowContent(this._contentNode);
60
- } else {
61
- this._tooltipElement.html(() => {
62
- return this._tooltipHTMLCallback(this.data());
63
- });
64
- }
65
- if (this.fitContent()) {
66
- this._tooltipElement.style("width", "auto").style("height", "auto").style("padding", "0px").style("box-sizing", "content-box");
67
- const rect = this._tooltipElement.node().getBoundingClientRect();
68
- this.tooltipWidth_default(rect.width);
69
- this.tooltipHeight_default(rect.height);
70
- }
71
- this._closing = false;
72
- this._tooltipElement.style("background-color", this.tooltipColor()).style("color", this.fontColor()).style("width", this.tooltipWidth() + "px").style("height", this.tooltipHeight() + "px").style("opacity", 1).style("padding", this.padding() + "px").style("pointer-events", this.enablePointerEvents() ? "all" : "none").style("box-sizing", "content-box");
73
- this._arrowElement.style("opacity", 1).style("pointer-events", "none");
74
- this.updateTooltipPosition();
75
- }
76
- onShowContent(node) {
77
- }
78
- updateTooltipPosition() {
79
- const bbox = this.calcReferenceBBox();
80
- const direction = this.calcTooltipDirection(bbox);
81
- const box = bbox[direction];
82
- this._tooltipElement.style("top", box.y + "px").style("left", box.x + "px");
83
- this.setArrowPosition(box, direction);
84
- return box;
85
- }
86
- calcTooltipDirection(bbox) {
87
- const directions = Object.keys(bbox);
88
- const defaultDirection = this.direction();
89
- directions.sort((a, b) => a === defaultDirection ? -1 : 1);
90
- const windowRect = {
91
- top: 0,
92
- left: 0,
93
- width: window.innerWidth,
94
- height: window.innerHeight
95
- };
96
- for (let i = 0; i < directions.length; i++) {
97
- const tooltipRect = {
98
- top: bbox[directions[i]].y,
99
- left: bbox[directions[i]].x,
100
- width: this.tooltipWidth(),
101
- height: this.tooltipHeight()
102
- };
103
- if (this.rectFits(tooltipRect, windowRect)) {
104
- return directions[i];
105
- }
106
- }
107
- this._logger.warning(`Tooltip doesn't fit in the window for any of the directions. Defaulting to '${defaultDirection}'`);
108
- this._logger.debug(windowRect);
109
- this._logger.debug({
110
- top: bbox[defaultDirection].y,
111
- left: bbox[defaultDirection].x,
112
- width: this.tooltipWidth(),
113
- height: this.tooltipHeight()
114
- });
115
- return defaultDirection;
116
- }
117
- rectFits(innerRect, outerRect) {
118
- return innerRect.top >= outerRect.top && innerRect.left >= outerRect.left && innerRect.width + innerRect.left <= outerRect.width + outerRect.left && innerRect.height + innerRect.top <= outerRect.height + outerRect.top;
119
- }
120
- setArrowPosition(point, direction) {
121
- let top;
122
- let left;
123
- let visibleBorderStyle = "border-top-color";
124
- this._arrowElement.style("border", `${this.arrowHeight()}px solid ${this.tooltipColor()}`).style("border-top-color", "transparent").style("border-right-color", "transparent").style("border-bottom-color", "transparent").style("border-left-color", "transparent");
125
- switch (direction) {
126
- case "n":
127
- top = point.y + this.tooltipHeight() + this.padding() * 2;
128
- left = point.x + this.tooltipWidth() / 2 - this.arrowWidth() / 2 + this.padding();
129
- visibleBorderStyle = "border-top-color";
130
- this._arrowElement.style("border-top-width", `${this.arrowHeight()}px`).style("border-bottom-width", "0px").style("border-left-width", `${this.arrowWidth() / 2}px`).style("border-right-width", `${this.arrowWidth() / 2}px`);
131
- break;
132
- case "s":
133
- top = point.y - this.arrowHeight();
134
- left = point.x + this.padding() + this.tooltipWidth() / 2 - this.arrowWidth() / 2;
135
- visibleBorderStyle = "border-bottom-color";
136
- this._arrowElement.style("border-top-width", "0px").style("border-bottom-width", `${this.arrowHeight()}px`).style("border-left-width", `${this.arrowWidth() / 2}px`).style("border-right-width", `${this.arrowWidth() / 2}px`);
137
- break;
138
- case "e":
139
- top = point.y + this.tooltipHeight() / 2 + this.padding() - this.arrowWidth() / 2;
140
- left = point.x - this.arrowHeight();
141
- visibleBorderStyle = "border-right-color";
142
- this._arrowElement.style("border-top-width", `${this.arrowWidth() / 2}px`).style("border-bottom-width", `${this.arrowWidth() / 2}px`).style("border-left-width", "0px").style("border-right-width", `${this.arrowHeight()}px`);
143
- break;
144
- case "w":
145
- top = point.y + this.tooltipHeight() / 2 - this.arrowWidth() / 2 + this.padding();
146
- left = point.x + this.tooltipWidth() + this.padding() * 2;
147
- visibleBorderStyle = "border-left-color";
148
- this._arrowElement.style("border-top-width", `${this.arrowWidth() / 2}px`).style("border-bottom-width", `${this.arrowWidth() / 2}px`).style("border-left-width", `${this.arrowHeight()}px`).style("border-right-width", "0px");
149
- break;
150
- }
151
- if (typeof top !== "undefined" && typeof left !== "undefined") {
152
- this._arrowElement.style("top", top + "px").style("left", left + "px").style(visibleBorderStyle, this.tooltipColor()).style("opacity", 1);
153
- } else {
154
- this._arrowElement.style("opacity", 0);
155
- }
156
- return point;
157
- }
158
- getReferenceNode() {
159
- if (!this._triggerElement) {
160
- return this.element().node().parentNode.parentNode;
161
- }
162
- return this._triggerElement.node();
163
- }
164
- _cursorLoc;
165
- calcReferenceBBox() {
166
- const node = this.getReferenceNode();
167
- let { top, left, width, height } = node.getBoundingClientRect();
168
- const wholeW = this.tooltipWidth();
169
- const wholeH = this.tooltipHeight();
170
- const halfW = wholeW / 2;
171
- const halfH = wholeH / 2;
172
- const arrowH = this.arrowHeight();
173
- const p = this.padding();
174
- const p2 = p * 2;
175
- if (this.followCursor() && this._cursorLoc) {
176
- left = this._cursorLoc[0];
177
- top = this._cursorLoc[1];
178
- width = 1;
179
- height = 1;
180
- }
181
- const bbox = {
182
- n: {
183
- x: left + width / 2 - halfW - p,
184
- y: top - wholeH - arrowH - p2
185
- },
186
- e: {
187
- x: left + width + arrowH,
188
- y: top + height / 2 - halfH - p
189
- },
190
- s: {
191
- x: left + width / 2 - halfW - p,
192
- y: top + height + arrowH
193
- },
194
- w: {
195
- x: left - wholeW - arrowH - p2,
196
- y: top + height / 2 - halfH - p
197
- },
198
- nw: {
199
- x: left - wholeW - p2,
200
- y: top - wholeH - p2
201
- },
202
- ne: {
203
- x: left + width,
204
- y: top - wholeH - p2
205
- },
206
- se: {
207
- x: left + width,
208
- y: top + height
209
- },
210
- sw: {
211
- x: left - wholeW - p2,
212
- y: top + height
213
- }
214
- };
215
- return bbox;
216
- }
217
- _closing = false;
218
- mouseout() {
219
- this._closing = true;
220
- this._tooltipElement.on("mouseover", () => {
221
- this._closing = false;
222
- });
223
- this._tooltipElement.on("mouseout", () => {
224
- this.mouseout();
225
- });
226
- setTimeout(() => {
227
- if (this._closing) {
228
- this.visible(false);
229
- }
230
- }, this.closeDelay());
231
- }
232
- visible(_) {
233
- if (!arguments.length) return super.visible();
234
- if (this._arrowElement) {
235
- this._arrowElement.style("visibility", _ ? "visible" : "hidden");
236
- this._tooltipElement.style("visibility", _ ? "visible" : "hidden");
237
- }
238
- super.visible(_);
239
- return this;
240
- }
241
- exit(domNode, element) {
242
- if (this._arrowElement) {
243
- this._arrowElement.remove();
244
- this._tooltipElement.remove();
245
- }
246
- super.exit(domNode, element);
247
- }
248
- };
249
- __name(_HTMLTooltip, "HTMLTooltip");
250
- let HTMLTooltip = _HTMLTooltip;
251
- HTMLTooltip.prototype._class += " html_HTMLTooltip";
252
- HTMLTooltip.prototype.publish("fitContent", false, "boolean", "If true, tooltip will grow to fit its html content");
253
- HTMLTooltip.prototype.publish("followCursor", false, "boolean", "If true, tooltip will display relative to cursor location");
254
- HTMLTooltip.prototype.publish("closeDelay", 400, "number", "Number of milliseconds to wait before closing tooltip (cancelled on tooltip mouseover event)");
255
- HTMLTooltip.prototype.publish("direction", "n", "set", "Direction in which to display the tooltip", ["n", "s", "e", "w", "ne", "nw", "se", "sw"]);
256
- HTMLTooltip.prototype.publish("padding", 8, "number", "Padding (pixels)");
257
- HTMLTooltip.prototype.publish("arrowWidth", 16, "number", "Width (or height depending on direction) of the tooltip arrow (pixels)");
258
- HTMLTooltip.prototype.publish("arrowHeight", 8, "number", "Height (or width depending on direction) of the tooltip arrow (pixels)");
259
- HTMLTooltip.prototype.publish("fontColor", "#FFF", "html-color", "The default font color for text in the tooltip");
260
- HTMLTooltip.prototype.publish("tooltipColor", "#000000EE", "html-color", "Background color of the tooltip");
261
- HTMLTooltip.prototype.publish("tooltipWidth", 200, "number", "Width of the tooltip (not including arrow) (pixels)");
262
- HTMLTooltip.prototype.publish("tooltipHeight", 200, "number", "Height of the tooltip (not including arrow) (pixels)");
263
- HTMLTooltip.prototype.publish("enablePointerEvents", false, "boolean", "If true, the 'pointer-events: all' style will be used");
264
- const _SimpleTable = class _SimpleTable extends HTMLWidget {
265
- _table;
266
- _tbody;
267
- _thead;
268
- _theadRow;
269
- constructor() {
270
- super();
271
- }
272
- transformData() {
273
- return this.data();
274
- }
275
- enter(domNode, element) {
276
- super.enter(domNode, element);
277
- this._table = element.append("table");
278
- this._thead = this._table.append("thead");
279
- this._theadRow = this._thead.append("tr");
280
- this._tbody = this._table.append("tbody");
281
- }
282
- update(domNode, element) {
283
- super.update(domNode, element);
284
- this._table.style("width", this.autoWidth() ? "auto" : "100%");
285
- const theadTrSelection = this._theadRow.selectAll("th").data(this.columns());
286
- theadTrSelection.enter().append("th").attr("class", (n, i) => `th-${i}`).merge(theadTrSelection).text((_d) => _d.toString());
287
- theadTrSelection.exit().remove();
288
- const trSelection = this._tbody.selectAll("tr").data(this.transformData());
289
- trSelection.enter().append("tr").merge(trSelection).each(function(d) {
290
- const tr = select(this);
291
- const tdSelection = tr.selectAll("td").data(d);
292
- tdSelection.enter().append("td").attr("class", (n, i) => `col-${i}`).merge(tdSelection).text((_d) => _d.toString());
293
- tdSelection.exit().remove();
294
- });
295
- trSelection.exit().remove();
296
- }
297
- };
298
- __name(_SimpleTable, "SimpleTable");
299
- let SimpleTable = _SimpleTable;
300
- SimpleTable.prototype._class += " html_SimpleTable";
301
- SimpleTable.prototype.publish("autoWidth", false, "boolean", "If true, table width will be set to 'auto'. If false, the width is set to '100%'");
302
- const _StyledTable = class _StyledTable extends SimpleTable {
303
- constructor() {
304
- super();
305
- }
306
- applyStyleObject(selection, styleObject) {
307
- Object.keys(styleObject).forEach((styleName) => {
308
- selection.style(styleName, styleObject[styleName]);
309
- });
310
- }
311
- update(domNode, element) {
312
- super.update(domNode, element);
313
- element.selectAll("tr,th,td").attr("style", "").style("font-family", this.fontFamily()).style("color", this.fontColor());
314
- this.theadColumnStyles().forEach((styleObj, i) => {
315
- this.applyStyleObject(element.select(`.th-${i}`), styleObj);
316
- });
317
- this.tbodyColumnStyles().forEach((styleObj, i) => {
318
- this.applyStyleObject(element.selectAll(`.col-${i}`), styleObj);
319
- });
320
- const evenRowStylesExist = Object.keys(this.evenRowStyles()).length > 0;
321
- const lastRowStylesExist = Object.keys(this.lastRowStyles()).length > 0;
322
- const tbodyRows = element.selectAll("tbody > tr");
323
- if (evenRowStylesExist) {
324
- const tbodyEvenRows = tbodyRows.select(function(d, i) {
325
- return i % 2 ? this : null;
326
- });
327
- this.applyStyleObject(tbodyEvenRows, this.evenRowStyles());
328
- }
329
- if (lastRowStylesExist) {
330
- const tbodyLastRow = tbodyRows.select(function(d, i, arr) {
331
- return i === arr.length - 1 ? this : null;
332
- });
333
- this.applyStyleObject(tbodyLastRow, this.lastRowStyles());
334
- }
335
- }
336
- };
337
- __name(_StyledTable, "StyledTable");
338
- let StyledTable = _StyledTable;
339
- StyledTable.prototype._class += " html_StyledTable";
340
- StyledTable.prototype.publish("fontFamily", "Verdana", "string", "Base font-family used within the table");
341
- StyledTable.prototype.publish("fontColor", "#333", "string", "Base font color used within the table");
342
- StyledTable.prototype.publish("theadColumnStyles", [], "array", 'Array of objects containing styles for the thead columns (ex: [{"color":"red"},{"color":"blue"}])');
343
- StyledTable.prototype.publish("tbodyColumnStyles", [], "array", 'Array of objects containing styles for the tbody columns (ex: [{"color":"red"},{"color":"blue"}])');
344
- StyledTable.prototype.publish("lastRowStyles", {}, "object", 'Object containing styles for the last row (ex: {"color":"red"})');
345
- StyledTable.prototype.publish("evenRowStyles", {}, "object", 'Object containing styles for even rows (ex: {"background-color":"#AAA"})');
346
- const _BreakdownTable = class _BreakdownTable extends StyledTable {
347
- // protected _table;
348
- // protected _tbody;
349
- _tooltip;
350
- constructor() {
351
- super();
352
- }
353
- transformData() {
354
- const rowCount = this.useCalculatedRowCount() ? this.calculateRowCount() : this.rowCount();
355
- return this.breakdownData(rowCount);
356
- }
357
- breakdownData(limit) {
358
- const len = this.data().length;
359
- const sum = this.data().reduce((acc, row) => acc + row[1], 0);
360
- const data = [];
361
- let percSum = 0;
362
- this.data().sort((a, b) => a[1] > b[1] ? -1 : 1);
363
- const hiddenRowCount = len - limit;
364
- const showOther = hiddenRowCount > 0;
365
- this.data().filter((_, i) => showOther ? i < limit - 1 : true).forEach((row) => {
366
- const perc = Math.round(row[1] / sum * 100);
367
- percSum += perc;
368
- data.push([row[0], perc + "%"]);
369
- });
370
- if (showOther) {
371
- const otherLabel = `${this.otherLabel()} (${len - limit + 1})`;
372
- const otherPercentage = "~" + (100 - percSum) + "%";
373
- data.push([otherLabel, otherPercentage]);
374
- }
375
- return data;
376
- }
377
- calculateRowCount() {
378
- const theadRowHeight = this.columns().length > 0 ? this.thFontSize() + 5 : 0;
379
- const tbodyRowHeight = this.fontSize() + 5;
380
- const tbodyAvailableHeight = this.height() - theadRowHeight;
381
- const rowCount = Math.floor(tbodyAvailableHeight / tbodyRowHeight);
382
- return rowCount;
383
- }
384
- enter(domNode, element) {
385
- super.enter(domNode, element);
386
- this._tooltip = new HTMLTooltip().target(domNode);
387
- this._tooltip.tooltipHTML((data) => {
388
- const rowCount = this.useCalculatedRowCount() ? this.calculateRowCount() : this.rowCount();
389
- const rowHeight = Math.max(...data.map((row) => this.textSize(row[0], this.fontFamily(), this.fontSize()).height)) ?? this.fontSize();
390
- const widestLabel = Math.max(...data.map((row) => this.textSize(row[0], this.fontFamily(), this.fontSize()).width));
391
- const widestPerc = 30;
392
- const colCount = 2;
393
- const w = colCount * (widestLabel + widestPerc) + this._tooltip.padding() * 2;
394
- const h = rowHeight * Math.ceil((data.length - rowCount) / colCount) + this._tooltip.padding() * 2;
395
- this._tooltip.tooltipWidth(w);
396
- this._tooltip.tooltipHeight(h);
397
- const otherData = this.breakdownData(this.data().length).slice(rowCount - 1);
398
- return `<div style="
399
- width: 100%;
400
- height: 100%;
401
- font-size: ${this.fontSize()}px;
402
- ">${otherData.map(
403
- (row) => `<div style="
404
- float:left;
405
- width:${Math.floor(99 / colCount)}%;
406
- ">${row[0]}: ${row[1]}</div>`
407
- ).join("")}</div>`;
408
- });
409
- }
410
- update(domNode, element) {
411
- this.theadColumnStyles_default([
412
- {
413
- "color": this.thFirstColor(),
414
- "font-size": this.thFontSize() + "px",
415
- "font-weight": this.thFontWeight(),
416
- "text-align": this.labelAlignment(),
417
- "width": "auto",
418
- "padding": "0px"
419
- },
420
- {
421
- "width": "1%",
422
- "font-size": this.thFontSize() + "px",
423
- "font-weight": this.thFontWeight(),
424
- "text-align": this.percentageAlignment(),
425
- "padding": "0px"
426
- }
427
- ]);
428
- this.tbodyColumnStyles_default([
429
- {
430
- "color": this.topLabelColor(),
431
- "font-size": this.fontSize() + "px",
432
- "font-weight": "normal",
433
- "text-align": this.labelAlignment(),
434
- "width": "auto",
435
- "padding": "0px"
436
- },
437
- {
438
- "color": this.topPercentageColor(),
439
- "font-size": this.fontSize() + "px",
440
- "font-weight": "normal",
441
- "text-align": this.percentageAlignment(),
442
- "width": "1%",
443
- "padding": "0px"
444
- }
445
- ]);
446
- this.lastRowStyles_default([
447
- {
448
- "color": this.otherLabelColor(),
449
- "font-size": this.fontSize() + "px",
450
- "font-weight": this.otherLabelBold() ? "bold" : "normal",
451
- "text-align": this.labelAlignment(),
452
- "width": "auto",
453
- "padding": "0px"
454
- },
455
- {
456
- "color": this.otherLabelColor(),
457
- "font-size": this.fontSize() + "px",
458
- "font-weight": this.otherPercentageBold() ? "bold" : "normal",
459
- "text-align": this.percentageAlignment(),
460
- "width": "1%",
461
- "padding": "0px"
462
- }
463
- ]);
464
- super.update(domNode, element);
465
- const rowCount = this.useCalculatedRowCount() ? this.calculateRowCount() : this.rowCount();
466
- if (rowCount < this.data().length) {
467
- const lastRow = element.select("tbody > tr:last-child");
468
- const context = this;
469
- lastRow.on("mouseout.tooltip", (d) => {
470
- context._tooltip._triggerElement = lastRow;
471
- context._tooltip.visible(false).render();
472
- }).on("mouseenter.tooltip", (d) => {
473
- context._tooltip._triggerElement = lastRow;
474
- context._tooltip.direction("n").data(context.data()).visible(true).render();
475
- });
476
- }
477
- }
478
- };
479
- __name(_BreakdownTable, "BreakdownTable");
480
- let BreakdownTable = _BreakdownTable;
481
- BreakdownTable.prototype._class += " html_BreakdownTable";
482
- BreakdownTable.prototype.publish("useCalculatedRowCount", true, "boolean", "If true, rowCount will be calculated and its default will be overwritten");
483
- BreakdownTable.prototype.publish("rowCount", 5, "number", "Number of total rows to display (including the 'other' row)", void 0, { disable: /* @__PURE__ */ __name((w) => w.useCalculatedRowCount(), "disable") });
484
- BreakdownTable.prototype.publish("fontSize", 14, "number", "Font size (pixels)");
485
- BreakdownTable.prototype.publish("labelAlignment", "left", "set", "Alignment of the label column text", ["left", "center", "right"]);
486
- BreakdownTable.prototype.publish("percentageAlignment", "center", "set", "Alignment of the percentage column text", ["left", "center", "right"]);
487
- BreakdownTable.prototype.publish("topLabelColor", "#333", "html-color", "Color of displayed 'top' labels");
488
- BreakdownTable.prototype.publish("topPercentageColor", "#1A99D5", "html-color", "Color of displayed 'top' percentages");
489
- BreakdownTable.prototype.publish("topPercentageBold", true, "html-color", "If true, the 'top' percentages will be bold");
490
- BreakdownTable.prototype.publish("otherLabel", "Other", "string", "Label text for the 'other' row");
491
- BreakdownTable.prototype.publish("otherLabelColor", "#AAA", "html-color", "Color of the 'other' label");
492
- BreakdownTable.prototype.publish("otherLabelBold", false, "html-color", "If true, the 'other' label will be bold");
493
- BreakdownTable.prototype.publish("otherPercentageColor", "#AAA", "html-color", "Color of the 'other' percentage");
494
- BreakdownTable.prototype.publish("otherPercentageBold", false, "html-color", "If true, the 'other' percentage will be bold");
495
- BreakdownTable.prototype.publish("thFontWeight", "bold", "string", "Font weight for th elements");
496
- BreakdownTable.prototype.publish("thFontSize", 26, "number", "Font size for th elements");
497
- BreakdownTable.prototype.publish("thFirstColor", "#333", "html-color", "Text color of the first th element");
498
- BreakdownTable.prototype.publish("thLastColor", "#333", "html-color", "Text color of the last th element");
499
- const _JSXWidget = class _JSXWidget extends HTMLWidget {
500
- rootNode;
501
- jsxRender(jsx, domNode) {
502
- this.rootNode = React.render(jsx, domNode, this.rootNode);
503
- }
504
- };
505
- __name(_JSXWidget, "JSXWidget");
506
- __publicField(_JSXWidget, "Component", React.Component);
507
- __publicField(_JSXWidget, "createElement", React.createElement);
508
- let JSXWidget = _JSXWidget;
509
- JSXWidget.prototype._class += " html_JSXWidget";
510
- const _VNode = class _VNode {
511
- _attrs;
512
- _children;
513
- constructor(attrs, children) {
514
- this._attrs = attrs;
515
- this._children = children;
516
- }
517
- type() {
518
- return "div";
519
- }
520
- attrs() {
521
- return this._attrs;
522
- }
523
- attr(key) {
524
- return this._attrs[key];
525
- }
526
- children() {
527
- return this._children;
528
- }
529
- update(targetElement) {
530
- for (const key in this._attrs) {
531
- targetElement.attr(key, this._attrs[key]);
532
- }
533
- }
534
- render(targetElement) {
535
- const thisElement = targetElement.selectAll(`${targetElement.node().tagName} > *`).data([this]);
536
- thisElement.exit().remove();
537
- return thisElement.enter().append(this.type()).attr("reactd3", 0).merge(thisElement).each(function(d) {
538
- const element = select(this);
539
- d.update(element);
540
- d.renderChildren(element);
541
- });
542
- }
543
- renderChildren(targetElement) {
544
- const thisElement = targetElement.selectAll(`${targetElement.node().tagName} > *`).data(this._children);
545
- thisElement.exit().remove();
546
- return thisElement.enter().append((d) => document.createElement(d.type())).attr("reactd3", (_d, i) => i).merge(thisElement).each(function(d) {
547
- const element = select(this);
548
- d.update(element);
549
- d.renderChildren(element);
550
- });
551
- }
552
- };
553
- __name(_VNode, "VNode");
554
- let VNode = _VNode;
555
- const _ConstVNode = class _ConstVNode extends VNode {
556
- _type;
557
- constructor(type, attrs, children) {
558
- super(attrs, children);
559
- this._type = type;
560
- }
561
- type() {
562
- return this._type;
563
- }
564
- };
565
- __name(_ConstVNode, "ConstVNode");
566
- let ConstVNode = _ConstVNode;
567
- const _TextVNode = class _TextVNode extends VNode {
568
- _text;
569
- constructor(text) {
570
- super({}, []);
571
- this._text = text;
572
- }
573
- type() {
574
- return "span";
575
- }
576
- update(targetElement) {
577
- super.update(targetElement);
578
- targetElement.text(this._text);
579
- }
580
- };
581
- __name(_TextVNode, "TextVNode");
582
- let TextVNode = _TextVNode;
583
- function isReactFn(_) {
584
- return typeof _ === "function";
585
- }
586
- __name(isReactFn, "isReactFn");
587
- function isIVNode(_) {
588
- return _.prototype && _.prototype instanceof VNode;
589
- }
590
- __name(isIVNode, "isIVNode");
591
- const _ReactD3 = class _ReactD3 {
592
- // static createElementXXX(type: string | ReactFn | IVNode, attrs: { [key: string]: string }, ...children: Array<string | VNode>): VNode {
593
- static createElement(type, attrs, ...children) {
594
- if (isIVNode(type)) {
595
- return new type(attrs);
596
- } else if (isReactFn(type)) {
597
- return type(attrs);
598
- }
599
- return new ConstVNode(type, attrs, children.map((child) => {
600
- if (typeof child === "string") {
601
- return new TextVNode(child);
602
- }
603
- return child;
604
- }));
605
- }
606
- static render(vdom, targetElement) {
607
- vdom.render(targetElement);
608
- }
609
- };
610
- __name(_ReactD3, "ReactD3");
611
- let ReactD3 = _ReactD3;
612
- var l;
613
- l = { __e: /* @__PURE__ */ __name(function(n, l2, u2, t) {
614
- for (var i, r, o; l2 = l2.__; ) if ((i = l2.__c) && !i.__) try {
615
- if ((r = i.constructor) && null != r.getDerivedStateFromError && (i.setState(r.getDerivedStateFromError(n)), o = i.__d), null != i.componentDidCatch && (i.componentDidCatch(n, t || {}), o = i.__d), o) return i.__E = i;
616
- } catch (l3) {
617
- n = l3;
618
- }
619
- throw n;
620
- }, "__e") }, "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
621
- var f = 0;
622
- function u(e, t, n, o, i, u2) {
623
- t || (t = {});
624
- var a, c, p = t;
625
- if ("ref" in p) for (c in p = {}, t) "ref" == c ? a = t[c] : p[c] = t[c];
626
- var l$1 = { type: e, props: p, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --f, __i: -1, __u: 0, __source: i, __self: u2 };
627
- return l.vnode && l.vnode(l$1), l$1;
628
- }
629
- __name(u, "u");
630
- const _VizComponent = class _VizComponent extends JSXWidget.Component {
631
- widget;
632
- refreshProps() {
633
- for (const key in this.props) {
634
- if (this.widget[key] && typeof this.widget[key] === "function") {
635
- this.widget[key](this.props[key]);
636
- }
637
- }
638
- }
639
- componentDidMount() {
640
- this.widget = new this.props.type().target(this.base);
641
- this.refreshProps();
642
- this.widget.render();
643
- }
644
- componentWillUnmount() {
645
- this.widget.target(null).render();
646
- }
647
- render() {
648
- return /* @__PURE__ */ u("div", { style: this.props.style });
649
- }
650
- componentDidUpdate() {
651
- this.refreshProps();
652
- this.widget.render();
653
- }
654
- };
655
- __name(_VizComponent, "VizComponent");
656
- let VizComponent = _VizComponent;
657
- const _VizInstance = class _VizInstance extends JSXWidget.Component {
658
- widget;
659
- refreshProps() {
660
- for (const key in this.props) {
661
- if (this.widget[key] && typeof this.widget[key] === "function") {
662
- this.widget[key](this.props[key]);
663
- }
664
- }
665
- }
666
- componentDidMount() {
667
- this.widget = this.props.instance.target(this.base);
668
- this.refreshProps();
669
- this.widget.render();
670
- }
671
- componentWillUnmount() {
672
- this.widget.target(null).render();
673
- }
674
- render() {
675
- return /* @__PURE__ */ u("div", { style: this.props.style });
676
- }
677
- componentDidUpdate() {
678
- this.refreshProps();
679
- this.widget.render();
680
- }
681
- };
682
- __name(_VizInstance, "VizInstance");
683
- let VizInstance = _VizInstance;
684
- const _StatsTable = class _StatsTable extends StyledTable {
685
- transformData() {
686
- const totalRow = [["Total", 0, 0]];
687
- const data = this.data();
688
- data.forEach((row) => {
689
- totalRow[0][1] += row[1];
690
- totalRow[0][2] += row[2];
691
- });
692
- return data.concat(totalRow).map((row) => {
693
- return [
694
- row[0],
695
- this.secondColumnFormat_exists() ? format(this.secondColumnFormat())(row[1]) : row[1],
696
- this.thirdColumnFormat_exists() ? format(this.thirdColumnFormat())(row[2]) : row[2]
697
- ];
698
- });
699
- }
700
- update(domNode, element) {
701
- this.tbodyColumnStyles_default([
702
- {
703
- "font-weight": "bold",
704
- "width": this.firstColumnWidth(),
705
- "text-align": "left"
706
- },
707
- {
708
- "width": this.secondColumnWidth(),
709
- "text-align": "right"
710
- },
711
- {
712
- "width": this.thirdColumnWidth(),
713
- "text-align": "right"
714
- }
715
- ]);
716
- this.evenRowStyles_default([
717
- {
718
- "font-weight": "bold",
719
- "width": this.firstColumnWidth(),
720
- "text-align": "left",
721
- "font-color": this.evenRowFontColor(),
722
- "background-color": this.evenRowBackgroundColor()
723
- },
724
- {
725
- "width": this.secondColumnWidth(),
726
- "text-align": "right",
727
- "font-color": this.evenRowFontColor(),
728
- "background-color": this.evenRowBackgroundColor()
729
- },
730
- {
731
- "width": this.thirdColumnWidth(),
732
- "text-align": "right",
733
- "font-color": this.evenRowFontColor(),
734
- "background-color": this.evenRowBackgroundColor()
735
- }
736
- ]);
737
- this.lastRowStyles_default({
738
- "font-weight": "bold"
739
- });
740
- super.update(domNode, element);
741
- }
742
- };
743
- __name(_StatsTable, "StatsTable");
744
- let StatsTable = _StatsTable;
745
- StatsTable.prototype._class += " html_StatsTable";
746
- StatsTable.prototype.publish("labelColor", "#333", "html-color", "Color of the text in the first column");
747
- StatsTable.prototype.publish("primaryValueColor", "#333", "html-color", "Color of the text in the second column");
748
- StatsTable.prototype.publish("secondaryValueColor", "#333", "html-color", "Color of the text in the third column");
749
- StatsTable.prototype.publish("evenRowBackgroundColor", "#333", "html-color", "Background color of the even rows");
750
- StatsTable.prototype.publish("evenRowFontColor", "#333", "html-color", "Font color of the even rows");
751
- StatsTable.prototype.publish("firstColumnWidth", "auto", "string", "CSS style applied as the 'width' for the first column (ex: 40px)");
752
- StatsTable.prototype.publish("secondColumnWidth", "1%", "string", "CSS style applied as the 'width' for the second column (ex: 40px)");
753
- StatsTable.prototype.publish("thirdColumnWidth", "1%", "string", "CSS style applied as the 'width' for the third column (ex: 40px)");
754
- StatsTable.prototype.publish("secondColumnFormat", "$,.0f", "string", "d3-format specifier applied to the second column's values", void 0, { optional: true });
755
- StatsTable.prototype.publish("thirdColumnFormat", null, "string", "d3-format specifier applied to the third column's values", void 0, { optional: true });
756
- const _Item = class _Item extends HTMLWidget {
757
- _owner;
758
- constructor(owner) {
759
- super();
760
- this._owner = owner;
761
- this._tag = "a";
762
- }
763
- };
764
- __name(_Item, "Item");
765
- let Item = _Item;
766
- Item.prototype._class += " html_Item";
767
- const _Button = class _Button extends Item {
768
- _icon;
769
- constructor(owner, icon) {
770
- super(owner);
771
- this._icon = icon;
772
- }
773
- icon() {
774
- return this._icon;
775
- }
776
- enter(domNode, element) {
777
- super.enter(domNode, element);
778
- element.attr("href", "#").on("click", (d, idx, groups) => this._owner.titleBarClick(this, d, idx, groups)).append("i").attr("class", `fa ${this._icon} fa-lg fa-fw`);
779
- }
780
- };
781
- __name(_Button, "Button");
782
- let Button = _Button;
783
- Button.prototype._class += " html_Button";
784
- const _ToggleButton = class _ToggleButton extends Button {
785
- enter(domNode, element) {
786
- element.on("click.sel", (d, idx, groups) => {
787
- this.selected(!this.selected());
788
- this.render();
789
- });
790
- super.enter(domNode, element);
791
- }
792
- update(domNode, element) {
793
- super.update(domNode, element);
794
- this._element.classed("selected", this.selected());
795
- }
796
- };
797
- __name(_ToggleButton, "ToggleButton");
798
- let ToggleButton = _ToggleButton;
799
- ToggleButton.prototype._class += " html_ToggleButton";
800
- ToggleButton.prototype.publish("selected", false, "boolean");
801
- const _Spacer = class _Spacer extends Item {
802
- enter(domNode, element) {
803
- super.enter(domNode, element);
804
- element.attr("class", "spacer").attr("href", "#").append("i");
805
- }
806
- };
807
- __name(_Spacer, "Spacer");
808
- let Spacer = _Spacer;
809
- Spacer.prototype._class += " html_Spacer";
810
- const _TitleBar = class _TitleBar extends JSXWidget {
811
- _divMain;
812
- _divIconBar;
813
- _divTitle;
814
- constructor() {
815
- super();
816
- }
817
- enter(domNode, element) {
818
- super.enter(domNode, element);
819
- this._divMain = element.append("div").attr("class", "main");
820
- this._divIconBar = this._divMain.append("div").attr("class", "icon-bar");
821
- this._divTitle = this._divMain.append("div").attr("class", "title");
822
- }
823
- update(domNode, element) {
824
- super.update(domNode, element);
825
- this._divTitle.text(this.title());
826
- const icons = this._divIconBar.selectAll(".icon-bar-item").data(this.buttons());
827
- icons.enter().append("div").attr("class", "icon-bar-item").each(function(d) {
828
- d.target(this);
829
- }).merge(icons).each(function(d) {
830
- d.render();
831
- });
832
- icons.exit().each(function(d) {
833
- d.target(null);
834
- }).remove();
835
- icons.order();
836
- }
837
- };
838
- __name(_TitleBar, "TitleBar");
839
- let TitleBar = _TitleBar;
840
- TitleBar.prototype._class += " html_TitleBar";
841
- TitleBar.prototype.publish("title", "", "string");
842
- TitleBar.prototype.publish("buttons", [], "widgetArray");
843
- export {
844
- BUILD_VERSION,
845
- BreakdownTable,
846
- Button,
847
- HTMLTooltip,
848
- Item,
849
- JSXWidget,
850
- PKG_NAME,
851
- PKG_VERSION,
852
- ReactD3,
853
- SimpleTable,
854
- Spacer,
855
- StatsTable,
856
- StyledTable,
857
- TitleBar,
858
- ToggleButton,
859
- VNode,
860
- VizComponent,
861
- VizInstance
862
- };
1
+ var t=Object.defineProperty,e=(e,o)=>t(e,"name",{value:o,configurable:!0}),o=(e,o,i)=>((e,o,i)=>o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[o]=i)(e,"symbol"!=typeof o?o+"":o,i);import{HTMLWidget as i,select as r,format as s}from"@hpcc-js/common";import{scopedLogger as l}from"@hpcc-js/util";import{React as n}from"@hpcc-js/react";const h="@hpcc-js/html",a="3.3.2",p="3.16.0",d=class _HTMLTooltip extends i{_triggerElement;_contentNode;_prevContentNode;_tooltipElement;_arrowElement;_tooltipHTMLCallback=/* @__PURE__ */e(t=>"<b>_tooltipHTMLCallback is undefined</b>","_tooltipHTMLCallback");_logger=l("html/HTMLTooltip");constructor(){super(),this.visible(!1)}tooltipHTML(t){return this._tooltipHTMLCallback=t,this}tooltipContent(t){return arguments.length?(this._contentNode=t,this):this._contentNode}triggerElement(t){return this._triggerElement=t,this}enter(t,e){super.enter(t,e);const o=r("body");this._tooltipElement=o.append("div").attr("class","tooltip-div").style("z-index","2147483638").style("position","fixed"),this._arrowElement=o.append("div").attr("class","arrow-div").style("z-index","2147483638").style("position","fixed")}update(t,e){if(super.update(t,e),this._contentNode!==this._prevContentNode){const t=this._tooltipElement.node();[...t.querySelectorAll("*")].map(t=>t.__data__).filter(t=>t).forEach(t=>{"function"==typeof t.target&&t.target(null),"function"==typeof t.exit&&t.exit()}),t.innerHTML="",t.appendChild(this._contentNode),this._prevContentNode=this._contentNode}if(this._contentNode?this.onShowContent(this._contentNode):this._tooltipElement.html(()=>this._tooltipHTMLCallback(this.data())),this.fitContent()){this._tooltipElement.style("width","auto").style("height","auto").style("padding","0px").style("box-sizing","content-box");const t=this._tooltipElement.node().getBoundingClientRect();this.tooltipWidth_default(t.width),this.tooltipHeight_default(t.height)}this._closing=!1,this._tooltipElement.style("background-color",this.tooltipColor()).style("color",this.fontColor()).style("width",this.tooltipWidth()+"px").style("height",this.tooltipHeight()+"px").style("opacity",1).style("padding",this.padding()+"px").style("pointer-events",this.enablePointerEvents()?"all":"none").style("box-sizing","content-box"),this._arrowElement.style("opacity",1).style("pointer-events","none"),this.updateTooltipPosition()}onShowContent(t){}updateTooltipPosition(){const t=this.calcReferenceBBox(),e=this.calcTooltipDirection(t),o=t[e];return this._tooltipElement.style("top",o.y+"px").style("left",o.x+"px"),this.setArrowPosition(o,e),o}calcTooltipDirection(t){const e=Object.keys(t),o=this.direction();e.sort((t,e)=>t===o?-1:1);const i={top:0,left:0,width:window.innerWidth,height:window.innerHeight};for(let r=0;r<e.length;r++){const o={top:t[e[r]].y,left:t[e[r]].x,width:this.tooltipWidth(),height:this.tooltipHeight()};if(this.rectFits(o,i))return e[r]}return this._logger.warning(`Tooltip doesn't fit in the window for any of the directions. Defaulting to '${o}'`),this._logger.debug(i),this._logger.debug({top:t[o].y,left:t[o].x,width:this.tooltipWidth(),height:this.tooltipHeight()}),o}rectFits(t,e){return t.top>=e.top&&t.left>=e.left&&t.width+t.left<=e.width+e.left&&t.height+t.top<=e.height+e.top}setArrowPosition(t,e){let o,i,r="border-top-color";switch(this._arrowElement.style("border",`${this.arrowHeight()}px solid ${this.tooltipColor()}`).style("border-top-color","transparent").style("border-right-color","transparent").style("border-bottom-color","transparent").style("border-left-color","transparent"),e){case"n":o=t.y+this.tooltipHeight()+2*this.padding(),i=t.x+this.tooltipWidth()/2-this.arrowWidth()/2+this.padding(),r="border-top-color",this._arrowElement.style("border-top-width",`${this.arrowHeight()}px`).style("border-bottom-width","0px").style("border-left-width",this.arrowWidth()/2+"px").style("border-right-width",this.arrowWidth()/2+"px");break;case"s":o=t.y-this.arrowHeight(),i=t.x+this.padding()+this.tooltipWidth()/2-this.arrowWidth()/2,r="border-bottom-color",this._arrowElement.style("border-top-width","0px").style("border-bottom-width",`${this.arrowHeight()}px`).style("border-left-width",this.arrowWidth()/2+"px").style("border-right-width",this.arrowWidth()/2+"px");break;case"e":o=t.y+this.tooltipHeight()/2+this.padding()-this.arrowWidth()/2,i=t.x-this.arrowHeight(),r="border-right-color",this._arrowElement.style("border-top-width",this.arrowWidth()/2+"px").style("border-bottom-width",this.arrowWidth()/2+"px").style("border-left-width","0px").style("border-right-width",`${this.arrowHeight()}px`);break;case"w":o=t.y+this.tooltipHeight()/2-this.arrowWidth()/2+this.padding(),i=t.x+this.tooltipWidth()+2*this.padding(),r="border-left-color",this._arrowElement.style("border-top-width",this.arrowWidth()/2+"px").style("border-bottom-width",this.arrowWidth()/2+"px").style("border-left-width",`${this.arrowHeight()}px`).style("border-right-width","0px")}return void 0!==o&&void 0!==i?this._arrowElement.style("top",o+"px").style("left",i+"px").style(r,this.tooltipColor()).style("opacity",1):this._arrowElement.style("opacity",0),t}getReferenceNode(){return this._triggerElement?this._triggerElement.node():this.element().node().parentNode.parentNode}_cursorLoc;calcReferenceBBox(){const t=this.getReferenceNode();let{top:e,left:o,width:i,height:r}=t.getBoundingClientRect();const s=this.tooltipWidth(),l=this.tooltipHeight(),n=s/2,h=l/2,a=this.arrowHeight(),p=this.padding(),d=2*p;this.followCursor()&&this._cursorLoc&&(o=this._cursorLoc[0],e=this._cursorLoc[1],i=1,r=1);return{n:{x:o+i/2-n-p,y:e-l-a-d},e:{x:o+i+a,y:e+r/2-h-p},s:{x:o+i/2-n-p,y:e+r+a},w:{x:o-s-a-d,y:e+r/2-h-p},nw:{x:o-s-d,y:e-l-d},ne:{x:o+i,y:e-l-d},se:{x:o+i,y:e+r},sw:{x:o-s-d,y:e+r}}}_closing=!1;mouseout(){this._closing=!0,this._tooltipElement.on("mouseover",()=>{this._closing=!1}),this._tooltipElement.on("mouseout",()=>{this.mouseout()}),setTimeout(()=>{this._closing&&this.visible(!1)},this.closeDelay())}visible(t){return arguments.length?(this._arrowElement&&(this._arrowElement.style("visibility",t?"visible":"hidden"),this._tooltipElement.style("visibility",t?"visible":"hidden")),super.visible(t),this):super.visible()}exit(t,e){this._arrowElement&&(this._arrowElement.remove(),this._tooltipElement.remove()),super.exit(t,e)}};e(d,"HTMLTooltip");let c=d;c.prototype._class+=" html_HTMLTooltip",c.prototype.publish("fitContent",!1,"boolean","If true, tooltip will grow to fit its html content"),c.prototype.publish("followCursor",!1,"boolean","If true, tooltip will display relative to cursor location"),c.prototype.publish("closeDelay",400,"number","Number of milliseconds to wait before closing tooltip (cancelled on tooltip mouseover event)"),c.prototype.publish("direction","n","set","Direction in which to display the tooltip",["n","s","e","w","ne","nw","se","sw"]),c.prototype.publish("padding",8,"number","Padding (pixels)"),c.prototype.publish("arrowWidth",16,"number","Width (or height depending on direction) of the tooltip arrow (pixels)"),c.prototype.publish("arrowHeight",8,"number","Height (or width depending on direction) of the tooltip arrow (pixels)"),c.prototype.publish("fontColor","#FFF","html-color","The default font color for text in the tooltip"),c.prototype.publish("tooltipColor","#000000EE","html-color","Background color of the tooltip"),c.prototype.publish("tooltipWidth",200,"number","Width of the tooltip (not including arrow) (pixels)"),c.prototype.publish("tooltipHeight",200,"number","Height of the tooltip (not including arrow) (pixels)"),c.prototype.publish("enablePointerEvents",!1,"boolean","If true, the 'pointer-events: all' style will be used");const u=class _SimpleTable extends i{_table;_tbody;_thead;_theadRow;constructor(){super()}transformData(){return this.data()}enter(t,e){super.enter(t,e),this._table=e.append("table"),this._thead=this._table.append("thead"),this._theadRow=this._thead.append("tr"),this._tbody=this._table.append("tbody")}update(t,e){super.update(t,e),this._table.style("width",this.autoWidth()?"auto":"100%");const o=this._theadRow.selectAll("th").data(this.columns());o.enter().append("th").attr("class",(t,e)=>`th-${e}`).merge(o).text(t=>t.toString()),o.exit().remove();const i=this._tbody.selectAll("tr").data(this.transformData());i.enter().append("tr").merge(i).each(function(t){const e=r(this).selectAll("td").data(t);e.enter().append("td").attr("class",(t,e)=>`col-${e}`).merge(e).text(t=>t.toString()),e.exit().remove()}),i.exit().remove()}};e(u,"SimpleTable");let g=u;g.prototype._class+=" html_SimpleTable",g.prototype.publish("autoWidth",!1,"boolean","If true, table width will be set to 'auto'. If false, the width is set to '100%'");const y=class _StyledTable extends g{constructor(){super()}applyStyleObject(t,e){Object.keys(e).forEach(o=>{t.style(o,e[o])})}update(t,e){super.update(t,e),e.selectAll("tr,th,td").attr("style","").style("font-family",this.fontFamily()).style("color",this.fontColor()),this.theadColumnStyles().forEach((t,o)=>{this.applyStyleObject(e.select(`.th-${o}`),t)}),this.tbodyColumnStyles().forEach((t,o)=>{this.applyStyleObject(e.selectAll(`.col-${o}`),t)});const o=Object.keys(this.evenRowStyles()).length>0,i=Object.keys(this.lastRowStyles()).length>0,r=e.selectAll("tbody > tr");if(o){const t=r.select(function(t,e){return e%2?this:null});this.applyStyleObject(t,this.evenRowStyles())}if(i){const t=r.select(function(t,e,o){return e===o.length-1?this:null});this.applyStyleObject(t,this.lastRowStyles())}}};e(y,"StyledTable");let b=y;b.prototype._class+=" html_StyledTable",b.prototype.publish("fontFamily","Verdana","string","Base font-family used within the table"),b.prototype.publish("fontColor","#333","string","Base font color used within the table"),b.prototype.publish("theadColumnStyles",[],"array",'Array of objects containing styles for the thead columns (ex: [{"color":"red"},{"color":"blue"}])'),b.prototype.publish("tbodyColumnStyles",[],"array",'Array of objects containing styles for the tbody columns (ex: [{"color":"red"},{"color":"blue"}])'),b.prototype.publish("lastRowStyles",{},"object",'Object containing styles for the last row (ex: {"color":"red"})'),b.prototype.publish("evenRowStyles",{},"object",'Object containing styles for even rows (ex: {"background-color":"#AAA"})');const m=class _BreakdownTable extends b{_tooltip;constructor(){super()}transformData(){const t=this.useCalculatedRowCount()?this.calculateRowCount():this.rowCount();return this.breakdownData(t)}breakdownData(t){const e=this.data().length,o=this.data().reduce((t,e)=>t+e[1],0),i=[];let r=0;this.data().sort((t,e)=>t[1]>e[1]?-1:1);const s=e-t>0;if(this.data().filter((e,o)=>!s||o<t-1).forEach(t=>{const e=Math.round(t[1]/o*100);r+=e,i.push([t[0],e+"%"])}),s){const o=`${this.otherLabel()} (${e-t+1})`,s="~"+(100-r)+"%";i.push([o,s])}return i}calculateRowCount(){const t=this.columns().length>0?this.thFontSize()+5:0,e=this.fontSize()+5,o=this.height()-t;return Math.floor(o/e)}enter(t,e){super.enter(t,e),this._tooltip=(new c).target(t),this._tooltip.tooltipHTML(t=>{const e=this.useCalculatedRowCount()?this.calculateRowCount():this.rowCount(),o=Math.max(...t.map(t=>this.textSize(t[0],this.fontFamily(),this.fontSize()).height))??this.fontSize(),i=Math.max(...t.map(t=>this.textSize(t[0],this.fontFamily(),this.fontSize()).width)),r=2*(i+30)+2*this._tooltip.padding(),s=o*Math.ceil((t.length-e)/2)+2*this._tooltip.padding();this._tooltip.tooltipWidth(r),this._tooltip.tooltipHeight(s);const l=this.breakdownData(this.data().length).slice(e-1);return`<div style="\n width: 100%;\n height: 100%;\n font-size: ${this.fontSize()}px;\n ">${l.map(t=>`<div style="\n float:left;\n width:${Math.floor(49.5)}%;\n ">${t[0]}: ${t[1]}</div>`).join("")}</div>`})}update(t,e){this.theadColumnStyles_default([{color:this.thFirstColor(),"font-size":this.thFontSize()+"px","font-weight":this.thFontWeight(),"text-align":this.labelAlignment(),width:"auto",padding:"0px"},{width:"1%","font-size":this.thFontSize()+"px","font-weight":this.thFontWeight(),"text-align":this.percentageAlignment(),padding:"0px"}]),this.tbodyColumnStyles_default([{color:this.topLabelColor(),"font-size":this.fontSize()+"px","font-weight":"normal","text-align":this.labelAlignment(),width:"auto",padding:"0px"},{color:this.topPercentageColor(),"font-size":this.fontSize()+"px","font-weight":"normal","text-align":this.percentageAlignment(),width:"1%",padding:"0px"}]),this.lastRowStyles_default([{color:this.otherLabelColor(),"font-size":this.fontSize()+"px","font-weight":this.otherLabelBold()?"bold":"normal","text-align":this.labelAlignment(),width:"auto",padding:"0px"},{color:this.otherLabelColor(),"font-size":this.fontSize()+"px","font-weight":this.otherPercentageBold()?"bold":"normal","text-align":this.percentageAlignment(),width:"1%",padding:"0px"}]),super.update(t,e);if((this.useCalculatedRowCount()?this.calculateRowCount():this.rowCount())<this.data().length){const t=e.select("tbody > tr:last-child"),o=this;t.on("mouseout.tooltip",e=>{o._tooltip._triggerElement=t,o._tooltip.visible(!1).render()}).on("mouseenter.tooltip",e=>{o._tooltip._triggerElement=t,o._tooltip.direction("n").data(o.data()).visible(!0).render()})}}};e(m,"BreakdownTable");let f=m;f.prototype._class+=" html_BreakdownTable",f.prototype.publish("useCalculatedRowCount",!0,"boolean","If true, rowCount will be calculated and its default will be overwritten"),f.prototype.publish("rowCount",5,"number","Number of total rows to display (including the 'other' row)",void 0,{disable:/* @__PURE__ */e(t=>t.useCalculatedRowCount(),"disable")}),f.prototype.publish("fontSize",14,"number","Font size (pixels)"),f.prototype.publish("labelAlignment","left","set","Alignment of the label column text",["left","center","right"]),f.prototype.publish("percentageAlignment","center","set","Alignment of the percentage column text",["left","center","right"]),f.prototype.publish("topLabelColor","#333","html-color","Color of displayed 'top' labels"),f.prototype.publish("topPercentageColor","#1A99D5","html-color","Color of displayed 'top' percentages"),f.prototype.publish("topPercentageBold",!0,"html-color","If true, the 'top' percentages will be bold"),f.prototype.publish("otherLabel","Other","string","Label text for the 'other' row"),f.prototype.publish("otherLabelColor","#AAA","html-color","Color of the 'other' label"),f.prototype.publish("otherLabelBold",!1,"html-color","If true, the 'other' label will be bold"),f.prototype.publish("otherPercentageColor","#AAA","html-color","Color of the 'other' percentage"),f.prototype.publish("otherPercentageBold",!1,"html-color","If true, the 'other' percentage will be bold"),f.prototype.publish("thFontWeight","bold","string","Font weight for th elements"),f.prototype.publish("thFontSize",26,"number","Font size for th elements"),f.prototype.publish("thFirstColor","#333","html-color","Text color of the first th element"),f.prototype.publish("thLastColor","#333","html-color","Text color of the last th element");const _=class _JSXWidget extends i{rootNode;jsxRender(t,e){this.rootNode=n.render(t,e,this.rootNode)}};e(_,"JSXWidget"),o(_,"Component",n.Component),o(_,"createElement",n.createElement);let w=_;w.prototype._class+=" html_JSXWidget";const x=class _VNode{_attrs;_children;constructor(t,e){this._attrs=t,this._children=e}type(){return"div"}attrs(){return this._attrs}attr(t){return this._attrs[t]}children(){return this._children}update(t){for(const e in this._attrs)t.attr(e,this._attrs[e])}render(t){const e=t.selectAll(`${t.node().tagName} > *`).data([this]);return e.exit().remove(),e.enter().append(this.type()).attr("reactd3",0).merge(e).each(function(t){const e=r(this);t.update(e),t.renderChildren(e)})}renderChildren(t){const e=t.selectAll(`${t.node().tagName} > *`).data(this._children);return e.exit().remove(),e.enter().append(t=>document.createElement(t.type())).attr("reactd3",(t,e)=>e).merge(e).each(function(t){const e=r(this);t.update(e),t.renderChildren(e)})}};e(x,"VNode");let C=x;const v=class _ConstVNode extends C{_type;constructor(t,e,o){super(e,o),this._type=t}type(){return this._type}};e(v,"ConstVNode");let S=v;const E=class _TextVNode extends C{_text;constructor(t){super({},[]),this._text=t}type(){return"span"}update(t){super.update(t),t.text(this._text)}};e(E,"TextVNode");let T=E;function W(t){return"function"==typeof t}function R(t){return t.prototype&&t.prototype instanceof C}e(W,"isReactFn"),e(R,"isIVNode");const A=class _ReactD3{static createElement(t,e,...o){return R(t)?new t(e):W(t)?t(e):new S(t,e,o.map(t=>"string"==typeof t?new T(t):t))}static render(t,e){t.render(e)}};e(A,"ReactD3");let B=A;var F;F={__e:/* @__PURE__ */e(function(t,e,o,i){for(var r,s,l;e=e.__;)if((r=e.__c)&&!r.__)try{if((s=r.constructor)&&null!=s.getDerivedStateFromError&&(r.setState(s.getDerivedStateFromError(t)),l=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(t,i||{}),l=r.__d),l)return r.__E=r}catch(n){t=n}throw t},"__e")},"function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout;var k=0;function H(t,e,o,i,r,s){e||(e={});var l,n,h=e;if("ref"in h)for(n in h={},e)"ref"==n?l=e[n]:h[n]=e[n];var a={type:t,props:h,key:o,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--k,__i:-1,__u:0,__source:r,__self:s};return F.vnode&&F.vnode(a),a}e(H,"u");const z=class _VizComponent extends w.Component{widget;refreshProps(){for(const t in this.props)this.widget[t]&&"function"==typeof this.widget[t]&&this.widget[t](this.props[t])}componentDidMount(){this.widget=(new this.props.type).target(this.base),this.refreshProps(),this.widget.render()}componentWillUnmount(){this.widget.target(null).render()}render(){/* @__PURE__ */
2
+ return H("div",{style:this.props.style})}componentDidUpdate(){this.refreshProps(),this.widget.render()}};e(z,"VizComponent");let N=z;const L=class _VizInstance extends w.Component{widget;refreshProps(){for(const t in this.props)this.widget[t]&&"function"==typeof this.widget[t]&&this.widget[t](this.props[t])}componentDidMount(){this.widget=this.props.instance.target(this.base),this.refreshProps(),this.widget.render()}componentWillUnmount(){this.widget.target(null).render()}render(){/* @__PURE__ */
3
+ return H("div",{style:this.props.style})}componentDidUpdate(){this.refreshProps(),this.widget.render()}};e(L,"VizInstance");let D=L;const M=class _StatsTable extends b{transformData(){const t=[["Total",0,0]],e=this.data();return e.forEach(e=>{t[0][1]+=e[1],t[0][2]+=e[2]}),e.concat(t).map(t=>[t[0],this.secondColumnFormat_exists()?s(this.secondColumnFormat())(t[1]):t[1],this.thirdColumnFormat_exists()?s(this.thirdColumnFormat())(t[2]):t[2]])}update(t,e){this.tbodyColumnStyles_default([{"font-weight":"bold",width:this.firstColumnWidth(),"text-align":"left"},{width:this.secondColumnWidth(),"text-align":"right"},{width:this.thirdColumnWidth(),"text-align":"right"}]),this.evenRowStyles_default([{"font-weight":"bold",width:this.firstColumnWidth(),"text-align":"left","font-color":this.evenRowFontColor(),"background-color":this.evenRowBackgroundColor()},{width:this.secondColumnWidth(),"text-align":"right","font-color":this.evenRowFontColor(),"background-color":this.evenRowBackgroundColor()},{width:this.thirdColumnWidth(),"text-align":"right","font-color":this.evenRowFontColor(),"background-color":this.evenRowBackgroundColor()}]),this.lastRowStyles_default({"font-weight":"bold"}),super.update(t,e)}};e(M,"StatsTable");let P=M;P.prototype._class+=" html_StatsTable",P.prototype.publish("labelColor","#333","html-color","Color of the text in the first column"),P.prototype.publish("primaryValueColor","#333","html-color","Color of the text in the second column"),P.prototype.publish("secondaryValueColor","#333","html-color","Color of the text in the third column"),P.prototype.publish("evenRowBackgroundColor","#333","html-color","Background color of the even rows"),P.prototype.publish("evenRowFontColor","#333","html-color","Font color of the even rows"),P.prototype.publish("firstColumnWidth","auto","string","CSS style applied as the 'width' for the first column (ex: 40px)"),P.prototype.publish("secondColumnWidth","1%","string","CSS style applied as the 'width' for the second column (ex: 40px)"),P.prototype.publish("thirdColumnWidth","1%","string","CSS style applied as the 'width' for the third column (ex: 40px)"),P.prototype.publish("secondColumnFormat","$,.0f","string","d3-format specifier applied to the second column's values",void 0,{optional:!0}),P.prototype.publish("thirdColumnFormat",null,"string","d3-format specifier applied to the third column's values",void 0,{optional:!0});const j=class _Item extends i{_owner;constructor(t){super(),this._owner=t,this._tag="a"}};e(j,"Item");let $=j;$.prototype._class+=" html_Item";const I=class _Button extends ${_icon;constructor(t,e){super(t),this._icon=e}icon(){return this._icon}enter(t,e){super.enter(t,e),e.attr("href","#").on("click",(t,e,o)=>this._owner.titleBarClick(this,t,e,o)).append("i").attr("class",`fa ${this._icon} fa-lg fa-fw`)}};e(I,"Button");let V=I;V.prototype._class+=" html_Button";const O=class _ToggleButton extends V{enter(t,e){e.on("click.sel",(t,e,o)=>{this.selected(!this.selected()),this.render()}),super.enter(t,e)}update(t,e){super.update(t,e),this._element.classed("selected",this.selected())}};e(O,"ToggleButton");let U=O;U.prototype._class+=" html_ToggleButton",U.prototype.publish("selected",!1,"boolean");const J=class _Spacer extends ${enter(t,e){super.enter(t,e),e.attr("class","spacer").attr("href","#").append("i")}};e(J,"Spacer");let X=J;X.prototype._class+=" html_Spacer";const q=class _TitleBar extends w{_divMain;_divIconBar;_divTitle;constructor(){super()}enter(t,e){super.enter(t,e),this._divMain=e.append("div").attr("class","main"),this._divIconBar=this._divMain.append("div").attr("class","icon-bar"),this._divTitle=this._divMain.append("div").attr("class","title")}update(t,e){super.update(t,e),this._divTitle.text(this.title());const o=this._divIconBar.selectAll(".icon-bar-item").data(this.buttons());o.enter().append("div").attr("class","icon-bar-item").each(function(t){t.target(this)}).merge(o).each(function(t){t.render()}),o.exit().each(function(t){t.target(null)}).remove(),o.order()}};e(q,"TitleBar");let G=q;G.prototype._class+=" html_TitleBar",G.prototype.publish("title","","string"),G.prototype.publish("buttons",[],"widgetArray");export{p as BUILD_VERSION,f as BreakdownTable,V as Button,c as HTMLTooltip,$ as Item,w as JSXWidget,h as PKG_NAME,a as PKG_VERSION,B as ReactD3,g as SimpleTable,X as Spacer,P as StatsTable,b as StyledTable,G as TitleBar,U as ToggleButton,C as VNode,N as VizComponent,D as VizInstance};
863
4
  //# sourceMappingURL=index.js.map
864
5
  !function(){"use strict";try{if("undefined"!=typeof document){var t=document.createElement("style");t.appendChild(document.createTextNode("#wrap{width:100%}#left,#right{padding:5px}#left{background-color:red;text-align:left;display:block;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}#right{background-color:orange;float:right;text-align:right;white-space:nowrap}.html_TitleBar>.main{width:100%;display:block}.html_TitleBar .title{padding:4px;text-align:left;display:block;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;font-size:20px;font-weight:700}.html_TitleBar .icon-bar{padding:4px;float:right;text-align:right;white-space:nowrap;line-height:28px}.html_TitleBar .icon-bar-item{display:inline}.html_TitleBar .icon-bar-item>div{display:inline}.html_TitleBar .icon-bar a{text-align:center;padding-top:4px;padding-bottom:4px;transition:all .3s ease;color:#a9a9a9}.html_TitleBar .icon-bar a:hover{background-color:#f5f5f5}.html_TitleBar .icon-bar a.selected{background-color:#efe5e5}.html_TitleBar .icon-bar a.spacer{text-align:center;padding-top:2px;padding-left:8px;padding-bottom:0;color:none}.html_TitleBar .icon-bar a.spacer:hover{background-color:transparent}.html_TitleBar .icon-bar .active{background-color:#4caf50}")),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}}();