@hpcc-js/tree 3.2.9 → 3.2.11

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.
@@ -1,157 +1,157 @@
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
+ 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"] });
package/src/Treemap.css CHANGED
@@ -1,41 +1,46 @@
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
+
5
+ .tree_Treemap .node {
6
+ border: solid 1px #333;
7
+ overflow: hidden;
8
+ text-overflow: ellipsis;
9
+ position: absolute;
10
+ }
11
+
12
+ .tree_Treemap .node.selected {
13
+ border-color: red;
14
+ }
15
+
16
+ .tree_Treemap .node.over {
17
+ border-color: orange;
18
+ }
19
+
20
+ .tree_Treemap .node.selected.over {
21
+ border-color: red;
22
+ }
23
+
24
+ .tree_Treemap .node>span.treemap-parent-label {
25
+ font-weight: bold;
26
+ display: inline-block;
27
+ margin: 4px 4px 0 4px;
28
+ }
29
+
30
+ .tree_Treemap .node>span.treemap-parent-value {
31
+ font-weight: normal;
32
+ font-style: italic;
33
+ margin: 4px 0 0 0;
34
+ }
35
+
36
+ .tree_Treemap .node>span.treemap-singleton-label {
37
+ font-weight: normal;
38
+ display: block;
39
+ margin: 4px 0 0 4px;
40
+ }
41
+
42
+ .tree_Treemap .node>span.treemap-singleton-value {
43
+ font-style: italic;
44
+ display: block;
45
+ margin: 0 0 0 4px;
46
+ }