@hpcc-js/tree 3.2.12 → 3.2.15

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/src/Treemap.ts CHANGED
@@ -1,346 +1,346 @@
1
- import { ITree } from "@hpcc-js/api";
2
- import { HTMLWidget, Palette, PropertyExt, Utility } from "@hpcc-js/common";
3
- import { rgb as d3rgb } from "d3-color";
4
- import { hierarchy as d3Hierarchy, treemap as d3Treemap, treemapBinary as d3treemapBinary, treemapDice as d3treemapDice, treemapResquarify as d3treemapResquarify, treemapSlice as d3treemapSlice, treemapSliceDice as d3treemapSliceDice, treemapSquarify as d3treemapSquarify } from "d3-hierarchy";
5
-
6
- import "../src/Treemap.css";
7
-
8
- export class TreemapColumn extends PropertyExt {
9
- _owner: Treemap;
10
-
11
- constructor() {
12
- super();
13
- }
14
-
15
- owner(): Treemap;
16
- owner(_: Treemap): this;
17
- owner(_?: Treemap): Treemap | this {
18
- if (!arguments.length) return this._owner;
19
- this._owner = _;
20
- return this;
21
- }
22
-
23
- valid(): boolean {
24
- return !!this.column();
25
- }
26
-
27
- column: { (): string; (_: string): TreemapColumn; };
28
- }
29
- TreemapColumn.prototype._class += " tree_Dendrogram.TreemapColumn";
30
-
31
- TreemapColumn.prototype.publish("column", null, "set", "Field", function (this: TreemapColumn) { return this._owner ? this._owner.columns() : []; }, { optional: true });
32
-
33
- // ===
34
- export class Treemap extends HTMLWidget {
35
- Column;
36
- protected _d3Treemap;
37
- protected _elementDIV;
38
- protected _selection;
39
- constructor() {
40
- super();
41
- ITree.call(this);
42
- Utility.SimpleSelectionMixin.call(this, true);
43
- }
44
-
45
- private getTilingMethod() {
46
- switch (this.tilingMethod()) {
47
- case "treemapBinary":
48
- return d3treemapBinary;
49
- case "treemapDice":
50
- return d3treemapDice;
51
- case "treemapSlice":
52
- return d3treemapSlice;
53
- case "treemapSliceDice":
54
- return d3treemapSliceDice;
55
- case "treemapResquarify":
56
- return d3treemapResquarify;
57
- case "treemapSquarify":
58
- default:
59
- return d3treemapSquarify;
60
- }
61
- }
62
-
63
- treemapData() {
64
- if (!this.mappings().filter(mapping => mapping.valid()).length) {
65
- return this.data();
66
- }
67
-
68
- const view = this._db.aggregateView(this.mappings().map(function (mapping) { return mapping.column(); }), this.aggrType(), this.aggrColumn());
69
- const retVal = {
70
- key: "root",
71
- values: view.entries()
72
- };
73
- return formatData(retVal);
74
-
75
- function formatData(node): any {
76
- if (node.values instanceof Array) {
77
- const children = node.values.filter(function (value) {
78
- return !(value instanceof Array);
79
- }).map(function (value) {
80
- return formatData(value);
81
- });
82
- const retVal2: any = {
83
- label: node.key
84
- };
85
- if (children.length) {
86
- retVal2.children = children;
87
- } else {
88
- retVal2.size = 22;
89
- }
90
- return retVal2;
91
- }
92
- return {
93
- label: node.key,
94
- size: node.values.aggregate,
95
- origRows: node.values
96
- };
97
- }
98
- }
99
-
100
- enter(domNode, element) {
101
- super.enter(domNode, element);
102
- this._d3Treemap = d3Treemap();
103
-
104
- this._elementDIV = element.append("div");
105
- this._selection.widgetElement(this._elementDIV);
106
- }
107
-
108
- update(domNode, element) {
109
- super.update(domNode, element);
110
- const context = this;
111
-
112
- this._palette = this._palette.switch(this.paletteID());
113
- if (this.useClonedPalette()) {
114
- this._palette = this._palette.cloneNotExists(this.paletteID() + "_" + this.id());
115
- }
116
-
117
- const root = d3Hierarchy(this.treemapData())
118
- .sum(this.nodeWeight)
119
- ;
120
-
121
- this._d3Treemap
122
- .size([this.width(), this.height()])
123
- .paddingInner(this.paddingInner())
124
- .paddingOuter(this.paddingOuter())
125
- .paddingTop(this.paddingTop())
126
- ;
127
- if (["treemapSquarify", "treemapResquarify"].indexOf(this.tilingMethod()) !== -1) {
128
- this._d3Treemap.tile(this.getTilingMethod()["ratio"](this.squarifyRatio()));
129
- } else {
130
- this._d3Treemap.tile(this.getTilingMethod());
131
- }
132
- this._d3Treemap(root);
133
-
134
- this._elementDIV
135
- .style("font-size", this.fontSize_exists() ? this.fontSize() + "px" : null)
136
- .style("line-height", this.fontSize_exists() ? (this.fontSize() + 2) + "px" : null)
137
- ;
138
-
139
- const node = this._elementDIV.selectAll(".node").data(root.descendants());
140
- node.enter().append("div")
141
- .attr("class", "node")
142
- .call(this._selection.enter.bind(this._selection))
143
- .on("click", function (d) {
144
- if (d) {
145
- let columnLabel = "";
146
- context.mappings().forEach(function (mapping) {
147
- if (mapping.column()) {
148
- columnLabel = mapping.column();
149
- }
150
- });
151
- if (d.origRows) {
152
- context.click(context.rowToObj(d.origRows[0]), columnLabel, context._selection.selected(this));
153
- } else {
154
- context.click(d.data, columnLabel, context._selection.selected(this));
155
- }
156
- }
157
- })
158
- .on("dblclick", function (d) {
159
- if (d) {
160
- let columnLabel = "";
161
- context.mappings().forEach(function (mapping) {
162
- if (mapping.column()) {
163
- columnLabel = mapping.column();
164
- }
165
- });
166
- if (d.origRows) {
167
- context.dblclick(context.rowToObj(d.origRows[0]), columnLabel, context._selection.selected(this));
168
- } else {
169
- context.dblclick(d.data, columnLabel, context._selection.selected(this));
170
- }
171
- }
172
- })
173
- .merge(node)
174
- .style("left", function (d) { return (d.x0 + Math.max(0, d.x1 - d.x0) / 2) + "px"; })
175
- .style("top", function (d) { return (d.y0 + Math.max(0, d.y1 - d.y0) / 2) + "px"; })
176
- .style("width", function () { return 0 + "px"; })
177
- .style("height", function () { return 0 + "px"; })
178
- .style("font-size", function (d) { return (d.children ? context.parentFontSize() : context.leafFontSize()) + "px"; })
179
- .style("line-height", function (d) { return (d.children ? context.parentFontSize() : context.leafFontSize()) + "px"; })
180
- .attr("title", tooltip)
181
- .html(function (d) {
182
- if (!context.showRoot() && d.depth === 0) {
183
- return null;
184
- }
185
- if (d.children) {
186
- if (context.enableParentLabels()) {
187
- return context.parentWeightHTML(d);
188
- } else {
189
- return null;
190
- }
191
- } else {
192
- return context.leafWeightHTML(d);
193
- }
194
- })
195
- .style("background", function (d) {
196
- if (!context.showRoot() && d.depth === 0) {
197
- this.style.color = "transparent";
198
- return "transparent";
199
- }
200
- const light_dark = context.brighterLeafNodes() ? "brighter" : "darker";
201
- let _color;
202
- if (context.usePaletteOnParentNodes()) {
203
- _color = d.children ? context._palette(d.data.label) : d3rgb(context._palette(d.parent.data.label))[light_dark](1);
204
- } else {
205
- if (d.depth > context.depthColorLimit()) {
206
- _color = d3rgb(d.parent.color)[light_dark](1);
207
- } else {
208
- _color = context._palette(d.data.label);
209
- }
210
- d.color = _color;
211
- }
212
- this.style.color = Palette.textColor(_color);
213
- return _color;
214
- })
215
- .transition().duration(this.transitionDuration())
216
- .style("pointer-events", function (d) { return !context.showRoot() && d.depth === 0 ? "none" : "all"; })
217
- .style("opacity", function (d) { return d.children ? 1 : null; })
218
- .style("left", function (d) { return d.x0 + "px"; })
219
- .style("top", function (d) { return d.y0 + "px"; })
220
- .style("width", function (d) { return Math.max(0, d.x1 - d.x0) + "px"; })
221
- .style("height", function (d) { return Math.max(0, d.y1 - d.y0) + "px"; })
222
- .each(function (d) {
223
- if (d.depth === 0) {
224
- this.style.color = !context.showRoot() ? "transparent" : "";
225
- this.style.borderColor = !context.showRoot() ? "transparent" : "";
226
- }
227
- })
228
- ;
229
- node.exit().transition().duration(this.transitionDuration())
230
- .style("opacity", 0)
231
- .remove()
232
- ;
233
- function tooltip(d) {
234
- if (d.children && !context.enableParentTooltips()) {
235
- return null;
236
- }
237
- let retVal = d.data.label + " (" + d.value + ")";
238
- while (d.parent && d.parent.parent) {
239
- retVal = d.parent.data.label + " -> " + retVal;
240
- d = d.parent;
241
- }
242
- return retVal;
243
- }
244
- }
245
-
246
- exit(domNode, element) {
247
- super.exit(domNode, element);
248
- }
249
-
250
- nodeWeight(d) {
251
- return d.size || 1;
252
- }
253
-
254
- parentWeightHTML(d) {
255
- return this.showParentWeight() ? `<span class="treemap-parent-label">${d.data.label}</span><span class="treemap-parent-value">${d.value}${this.weightSuffix()}</span>` : `<span class="treemap-parent-label">${d.data.label}</span>`;
256
- }
257
-
258
- leafWeightHTML(d) {
259
- return this.showLeafWeight() ? `<span class="treemap-leaf-label">${d.data.label}</span><span class="treemap-leaf-value">${d.value}${this.weightSuffix()}</span>` : `<span class="treemap-leaf-label">${d.data.label}</span>`;
260
- }
261
- }
262
- Treemap.prototype._class += " tree_Treemap";
263
- Treemap.prototype.implements(ITree.prototype);
264
- Treemap.prototype.mixin(Utility.SimpleSelectionMixin);
265
- Treemap.prototype.Column = TreemapColumn;
266
-
267
- export interface Treemap {
268
- _palette;
269
-
270
- // ITree ---
271
- click(row, column, selected): void;
272
- dblclick(row, column, selected): void;
273
-
274
- // Properties ---
275
- paletteID(): string;
276
- paletteID(_: string): this;
277
- useClonedPalette(): boolean;
278
- useClonedPalette(_: boolean): this;
279
- mappings(): TreemapColumn[];
280
- mappings(_: TreemapColumn[]): this;
281
- aggrType(): string;
282
- aggrType(_: string): this;
283
- aggrColumn(): string;
284
- aggrColumn(_: string): this;
285
- fontSize(): number;
286
- fontSize(_: number): this;
287
- fontSize_exists(): boolean;
288
- paddingInner(): number;
289
- paddingInner(_: number): this;
290
- paddingOuter(): number;
291
- paddingOuter(_: number): this;
292
- paddingTop(): number;
293
- paddingTop(_: number): this;
294
- showRoot(): boolean;
295
- showRoot(_: boolean): this;
296
- parentFontSize(): number;
297
- parentFontSize(_: number): this;
298
- leafFontSize(): number;
299
- leafFontSize(_: number): this;
300
- usePaletteOnParentNodes(): boolean;
301
- usePaletteOnParentNodes(_: boolean): this;
302
- depthColorLimit(): number;
303
- depthColorLimit(_: number): this;
304
- squarifyRatio(): number;
305
- squarifyRatio(_: number): this;
306
- showParentWeight(): boolean;
307
- showParentWeight(_: boolean): this;
308
- showLeafWeight(): boolean;
309
- showLeafWeight(_: boolean): this;
310
- weightSuffix(): string;
311
- weightSuffix(_: string): this;
312
- brighterLeafNodes(): boolean;
313
- brighterLeafNodes(_: boolean): this;
314
- enableParentLabels(): boolean;
315
- enableParentLabels(_: boolean): this;
316
- enableParentTooltips(): boolean;
317
- enableParentTooltips(_: boolean): this;
318
- transitionDuration(): number[];
319
- transitionDuration(_: number[]): this;
320
- tilingMethod(): string;
321
- tilingMethod(_: string): this;
322
- }
323
-
324
- Treemap.prototype.publish("paletteID", "default", "set", "Color palette for this widget", Treemap.prototype._palette.switch(), { tags: ["Basic", "Shared"] });
325
- Treemap.prototype.publish("useClonedPalette", false, "boolean", "Enable or disable using a cloned palette", null, { tags: ["Intermediate", "Shared"] });
326
- Treemap.prototype.publish("mappings", [], "propertyArray", "Source Columns", null, { autoExpand: TreemapColumn });
327
- Treemap.prototype.publish("aggrType", null, "set", "Aggregation Type", [null, "mean", "median", "sum", "min", "max"], { optional: true });
328
- Treemap.prototype.publish("aggrColumn", null, "set", "Aggregation Field", function () { return this.columns(); }, { optional: true, disable: (w) => !w.aggrType() });
329
- Treemap.prototype.publish("fontSize", null, "number", "Font Size", null, { optional: true });
330
- Treemap.prototype.publish("paddingInner", 18.6, "number", "Pixel spacing between each sibling node");
331
- Treemap.prototype.publish("paddingOuter", 30, "number", "Pixel padding of parent nodes");
332
- Treemap.prototype.publish("paddingTop", 41.4, "number", "Additional top pixel padding of parent nodes");
333
- Treemap.prototype.publish("showRoot", false, "boolean", "Show root element");
334
- Treemap.prototype.publish("parentFontSize", 18, "number", "Parent font-size");
335
- Treemap.prototype.publish("leafFontSize", 16, "number", "Leaf font-size");
336
- Treemap.prototype.publish("usePaletteOnParentNodes", false, "boolean", "Assign a color from the palette to every parent node");
337
- Treemap.prototype.publish("depthColorLimit", 1, "number", "Assign a color from the palette to node with depth lower than this value", null, { optional: true, disable: (w) => w.usePaletteOnParentNodes() });
338
- Treemap.prototype.publish("squarifyRatio", 1, "number", "Specifies the desired aspect ratio of the generated rectangles (must be >= 1)", null, { optional: true, disable: (w) => ["treemapSquarify", "treemapResquarify"].indexOf(w.tilingMethod()) === -1 });
339
- Treemap.prototype.publish("showParentWeight", true, "boolean", "Show weight of parent nodes");
340
- Treemap.prototype.publish("showLeafWeight", true, "boolean", "Show weight of leaf nodes");
341
- Treemap.prototype.publish("weightSuffix", "", "string", "Weight suffix (ex: 'ms')");
342
- Treemap.prototype.publish("brighterLeafNodes", false, "boolean", "Brighter/darker leaf node color (false = darker)");
343
- Treemap.prototype.publish("enableParentLabels", true, "boolean", "Enable parent labels");
344
- Treemap.prototype.publish("enableParentTooltips", true, "boolean", "Enable parent tooltips");
345
- Treemap.prototype.publish("transitionDuration", 250, "number", "Transition Duration");
346
- Treemap.prototype.publish("tilingMethod", "treemapSquarify", "set", "Transition Duration", ["treemapBinary", "treemapDice", "treemapResquarify", "treemapSlice", "treemapSliceDice", "treemapSquarify"]);
1
+ import { ITree } from "@hpcc-js/api";
2
+ import { HTMLWidget, Palette, PropertyExt, Utility } from "@hpcc-js/common";
3
+ import { rgb as d3rgb } from "d3-color";
4
+ import { hierarchy as d3Hierarchy, treemap as d3Treemap, treemapBinary as d3treemapBinary, treemapDice as d3treemapDice, treemapResquarify as d3treemapResquarify, treemapSlice as d3treemapSlice, treemapSliceDice as d3treemapSliceDice, treemapSquarify as d3treemapSquarify } from "d3-hierarchy";
5
+
6
+ import "../src/Treemap.css";
7
+
8
+ export class TreemapColumn extends PropertyExt {
9
+ _owner: Treemap;
10
+
11
+ constructor() {
12
+ super();
13
+ }
14
+
15
+ owner(): Treemap;
16
+ owner(_: Treemap): this;
17
+ owner(_?: Treemap): Treemap | this {
18
+ if (!arguments.length) return this._owner;
19
+ this._owner = _;
20
+ return this;
21
+ }
22
+
23
+ valid(): boolean {
24
+ return !!this.column();
25
+ }
26
+
27
+ column: { (): string; (_: string): TreemapColumn; };
28
+ }
29
+ TreemapColumn.prototype._class += " tree_Dendrogram.TreemapColumn";
30
+
31
+ TreemapColumn.prototype.publish("column", null, "set", "Field", function (this: TreemapColumn) { return this._owner ? this._owner.columns() : []; }, { optional: true });
32
+
33
+ // ===
34
+ export class Treemap extends HTMLWidget {
35
+ Column;
36
+ protected _d3Treemap;
37
+ protected _elementDIV;
38
+ protected _selection;
39
+ constructor() {
40
+ super();
41
+ ITree.call(this);
42
+ Utility.SimpleSelectionMixin.call(this, true);
43
+ }
44
+
45
+ private getTilingMethod() {
46
+ switch (this.tilingMethod()) {
47
+ case "treemapBinary":
48
+ return d3treemapBinary;
49
+ case "treemapDice":
50
+ return d3treemapDice;
51
+ case "treemapSlice":
52
+ return d3treemapSlice;
53
+ case "treemapSliceDice":
54
+ return d3treemapSliceDice;
55
+ case "treemapResquarify":
56
+ return d3treemapResquarify;
57
+ case "treemapSquarify":
58
+ default:
59
+ return d3treemapSquarify;
60
+ }
61
+ }
62
+
63
+ treemapData() {
64
+ if (!this.mappings().filter(mapping => mapping.valid()).length) {
65
+ return this.data();
66
+ }
67
+
68
+ const view = this._db.aggregateView(this.mappings().map(function (mapping) { return mapping.column(); }), this.aggrType(), this.aggrColumn());
69
+ const retVal = {
70
+ key: "root",
71
+ values: view.entries()
72
+ };
73
+ return formatData(retVal);
74
+
75
+ function formatData(node): any {
76
+ if (node.values instanceof Array) {
77
+ const children = node.values.filter(function (value) {
78
+ return !(value instanceof Array);
79
+ }).map(function (value) {
80
+ return formatData(value);
81
+ });
82
+ const retVal2: any = {
83
+ label: node.key
84
+ };
85
+ if (children.length) {
86
+ retVal2.children = children;
87
+ } else {
88
+ retVal2.size = 22;
89
+ }
90
+ return retVal2;
91
+ }
92
+ return {
93
+ label: node.key,
94
+ size: node.values.aggregate,
95
+ origRows: node.values
96
+ };
97
+ }
98
+ }
99
+
100
+ enter(domNode, element) {
101
+ super.enter(domNode, element);
102
+ this._d3Treemap = d3Treemap();
103
+
104
+ this._elementDIV = element.append("div");
105
+ this._selection.widgetElement(this._elementDIV);
106
+ }
107
+
108
+ update(domNode, element) {
109
+ super.update(domNode, element);
110
+ const context = this;
111
+
112
+ this._palette = this._palette.switch(this.paletteID());
113
+ if (this.useClonedPalette()) {
114
+ this._palette = this._palette.cloneNotExists(this.paletteID() + "_" + this.id());
115
+ }
116
+
117
+ const root = d3Hierarchy(this.treemapData())
118
+ .sum(this.nodeWeight)
119
+ ;
120
+
121
+ this._d3Treemap
122
+ .size([this.width(), this.height()])
123
+ .paddingInner(this.paddingInner())
124
+ .paddingOuter(this.paddingOuter())
125
+ .paddingTop(this.paddingTop())
126
+ ;
127
+ if (["treemapSquarify", "treemapResquarify"].indexOf(this.tilingMethod()) !== -1) {
128
+ this._d3Treemap.tile(this.getTilingMethod()["ratio"](this.squarifyRatio()));
129
+ } else {
130
+ this._d3Treemap.tile(this.getTilingMethod());
131
+ }
132
+ this._d3Treemap(root);
133
+
134
+ this._elementDIV
135
+ .style("font-size", this.fontSize_exists() ? this.fontSize() + "px" : null)
136
+ .style("line-height", this.fontSize_exists() ? (this.fontSize() + 2) + "px" : null)
137
+ ;
138
+
139
+ const node = this._elementDIV.selectAll(".node").data(root.descendants());
140
+ node.enter().append("div")
141
+ .attr("class", "node")
142
+ .call(this._selection.enter.bind(this._selection))
143
+ .on("click", function (d) {
144
+ if (d) {
145
+ let columnLabel = "";
146
+ context.mappings().forEach(function (mapping) {
147
+ if (mapping.column()) {
148
+ columnLabel = mapping.column();
149
+ }
150
+ });
151
+ if (d.origRows) {
152
+ context.click(context.rowToObj(d.origRows[0]), columnLabel, context._selection.selected(this));
153
+ } else {
154
+ context.click(d.data, columnLabel, context._selection.selected(this));
155
+ }
156
+ }
157
+ })
158
+ .on("dblclick", function (d) {
159
+ if (d) {
160
+ let columnLabel = "";
161
+ context.mappings().forEach(function (mapping) {
162
+ if (mapping.column()) {
163
+ columnLabel = mapping.column();
164
+ }
165
+ });
166
+ if (d.origRows) {
167
+ context.dblclick(context.rowToObj(d.origRows[0]), columnLabel, context._selection.selected(this));
168
+ } else {
169
+ context.dblclick(d.data, columnLabel, context._selection.selected(this));
170
+ }
171
+ }
172
+ })
173
+ .merge(node)
174
+ .style("left", function (d) { return (d.x0 + Math.max(0, d.x1 - d.x0) / 2) + "px"; })
175
+ .style("top", function (d) { return (d.y0 + Math.max(0, d.y1 - d.y0) / 2) + "px"; })
176
+ .style("width", function () { return 0 + "px"; })
177
+ .style("height", function () { return 0 + "px"; })
178
+ .style("font-size", function (d) { return (d.children ? context.parentFontSize() : context.leafFontSize()) + "px"; })
179
+ .style("line-height", function (d) { return (d.children ? context.parentFontSize() : context.leafFontSize()) + "px"; })
180
+ .attr("title", tooltip)
181
+ .html(function (d) {
182
+ if (!context.showRoot() && d.depth === 0) {
183
+ return null;
184
+ }
185
+ if (d.children) {
186
+ if (context.enableParentLabels()) {
187
+ return context.parentWeightHTML(d);
188
+ } else {
189
+ return null;
190
+ }
191
+ } else {
192
+ return context.leafWeightHTML(d);
193
+ }
194
+ })
195
+ .style("background", function (d) {
196
+ if (!context.showRoot() && d.depth === 0) {
197
+ this.style.color = "transparent";
198
+ return "transparent";
199
+ }
200
+ const light_dark = context.brighterLeafNodes() ? "brighter" : "darker";
201
+ let _color;
202
+ if (context.usePaletteOnParentNodes()) {
203
+ _color = d.children ? context._palette(d.data.label) : d3rgb(context._palette(d.parent.data.label))[light_dark](1);
204
+ } else {
205
+ if (d.depth > context.depthColorLimit()) {
206
+ _color = d3rgb(d.parent.color)[light_dark](1);
207
+ } else {
208
+ _color = context._palette(d.data.label);
209
+ }
210
+ d.color = _color;
211
+ }
212
+ this.style.color = Palette.textColor(_color);
213
+ return _color;
214
+ })
215
+ .transition().duration(this.transitionDuration())
216
+ .style("pointer-events", function (d) { return !context.showRoot() && d.depth === 0 ? "none" : "all"; })
217
+ .style("opacity", function (d) { return d.children ? 1 : null; })
218
+ .style("left", function (d) { return d.x0 + "px"; })
219
+ .style("top", function (d) { return d.y0 + "px"; })
220
+ .style("width", function (d) { return Math.max(0, d.x1 - d.x0) + "px"; })
221
+ .style("height", function (d) { return Math.max(0, d.y1 - d.y0) + "px"; })
222
+ .each(function (d) {
223
+ if (d.depth === 0) {
224
+ this.style.color = !context.showRoot() ? "transparent" : "";
225
+ this.style.borderColor = !context.showRoot() ? "transparent" : "";
226
+ }
227
+ })
228
+ ;
229
+ node.exit().transition().duration(this.transitionDuration())
230
+ .style("opacity", 0)
231
+ .remove()
232
+ ;
233
+ function tooltip(d) {
234
+ if (d.children && !context.enableParentTooltips()) {
235
+ return null;
236
+ }
237
+ let retVal = d.data.label + " (" + d.value + ")";
238
+ while (d.parent && d.parent.parent) {
239
+ retVal = d.parent.data.label + " -> " + retVal;
240
+ d = d.parent;
241
+ }
242
+ return retVal;
243
+ }
244
+ }
245
+
246
+ exit(domNode, element) {
247
+ super.exit(domNode, element);
248
+ }
249
+
250
+ nodeWeight(d) {
251
+ return d.size || 1;
252
+ }
253
+
254
+ parentWeightHTML(d) {
255
+ return this.showParentWeight() ? `<span class="treemap-parent-label">${d.data.label}</span><span class="treemap-parent-value">${d.value}${this.weightSuffix()}</span>` : `<span class="treemap-parent-label">${d.data.label}</span>`;
256
+ }
257
+
258
+ leafWeightHTML(d) {
259
+ return this.showLeafWeight() ? `<span class="treemap-leaf-label">${d.data.label}</span><span class="treemap-leaf-value">${d.value}${this.weightSuffix()}</span>` : `<span class="treemap-leaf-label">${d.data.label}</span>`;
260
+ }
261
+ }
262
+ Treemap.prototype._class += " tree_Treemap";
263
+ Treemap.prototype.implements(ITree.prototype);
264
+ Treemap.prototype.mixin(Utility.SimpleSelectionMixin);
265
+ Treemap.prototype.Column = TreemapColumn;
266
+
267
+ export interface Treemap {
268
+ _palette;
269
+
270
+ // ITree ---
271
+ click(row, column, selected): void;
272
+ dblclick(row, column, selected): void;
273
+
274
+ // Properties ---
275
+ paletteID(): string;
276
+ paletteID(_: string): this;
277
+ useClonedPalette(): boolean;
278
+ useClonedPalette(_: boolean): this;
279
+ mappings(): TreemapColumn[];
280
+ mappings(_: TreemapColumn[]): this;
281
+ aggrType(): string;
282
+ aggrType(_: string): this;
283
+ aggrColumn(): string;
284
+ aggrColumn(_: string): this;
285
+ fontSize(): number;
286
+ fontSize(_: number): this;
287
+ fontSize_exists(): boolean;
288
+ paddingInner(): number;
289
+ paddingInner(_: number): this;
290
+ paddingOuter(): number;
291
+ paddingOuter(_: number): this;
292
+ paddingTop(): number;
293
+ paddingTop(_: number): this;
294
+ showRoot(): boolean;
295
+ showRoot(_: boolean): this;
296
+ parentFontSize(): number;
297
+ parentFontSize(_: number): this;
298
+ leafFontSize(): number;
299
+ leafFontSize(_: number): this;
300
+ usePaletteOnParentNodes(): boolean;
301
+ usePaletteOnParentNodes(_: boolean): this;
302
+ depthColorLimit(): number;
303
+ depthColorLimit(_: number): this;
304
+ squarifyRatio(): number;
305
+ squarifyRatio(_: number): this;
306
+ showParentWeight(): boolean;
307
+ showParentWeight(_: boolean): this;
308
+ showLeafWeight(): boolean;
309
+ showLeafWeight(_: boolean): this;
310
+ weightSuffix(): string;
311
+ weightSuffix(_: string): this;
312
+ brighterLeafNodes(): boolean;
313
+ brighterLeafNodes(_: boolean): this;
314
+ enableParentLabels(): boolean;
315
+ enableParentLabels(_: boolean): this;
316
+ enableParentTooltips(): boolean;
317
+ enableParentTooltips(_: boolean): this;
318
+ transitionDuration(): number[];
319
+ transitionDuration(_: number[]): this;
320
+ tilingMethod(): string;
321
+ tilingMethod(_: string): this;
322
+ }
323
+
324
+ Treemap.prototype.publish("paletteID", "default", "set", "Color palette for this widget", Treemap.prototype._palette.switch(), { tags: ["Basic", "Shared"] });
325
+ Treemap.prototype.publish("useClonedPalette", false, "boolean", "Enable or disable using a cloned palette", null, { tags: ["Intermediate", "Shared"] });
326
+ Treemap.prototype.publish("mappings", [], "propertyArray", "Source Columns", null, { autoExpand: TreemapColumn });
327
+ Treemap.prototype.publish("aggrType", null, "set", "Aggregation Type", [null, "mean", "median", "sum", "min", "max"], { optional: true });
328
+ Treemap.prototype.publish("aggrColumn", null, "set", "Aggregation Field", function () { return this.columns(); }, { optional: true, disable: (w) => !w.aggrType() });
329
+ Treemap.prototype.publish("fontSize", null, "number", "Font Size", null, { optional: true });
330
+ Treemap.prototype.publish("paddingInner", 18.6, "number", "Pixel spacing between each sibling node");
331
+ Treemap.prototype.publish("paddingOuter", 30, "number", "Pixel padding of parent nodes");
332
+ Treemap.prototype.publish("paddingTop", 41.4, "number", "Additional top pixel padding of parent nodes");
333
+ Treemap.prototype.publish("showRoot", false, "boolean", "Show root element");
334
+ Treemap.prototype.publish("parentFontSize", 18, "number", "Parent font-size");
335
+ Treemap.prototype.publish("leafFontSize", 16, "number", "Leaf font-size");
336
+ Treemap.prototype.publish("usePaletteOnParentNodes", false, "boolean", "Assign a color from the palette to every parent node");
337
+ Treemap.prototype.publish("depthColorLimit", 1, "number", "Assign a color from the palette to node with depth lower than this value", null, { optional: true, disable: (w) => w.usePaletteOnParentNodes() });
338
+ Treemap.prototype.publish("squarifyRatio", 1, "number", "Specifies the desired aspect ratio of the generated rectangles (must be >= 1)", null, { optional: true, disable: (w) => ["treemapSquarify", "treemapResquarify"].indexOf(w.tilingMethod()) === -1 });
339
+ Treemap.prototype.publish("showParentWeight", true, "boolean", "Show weight of parent nodes");
340
+ Treemap.prototype.publish("showLeafWeight", true, "boolean", "Show weight of leaf nodes");
341
+ Treemap.prototype.publish("weightSuffix", "", "string", "Weight suffix (ex: 'ms')");
342
+ Treemap.prototype.publish("brighterLeafNodes", false, "boolean", "Brighter/darker leaf node color (false = darker)");
343
+ Treemap.prototype.publish("enableParentLabels", true, "boolean", "Enable parent labels");
344
+ Treemap.prototype.publish("enableParentTooltips", true, "boolean", "Enable parent tooltips");
345
+ Treemap.prototype.publish("transitionDuration", 250, "number", "Transition Duration");
346
+ Treemap.prototype.publish("tilingMethod", "treemapSquarify", "set", "Transition Duration", ["treemapBinary", "treemapDice", "treemapResquarify", "treemapSlice", "treemapSliceDice", "treemapSquarify"]);