@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
|
@@ -19,384 +19,404 @@
|
|
|
19
19
|
text-align: right;
|
|
20
20
|
padding: 0.25em 0;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
.pdl-layout.legend-bottom > div[data-type=layout] {
|
|
23
|
+
grid-template-columns: 1fr fit-content(1em);
|
|
24
|
+
grid-template-rows: 1fr fit-content(3em);
|
|
25
|
+
}
|
|
26
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=view] {
|
|
27
|
+
grid-column: 1/span 2;
|
|
28
|
+
grid-row: 1;
|
|
29
|
+
}
|
|
30
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=legend] {
|
|
31
|
+
padding-top: 1em;
|
|
32
|
+
grid-column: 1;
|
|
33
|
+
grid-row: 2;
|
|
34
|
+
}
|
|
35
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=unit] {
|
|
36
|
+
padding-top: 1em;
|
|
37
|
+
grid-column: 2;
|
|
38
|
+
grid-row: 2;
|
|
39
|
+
}
|
|
40
|
+
</style><script type="@plotdb/block">var mod;
|
|
41
|
+
module.exports = {
|
|
42
|
+
pkg: {
|
|
43
|
+
name: 'bubble',
|
|
44
|
+
version: '0.0.1',
|
|
45
|
+
extend: {
|
|
46
|
+
name: "base",
|
|
47
|
+
version: "0.0.1"
|
|
41
48
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
t: t
|
|
49
|
-
})
|
|
50
|
-
}).then(function(it){
|
|
51
|
-
return it[0];
|
|
52
|
-
});
|
|
49
|
+
dependencies: [],
|
|
50
|
+
i18n: {
|
|
51
|
+
"zh-TW": {
|
|
52
|
+
"K": '千',
|
|
53
|
+
"M": '百萬'
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
context = arg$.context, t = arg$.t;
|
|
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
|
-
config: {},
|
|
86
|
-
dimension: {
|
|
87
|
-
group: {
|
|
88
|
-
type: 'C',
|
|
89
|
-
name: "group",
|
|
90
|
-
priority: 2
|
|
91
|
-
},
|
|
92
|
-
color: {
|
|
93
|
-
type: 'NR',
|
|
94
|
-
name: "color",
|
|
95
|
-
priority: 4
|
|
96
|
-
},
|
|
97
|
-
area: {
|
|
98
|
-
type: 'R',
|
|
99
|
-
name: "area",
|
|
100
|
-
priority: 1
|
|
101
|
-
},
|
|
102
|
-
name: {
|
|
103
|
-
type: 'NC',
|
|
104
|
-
name: "name",
|
|
105
|
-
priority: 3
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
init: function(){
|
|
109
|
-
var tint, node, this$ = this;
|
|
110
|
-
this.tint = tint = new chart.utils.tint();
|
|
111
|
-
this.parsed = this.parsed || [];
|
|
112
|
-
this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
|
|
113
|
-
return [it, d3.select(this$.layout.getGroup(it))];
|
|
114
|
-
}));
|
|
115
|
-
node = this.root.querySelector('[ld=tip]');
|
|
116
|
-
this.tip = new chart.utils.tip({
|
|
117
|
-
root: this.root,
|
|
118
|
-
accessor: function(arg$){
|
|
119
|
-
var evt, data;
|
|
120
|
-
evt = arg$.evt;
|
|
121
|
-
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
name: data.name,
|
|
126
|
-
value: data.area + "" + (this$.binding.area.unit || '')
|
|
127
|
-
};
|
|
56
|
+
},
|
|
57
|
+
init: function(arg$){
|
|
58
|
+
var root, context, pubsub, t;
|
|
59
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
|
|
60
|
+
return pubsub.fire('init', {
|
|
61
|
+
mod: mod({
|
|
62
|
+
context: context,
|
|
63
|
+
t: t
|
|
64
|
+
})
|
|
65
|
+
}).then(function(it){
|
|
66
|
+
return it[0];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
mod = function(arg$){
|
|
71
|
+
var context, t, d3, forceBoundary, ldcolor, chart;
|
|
72
|
+
context = arg$.context, t = arg$.t;
|
|
73
|
+
d3 = context.d3, forceBoundary = context.forceBoundary, ldcolor = context.ldcolor, chart = context.chart;
|
|
74
|
+
return {
|
|
75
|
+
sample: function(){
|
|
76
|
+
return {
|
|
77
|
+
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){
|
|
78
|
+
return {
|
|
79
|
+
val: val,
|
|
80
|
+
cat: Math.floor(Math.random() * 5),
|
|
81
|
+
name: val
|
|
82
|
+
};
|
|
83
|
+
}),
|
|
84
|
+
binding: {
|
|
85
|
+
group: {
|
|
86
|
+
key: 'cat'
|
|
128
87
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
this.legend = new chart.utils.legend({
|
|
134
|
-
layout: this.layout,
|
|
135
|
-
name: 'legend',
|
|
136
|
-
root: this.root,
|
|
137
|
-
shape: function(d){
|
|
138
|
-
return d3.select(this).attr('fill', tint.get(d.key));
|
|
88
|
+
name: {
|
|
89
|
+
key: 'name'
|
|
139
90
|
},
|
|
140
|
-
|
|
141
|
-
|
|
91
|
+
color: {
|
|
92
|
+
key: 'cat'
|
|
93
|
+
},
|
|
94
|
+
area: {
|
|
95
|
+
key: 'val'
|
|
142
96
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
config: import$({}, chart.utils.config.preset['default']),
|
|
101
|
+
dimension: {
|
|
102
|
+
group: {
|
|
103
|
+
type: 'C',
|
|
104
|
+
name: "group",
|
|
105
|
+
priority: 2
|
|
149
106
|
},
|
|
150
|
-
|
|
151
|
-
|
|
107
|
+
color: {
|
|
108
|
+
type: 'NR',
|
|
109
|
+
name: "color",
|
|
110
|
+
priority: 4
|
|
152
111
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.groups = Array.from(new Set(this.valid.map(function(it){
|
|
158
|
-
return it.group;
|
|
159
|
-
}))).filter(function(it){
|
|
160
|
-
return it;
|
|
161
|
-
});
|
|
162
|
-
this.sim = null;
|
|
163
|
-
return this.legend.data(this.groups.map(function(it){
|
|
164
|
-
return {
|
|
165
|
-
key: it,
|
|
166
|
-
text: it
|
|
167
|
-
};
|
|
168
|
-
}));
|
|
112
|
+
area: {
|
|
113
|
+
type: 'R',
|
|
114
|
+
name: "area",
|
|
115
|
+
priority: 1
|
|
169
116
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
117
|
+
name: {
|
|
118
|
+
type: 'NC',
|
|
119
|
+
name: "name",
|
|
120
|
+
priority: 3
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
init: function(){
|
|
124
|
+
var tint, node, ref$, this$ = this;
|
|
125
|
+
this.tint = tint = new chart.utils.tint();
|
|
126
|
+
this.parsed = this.parsed || [];
|
|
127
|
+
this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
|
|
128
|
+
return [it, d3.select(this$.layout.getGroup(it))];
|
|
129
|
+
}));
|
|
130
|
+
node = this.root.querySelector('[ld=tip]');
|
|
131
|
+
this.tip = new chart.utils.tip({
|
|
132
|
+
root: this.root,
|
|
133
|
+
accessor: function(arg$){
|
|
134
|
+
var evt, data;
|
|
135
|
+
evt = arg$.evt;
|
|
136
|
+
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
179
139
|
return {
|
|
180
|
-
|
|
140
|
+
name: data.name,
|
|
141
|
+
value: data.area + "" + (this$.binding.area.unit || '')
|
|
181
142
|
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
143
|
+
},
|
|
144
|
+
range: function(){
|
|
145
|
+
return this$.layout.getNode('view').getBoundingClientRect();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
this.legend = new chart.utils.legend({
|
|
149
|
+
layout: this.layout,
|
|
150
|
+
name: 'legend',
|
|
151
|
+
root: this.root,
|
|
152
|
+
shape: function(d){
|
|
153
|
+
return d3.select(this).attr('fill', tint.get(d.key));
|
|
154
|
+
},
|
|
155
|
+
direction: ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom' ? 'horizontal' : 'vertical',
|
|
156
|
+
cfg: {
|
|
157
|
+
selectable: true
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return this.legend.on('select', function(){
|
|
161
|
+
this$.bind();
|
|
162
|
+
this$.resize();
|
|
163
|
+
return this$.render();
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
destroy: function(){
|
|
167
|
+
return this.tip.destroy();
|
|
168
|
+
},
|
|
169
|
+
parse: function(){
|
|
170
|
+
this.valid = this.data.filter(function(it){
|
|
171
|
+
return !isNaN(it.area);
|
|
172
|
+
});
|
|
173
|
+
this.groups = Array.from(new Set(this.valid.map(function(it){
|
|
174
|
+
return it.group;
|
|
175
|
+
}))).filter(function(it){
|
|
176
|
+
return it;
|
|
177
|
+
});
|
|
178
|
+
this.sim = null;
|
|
179
|
+
return this.legend.data(this.groups.map(function(it){
|
|
180
|
+
return {
|
|
181
|
+
key: it,
|
|
182
|
+
text: it
|
|
183
|
+
};
|
|
184
|
+
}));
|
|
185
|
+
},
|
|
186
|
+
resize: function(){
|
|
187
|
+
var ref$, list, ret, box, pack, this$ = this;
|
|
188
|
+
this.root.querySelector('.pdl-layout').classList.toggle('legend-bottom', ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom');
|
|
189
|
+
this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
|
|
190
|
+
(ref$ = this.cfg).legend || (ref$.legend = {});
|
|
191
|
+
this.random = d3.randomUniform.source(d3.randomLcg(+Date.now()))(0, 1);
|
|
192
|
+
list = [{
|
|
193
|
+
key: 'root',
|
|
194
|
+
root: true
|
|
195
|
+
}].concat(this.groups.map(function(it){
|
|
196
|
+
return {
|
|
197
|
+
key: "group-" + it
|
|
198
|
+
};
|
|
199
|
+
}), this.valid.filter(function(it){
|
|
200
|
+
return !this$.cfg.legend.enabled || this$.legend.isSelected(it.group);
|
|
201
|
+
}));
|
|
202
|
+
if (this.legend.enabled()) {
|
|
203
|
+
list = list.filter(function(it){
|
|
204
|
+
return !it._raw || this$.legend.isSelected(it.group);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
this.legend.config(this.cfg.legend);
|
|
208
|
+
this.legend.update();
|
|
209
|
+
this.layout.update(false);
|
|
210
|
+
ret = d3.hierarchy(d3.stratify().id(function(it){
|
|
211
|
+
if (it._idx != null) {
|
|
212
|
+
return it._idx;
|
|
213
|
+
} else {
|
|
214
|
+
return it.key;
|
|
215
|
+
}
|
|
216
|
+
}).parentId(function(it){
|
|
217
|
+
var that;
|
|
218
|
+
if (it.root) {
|
|
219
|
+
return '';
|
|
220
|
+
} else if (that = it.group) {
|
|
221
|
+
return "group-" + that;
|
|
222
|
+
} else {
|
|
223
|
+
return 'root';
|
|
189
224
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
225
|
+
})(list)).sum(function(it){
|
|
226
|
+
return it.data.area;
|
|
227
|
+
}).sort(function(a, b){
|
|
228
|
+
return b.value - a.value;
|
|
229
|
+
});
|
|
230
|
+
box = this.vbox = this.layout.getBox('view');
|
|
231
|
+
pack = d3.pack().size([box.width, box.height])(ret);
|
|
232
|
+
this.parsed = ret.leaves().map(function(d){
|
|
233
|
+
var ddata, pos, od, p, x, y;
|
|
234
|
+
d._raw = d.data.data._raw;
|
|
235
|
+
ddata = d.data.data;
|
|
236
|
+
pos = !(this$.cfg.grouping != null) && this$.cfg.grouping
|
|
237
|
+
? d
|
|
238
|
+
: {
|
|
239
|
+
x: Math.random() * box.width * 0.8 + box.width * 0.1,
|
|
240
|
+
y: Math.random() * box.height * 0.8 + box.height * 0.1
|
|
241
|
+
};
|
|
242
|
+
od = this$.parsed ? (p = this$.parsed.filter(function(p){
|
|
243
|
+
if (p.name != null || ddata.name != null) {
|
|
244
|
+
return p.name === ddata.name;
|
|
196
245
|
} else {
|
|
197
|
-
return
|
|
246
|
+
return p._idx === ddata._idx;
|
|
198
247
|
}
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
248
|
+
})[0], p ? p : d) : d;
|
|
249
|
+
x = d.x, y = d.y;
|
|
250
|
+
d.radius = Math.pow(ddata.area, 0.5);
|
|
251
|
+
d.x = x;
|
|
252
|
+
d.y = y;
|
|
253
|
+
d._idx = ddata._idx;
|
|
254
|
+
d.name = ddata.name;
|
|
255
|
+
d.color = ddata.color;
|
|
256
|
+
d.group = ddata.group;
|
|
257
|
+
d.area = ddata.area;
|
|
258
|
+
if (od._x) {
|
|
259
|
+
d._x = od._x;
|
|
260
|
+
} else if (!d._x) {
|
|
261
|
+
d._x = d.x;
|
|
262
|
+
}
|
|
263
|
+
if (od._y) {
|
|
264
|
+
d._y = od._y;
|
|
265
|
+
} else if (!d._y) {
|
|
266
|
+
d._y = d.y;
|
|
267
|
+
}
|
|
268
|
+
return d;
|
|
269
|
+
}).filter(function(it){
|
|
270
|
+
return it.area != null;
|
|
271
|
+
});
|
|
272
|
+
this.sim = null;
|
|
273
|
+
return this.start();
|
|
274
|
+
},
|
|
275
|
+
render: function(){
|
|
276
|
+
var binding, tint, box, rate, x$, y$, this$ = this;
|
|
277
|
+
binding = this.binding, tint = this.tint;
|
|
278
|
+
box = this.vbox;
|
|
279
|
+
this.rate = rate = 0.85 * Math.PI / (2 * Math.sqrt(3)) * Math.sqrt(box.width * box.height / this.parsed.map(function(it){
|
|
280
|
+
return Math.PI * Math.pow(it.r, 2);
|
|
281
|
+
}).reduce(function(a, b){
|
|
282
|
+
return a + b;
|
|
283
|
+
}, 0));
|
|
284
|
+
this.parsed.map(function(d, i){
|
|
285
|
+
var ref$;
|
|
286
|
+
return d.rr = (ref$ = d.r * this$.rate) > 2 ? ref$ : 2;
|
|
287
|
+
});
|
|
288
|
+
tint.set(this.cfg.palette);
|
|
289
|
+
x$ = this.g.view.selectAll('circle.bubble').data(this.parsed, function(it){
|
|
290
|
+
return it.name || it._idx;
|
|
291
|
+
});
|
|
292
|
+
x$.exit().remove();
|
|
293
|
+
x$.enter().append('circle').attr('class', 'bubble data').attr('r', function(d, i){
|
|
294
|
+
return 0;
|
|
295
|
+
}).attr('fill', function(d, i){
|
|
296
|
+
return tint.get(d.color || d.group || d.name);
|
|
297
|
+
}).attr('cx', function(d, i){
|
|
298
|
+
return d._x;
|
|
299
|
+
}).attr('cy', function(d, i){
|
|
300
|
+
return d._y;
|
|
301
|
+
});
|
|
302
|
+
this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
|
|
303
|
+
return d._x;
|
|
304
|
+
}).attr('cy', function(d, i){
|
|
305
|
+
return d._y;
|
|
306
|
+
}).transition().duration(350).attr('fill', function(d, i){
|
|
307
|
+
return tint.get(d.color || d.group || d.name);
|
|
308
|
+
}).attr('r', function(d, i){
|
|
309
|
+
return d.rr;
|
|
310
|
+
});
|
|
311
|
+
y$ = this.g.view.selectAll('g.label').data(this.parsed, function(it){
|
|
312
|
+
return it.name || it._idx;
|
|
313
|
+
});
|
|
314
|
+
y$.exit().remove();
|
|
315
|
+
y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
|
|
316
|
+
return "translate(" + d.x + "," + d.y + ")";
|
|
317
|
+
}).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer').each(function(d, i){
|
|
318
|
+
var this$ = this;
|
|
319
|
+
return [0, 1].map(function(){
|
|
320
|
+
return d3.select(this$).append('text');
|
|
321
|
+
}).map(function(it){
|
|
322
|
+
return it.attr('dy', '-.28em').attr('text-anchor', 'middle').style('pointer-event', 'none');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
326
|
+
return "translate(" + d._x + "," + d._y + ")";
|
|
327
|
+
}).each(function(d, i){
|
|
328
|
+
return d3.select(this).selectAll('text').attr('dy', function(e, i){
|
|
329
|
+
if (i === 0) {
|
|
330
|
+
return '-.28em';
|
|
205
331
|
} else {
|
|
206
|
-
return '
|
|
332
|
+
return '.88em';
|
|
207
333
|
}
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
? d
|
|
221
|
-
: {
|
|
222
|
-
x: Math.random() * box.width * 0.8 + box.width * 0.1,
|
|
223
|
-
y: Math.random() * box.height * 0.8 + box.height * 0.1
|
|
224
|
-
};
|
|
225
|
-
od = this$.parsed ? (p = this$.parsed.filter(function(p){
|
|
226
|
-
if (p.name != null || ddata.name != null) {
|
|
227
|
-
return p.name === ddata.name;
|
|
228
|
-
} else {
|
|
229
|
-
return p._idx === ddata._idx;
|
|
334
|
+
}).text(function(e, i){
|
|
335
|
+
var area, ret;
|
|
336
|
+
if (i === 0) {
|
|
337
|
+
area = d3.format('.3s')(d.area);
|
|
338
|
+
/*
|
|
339
|
+
ret = if area > 1000000 => (area/1000000).toFixed(1) + t(\M)
|
|
340
|
+
else if area > 1000 => (area/1000).toFixed(1) + t(\K)
|
|
341
|
+
else (area).toFixed(0)
|
|
342
|
+
*/
|
|
343
|
+
ret = area;
|
|
344
|
+
if (ret) {
|
|
345
|
+
ret = ret + "" + (binding.area.unit || '');
|
|
230
346
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
d.x = x;
|
|
235
|
-
d.y = y;
|
|
236
|
-
d._idx = ddata._idx;
|
|
237
|
-
d.name = ddata.name;
|
|
238
|
-
d.color = ddata.color;
|
|
239
|
-
d.group = ddata.group;
|
|
240
|
-
d.area = ddata.area;
|
|
241
|
-
if (od._x) {
|
|
242
|
-
d._x = od._x;
|
|
243
|
-
} else if (!d._x) {
|
|
244
|
-
d._x = d.x;
|
|
245
|
-
}
|
|
246
|
-
if (od._y) {
|
|
247
|
-
d._y = od._y;
|
|
248
|
-
} else if (!d._y) {
|
|
249
|
-
d._y = d.y;
|
|
347
|
+
return ret;
|
|
348
|
+
} else {
|
|
349
|
+
return d.name || '';
|
|
250
350
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
render: function(){
|
|
259
|
-
var binding, tint, box, rate, x$, y$, this$ = this;
|
|
260
|
-
binding = this.binding, tint = this.tint;
|
|
261
|
-
box = this.vbox;
|
|
262
|
-
this.rate = rate = 0.85 * Math.PI / (2 * Math.sqrt(3)) * Math.sqrt(box.width * box.height / this.parsed.map(function(it){
|
|
263
|
-
return Math.PI * Math.pow(it.r, 2);
|
|
264
|
-
}).reduce(function(a, b){
|
|
265
|
-
return a + b;
|
|
266
|
-
}, 0));
|
|
267
|
-
this.parsed.map(function(d, i){
|
|
268
|
-
var ref$;
|
|
269
|
-
return d.rr = (ref$ = d.r * this$.rate) > 2 ? ref$ : 2;
|
|
270
|
-
});
|
|
271
|
-
tint.set(this.cfg.palette);
|
|
272
|
-
x$ = this.g.view.selectAll('circle.bubble').data(this.parsed, function(it){
|
|
273
|
-
return it.name || it._idx;
|
|
274
|
-
});
|
|
275
|
-
x$.exit().remove();
|
|
276
|
-
x$.enter().append('circle').attr('class', 'bubble data').attr('r', function(d, i){
|
|
277
|
-
return 0;
|
|
278
|
-
}).attr('fill', function(d, i){
|
|
279
|
-
return tint.get(d.color || d.group || d.name);
|
|
280
|
-
}).attr('cx', function(d, i){
|
|
281
|
-
return d._x;
|
|
282
|
-
}).attr('cy', function(d, i){
|
|
283
|
-
return d._y;
|
|
284
|
-
});
|
|
285
|
-
this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
|
|
286
|
-
return d._x;
|
|
287
|
-
}).attr('cy', function(d, i){
|
|
288
|
-
return d._y;
|
|
289
|
-
}).transition().duration(350).attr('fill', function(d, i){
|
|
290
|
-
return tint.get(d.color || d.group || d.name);
|
|
291
|
-
}).attr('r', function(d, i){
|
|
292
|
-
return d.rr;
|
|
293
|
-
});
|
|
294
|
-
y$ = this.g.view.selectAll('g.label').data(this.parsed, function(it){
|
|
295
|
-
return it.name || it._idx;
|
|
296
|
-
});
|
|
297
|
-
y$.exit().remove();
|
|
298
|
-
y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
|
|
299
|
-
return "translate(" + d.x + "," + d.y + ")";
|
|
300
|
-
}).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer').each(function(d, i){
|
|
301
|
-
var this$ = this;
|
|
302
|
-
return [0, 1].map(function(){
|
|
303
|
-
return d3.select(this$).append('text');
|
|
304
|
-
}).map(function(it){
|
|
305
|
-
return it.attr('dy', '-.28em').attr('text-anchor', 'middle').style('pointer-event', 'none');
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
309
|
-
return "translate(" + d._x + "," + d._y + ")";
|
|
310
|
-
}).each(function(d, i){
|
|
311
|
-
return d3.select(this).selectAll('text').attr('dy', function(e, i){
|
|
312
|
-
if (i === 0) {
|
|
313
|
-
return '-.28em';
|
|
314
|
-
} else {
|
|
315
|
-
return '.88em';
|
|
316
|
-
}
|
|
317
|
-
}).text(function(e, i){
|
|
318
|
-
var area, ret;
|
|
319
|
-
if (i === 0) {
|
|
320
|
-
area = d3.format('.3s')(d.area);
|
|
321
|
-
/*
|
|
322
|
-
ret = if area > 1000000 => (area/1000000).toFixed(1) + t(\M)
|
|
323
|
-
else if area > 1000 => (area/1000).toFixed(1) + t(\K)
|
|
324
|
-
else (area).toFixed(0)
|
|
325
|
-
*/
|
|
326
|
-
ret = area;
|
|
327
|
-
if (ret) {
|
|
328
|
-
ret = ret + "" + (binding.area.unit || '');
|
|
329
|
-
}
|
|
330
|
-
return ret;
|
|
331
|
-
} else {
|
|
332
|
-
return d.name || '';
|
|
333
|
-
}
|
|
334
|
-
}).attr('font-size', function(d, i){
|
|
335
|
-
return i ? '0.9em' : '1.1em';
|
|
336
|
-
}).transition().duration(350).attr('fill', function(){
|
|
337
|
-
var hcl;
|
|
338
|
-
hcl = ldcolor.hcl(tint.get(d.color) || d.group || d.name);
|
|
339
|
-
if (hcl.l < 50) {
|
|
340
|
-
return '#fff';
|
|
341
|
-
} else {
|
|
342
|
-
return '#000';
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
this.g.view.selectAll('g.label').transition().duration(350).attr('opacity', function(d, i){
|
|
347
|
-
var box, ref$, w, h;
|
|
348
|
-
box = this.getBoundingClientRect();
|
|
349
|
-
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
350
|
-
if (2 * d.rr < w || 2 * d.rr < h) {
|
|
351
|
-
return 0;
|
|
351
|
+
}).attr('font-size', function(d, i){
|
|
352
|
+
return i ? '0.9em' : '1.1em';
|
|
353
|
+
}).transition().duration(350).attr('fill', function(){
|
|
354
|
+
var hcl;
|
|
355
|
+
hcl = ldcolor.hcl(tint.get(d.color) || d.group || d.name);
|
|
356
|
+
if (hcl.l < 50) {
|
|
357
|
+
return '#fff';
|
|
352
358
|
} else {
|
|
353
|
-
return
|
|
359
|
+
return '#000';
|
|
354
360
|
}
|
|
355
361
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.fc = fc = d3.forceCollide().strength(0.5).iterations(20).radius(function(it){
|
|
366
|
-
return this$.rate * it.r;
|
|
367
|
-
});
|
|
368
|
-
this.fg = d3.forceCenter().strength(0.5);
|
|
369
|
-
this.fb = forceBoundary(function(it){
|
|
370
|
-
return it.rr + pad;
|
|
371
|
-
}, function(it){
|
|
372
|
-
return it.rr + pad;
|
|
373
|
-
}, function(it){
|
|
374
|
-
return box.width - it.rr - pad;
|
|
375
|
-
}, function(it){
|
|
376
|
-
return box.height - it.rr - pad;
|
|
377
|
-
}).strength(0.5);
|
|
378
|
-
this.sim = d3.forceSimulation().force('b', this.fb).force('collide', this.fc);
|
|
379
|
-
this.sim.stop();
|
|
380
|
-
this.sim.alpha(0.9);
|
|
362
|
+
});
|
|
363
|
+
this.g.view.selectAll('g.label').transition().duration(350).attr('opacity', function(d, i){
|
|
364
|
+
var box, ref$, w, h;
|
|
365
|
+
box = this.getBoundingClientRect();
|
|
366
|
+
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
367
|
+
if (2 * d.rr < w || 2 * d.rr < h) {
|
|
368
|
+
return 0;
|
|
369
|
+
} else {
|
|
370
|
+
return 1;
|
|
381
371
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return
|
|
394
|
-
});
|
|
395
|
-
return this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
396
|
-
return "translate(" + d._x + "," + d._y + ")";
|
|
372
|
+
});
|
|
373
|
+
return this.legend.render();
|
|
374
|
+
},
|
|
375
|
+
tick: function(){
|
|
376
|
+
var cfg, pad, box, kickoff, fc, this$ = this;
|
|
377
|
+
cfg = this.cfg;
|
|
378
|
+
pad = cfg.pad || 5;
|
|
379
|
+
box = this.vbox;
|
|
380
|
+
if (!this.sim) {
|
|
381
|
+
kickoff = true;
|
|
382
|
+
this.fc = fc = d3.forceCollide().strength(0.5).iterations(20).radius(function(it){
|
|
383
|
+
return this$.rate * it.r;
|
|
397
384
|
});
|
|
385
|
+
this.fg = d3.forceCenter().strength(0.5);
|
|
386
|
+
this.fb = forceBoundary(function(it){
|
|
387
|
+
return it.rr + pad;
|
|
388
|
+
}, function(it){
|
|
389
|
+
return it.rr + pad;
|
|
390
|
+
}, function(it){
|
|
391
|
+
return box.width - it.rr - pad;
|
|
392
|
+
}, function(it){
|
|
393
|
+
return box.height - it.rr - pad;
|
|
394
|
+
}).strength(0.5);
|
|
395
|
+
this.sim = d3.forceSimulation().force('b', this.fb).force('collide', this.fc);
|
|
396
|
+
this.sim.stop();
|
|
397
|
+
this.sim.alpha(0.9);
|
|
398
398
|
}
|
|
399
|
-
|
|
399
|
+
this.fg.x(box.width / 2);
|
|
400
|
+
this.fg.y(box.height / 2);
|
|
401
|
+
this.sim.nodes(this.parsed);
|
|
402
|
+
this.sim.tick(kickoff ? 10 : 1);
|
|
403
|
+
this.parsed.map(function(it){
|
|
404
|
+
it._x = it._x + (it.x - it._x) * 0.1;
|
|
405
|
+
return it._y = it._y + (it.y - it._y) * 0.1;
|
|
406
|
+
});
|
|
407
|
+
this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
|
|
408
|
+
return d._x;
|
|
409
|
+
}).attr('cy', function(d, i){
|
|
410
|
+
return d._y;
|
|
411
|
+
});
|
|
412
|
+
return this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
413
|
+
return "translate(" + d._x + "," + d._y + ")";
|
|
414
|
+
});
|
|
415
|
+
}
|
|
400
416
|
};
|
|
401
|
-
|
|
402
|
-
|
|
417
|
+
};
|
|
418
|
+
function import$(obj, src){
|
|
419
|
+
var own = {}.hasOwnProperty;
|
|
420
|
+
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
|
421
|
+
return obj;
|
|
422
|
+
}</script></div>
|