@hpcc-js/tree 2.44.0 → 2.45.1

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 (48) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +454 -454
  3. package/dist/index.es6.js +2836 -0
  4. package/dist/index.es6.js.map +1 -0
  5. package/dist/index.js +2852 -2020
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +2 -0
  8. package/dist/index.min.js.map +1 -0
  9. package/package.json +34 -32
  10. package/src/CirclePacking.css +16 -16
  11. package/src/CirclePacking.ts +148 -152
  12. package/src/Dendrogram.css +42 -42
  13. package/src/Dendrogram.ts +284 -296
  14. package/src/DirectoryTree.ts +310 -306
  15. package/src/Indented.css +16 -16
  16. package/src/Indented.ts +283 -290
  17. package/src/SunburstPartition.css +5 -5
  18. package/src/SunburstPartition.ts +151 -157
  19. package/src/Treemap.css +41 -41
  20. package/src/Treemap.ts +320 -346
  21. package/src/__package__.ts +3 -3
  22. package/src/index.ts +7 -7
  23. package/types/CirclePacking.d.ts +6 -7
  24. package/types/CirclePacking.d.ts.map +1 -0
  25. package/types/Dendrogram.d.ts +35 -20
  26. package/types/Dendrogram.d.ts.map +1 -0
  27. package/types/DirectoryTree.d.ts +16 -11
  28. package/types/DirectoryTree.d.ts.map +1 -0
  29. package/types/Indented.d.ts +16 -11
  30. package/types/Indented.d.ts.map +1 -0
  31. package/types/SunburstPartition.d.ts +5 -8
  32. package/types/SunburstPartition.d.ts.map +1 -0
  33. package/types/Treemap.d.ts +96 -51
  34. package/types/Treemap.d.ts.map +1 -0
  35. package/types/__package__.d.ts +3 -2
  36. package/types/__package__.d.ts.map +1 -0
  37. package/types/index.d.ts +8 -7
  38. package/types/index.d.ts.map +1 -0
  39. package/types-3.4/CirclePacking.d.ts +32 -0
  40. package/types-3.4/Dendrogram.d.ts +60 -0
  41. package/types-3.4/DirectoryTree.d.ts +62 -0
  42. package/types-3.4/Indented.d.ts +46 -0
  43. package/types-3.4/SunburstPartition.d.ts +23 -0
  44. package/types-3.4/Treemap.d.ts +125 -0
  45. package/types-3.4/__package__.d.ts +4 -0
  46. package/types-3.4/index.d.ts +8 -0
  47. package/dist/index.umd.cjs +0 -2
  48. package/dist/index.umd.cjs.map +0 -1
@@ -1,157 +1,151 @@
1
- import { ITree } from "@hpcc-js/api";
2
- import { d3Event, select as d3Select, SVGWidget } from "@hpcc-js/common";
3
- import { hierarchy as d3Hierarchy, partition as d3Parition } from "d3-hierarchy";
4
- import { interpolate as d3Interpolate } from "d3-interpolate";
5
- import { scaleLinear as d3ScaleLinear, scaleSqrt as d3ScaleSqrt } from "d3-scale";
6
- import { arc as d3Arc } from "d3-shape";
7
-
8
- import "../src/SunburstPartition.css";
9
-
10
- export class SunburstPartition extends SVGWidget {
11
- svg;
12
- radius;
13
- _xScale;
14
- _yScale;
15
- partition;
16
- arc;
17
- _resetRoot;
18
-
19
- constructor() {
20
- super();
21
- ITree.call(this);
22
- }
23
-
24
- data(): any;
25
- data(_: any): this;
26
- data(_?: any): any | this {
27
- const retVal = SVGWidget.prototype.data.apply(this, arguments);
28
- if (arguments.length) {
29
- this._resetRoot = true;
30
- }
31
- return retVal;
32
- }
33
-
34
- enter(_domNode, element) {
35
- const context = this;
36
-
37
- this.radius = Math.min(this.width(), this.height()) / 2;
38
-
39
- this._xScale = d3ScaleLinear()
40
- .range([0, 2 * Math.PI])
41
- ;
42
-
43
- this._yScale = d3ScaleSqrt()
44
- .range([0, this.radius])
45
- ;
46
-
47
- this.partition = d3Parition();
48
-
49
- this.arc = d3Arc()
50
- .startAngle(function (d: any) {
51
- return Math.max(0, Math.min(2 * Math.PI, context._xScale(d.x0)));
52
- })
53
- .endAngle(function (d: any) {
54
- return Math.max(0, Math.min(2 * Math.PI, context._xScale(d.x1)));
55
- })
56
- .innerRadius(function (d: any) {
57
- return Math.max(0, context._yScale(d.y0));
58
- })
59
- .outerRadius(function (d: any) {
60
- return Math.max(0, context._yScale(d.y1));
61
- })
62
- ;
63
-
64
- this.svg = element.append("g");
65
- }
66
-
67
- update(_domNode, _element) {
68
- const context = this;
69
-
70
- this._palette = this._palette.switch(this.paletteID());
71
- if (this.useClonedPalette()) {
72
- this._palette = this._palette.cloneNotExists(this.paletteID() + "_" + this.id());
73
- }
74
-
75
- this.radius = Math.min(this.width(), this.height()) / 2;
76
- this._yScale.range([0, this.radius]);
77
-
78
- const root = d3Hierarchy(this.data())
79
- .sum(function (d) {
80
- return d.size !== undefined ? d.size : 1;
81
- })
82
- ;
83
-
84
- const paths = this.svg.selectAll("path").data(this.partition(root).descendants(), function (d, i) {
85
- return d.data.label !== undefined ? d.data.label : i;
86
- });
87
-
88
- paths.enter().append("path")
89
- .on("click", function (d) { context.click(d.data, null, null); })
90
- .on("dblclick", function (d) {
91
- const event = d3Event();
92
- if (event) {
93
- event.stopPropagation();
94
- }
95
- context.zoomTo(d);
96
- })
97
- .each(function () {
98
- const element = d3Select(this);
99
- element
100
- .append("title")
101
- ;
102
- })
103
- .merge(paths)
104
- .attr("d", this.arc)
105
- .style("fill", function (d) {
106
- return d.data.__viz_fill ? d.data.__viz_fill : context._palette(d.data.label);
107
- })
108
- .style("stroke", function (d) {
109
- return d.value > 16 ? "white" : "none";
110
- })
111
- .select("title")
112
- .text(function (d) {
113
- return d.data.label;
114
- })
115
- ;
116
-
117
- paths.exit().remove();
118
-
119
- if (this._resetRoot) {
120
- this._resetRoot = false;
121
- this.zoomTo(root);
122
- }
123
- }
124
-
125
- zoomTo(d) {
126
- const context = this;
127
- this.svg.transition()
128
- .duration(750)
129
- .tween("scale", function () {
130
- const xd = d3Interpolate(context._xScale.domain(), [d.x0, d.x1]);
131
- const yd = d3Interpolate(context._yScale.domain(), [d.y0, 1]);
132
- const yr = d3Interpolate(context._yScale.range(), [d.y0 ? 20 : 0, context.radius]);
133
- return function (t) { context._xScale.domain(xd(t)); context._yScale.domain(yd(t)).range(yr(t)); };
134
- })
135
- .selectAll("path")
136
- .attrTween("d", function (d2) { return function () { return context.arc(d2); }; });
137
- }
138
- }
139
- SunburstPartition.prototype._class += " tree_SunburstPartition";
140
- SunburstPartition.prototype.implements(ITree.prototype);
141
-
142
- export interface SunburstPartition {
143
- _palette;
144
-
145
- // ITree ---
146
- click(row, column, selected): void;
147
- dblclick(row, column, selected): void;
148
-
149
- // Properties ---
150
- paletteID(): string;
151
- paletteID(_: string): this;
152
- useClonedPalette(): boolean;
153
- useClonedPalette(_: boolean): this;
154
- }
155
-
156
- SunburstPartition.prototype.publish("paletteID", "default", "set", "Color palette for this widget", SunburstPartition.prototype._palette.switch(), { tags: ["Basic", "Shared"] });
157
- SunburstPartition.prototype.publish("useClonedPalette", false, "boolean", "Enable or disable using a cloned palette", null, { tags: ["Intermediate", "Shared"] });
1
+ import { ITree } from "@hpcc-js/api";
2
+ import { d3Event, select as d3Select, SVGWidget } from "@hpcc-js/common";
3
+ import { hierarchy as d3Hierarchy, partition as d3Parition } from "d3-hierarchy";
4
+ import { interpolate as d3Interpolate } from "d3-interpolate";
5
+ import { scaleLinear as d3ScaleLinear, scaleSqrt as d3ScaleSqrt } from "d3-scale";
6
+ import { arc as d3Arc } from "d3-shape";
7
+
8
+ import "../src/SunburstPartition.css";
9
+
10
+ export class SunburstPartition extends SVGWidget {
11
+ svg;
12
+ radius;
13
+ _xScale;
14
+ _yScale;
15
+ partition;
16
+ arc;
17
+ _resetRoot;
18
+
19
+ constructor() {
20
+ super();
21
+ ITree.call(this);
22
+ }
23
+
24
+ data(): any;
25
+ data(_: any): this;
26
+ data(_?: any): any | this {
27
+ const retVal = SVGWidget.prototype.data.apply(this, arguments);
28
+ if (arguments.length) {
29
+ this._resetRoot = true;
30
+ }
31
+ return retVal;
32
+ }
33
+
34
+ enter(_domNode, element) {
35
+ const context = this;
36
+
37
+ this.radius = Math.min(this.width(), this.height()) / 2;
38
+
39
+ this._xScale = d3ScaleLinear()
40
+ .range([0, 2 * Math.PI])
41
+ ;
42
+
43
+ this._yScale = d3ScaleSqrt()
44
+ .range([0, this.radius])
45
+ ;
46
+
47
+ this.partition = d3Parition();
48
+
49
+ this.arc = d3Arc()
50
+ .startAngle(function (d: any) {
51
+ return Math.max(0, Math.min(2 * Math.PI, context._xScale(d.x0)));
52
+ })
53
+ .endAngle(function (d: any) {
54
+ return Math.max(0, Math.min(2 * Math.PI, context._xScale(d.x1)));
55
+ })
56
+ .innerRadius(function (d: any) {
57
+ return Math.max(0, context._yScale(d.y0));
58
+ })
59
+ .outerRadius(function (d: any) {
60
+ return Math.max(0, context._yScale(d.y1));
61
+ })
62
+ ;
63
+
64
+ this.svg = element.append("g");
65
+ }
66
+
67
+ update(_domNode, _element) {
68
+ const context = this;
69
+
70
+ this._palette = this._palette.switch(this.paletteID());
71
+ if (this.useClonedPalette()) {
72
+ this._palette = this._palette.cloneNotExists(this.paletteID() + "_" + this.id());
73
+ }
74
+
75
+ this.radius = Math.min(this.width(), this.height()) / 2;
76
+ this._yScale.range([0, this.radius]);
77
+
78
+ const root = d3Hierarchy(this.data())
79
+ .sum(function (d) {
80
+ return d.size !== undefined ? d.size : 1;
81
+ })
82
+ ;
83
+
84
+ const paths = this.svg.selectAll("path").data(this.partition(root).descendants(), function (d, i) {
85
+ return d.data.label !== undefined ? d.data.label : i;
86
+ });
87
+
88
+ paths.enter().append("path")
89
+ .on("click", function (d) { context.click(d.data, null, null); })
90
+ .on("dblclick", function (d) {
91
+ const event = d3Event();
92
+ if (event) {
93
+ event.stopPropagation();
94
+ }
95
+ context.zoomTo(d);
96
+ })
97
+ .each(function () {
98
+ const element = d3Select(this);
99
+ element
100
+ .append("title")
101
+ ;
102
+ })
103
+ .merge(paths)
104
+ .attr("d", this.arc)
105
+ .style("fill", function (d) {
106
+ return d.data.__viz_fill ? d.data.__viz_fill : context._palette(d.data.label);
107
+ })
108
+ .style("stroke", function (d) {
109
+ return d.value > 16 ? "white" : "none";
110
+ })
111
+ .select("title")
112
+ .text(function (d) {
113
+ return d.data.label;
114
+ })
115
+ ;
116
+
117
+ paths.exit().remove();
118
+
119
+ if (this._resetRoot) {
120
+ this._resetRoot = false;
121
+ this.zoomTo(root);
122
+ }
123
+ }
124
+
125
+ zoomTo(d) {
126
+ const context = this;
127
+ this.svg.transition()
128
+ .duration(750)
129
+ .tween("scale", function () {
130
+ const xd = d3Interpolate(context._xScale.domain(), [d.x0, d.x1]);
131
+ const yd = d3Interpolate(context._yScale.domain(), [d.y0, 1]);
132
+ const yr = d3Interpolate(context._yScale.range(), [d.y0 ? 20 : 0, context.radius]);
133
+ return function (t) { context._xScale.domain(xd(t)); context._yScale.domain(yd(t)).range(yr(t)); };
134
+ })
135
+ .selectAll("path")
136
+ .attrTween("d", function (d2) { return function () { return context.arc(d2); }; });
137
+ }
138
+
139
+ paletteID: (_?: string) => string | SunburstPartition;
140
+ useClonedPalette: (_?: boolean) => boolean | SunburstPartition;
141
+
142
+ // ITree
143
+ _palette;
144
+ click: (row, column, selected) => void;
145
+ dblclick: (row, column, selected) => void;
146
+ }
147
+ SunburstPartition.prototype._class += " tree_SunburstPartition";
148
+ SunburstPartition.prototype.implements(ITree.prototype);
149
+
150
+ SunburstPartition.prototype.publish("paletteID", "default", "set", "Color palette for this widget", SunburstPartition.prototype._palette.switch(), { tags: ["Basic", "Shared"] });
151
+ SunburstPartition.prototype.publish("useClonedPalette", false, "boolean", "Enable or disable using a cloned palette", null, { tags: ["Intermediate", "Shared"] });
package/src/Treemap.css CHANGED
@@ -1,41 +1,41 @@
1
- .tree_Treemap * {
2
- box-sizing: border-box;
3
- }
4
- .tree_Treemap .node {
5
- border: solid 1px #333;
6
- overflow: hidden;
7
- text-overflow: ellipsis;
8
- position: absolute;
9
- }
10
-
11
- .tree_Treemap .node.selected {
12
- border-color: red;
13
- }
14
-
15
- .tree_Treemap .node.over {
16
- border-color: orange;
17
- }
18
-
19
- .tree_Treemap .node.selected.over {
20
- border-color: red;
21
- }
22
- .tree_Treemap .node > span.treemap-parent-label {
23
- font-weight: bold;
24
- display: inline-block;
25
- margin: 4px 4px 0 4px;
26
- }
27
- .tree_Treemap .node > span.treemap-parent-value {
28
- font-weight: normal;
29
- font-style: italic;
30
- margin: 4px 0 0 0;
31
- }
32
- .tree_Treemap .node > span.treemap-singleton-label {
33
- font-weight: normal;
34
- display: block;
35
- margin: 4px 0 0 4px;
36
- }
37
- .tree_Treemap .node > span.treemap-singleton-value {
38
- font-style: italic;
39
- display: block;
40
- margin: 0 0 0 4px;
41
- }
1
+ .tree_Treemap * {
2
+ box-sizing: border-box;
3
+ }
4
+ .tree_Treemap .node {
5
+ border: solid 1px #333;
6
+ overflow: hidden;
7
+ text-overflow: ellipsis;
8
+ position: absolute;
9
+ }
10
+
11
+ .tree_Treemap .node.selected {
12
+ border-color: red;
13
+ }
14
+
15
+ .tree_Treemap .node.over {
16
+ border-color: orange;
17
+ }
18
+
19
+ .tree_Treemap .node.selected.over {
20
+ border-color: red;
21
+ }
22
+ .tree_Treemap .node > span.treemap-parent-label {
23
+ font-weight: bold;
24
+ display: inline-block;
25
+ margin: 4px 4px 0 4px;
26
+ }
27
+ .tree_Treemap .node > span.treemap-parent-value {
28
+ font-weight: normal;
29
+ font-style: italic;
30
+ margin: 4px 0 0 0;
31
+ }
32
+ .tree_Treemap .node > span.treemap-singleton-label {
33
+ font-weight: normal;
34
+ display: block;
35
+ margin: 4px 0 0 4px;
36
+ }
37
+ .tree_Treemap .node > span.treemap-singleton-value {
38
+ font-style: italic;
39
+ display: block;
40
+ margin: 0 0 0 4px;
41
+ }