@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
|
@@ -36,323 +36,318 @@
|
|
|
36
36
|
grid-column: 2;
|
|
37
37
|
grid-row: 2;
|
|
38
38
|
}
|
|
39
|
-
</style><script type="@plotdb/block">
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name:
|
|
46
|
-
version:
|
|
47
|
-
extend: {
|
|
48
|
-
name: "base",
|
|
49
|
-
version: "0.0.1"
|
|
50
|
-
},
|
|
51
|
-
dependencies: [],
|
|
52
|
-
i18n: {
|
|
53
|
-
"zh-TW": {
|
|
54
|
-
"other": "其它",
|
|
55
|
-
"unit": "單位"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
39
|
+
</style><script type="@plotdb/block">var mod;
|
|
40
|
+
module.exports = {
|
|
41
|
+
pkg: {
|
|
42
|
+
name: 'treemap',
|
|
43
|
+
version: '0.0.1',
|
|
44
|
+
extend: {
|
|
45
|
+
name: "base",
|
|
46
|
+
version: "0.0.1"
|
|
58
47
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
context: context,
|
|
66
|
-
t: t
|
|
67
|
-
})
|
|
68
|
-
});
|
|
48
|
+
dependencies: [],
|
|
49
|
+
i18n: {
|
|
50
|
+
"zh-TW": {
|
|
51
|
+
"other": "其它",
|
|
52
|
+
"unit": "單位"
|
|
53
|
+
}
|
|
69
54
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
var root, context,
|
|
73
|
-
root = arg$.root, context = arg$.context, t = arg$.t;
|
|
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
|
-
},
|
|
101
|
-
config: {
|
|
102
|
-
unitPosition: {
|
|
103
|
-
type: 'choice',
|
|
104
|
-
values: ['inner', 'outside', 'none']
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
dimension: {
|
|
108
|
-
color: {
|
|
109
|
-
type: 'RC',
|
|
110
|
-
name: "顏色",
|
|
111
|
-
priority: 4
|
|
112
|
-
},
|
|
113
|
-
area: {
|
|
114
|
-
type: 'R',
|
|
115
|
-
name: "面積",
|
|
116
|
-
priority: 1
|
|
117
|
-
},
|
|
118
|
-
name: {
|
|
119
|
-
type: 'NC',
|
|
120
|
-
name: "名稱",
|
|
121
|
-
priority: 2
|
|
122
|
-
},
|
|
123
|
-
category: {
|
|
124
|
-
type: 'C',
|
|
125
|
-
name: "分類",
|
|
126
|
-
priority: 3
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
init: function(){
|
|
130
|
-
var tint, textRenderer, ref$, this$ = this;
|
|
131
|
-
this.tint = tint = new chart.utils.tint();
|
|
132
|
-
this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
|
|
133
|
-
return [it, d3.select(this$.layout.getGroup(it))];
|
|
134
|
-
}));
|
|
135
|
-
this.textRenderer = textRenderer = document.createElement('div');
|
|
136
|
-
import$(textRenderer.style, {
|
|
137
|
-
textAlign: 'right',
|
|
138
|
-
fontSize: '0.9em',
|
|
139
|
-
padding: ".5em .5em",
|
|
140
|
-
lineHeight: '1.1em',
|
|
141
|
-
whiteSpace: "pre-line",
|
|
142
|
-
display: 'inline-block',
|
|
143
|
-
position: 'absolute',
|
|
144
|
-
top: 0,
|
|
145
|
-
left: 0,
|
|
146
|
-
opacity: 0,
|
|
147
|
-
pointerEvents: 'none',
|
|
148
|
-
userSelect: 'none',
|
|
149
|
-
zIndex: 0
|
|
150
|
-
});
|
|
151
|
-
root.appendChild(textRenderer);
|
|
152
|
-
this.legend = new chart.utils.legend({
|
|
153
|
-
layout: this.layout,
|
|
154
|
-
name: 'legend',
|
|
155
|
-
root: this.root,
|
|
156
|
-
shape: function(d){
|
|
157
|
-
return d3.select(this).attr('fill', tint.get(d.key));
|
|
55
|
+
},
|
|
56
|
+
init: function(arg$){
|
|
57
|
+
var root, context, pubsub, t;
|
|
58
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
|
|
59
|
+
return pubsub.fire('init', {
|
|
60
|
+
mod: mod({
|
|
61
|
+
root: root,
|
|
62
|
+
context: context,
|
|
63
|
+
t: t
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
mod = function(arg$){
|
|
69
|
+
var root, context, t, chart, d3, ldcolor, wrapSvgText;
|
|
70
|
+
root = arg$.root, context = arg$.context, t = arg$.t;
|
|
71
|
+
chart = context.chart, d3 = context.d3, ldcolor = context.ldcolor, wrapSvgText = context.wrapSvgText;
|
|
72
|
+
return {
|
|
73
|
+
sample: function(){
|
|
74
|
+
return {
|
|
75
|
+
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].map(function(val){
|
|
76
|
+
return {
|
|
77
|
+
val: Math.random().toFixed(2),
|
|
78
|
+
cat: Math.floor(1 + 6 * Math.random())
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
binding: {
|
|
82
|
+
color: {
|
|
83
|
+
key: 'cat'
|
|
158
84
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
this.legend.on('select', function(){
|
|
165
|
-
this$.bind();
|
|
166
|
-
this$.resize();
|
|
167
|
-
return this$.render();
|
|
168
|
-
});
|
|
169
|
-
return this.tip = new chart.utils.tip({
|
|
170
|
-
root: this.root,
|
|
171
|
-
accessor: function(arg$){
|
|
172
|
-
var evt, data, v;
|
|
173
|
-
evt = arg$.evt;
|
|
174
|
-
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
v = isNaN(data.data.area)
|
|
178
|
-
? '-'
|
|
179
|
-
: data.data.area.toFixed(2) + "" + (this$.binding.area.unit || '');
|
|
180
|
-
return {
|
|
181
|
-
name: data.data.name,
|
|
182
|
-
value: v
|
|
183
|
-
};
|
|
85
|
+
area: {
|
|
86
|
+
key: 'val',
|
|
87
|
+
unit: 'MB'
|
|
184
88
|
},
|
|
185
|
-
|
|
186
|
-
|
|
89
|
+
name: {
|
|
90
|
+
key: 'cat'
|
|
91
|
+
},
|
|
92
|
+
category: {
|
|
93
|
+
key: 'cat'
|
|
187
94
|
}
|
|
188
|
-
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
config: {
|
|
99
|
+
unitPosition: {
|
|
100
|
+
type: 'choice',
|
|
101
|
+
values: ['inner', 'outside', 'none']
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
dimension: {
|
|
105
|
+
color: {
|
|
106
|
+
type: 'RC',
|
|
107
|
+
name: "顏色",
|
|
108
|
+
priority: 4
|
|
189
109
|
},
|
|
190
|
-
|
|
191
|
-
|
|
110
|
+
area: {
|
|
111
|
+
type: 'R',
|
|
112
|
+
name: "面積",
|
|
113
|
+
priority: 1
|
|
192
114
|
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
115
|
+
name: {
|
|
116
|
+
type: 'NC',
|
|
117
|
+
name: "名稱",
|
|
118
|
+
priority: 2
|
|
119
|
+
},
|
|
120
|
+
category: {
|
|
121
|
+
type: 'C',
|
|
122
|
+
name: "分類",
|
|
123
|
+
priority: 3
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
init: function(){
|
|
127
|
+
var tint, textRenderer, ref$, this$ = this;
|
|
128
|
+
this.tint = tint = new chart.utils.tint();
|
|
129
|
+
this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
|
|
130
|
+
return [it, d3.select(this$.layout.getGroup(it))];
|
|
131
|
+
}));
|
|
132
|
+
this.textRenderer = textRenderer = document.createElement('div');
|
|
133
|
+
import$(textRenderer.style, {
|
|
134
|
+
textAlign: 'right',
|
|
135
|
+
fontSize: '0.9em',
|
|
136
|
+
padding: ".5em .5em",
|
|
137
|
+
lineHeight: '1.1em',
|
|
138
|
+
whiteSpace: "pre-line",
|
|
139
|
+
display: 'inline-block',
|
|
140
|
+
position: 'absolute',
|
|
141
|
+
top: 0,
|
|
142
|
+
left: 0,
|
|
143
|
+
opacity: 0,
|
|
144
|
+
pointerEvents: 'none',
|
|
145
|
+
userSelect: 'none',
|
|
146
|
+
zIndex: 0
|
|
147
|
+
});
|
|
148
|
+
root.appendChild(textRenderer);
|
|
149
|
+
this.legend = new chart.utils.legend({
|
|
150
|
+
layout: this.layout,
|
|
151
|
+
name: 'legend',
|
|
152
|
+
root: this.root,
|
|
153
|
+
shape: function(d){
|
|
154
|
+
return d3.select(this).attr('fill', tint.get(d.key));
|
|
155
|
+
},
|
|
156
|
+
direction: ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom' ? 'horizontal' : 'vertical',
|
|
157
|
+
cfg: {
|
|
158
|
+
selectable: true
|
|
207
159
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
for (k in ref$ = hash) {
|
|
222
|
-
v = ref$[k];
|
|
223
|
-
results$.push(v);
|
|
160
|
+
});
|
|
161
|
+
this.legend.on('select', function(){
|
|
162
|
+
this$.bind();
|
|
163
|
+
this$.resize();
|
|
164
|
+
return this$.render();
|
|
165
|
+
});
|
|
166
|
+
return this.tip = new chart.utils.tip({
|
|
167
|
+
root: this.root,
|
|
168
|
+
accessor: function(arg$){
|
|
169
|
+
var evt, data, v;
|
|
170
|
+
evt = arg$.evt;
|
|
171
|
+
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
172
|
+
return null;
|
|
224
173
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}]);
|
|
229
|
-
return this.legend.data(this.cats.map(function(it){
|
|
174
|
+
v = isNaN(data.data.area)
|
|
175
|
+
? '-'
|
|
176
|
+
: data.data.area.toFixed(2) + "" + (this$.binding.area.unit || '');
|
|
230
177
|
return {
|
|
231
|
-
|
|
232
|
-
|
|
178
|
+
name: data.data.name,
|
|
179
|
+
value: v
|
|
233
180
|
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
181
|
+
},
|
|
182
|
+
range: function(){
|
|
183
|
+
return this$.layout.getNode('view').getBoundingClientRect();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
destroy: function(){
|
|
188
|
+
return this.tip.destroy();
|
|
189
|
+
},
|
|
190
|
+
parse: function(){
|
|
191
|
+
var hash, k, v;
|
|
192
|
+
this.tint.reset();
|
|
193
|
+
hash = {};
|
|
194
|
+
this.data.map(function(d, i){
|
|
195
|
+
d.id = "name-" + i;
|
|
196
|
+
if (!d.category || d.category === "") {
|
|
197
|
+
return d.category = t("other");
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
if (!this.binding.category) {
|
|
201
|
+
this.data.map(function(d){
|
|
202
|
+
return d.category = 'root-1';
|
|
246
203
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
|
|
253
|
-
this.unit = {
|
|
254
|
-
inner: ((ref$ = this.cfg).unit || (ref$.unit = {})).position === 'inner' ? this.binding.area.unit || '' : '',
|
|
255
|
-
outer: (ref$ = ((ref1$ = this.cfg).unit || (ref1$.unit = {})).position) === 'inner' || ref$ === 'none'
|
|
256
|
-
? ''
|
|
257
|
-
: this.binding.area.unit ? t('unit') + ": " + (this.binding.area.unit || '') : ''
|
|
204
|
+
}
|
|
205
|
+
this.data.map(function(it){
|
|
206
|
+
return hash[it.category] = {
|
|
207
|
+
id: it.category,
|
|
208
|
+
category: 'root'
|
|
258
209
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}).
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
210
|
+
});
|
|
211
|
+
this.cats = Array.from(new Set(this.data.map(function(it){
|
|
212
|
+
return it.category;
|
|
213
|
+
}))).filter(function(it){
|
|
214
|
+
return it !== 'root-1';
|
|
215
|
+
});
|
|
216
|
+
this.data = this.data.concat((function(){
|
|
217
|
+
var ref$, results$ = [];
|
|
218
|
+
for (k in ref$ = hash) {
|
|
219
|
+
v = ref$[k];
|
|
220
|
+
results$.push(v);
|
|
221
|
+
}
|
|
222
|
+
return results$;
|
|
223
|
+
}()), [{
|
|
224
|
+
id: 'root'
|
|
225
|
+
}]);
|
|
226
|
+
return this.legend.data(this.cats.map(function(it){
|
|
227
|
+
return {
|
|
228
|
+
key: it,
|
|
229
|
+
text: it
|
|
230
|
+
};
|
|
231
|
+
}));
|
|
232
|
+
},
|
|
233
|
+
bind: function(){
|
|
234
|
+
var data, s, this$ = this;
|
|
235
|
+
data = this.data.filter(function(it){
|
|
236
|
+
var ref$;
|
|
237
|
+
return it.id === 'root' || ((ref$ = it.category) === 'root' || ref$ === 'root-1') || this$.legend.isSelected(it.category);
|
|
238
|
+
});
|
|
239
|
+
s = d3.stratify().id(function(it){
|
|
240
|
+
return it.id;
|
|
241
|
+
}).parentId(function(it){
|
|
242
|
+
return it.category;
|
|
243
|
+
});
|
|
244
|
+
return this.ret = s(data);
|
|
245
|
+
},
|
|
246
|
+
resize: function(){
|
|
247
|
+
var ref$, ref1$, x$, box, tree;
|
|
248
|
+
this.root.querySelector('.pdl-layout').classList.toggle('legend-bottom', ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom');
|
|
249
|
+
this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
|
|
250
|
+
this.unit = {
|
|
251
|
+
inner: ((ref$ = this.cfg).unit || (ref$.unit = {})).position === 'inner' ? this.binding.area.unit || '' : '',
|
|
252
|
+
outer: (ref$ = ((ref1$ = this.cfg).unit || (ref1$.unit = {})).position) === 'inner' || ref$ === 'none'
|
|
253
|
+
? ''
|
|
254
|
+
: this.binding.area.unit ? t('unit') + ": " + (this.binding.area.unit || '') : ''
|
|
255
|
+
};
|
|
256
|
+
x$ = this.layout.getNode('unit');
|
|
257
|
+
x$.style.display = !this.unit.outer ? 'none' : '';
|
|
258
|
+
x$.textContent = this.unit.outer;
|
|
259
|
+
this.legend.config(this.cfg.legend);
|
|
260
|
+
this.legend.update();
|
|
261
|
+
this.layout.update(false);
|
|
262
|
+
this.ret.sum(function(it){
|
|
263
|
+
return it.area;
|
|
264
|
+
});
|
|
265
|
+
box = this.layout.getBox('view');
|
|
266
|
+
tree = d3.treemap().padding(1).size([box.width, box.height])(this.ret);
|
|
267
|
+
this.nodes = this.ret.leaves().filter(function(it){
|
|
268
|
+
return it.data._raw;
|
|
269
|
+
});
|
|
270
|
+
this.nodes.map(function(it){
|
|
271
|
+
return it._raw = it.data._raw;
|
|
272
|
+
});
|
|
273
|
+
return this.extent = d3.extent(this.nodes.map(function(it){
|
|
274
|
+
return it.value;
|
|
275
|
+
}));
|
|
276
|
+
},
|
|
277
|
+
render: function(){
|
|
278
|
+
var cfg, unit, binding, layout, textRenderer, tint, x$, y$, this$ = this;
|
|
279
|
+
cfg = this.cfg, unit = this.unit, binding = this.binding, layout = this.layout, textRenderer = this.textRenderer, tint = this.tint;
|
|
280
|
+
tint.set(cfg.palette);
|
|
281
|
+
this.g.unit.call(function(){
|
|
282
|
+
var node, ret;
|
|
283
|
+
node = layout.getNode('unit');
|
|
284
|
+
ret = wrapSvgText({
|
|
285
|
+
node: node,
|
|
286
|
+
useRange: true
|
|
324
287
|
});
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
288
|
+
this$.g.unit.node().textContent = '';
|
|
289
|
+
return this$.g.unit.node().appendChild(ret);
|
|
290
|
+
});
|
|
291
|
+
x$ = this.g.view.selectAll('rect.data').data(this.nodes, function(it){
|
|
292
|
+
return it._raw._idx;
|
|
293
|
+
});
|
|
294
|
+
x$.exit().remove();
|
|
295
|
+
x$.enter().append('rect').attr('class', 'data').attr('x', function(it){
|
|
296
|
+
return (it.x1 + it.x0) / 2 - (it.x1 - it.x0) / 4;
|
|
297
|
+
}).attr('y', function(it){
|
|
298
|
+
return (it.y1 + it.y0) / 2 - (it.y1 - it.y0) / 4;
|
|
299
|
+
}).attr('width', function(it){
|
|
300
|
+
return (it.x1 - it.x0) / 2;
|
|
301
|
+
}).attr('height', function(it){
|
|
302
|
+
return (it.y1 - it.y0) / 2;
|
|
303
|
+
}).attr('fill', function(it){
|
|
304
|
+
return tint.get(it.data.color || it.data.category);
|
|
305
|
+
}).style('opacity', 0);
|
|
306
|
+
this.g.view.selectAll('rect').transition().duration(350).attr('x', function(it){
|
|
307
|
+
return it.x0;
|
|
308
|
+
}).attr('y', function(it){
|
|
309
|
+
return it.y0;
|
|
310
|
+
}).attr('width', function(it){
|
|
311
|
+
return it.x1 - it.x0;
|
|
312
|
+
}).attr('height', function(it){
|
|
313
|
+
return it.y1 - it.y0;
|
|
314
|
+
}).attr('fill', function(it){
|
|
315
|
+
var v;
|
|
316
|
+
v = (it.value - this$.extent[0]) / (this$.extent[1] - this$.extent[0]) - 0.5;
|
|
317
|
+
return tint.get(it.data.color || it.data.category);
|
|
318
|
+
}).style('opacity', 1);
|
|
319
|
+
y$ = this.g.view.selectAll('g.label').data(this.nodes, function(it){
|
|
320
|
+
return it._raw._idx;
|
|
321
|
+
});
|
|
322
|
+
y$.exit().remove();
|
|
323
|
+
y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
|
|
324
|
+
return "translate(" + d.x0 + "," + d.y0 + ")";
|
|
325
|
+
}).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer');
|
|
326
|
+
this.g.view.selectAll('g.label').attr('font-size', '0.9em').each(function(d, i){
|
|
327
|
+
var area, ret;
|
|
328
|
+
textRenderer.style.width = (d.x1 - d.x0) + "px";
|
|
329
|
+
area = d.data.area;
|
|
330
|
+
area = d3.format('.3s')(area);
|
|
331
|
+
textRenderer.innerHTML = "<div>" + (d.data.name || '') + "</div>\n<div>" + area + unit.inner + "</div>";
|
|
332
|
+
ret = wrapSvgText({
|
|
333
|
+
node: textRenderer,
|
|
334
|
+
useRange: true
|
|
349
335
|
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
336
|
+
this.textContent = '';
|
|
337
|
+
return this.appendChild(ret);
|
|
338
|
+
}).transition().duration(350).attr('transform', function(d, i){
|
|
339
|
+
return "translate(" + d.x0 + "," + d.y0 + ")";
|
|
340
|
+
}).attr('fill', function(it){
|
|
341
|
+
return tint.text(it.data.color || it.data.category);
|
|
342
|
+
}).attr('opacity', function(d, i){
|
|
343
|
+
var box;
|
|
344
|
+
box = this.getBBox();
|
|
345
|
+
return box.width > d.x1 - d.x0 || box.height > d.y1 - d.y0 ? 0 : 1;
|
|
346
|
+
});
|
|
347
|
+
return this.legend.render();
|
|
348
|
+
}
|
|
353
349
|
};
|
|
354
|
-
|
|
355
|
-
});
|
|
350
|
+
};
|
|
356
351
|
function import$(obj, src){
|
|
357
352
|
var own = {}.hasOwnProperty;
|
|
358
353
|
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|