@plotdb/chart 0.0.3 → 1.0.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.
- package/CHANGELOG.md +11 -1
- package/build +11 -5
- package/dist/index.css +8 -0
- package/dist/index.js +607 -0
- package/dist/index.min.css +1 -0
- package/dist/index.min.js +1 -0
- package/package.json +12 -9
- package/src/{chart.ls → index.ls} +0 -0
- package/src/{chart.styl → index.styl} +0 -0
- package/web/src/pug/base.pug +1 -0
- package/web/src/pug/block/axis/0.0.1/index.ls +1 -7
- package/web/src/pug/block/axis-bubble/0.0.1/index.ls +1 -5
- package/web/src/pug/block/bar/0.0.1/index.ls +1 -5
- package/web/src/pug/block/bar-list/0.0.1/index.ls +1 -5
- package/web/src/pug/block/bar-race/0.0.1/index.ls +1 -5
- package/web/src/pug/block/base/0.0.1/index.ls +63 -64
- package/web/src/pug/block/blank/0.0.1/index.ls +1 -5
- package/web/src/pug/block/bubble/0.0.1/index.ls +4 -6
- package/web/src/pug/block/bubble/0.0.1/index.pug +14 -0
- package/web/src/pug/block/curve-bar/0.0.1/index.ls +1 -5
- package/web/src/pug/block/dumbbell/0.0.1/index.ls +1 -5
- package/web/src/pug/block/empty/0.0.1/index.ls +25 -24
- package/web/src/pug/block/gauge/0.0.1/index.ls +1 -5
- package/web/src/pug/block/line/0.0.1/index.ls +1 -6
- package/web/src/pug/block/number/0.0.1/index.ls +1 -5
- package/web/src/pug/block/percent-list/0.0.1/index.ls +1 -7
- package/web/src/pug/block/pie/0.0.1/index.ls +1 -5
- package/web/src/pug/block/pie-bubble/0.0.1/index.ls +1 -5
- package/web/src/pug/block/radar/0.0.1/index.ls +1 -5
- package/web/src/pug/block/scatter/0.0.1/index.ls +1 -5
- package/web/src/pug/block/sheet/0.0.1/index.ls +1 -5
- package/web/src/pug/block/table/0.0.1/index.ls +1 -5
- package/web/src/pug/block/taiwancounty/0.0.1/index.ls +1 -5
- package/web/src/pug/block/taiwantown/0.0.1/index.ls +1 -5
- package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +1 -5
- package/web/src/pug/block/treemap/0.0.1/index.ls +1 -5
- package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +1 -5
- package/web/src/pug/block/wordcloud/0.0.1/index.ls +1 -5
- package/web/src/pug/block/worldmap/0.0.1/index.ls +1 -5
- package/web/src/styl/index.styl +6 -0
- package/web/static/block/axis/0.0.1/index.html +68 -73
- package/web/static/block/axis-bubble/0.0.1/index.html +205 -210
- package/web/static/block/bar/0.0.1/index.html +484 -489
- package/web/static/block/bar-list/0.0.1/index.html +188 -193
- package/web/static/block/bar-race/0.0.1/index.html +155 -160
- package/web/static/block/base/0.0.1/index.html +2 -2
- package/web/static/block/blank/0.0.1/index.html +35 -40
- package/web/static/block/bubble/0.0.1/index.html +377 -357
- package/web/static/block/curve-bar/0.0.1/index.html +126 -131
- package/web/static/block/dumbbell/0.0.1/index.html +160 -165
- package/web/static/block/empty/0.0.1/index.html +2 -2
- package/web/static/block/gauge/0.0.1/index.html +116 -121
- package/web/static/block/line/0.0.1/index.html +502 -507
- package/web/static/block/number/0.0.1/index.html +123 -128
- package/web/static/block/percent-list/0.0.1/index.html +263 -268
- package/web/static/block/pie/0.0.1/index.html +241 -246
- package/web/static/block/pie-bubble/0.0.1/index.html +295 -300
- package/web/static/block/radar/0.0.1/index.html +137 -142
- package/web/static/block/scatter/0.0.1/index.html +207 -212
- package/web/static/block/sheet/0.0.1/index.html +93 -98
- package/web/static/block/table/0.0.1/index.html +64 -70
- package/web/static/block/taiwancounty/0.0.1/index.html +180 -185
- package/web/static/block/taiwantown/0.0.1/index.html +104 -109
- package/web/static/block/taiwanvillage/0.0.1/index.html +114 -119
- package/web/static/block/treemap/0.0.1/index.html +296 -301
- package/web/static/block/voronoi-treemap/0.0.1/index.html +311 -316
- package/web/static/block/wordcloud/0.0.1/index.html +82 -87
- package/web/static/block/worldmap/0.0.1/index.html +186 -191
- package/web/static/css/index.css +6 -0
- package/web/static/css/index.min.css +1 -0
- package/web/static/index.html +1 -1
|
@@ -9,342 +9,337 @@
|
|
|
9
9
|
grid-column: 2;
|
|
10
10
|
padding: 0 0.5em 0 0.5em;
|
|
11
11
|
}
|
|
12
|
-
</style><script type="@plotdb/block">
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
name:
|
|
19
|
-
version:
|
|
20
|
-
extend: {
|
|
21
|
-
name: "base",
|
|
22
|
-
version: "0.0.1"
|
|
23
|
-
},
|
|
24
|
-
dependencies: [{
|
|
25
|
-
name: "@zbryikt/voronoijs",
|
|
26
|
-
version: "main",
|
|
27
|
-
path: "voronoi.min.js"
|
|
28
|
-
}]
|
|
12
|
+
</style><script type="@plotdb/block">var mod;
|
|
13
|
+
module.exports = {
|
|
14
|
+
pkg: {
|
|
15
|
+
name: 'voronoi-treemap',
|
|
16
|
+
version: '0.0.1',
|
|
17
|
+
extend: {
|
|
18
|
+
name: "base",
|
|
19
|
+
version: "0.0.1"
|
|
29
20
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
21
|
+
dependencies: [{
|
|
22
|
+
name: "@zbryikt/voronoijs",
|
|
23
|
+
version: "main",
|
|
24
|
+
path: "voronoi.min.js"
|
|
25
|
+
}]
|
|
26
|
+
},
|
|
27
|
+
init: function(arg$){
|
|
28
|
+
var root, context, pubsub;
|
|
29
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
30
|
+
return pubsub.fire('init', {
|
|
31
|
+
mod: mod({
|
|
32
|
+
context: context
|
|
33
|
+
})
|
|
34
|
+
}).then(function(it){
|
|
35
|
+
return it[0];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
mod = function(arg$){
|
|
40
|
+
var context, d3, ldcolor, voronoi, chart;
|
|
41
|
+
context = arg$.context;
|
|
42
|
+
d3 = context.d3, ldcolor = context.ldcolor, voronoi = context.voronoi, chart = context.chart;
|
|
43
|
+
return {
|
|
44
|
+
sample: function(){
|
|
45
|
+
return {
|
|
46
|
+
raw: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100].map(function(val){
|
|
47
|
+
return {
|
|
48
|
+
val: Math.random() * 10,
|
|
49
|
+
cat: Math.floor(1 + 10 * Math.random()),
|
|
50
|
+
name: val
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
binding: {
|
|
54
|
+
name: {
|
|
55
|
+
key: 'name'
|
|
56
|
+
},
|
|
57
|
+
area: {
|
|
58
|
+
key: 'val'
|
|
59
|
+
},
|
|
60
|
+
category: {
|
|
61
|
+
key: 'cat'
|
|
66
62
|
}
|
|
67
|
-
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
config: {},
|
|
67
|
+
dimension: {
|
|
68
|
+
area: {
|
|
69
|
+
type: 'R',
|
|
70
|
+
name: "area"
|
|
68
71
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
name: {
|
|
73
|
+
type: 'N',
|
|
74
|
+
desc: "name"
|
|
75
|
+
},
|
|
76
|
+
category: {
|
|
77
|
+
type: 'N',
|
|
78
|
+
desc: "category"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
init: function(){
|
|
82
|
+
var tint, g, this$ = this;
|
|
83
|
+
this.tint = tint = new chart.utils.tint();
|
|
84
|
+
this.g = Object.fromEntries(['view', 'legend'].map(function(it){
|
|
85
|
+
return [it, d3.select(this$.layout.getGroup(it))];
|
|
86
|
+
}));
|
|
87
|
+
this.layout.getGroup('view').appendChild(g = document.createElementNS("http://www.w3.org/2000/svg", "g"));
|
|
88
|
+
this.g.shape = d3.select(g);
|
|
89
|
+
this.siteBoxes = [];
|
|
90
|
+
this.legend = new chart.utils.legend({
|
|
91
|
+
layout: this.layout,
|
|
92
|
+
name: 'legend',
|
|
93
|
+
root: this.root,
|
|
94
|
+
shape: function(d){
|
|
95
|
+
return d3.select(this).attr('fill', tint.get(d.key));
|
|
78
96
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
desc: "category"
|
|
97
|
+
cfg: {
|
|
98
|
+
selectable: true
|
|
82
99
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this
|
|
87
|
-
this
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
root: this.root,
|
|
97
|
-
shape: function(d){
|
|
98
|
-
return d3.select(this).attr('fill', tint.get(d.key));
|
|
99
|
-
},
|
|
100
|
-
cfg: {
|
|
101
|
-
selectable: true
|
|
100
|
+
});
|
|
101
|
+
this.legend.on('select', function(){
|
|
102
|
+
this$.bind();
|
|
103
|
+
this$.resize();
|
|
104
|
+
return this$.render();
|
|
105
|
+
});
|
|
106
|
+
this.tip = new chart.utils.tip({
|
|
107
|
+
root: this.root,
|
|
108
|
+
accessor: function(arg$){
|
|
109
|
+
var evt, data;
|
|
110
|
+
evt = arg$.evt;
|
|
111
|
+
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
112
|
+
return null;
|
|
102
113
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this$.resize();
|
|
107
|
-
return this$.render();
|
|
108
|
-
});
|
|
109
|
-
this.tip = new chart.utils.tip({
|
|
110
|
-
root: this.root,
|
|
111
|
-
accessor: function(arg$){
|
|
112
|
-
var evt, data;
|
|
113
|
-
evt = arg$.evt;
|
|
114
|
-
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
115
|
-
return null;
|
|
114
|
+
if (Array.isArray(data)) {
|
|
115
|
+
if (!this$._sites) {
|
|
116
|
+
return;
|
|
116
117
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (!(data = this$._sites[data.idx])) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
118
|
+
if (!(data.idx != null)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!(data = this$._sites[data.idx])) {
|
|
122
|
+
return;
|
|
127
123
|
}
|
|
128
|
-
return {
|
|
129
|
-
name: data.name,
|
|
130
|
-
value: data.area.toFixed(2) + "" + (this$.binding.area.unit || '')
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
range: function(){
|
|
134
|
-
return this$.layout.getNode('view').getBoundingClientRect();
|
|
135
124
|
}
|
|
136
|
-
});
|
|
137
|
-
return this.start();
|
|
138
|
-
},
|
|
139
|
-
parse: function(){
|
|
140
|
-
this.data.map(function(it){
|
|
141
|
-
return it.key = it.name, it.value = it.area, it;
|
|
142
|
-
});
|
|
143
|
-
this.total = this.data.reduce(function(a, b){
|
|
144
|
-
return a + b.area;
|
|
145
|
-
}, 0);
|
|
146
|
-
this.cats = Array.from(new Set(this.data.map(function(d){
|
|
147
|
-
return d.category;
|
|
148
|
-
})));
|
|
149
|
-
return this.legend.data(this.cats.map(function(it){
|
|
150
125
|
return {
|
|
151
|
-
|
|
152
|
-
|
|
126
|
+
name: data.name,
|
|
127
|
+
value: data.area.toFixed(2) + "" + (this$.binding.area.unit || '')
|
|
153
128
|
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
129
|
+
},
|
|
130
|
+
range: function(){
|
|
131
|
+
return this$.layout.getNode('view').getBoundingClientRect();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return this.start();
|
|
135
|
+
},
|
|
136
|
+
parse: function(){
|
|
137
|
+
this.data.map(function(it){
|
|
138
|
+
return it.key = it.name, it.value = it.area, it;
|
|
139
|
+
});
|
|
140
|
+
this.total = this.data.reduce(function(a, b){
|
|
141
|
+
return a + b.area;
|
|
142
|
+
}, 0);
|
|
143
|
+
this.cats = Array.from(new Set(this.data.map(function(d){
|
|
144
|
+
return d.category;
|
|
145
|
+
})));
|
|
146
|
+
return this.legend.data(this.cats.map(function(it){
|
|
147
|
+
return {
|
|
148
|
+
key: it,
|
|
149
|
+
text: it
|
|
167
150
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
151
|
+
}));
|
|
152
|
+
},
|
|
153
|
+
bind: function(){
|
|
154
|
+
var data, box, ref$, w, h, sites, x$, y$, this$ = this;
|
|
155
|
+
data = this.data.filter(function(it){
|
|
156
|
+
return this$.legend.isSelected(it.category);
|
|
157
|
+
});
|
|
158
|
+
this.parsed = {
|
|
159
|
+
children: d3.nest().key(function(it){
|
|
160
|
+
return it.category;
|
|
161
|
+
}).entries(data).map(function(it){
|
|
162
|
+
return it.children = it.values, it;
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
box = this.box || this.svg.getBoundingClientRect();
|
|
166
|
+
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
167
|
+
w = h = Math.min(w, h);
|
|
168
|
+
this.treemap = new voronoi.Treemap(this.parsed, voronoi.Polygon.create(w, h, 60), w, h);
|
|
169
|
+
sites = this.treemap.getSites();
|
|
170
|
+
x$ = this.g.shape.selectAll('path.data').data(this.treemap.getPolygons());
|
|
171
|
+
x$.exit().remove();
|
|
172
|
+
x$.enter().append('path').attr('class', 'data').each(function(d, i){
|
|
173
|
+
return d.idx = i;
|
|
174
|
+
});
|
|
175
|
+
this.g.shape.selectAll('path.data').attr('class', function(d, i){
|
|
176
|
+
if (sites[i].lv <= 0) {
|
|
177
|
+
return 'data group';
|
|
178
|
+
} else {
|
|
179
|
+
return 'data';
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
this.polygons = this.g.shape.selectAll('path.data');
|
|
183
|
+
y$ = this.g.shape.selectAll('g.label').data(sites);
|
|
184
|
+
y$.exit().remove();
|
|
185
|
+
y$.enter().append('g').attr('class', 'label').each(function(d, i){
|
|
186
|
+
var x$;
|
|
187
|
+
x$ = d3.select(this);
|
|
188
|
+
x$.append('text').attr('class', 'name').attr('font-size', '.8em');
|
|
189
|
+
x$.append('text').attr('class', 'value');
|
|
190
|
+
return x$;
|
|
191
|
+
});
|
|
192
|
+
this.sites = this.g.shape.selectAll('g.label');
|
|
193
|
+
return this.sites.each(function(d, i){
|
|
194
|
+
return d3.select(this).selectAll('text').data([d, d]).attr('text-anchor', 'middle').attr('dominant-baseline', 'center');
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
resize: function(){
|
|
198
|
+
var box, ref$, w, h, s, sites;
|
|
199
|
+
box = this.layout.getBox('view');
|
|
200
|
+
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
201
|
+
s = Math.min(w, h);
|
|
202
|
+
this.legend.config(this.cfg.legend);
|
|
203
|
+
this.legend.update();
|
|
204
|
+
this.layout.update(false);
|
|
205
|
+
this.g.shape.attr('transform', "translate(" + (w / 2 - s / 2) + "," + (h / 2 - s / 2) + ")");
|
|
206
|
+
this.scale = {
|
|
207
|
+
x: d3.scaleLinear().domain([0, w]).range([0, w]),
|
|
208
|
+
y: d3.scaleLinear().domain([0, h]).range([0, h]),
|
|
209
|
+
color: d3.interpolateTurbo
|
|
210
|
+
};
|
|
211
|
+
if (this.cfg != null && this.cfg.palette) {
|
|
212
|
+
this.scale.color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
|
|
213
|
+
return ldcolor.web(it.value || it);
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
this.tint.set(this.cfg.palette);
|
|
217
|
+
sites = this.treemap.getSites();
|
|
218
|
+
this.count = 0;
|
|
219
|
+
return this.gbox = this.svg.getBoundingClientRect();
|
|
220
|
+
},
|
|
221
|
+
render: function(tick){
|
|
222
|
+
var sites, polygons, ref$, w, h, siteBoxes, boxes, this$ = this;
|
|
223
|
+
tick == null && (tick = false);
|
|
224
|
+
this._sites = sites = this.treemap.getSites();
|
|
225
|
+
polygons = this.treemap.getPolygons();
|
|
226
|
+
ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
|
|
227
|
+
if (!tick) {
|
|
228
|
+
this.legend.render();
|
|
229
|
+
this.sites.selectAll('.name').attr('dy', '0.88em').text(function(it){
|
|
230
|
+
var n;
|
|
231
|
+
n = (it.name || '') + "";
|
|
232
|
+
return n;
|
|
233
|
+
if (it.lv > 0) {
|
|
234
|
+
return n.substring(0, 7) + (n.length > 7 ? '...' : '');
|
|
181
235
|
} else {
|
|
182
|
-
return '
|
|
236
|
+
return '';
|
|
183
237
|
}
|
|
238
|
+
}).attr('fill', function(d, i){
|
|
239
|
+
if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
|
|
240
|
+
return '#000';
|
|
241
|
+
} else {
|
|
242
|
+
return '#eee';
|
|
243
|
+
}
|
|
244
|
+
}).style('pointer-events', 'none');
|
|
245
|
+
this.sites.selectAll('.value').attr('dy', '-0.28em').text(function(it){
|
|
246
|
+
if (it.lv > 0) {
|
|
247
|
+
return (it.value || 0).toFixed(2);
|
|
248
|
+
} else {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
}).attr('fill', function(d, i){
|
|
252
|
+
if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
|
|
253
|
+
return '#000';
|
|
254
|
+
} else {
|
|
255
|
+
return '#eee';
|
|
256
|
+
}
|
|
257
|
+
}).style('pointer-events', 'none');
|
|
258
|
+
this.siteBoxes = siteBoxes = [];
|
|
259
|
+
this.sites.each(function(d, i){
|
|
260
|
+
return siteBoxes.push(this.getBoundingClientRect());
|
|
184
261
|
});
|
|
185
|
-
this.polygons
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return d3.select(this).selectAll('text').data([d, d]).attr('text-anchor', 'middle').attr('dominant-baseline', 'center');
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
resize: function(){
|
|
201
|
-
var box, ref$, w, h, s, sites;
|
|
202
|
-
box = this.layout.getBox('view');
|
|
203
|
-
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
204
|
-
s = Math.min(w, h);
|
|
205
|
-
this.legend.config(this.cfg.legend);
|
|
206
|
-
this.legend.update();
|
|
207
|
-
this.layout.update(false);
|
|
208
|
-
this.g.shape.attr('transform', "translate(" + (w / 2 - s / 2) + "," + (h / 2 - s / 2) + ")");
|
|
209
|
-
this.scale = {
|
|
210
|
-
x: d3.scaleLinear().domain([0, w]).range([0, w]),
|
|
211
|
-
y: d3.scaleLinear().domain([0, h]).range([0, h]),
|
|
212
|
-
color: d3.interpolateTurbo
|
|
213
|
-
};
|
|
214
|
-
if (this.cfg != null && this.cfg.palette) {
|
|
215
|
-
this.scale.color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
|
|
216
|
-
return ldcolor.web(it.value || it);
|
|
217
|
-
}));
|
|
218
|
-
}
|
|
219
|
-
this.tint.set(this.cfg.palette);
|
|
220
|
-
sites = this.treemap.getSites();
|
|
221
|
-
this.count = 0;
|
|
222
|
-
return this.gbox = this.svg.getBoundingClientRect();
|
|
223
|
-
},
|
|
224
|
-
render: function(tick){
|
|
225
|
-
var sites, polygons, ref$, w, h, siteBoxes, boxes, this$ = this;
|
|
226
|
-
tick == null && (tick = false);
|
|
227
|
-
this._sites = sites = this.treemap.getSites();
|
|
228
|
-
polygons = this.treemap.getPolygons();
|
|
229
|
-
ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
|
|
230
|
-
if (!tick) {
|
|
231
|
-
this.legend.render();
|
|
232
|
-
this.sites.selectAll('.name').attr('dy', '0.88em').text(function(it){
|
|
233
|
-
var n;
|
|
234
|
-
n = (it.name || '') + "";
|
|
235
|
-
return n;
|
|
236
|
-
if (it.lv > 0) {
|
|
237
|
-
return n.substring(0, 7) + (n.length > 7 ? '...' : '');
|
|
238
|
-
} else {
|
|
239
|
-
return '';
|
|
240
|
-
}
|
|
241
|
-
}).attr('fill', function(d, i){
|
|
242
|
-
if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
|
|
243
|
-
return '#000';
|
|
244
|
-
} else {
|
|
245
|
-
return '#eee';
|
|
246
|
-
}
|
|
247
|
-
}).style('pointer-events', 'none');
|
|
248
|
-
this.sites.selectAll('.value').attr('dy', '-0.28em').text(function(it){
|
|
249
|
-
if (it.lv > 0) {
|
|
250
|
-
return (it.value || 0).toFixed(2);
|
|
251
|
-
} else {
|
|
252
|
-
return '';
|
|
253
|
-
}
|
|
254
|
-
}).attr('fill', function(d, i){
|
|
255
|
-
if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
|
|
256
|
-
return '#000';
|
|
257
|
-
} else {
|
|
258
|
-
return '#eee';
|
|
259
|
-
}
|
|
260
|
-
}).style('pointer-events', 'none');
|
|
261
|
-
this.siteBoxes = siteBoxes = [];
|
|
262
|
-
this.sites.each(function(d, i){
|
|
263
|
-
return siteBoxes.push(this.getBoundingClientRect());
|
|
264
|
-
});
|
|
265
|
-
this.polygons.attr('fill', function(d, i){
|
|
266
|
-
return this$.tint.get(sites[i].category);
|
|
267
|
-
}).attr('stroke', '#fff').attr('stroke-width', 1);
|
|
262
|
+
this.polygons.attr('fill', function(d, i){
|
|
263
|
+
return this$.tint.get(sites[i].category);
|
|
264
|
+
}).attr('stroke', '#fff').attr('stroke-width', 1);
|
|
265
|
+
}
|
|
266
|
+
siteBoxes = this.siteBoxes;
|
|
267
|
+
boxes = [];
|
|
268
|
+
this.polygons.data(polygons).attr('d', function(d, i){
|
|
269
|
+
var ret, ref$, min, max, i$, to$, idx, x, y;
|
|
270
|
+
d.idx = i;
|
|
271
|
+
if (!(d && d.length)) {
|
|
272
|
+
boxes.push({});
|
|
273
|
+
return "";
|
|
268
274
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
ret = [['M', d[0].x, d[0].y]];
|
|
276
|
+
ref$ = [
|
|
277
|
+
{
|
|
278
|
+
x: d[0].x,
|
|
279
|
+
y: d[0].y
|
|
280
|
+
}, {
|
|
281
|
+
x: d[0].x,
|
|
282
|
+
y: d[0].y
|
|
277
283
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
x: d[0].x,
|
|
285
|
-
y: d[0].y
|
|
286
|
-
}
|
|
287
|
-
], min = ref$[0], max = ref$[1];
|
|
288
|
-
for (i$ = 0, to$ = d.length; i$ < to$; ++i$) {
|
|
289
|
-
idx = i$;
|
|
290
|
-
ref$ = [d[idx].x, d[idx].y], x = ref$[0], y = ref$[1];
|
|
291
|
-
if (min.x > x) {
|
|
292
|
-
min.x = x;
|
|
293
|
-
}
|
|
294
|
-
if (max.x < x) {
|
|
295
|
-
max.x = x;
|
|
296
|
-
}
|
|
297
|
-
if (min.y > y) {
|
|
298
|
-
min.y = y;
|
|
299
|
-
}
|
|
300
|
-
if (max.y < y) {
|
|
301
|
-
max.y = y;
|
|
302
|
-
}
|
|
303
|
-
ret.push(['L', x, y]);
|
|
284
|
+
], min = ref$[0], max = ref$[1];
|
|
285
|
+
for (i$ = 0, to$ = d.length; i$ < to$; ++i$) {
|
|
286
|
+
idx = i$;
|
|
287
|
+
ref$ = [d[idx].x, d[idx].y], x = ref$[0], y = ref$[1];
|
|
288
|
+
if (min.x > x) {
|
|
289
|
+
min.x = x;
|
|
304
290
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
x: min.x,
|
|
308
|
-
y: min.y,
|
|
309
|
-
width: max.x - min.x,
|
|
310
|
-
height: max.y - min.y
|
|
311
|
-
});
|
|
312
|
-
return ret.map(function(it){
|
|
313
|
-
return it.join(' ');
|
|
314
|
-
}).join(' ');
|
|
315
|
-
});
|
|
316
|
-
return this.sites.each(function(d, i){
|
|
317
|
-
var box, mybox;
|
|
318
|
-
box = boxes[i];
|
|
319
|
-
mybox = siteBoxes[i];
|
|
320
|
-
if (!mybox) {
|
|
321
|
-
mybox = this.getBoundingClientRect();
|
|
291
|
+
if (max.x < x) {
|
|
292
|
+
max.x = x;
|
|
322
293
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
});
|
|
294
|
+
if (min.y > y) {
|
|
295
|
+
min.y = y;
|
|
296
|
+
}
|
|
297
|
+
if (max.y < y) {
|
|
298
|
+
max.y = y;
|
|
299
|
+
}
|
|
300
|
+
ret.push(['L', x, y]);
|
|
301
|
+
}
|
|
302
|
+
ret.push(['L', d[0].x, d[0].y]);
|
|
303
|
+
boxes.push({
|
|
304
|
+
x: min.x,
|
|
305
|
+
y: min.y,
|
|
306
|
+
width: max.x - min.x,
|
|
307
|
+
height: max.y - min.y
|
|
338
308
|
});
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
309
|
+
return ret.map(function(it){
|
|
310
|
+
return it.join(' ');
|
|
311
|
+
}).join(' ');
|
|
312
|
+
});
|
|
313
|
+
return this.sites.each(function(d, i){
|
|
314
|
+
var box, mybox;
|
|
315
|
+
box = boxes[i];
|
|
316
|
+
mybox = siteBoxes[i];
|
|
317
|
+
if (!mybox) {
|
|
318
|
+
mybox = this.getBoundingClientRect();
|
|
345
319
|
}
|
|
320
|
+
return d3.select(this).attr('transform', function(){
|
|
321
|
+
var x, y;
|
|
322
|
+
x = box.x + box.width / 2;
|
|
323
|
+
y = box.y + box.height / 2;
|
|
324
|
+
if (isNaN(x)) {
|
|
325
|
+
x = -10000;
|
|
326
|
+
}
|
|
327
|
+
if (isNaN(y)) {
|
|
328
|
+
y = -10000;
|
|
329
|
+
}
|
|
330
|
+
return "translate(" + x + ", " + y + ")";
|
|
331
|
+
}).attr('opacity', function(){
|
|
332
|
+
var ref$, ref1$, ref2$;
|
|
333
|
+
return (ref$ = 1 - 6 * ((ref1$ = mybox.width / ((ref2$ = box.width) > 0 ? ref2$ : 0) - 1) > 0 ? ref1$ : 0)) > 0 ? ref$ : 0;
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
tick: function(){
|
|
338
|
+
this.count = (this.count || 0) + 1;
|
|
339
|
+
if (this.count < 100) {
|
|
340
|
+
this.treemap.compute();
|
|
341
|
+
return this.render(true);
|
|
346
342
|
}
|
|
347
|
-
}
|
|
343
|
+
}
|
|
348
344
|
};
|
|
349
|
-
|
|
350
|
-
});</script></div>
|
|
345
|
+
};</script></div>
|