@plotdb/chart 0.0.2
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 -0
- package/README.md +50 -0
- package/build +39 -0
- package/dist/chart.css +8 -0
- package/dist/chart.js +603 -0
- package/dist/chart.min.css +1 -0
- package/dist/chart.min.js +1 -0
- package/dist/data/index.js +73 -0
- package/dist/utils/axis.js +357 -0
- package/dist/utils/axis.min.js +1 -0
- package/dist/utils/config.js +33 -0
- package/dist/utils/config.min.js +1 -0
- package/dist/utils/data.js +238 -0
- package/dist/utils/data.min.js +1 -0
- package/dist/utils/format.js +70 -0
- package/dist/utils/format.min.js +1 -0
- package/dist/utils/legend.css +40 -0
- package/dist/utils/legend.js +263 -0
- package/dist/utils/legend.min.css +1 -0
- package/dist/utils/legend.min.js +1 -0
- package/dist/utils/tint.js +138 -0
- package/dist/utils/tint.min.js +1 -0
- package/dist/utils/tip.js +148 -0
- package/dist/utils/tip.min.js +1 -0
- package/doc/charts.md +58 -0
- package/doc/config.md +44 -0
- package/doc/draft/chart.md +146 -0
- package/doc/draft/data.md +8 -0
- package/doc/draft/definition.md +0 -0
- package/doc/draft/events.md +0 -0
- package/doc/draft/filter.md +0 -0
- package/doc/draft/lifecycle.md +89 -0
- package/doc/spec.md +89 -0
- package/doc/todo.md +27 -0
- package/doc/utils/tip.md +84 -0
- package/package.json +83 -0
- package/src/chart.ls +320 -0
- package/src/chart.styl +6 -0
- package/src/data/en-US/category +20 -0
- package/src/data/en-US/fruit +39 -0
- package/src/data/en-US/movie +125 -0
- package/src/data/en-US/name +58 -0
- package/src/data/index.ls +34 -0
- package/src/data/zh-TW/category +20 -0
- package/src/data/zh-TW/fruits +38 -0
- package/src/data/zh-TW/movie +125 -0
- package/src/data/zh-TW/names +105 -0
- package/src/utils/axis.ls +229 -0
- package/src/utils/config.ls +11 -0
- package/src/utils/data.ls +104 -0
- package/src/utils/format.ls +30 -0
- package/src/utils/legend.ls +134 -0
- package/src/utils/legend.styl +37 -0
- package/src/utils/tint.ls +66 -0
- package/src/utils/tip.ls +97 -0
- package/web/src/pug/base.pug +19 -0
- package/web/src/pug/block/axis/0.0.1/index.ls +38 -0
- package/web/src/pug/block/axis/0.0.1/index.pug +1 -0
- package/web/src/pug/block/axis-bubble/0.0.1/index.ls +141 -0
- package/web/src/pug/block/axis-bubble/0.0.1/index.pug +1 -0
- package/web/src/pug/block/bar/0.0.1/index.ls +274 -0
- package/web/src/pug/block/bar/0.0.1/index.pug +35 -0
- package/web/src/pug/block/bar-list/0.0.1/index.ls +85 -0
- package/web/src/pug/block/bar-list/0.0.1/index.pug +30 -0
- package/web/src/pug/block/bar-race/0.0.1/index.ls +83 -0
- package/web/src/pug/block/bar-race/0.0.1/index.pug +21 -0
- package/web/src/pug/block/base/0.0.1/index.ls +67 -0
- package/web/src/pug/block/base/0.0.1/index.pug +5 -0
- package/web/src/pug/block/blank/0.0.1/index.ls +25 -0
- package/web/src/pug/block/blank/0.0.1/index.pug +1 -0
- package/web/src/pug/block/bubble/0.0.1/index.ls +220 -0
- package/web/src/pug/block/bubble/0.0.1/index.pug +28 -0
- package/web/src/pug/block/curve-bar/0.0.1/index.ls +89 -0
- package/web/src/pug/block/curve-bar/0.0.1/index.pug +16 -0
- package/web/src/pug/block/curve-bar/0.0.1/sample.js +338 -0
- package/web/src/pug/block/dumbbell/0.0.1/index.ls +90 -0
- package/web/src/pug/block/dumbbell/0.0.1/index.pug +1 -0
- package/web/src/pug/block/empty/0.0.1/index.ls +27 -0
- package/web/src/pug/block/empty/0.0.1/index.pug +2 -0
- package/web/src/pug/block/gauge/0.0.1/index.ls +100 -0
- package/web/src/pug/block/gauge/0.0.1/index.pug +31 -0
- package/web/src/pug/block/gauge/0.0.1/sample.js +338 -0
- package/web/src/pug/block/line/0.0.1/index.ls +265 -0
- package/web/src/pug/block/line/0.0.1/index.pug +33 -0
- package/web/src/pug/block/number/0.0.1/index.ls +69 -0
- package/web/src/pug/block/number/0.0.1/index.pug +20 -0
- package/web/src/pug/block/percent-list/0.0.1/index.ls +167 -0
- package/web/src/pug/block/percent-list/0.0.1/index.pug +34 -0
- package/web/src/pug/block/pie/0.0.1/index.ls +125 -0
- package/web/src/pug/block/pie/0.0.1/index.pug +19 -0
- package/web/src/pug/block/pie/0.0.1/sample.js +338 -0
- package/web/src/pug/block/pie-bubble/0.0.1/index.ls +185 -0
- package/web/src/pug/block/pie-bubble/0.0.1/index.pug +40 -0
- package/web/src/pug/block/radar/0.0.1/index.ls +113 -0
- package/web/src/pug/block/radar/0.0.1/index.pug +1 -0
- package/web/src/pug/block/radar/0.0.1/xx +285 -0
- package/web/src/pug/block/scatter/0.0.1/index.ls +128 -0
- package/web/src/pug/block/scatter/0.0.1/index.pug +30 -0
- package/web/src/pug/block/sheet/0.0.1/index.ls +38 -0
- package/web/src/pug/block/sheet/0.0.1/index.pug +5 -0
- package/web/src/pug/block/table/0.0.1/index.ls +40 -0
- package/web/src/pug/block/table/0.0.1/index.pug +3 -0
- package/web/src/pug/block/taiwantown/0.0.1/index.ls +48 -0
- package/web/src/pug/block/taiwantown/0.0.1/index.pug +52 -0
- package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +53 -0
- package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +52 -0
- package/web/src/pug/block/treemap/0.0.1/index.ls +172 -0
- package/web/src/pug/block/treemap/0.0.1/index.pug +42 -0
- package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +174 -0
- package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +17 -0
- package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +241 -0
- package/web/src/pug/block/wordcloud/0.0.1/index.ls +61 -0
- package/web/src/pug/block/wordcloud/0.0.1/index.pug +1 -0
- package/web/src/pug/block/worldmap/0.0.1/index.ls +83 -0
- package/web/src/pug/block/worldmap/0.0.1/index.pug +12 -0
- package/web/src/pug/index.ls +72 -0
- package/web/src/pug/index.pug +52 -0
- package/web/src/styl/index.styl +0 -0
- package/web/static/assets/block/cache.js +4 -0
- package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3.v4.js +17178 -0
- package/web/static/assets/custom-lib/d3/d3.v4.min.js +2 -0
- package/web/static/assets/data/countrycode.json +1 -0
- package/web/static/assets/data/world-110m.json +1 -0
- package/web/static/assets/data/zh-to-alpha2.json +1 -0
- package/web/static/assets/img/fluid.svg +16 -0
- package/web/static/block/axis/0.0.1/index.html +79 -0
- package/web/static/block/axis-bubble/0.0.1/index.html +222 -0
- package/web/static/block/bar/0.0.1/index.html +581 -0
- package/web/static/block/bar-list/0.0.1/index.html +231 -0
- package/web/static/block/bar-race/0.0.1/index.html +184 -0
- package/web/static/block/base/0.0.1/index.html +197 -0
- package/web/static/block/blank/0.0.1/index.html +42 -0
- package/web/static/block/bubble/0.0.1/index.html +402 -0
- package/web/static/block/bubble/0.0.1/test.html +0 -0
- package/web/static/block/curve-bar/0.0.1/index.html +148 -0
- package/web/static/block/dumbbell/0.0.1/index.html +178 -0
- package/web/static/block/empty/0.0.1/index.html +76 -0
- package/web/static/block/gauge/0.0.1/index.html +150 -0
- package/web/static/block/line/0.0.1/index.html +540 -0
- package/web/static/block/number/0.0.1/index.html +152 -0
- package/web/static/block/percent-list/0.0.1/index.html +316 -0
- package/web/static/block/pie/0.0.1/index.html +281 -0
- package/web/static/block/pie-bubble/0.0.1/index.html +358 -0
- package/web/static/block/radar/0.0.1/index.html +149 -0
- package/web/static/block/scatter/0.0.1/index.html +251 -0
- package/web/static/block/sheet/0.0.1/index.html +103 -0
- package/web/static/block/table/0.0.1/index.html +73 -0
- package/web/static/block/taiwantown/0.0.1/index.html +210 -0
- package/web/static/block/taiwanvillage/0.0.1/index.html +220 -0
- package/web/static/block/treemap/0.0.1/index.html +360 -0
- package/web/static/block/voronoi-treemap/0.0.1/index.html +350 -0
- package/web/static/block/wordcloud/0.0.1/index.html +92 -0
- package/web/static/block/worldmap/0.0.1/index.html +207 -0
- package/web/static/css/index.css +0 -0
- package/web/static/css/index.min.css +0 -0
- package/web/static/favicon.ico +0 -0
- package/web/static/index.html +153 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
<div><script type="@plotdb/block">(function(it){
|
|
2
|
+
return it();
|
|
3
|
+
})(function(){
|
|
4
|
+
var blockFactory, mod;
|
|
5
|
+
blockFactory = {
|
|
6
|
+
pkg: {
|
|
7
|
+
name: 'taiwanvillage',
|
|
8
|
+
version: '0.0.1',
|
|
9
|
+
extend: {
|
|
10
|
+
name: "base",
|
|
11
|
+
version: "0.0.1"
|
|
12
|
+
},
|
|
13
|
+
dependencies: [
|
|
14
|
+
{
|
|
15
|
+
url: "https://d3js.org/topojson.v2.min.js",
|
|
16
|
+
async: false
|
|
17
|
+
}, {
|
|
18
|
+
url: "/js/work/map.list.js",
|
|
19
|
+
async: false
|
|
20
|
+
}, {
|
|
21
|
+
url: "https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist/pdmaptw.min.js"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
init: function(arg$){
|
|
26
|
+
var root, context, pubsub;
|
|
27
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
28
|
+
return pubsub.fire('init', {
|
|
29
|
+
mod: mod({
|
|
30
|
+
context: context
|
|
31
|
+
})
|
|
32
|
+
}).then(function(it){
|
|
33
|
+
return it[0];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
mod = function(arg$){
|
|
38
|
+
var context, d3, forceBoundary, ldColor, repeatString$, pdmaptw, counties, towns, villages;
|
|
39
|
+
context = arg$.context;
|
|
40
|
+
d3 = context.d3, forceBoundary = context.forceBoundary, ldColor = context.ldColor, repeatString$ = context.repeatString$, pdmaptw = context.pdmaptw, counties = context.counties, towns = context.towns, villages = context.villages;
|
|
41
|
+
return {
|
|
42
|
+
sample: function(){
|
|
43
|
+
var val;
|
|
44
|
+
val = {
|
|
45
|
+
counties: counties.map(function(d, i){
|
|
46
|
+
return {
|
|
47
|
+
val: Math.random(),
|
|
48
|
+
county: d
|
|
49
|
+
};
|
|
50
|
+
}),
|
|
51
|
+
towns: towns.map(function(d, i){
|
|
52
|
+
return {
|
|
53
|
+
val: Math.random(),
|
|
54
|
+
town: d
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
villages: villages.map(function(d, i){
|
|
58
|
+
return {
|
|
59
|
+
val: Math.random(),
|
|
60
|
+
village: d
|
|
61
|
+
};
|
|
62
|
+
})
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
raw: val.villages,
|
|
66
|
+
binding: {
|
|
67
|
+
color: {
|
|
68
|
+
key: 'val'
|
|
69
|
+
},
|
|
70
|
+
name: {
|
|
71
|
+
key: 'village'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
config: {},
|
|
77
|
+
dimension: {
|
|
78
|
+
name: {
|
|
79
|
+
type: 'N',
|
|
80
|
+
name: "國家"
|
|
81
|
+
},
|
|
82
|
+
color: {
|
|
83
|
+
type: 'R',
|
|
84
|
+
name: "顏色"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
init: function(){
|
|
88
|
+
var this$ = this;
|
|
89
|
+
this.obj = pdmaptw.create({
|
|
90
|
+
root: this.svg,
|
|
91
|
+
type: 'village',
|
|
92
|
+
baseurl: 'https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist'
|
|
93
|
+
});
|
|
94
|
+
return this.obj.init().then(function(){
|
|
95
|
+
return this$.obj.fit();
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
parse: function(){
|
|
99
|
+
var this$ = this;
|
|
100
|
+
d3.select(this.svg).selectAll('path').each(function(d, i){
|
|
101
|
+
return d.data = this$.data.filter(function(it){
|
|
102
|
+
return it.name === d.properties.name;
|
|
103
|
+
})[0] || {};
|
|
104
|
+
});
|
|
105
|
+
d3.select(this.svg).selectAll('path').filter(function(d, i){
|
|
106
|
+
return !/彰化縣/.exec(d.properties.name);
|
|
107
|
+
}).remove();
|
|
108
|
+
return this.obj.fit();
|
|
109
|
+
},
|
|
110
|
+
resize: function(){},
|
|
111
|
+
render: function(){
|
|
112
|
+
var this$ = this;
|
|
113
|
+
this.color = d3.interpolateTurbo;
|
|
114
|
+
if (this.cfg != null && this.cfg.palette) {
|
|
115
|
+
this.color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
|
|
116
|
+
return ldColor.web(it.value || it);
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
return d3.select(this.svg).selectAll('path').transition().duration(350).attr('fill', function(d, i){
|
|
120
|
+
return this$.color(d.data.color);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
return blockFactory;
|
|
126
|
+
});</script></div><div><script type="@plotdb/block">({
|
|
127
|
+
pkg: {
|
|
128
|
+
name: 'taiwantown',
|
|
129
|
+
version: '0.0.1',
|
|
130
|
+
dependencies: [
|
|
131
|
+
{
|
|
132
|
+
url: "https://d3js.org/d3.v4.js",
|
|
133
|
+
async: false
|
|
134
|
+
}, "https://d3js.org/d3-format.v2.min.js", "https://d3js.org/d3-array.v2.min.js", "https://d3js.org/topojson.v2.min.js", {
|
|
135
|
+
url: "https://d3js.org/d3-color.v1.min.js",
|
|
136
|
+
async: false
|
|
137
|
+
}, {
|
|
138
|
+
url: "https://d3js.org/d3-interpolate.v1.min.js",
|
|
139
|
+
async: false
|
|
140
|
+
}, {
|
|
141
|
+
url: "https://d3js.org/d3-scale-chromatic.v1.min.js",
|
|
142
|
+
async: false
|
|
143
|
+
}, "/js/map.list.js", "https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist/pdmaptw.min.js"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
init: function(arg$){
|
|
147
|
+
var root, context, counties, towns, c;
|
|
148
|
+
root = arg$.root, context = arg$.context;
|
|
149
|
+
counties = context.counties.map(function(d, i){
|
|
150
|
+
return {
|
|
151
|
+
val: Math.random(),
|
|
152
|
+
county: d
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
towns = context.towns.map(function(d, i){
|
|
156
|
+
return {
|
|
157
|
+
val: Math.random(),
|
|
158
|
+
town: d
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
c = new chart({
|
|
162
|
+
root: root,
|
|
163
|
+
raw: towns,
|
|
164
|
+
mod: this.mod({
|
|
165
|
+
context: context
|
|
166
|
+
}),
|
|
167
|
+
binding: {
|
|
168
|
+
color: {
|
|
169
|
+
name: 'val'
|
|
170
|
+
},
|
|
171
|
+
name: {
|
|
172
|
+
name: 'town'
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
c.init().then(function(){
|
|
177
|
+
return c.render();
|
|
178
|
+
});
|
|
179
|
+
return this.c = c;
|
|
180
|
+
},
|
|
181
|
+
'interface': function(){
|
|
182
|
+
return this.c;
|
|
183
|
+
},
|
|
184
|
+
mod: function(arg$){
|
|
185
|
+
var context;
|
|
186
|
+
context = arg$.context;
|
|
187
|
+
return {
|
|
188
|
+
init: function(){
|
|
189
|
+
var this$ = this;
|
|
190
|
+
this.obj = context.pdmaptw.create({
|
|
191
|
+
root: this.svg,
|
|
192
|
+
type: 'town',
|
|
193
|
+
baseurl: 'https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist'
|
|
194
|
+
});
|
|
195
|
+
return this.obj.init().then(function(){
|
|
196
|
+
return this$.obj.fit();
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
parse: function(){
|
|
200
|
+
var this$ = this;
|
|
201
|
+
return d3.select(this.svg).selectAll('path').each(function(d, i){
|
|
202
|
+
return d.data = this$.data.filter(function(it){
|
|
203
|
+
return it.name === d.properties.name;
|
|
204
|
+
})[0] || {};
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
resize: function(){},
|
|
208
|
+
render: function(){
|
|
209
|
+
var this$ = this;
|
|
210
|
+
this.color = d3.interpolateTurbo;
|
|
211
|
+
if (config.pal) {
|
|
212
|
+
this.color = d3.interpolateDiscrete(config.pal);
|
|
213
|
+
}
|
|
214
|
+
return d3.select(this.svg).selectAll('path').transition().duration(350).attr('fill', function(d, i){
|
|
215
|
+
return this$.color(d.data.color);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
});</script></div>
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
<div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="unit"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout > div[data-type=layout] {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: 1fr fit-content(10em);
|
|
4
|
+
grid-template-rows: 1fr fit-content(1em);
|
|
5
|
+
}
|
|
6
|
+
.pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
|
|
7
|
+
grid-area: 1/1;
|
|
8
|
+
}
|
|
9
|
+
.pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
|
|
10
|
+
grid-column: 2;
|
|
11
|
+
grid-row: 1/span 2;
|
|
12
|
+
padding: 0 0.5em 0 0.5em;
|
|
13
|
+
}
|
|
14
|
+
.pdl-layout > div[data-type=layout] > .pdl-cell[data-name=unit] {
|
|
15
|
+
grid-column: 1;
|
|
16
|
+
grid-row: 2;
|
|
17
|
+
line-height: 1em;
|
|
18
|
+
text-align: right;
|
|
19
|
+
padding: 0.25em 0;
|
|
20
|
+
}
|
|
21
|
+
.pdl-layout.legend-bottom > div[data-type=layout] {
|
|
22
|
+
grid-template-columns: 1fr fit-content(1em);
|
|
23
|
+
grid-template-rows: 1fr fit-content(3em);
|
|
24
|
+
}
|
|
25
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=view] {
|
|
26
|
+
grid-column: 1/span 2;
|
|
27
|
+
grid-row: 1;
|
|
28
|
+
}
|
|
29
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=legend] {
|
|
30
|
+
padding-top: 1em;
|
|
31
|
+
grid-column: 1;
|
|
32
|
+
grid-row: 2;
|
|
33
|
+
}
|
|
34
|
+
.pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=unit] {
|
|
35
|
+
padding-top: 1em;
|
|
36
|
+
grid-column: 2;
|
|
37
|
+
grid-row: 2;
|
|
38
|
+
}
|
|
39
|
+
</style><script type="@plotdb/block">(function(it){
|
|
40
|
+
return it();
|
|
41
|
+
})(function(){
|
|
42
|
+
var blockFactory, mod;
|
|
43
|
+
blockFactory = {
|
|
44
|
+
pkg: {
|
|
45
|
+
name: 'treemap',
|
|
46
|
+
version: '0.0.1',
|
|
47
|
+
extend: {
|
|
48
|
+
name: "base",
|
|
49
|
+
version: "0.0.1"
|
|
50
|
+
},
|
|
51
|
+
dependencies: [],
|
|
52
|
+
i18n: {
|
|
53
|
+
"zh-TW": {
|
|
54
|
+
"other": "其它",
|
|
55
|
+
"unit": "單位"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
init: function(arg$){
|
|
60
|
+
var root, context, pubsub, t;
|
|
61
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
|
|
62
|
+
return pubsub.fire('init', {
|
|
63
|
+
mod: mod({
|
|
64
|
+
root: root,
|
|
65
|
+
context: context,
|
|
66
|
+
t: t
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
mod = function(arg$){
|
|
72
|
+
var root, context, t, chart, d3, ldcolor, wrapSvgText;
|
|
73
|
+
root = arg$.root, context = arg$.context, t = arg$.t;
|
|
74
|
+
chart = context.chart, d3 = context.d3, ldcolor = context.ldcolor, wrapSvgText = context.wrapSvgText;
|
|
75
|
+
return {
|
|
76
|
+
sample: function(){
|
|
77
|
+
return {
|
|
78
|
+
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){
|
|
79
|
+
return {
|
|
80
|
+
val: Math.random().toFixed(2),
|
|
81
|
+
cat: Math.floor(1 + 6 * Math.random())
|
|
82
|
+
};
|
|
83
|
+
}),
|
|
84
|
+
binding: {
|
|
85
|
+
color: {
|
|
86
|
+
key: 'cat'
|
|
87
|
+
},
|
|
88
|
+
area: {
|
|
89
|
+
key: 'val',
|
|
90
|
+
unit: 'MB'
|
|
91
|
+
},
|
|
92
|
+
name: {
|
|
93
|
+
key: 'cat'
|
|
94
|
+
},
|
|
95
|
+
category: {
|
|
96
|
+
key: 'cat'
|
|
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));
|
|
158
|
+
},
|
|
159
|
+
direction: ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom' ? 'horizontal' : 'vertical',
|
|
160
|
+
cfg: {
|
|
161
|
+
selectable: true
|
|
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
|
+
};
|
|
184
|
+
},
|
|
185
|
+
range: function(){
|
|
186
|
+
return this$.layout.getNode('view').getBoundingClientRect();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
destroy: function(){
|
|
191
|
+
return this.tip.destroy();
|
|
192
|
+
},
|
|
193
|
+
parse: function(){
|
|
194
|
+
var hash, k, v;
|
|
195
|
+
this.tint.reset();
|
|
196
|
+
hash = {};
|
|
197
|
+
this.data.map(function(d, i){
|
|
198
|
+
d.id = "name-" + i;
|
|
199
|
+
if (!d.category || d.category === "") {
|
|
200
|
+
return d.category = t("other");
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (!this.binding.category) {
|
|
204
|
+
this.data.map(function(d){
|
|
205
|
+
return d.category = 'root-1';
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
this.data.map(function(it){
|
|
209
|
+
return hash[it.category] = {
|
|
210
|
+
id: it.category,
|
|
211
|
+
category: 'root'
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
this.cats = Array.from(new Set(this.data.map(function(it){
|
|
215
|
+
return it.category;
|
|
216
|
+
}))).filter(function(it){
|
|
217
|
+
return it !== 'root-1';
|
|
218
|
+
});
|
|
219
|
+
this.data = this.data.concat((function(){
|
|
220
|
+
var ref$, results$ = [];
|
|
221
|
+
for (k in ref$ = hash) {
|
|
222
|
+
v = ref$[k];
|
|
223
|
+
results$.push(v);
|
|
224
|
+
}
|
|
225
|
+
return results$;
|
|
226
|
+
}()), [{
|
|
227
|
+
id: 'root'
|
|
228
|
+
}]);
|
|
229
|
+
return this.legend.data(this.cats.map(function(it){
|
|
230
|
+
return {
|
|
231
|
+
key: it,
|
|
232
|
+
text: it
|
|
233
|
+
};
|
|
234
|
+
}));
|
|
235
|
+
},
|
|
236
|
+
bind: function(){
|
|
237
|
+
var data, s, this$ = this;
|
|
238
|
+
data = this.data.filter(function(it){
|
|
239
|
+
var ref$;
|
|
240
|
+
return it.id === 'root' || ((ref$ = it.category) === 'root' || ref$ === 'root-1') || this$.legend.isSelected(it.category);
|
|
241
|
+
});
|
|
242
|
+
s = d3.stratify().id(function(it){
|
|
243
|
+
return it.id;
|
|
244
|
+
}).parentId(function(it){
|
|
245
|
+
return it.category;
|
|
246
|
+
});
|
|
247
|
+
return this.ret = s(data);
|
|
248
|
+
},
|
|
249
|
+
resize: function(){
|
|
250
|
+
var ref$, ref1$, x$, box, tree;
|
|
251
|
+
this.root.querySelector('.pdl-layout').classList.toggle('legend-bottom', ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom');
|
|
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 || '') : ''
|
|
258
|
+
};
|
|
259
|
+
x$ = this.layout.getNode('unit');
|
|
260
|
+
x$.style.display = !this.unit.outer ? 'none' : '';
|
|
261
|
+
x$.textContent = this.unit.outer;
|
|
262
|
+
this.legend.config(this.cfg.legend);
|
|
263
|
+
this.legend.update();
|
|
264
|
+
this.layout.update(false);
|
|
265
|
+
this.ret.sum(function(it){
|
|
266
|
+
return it.area;
|
|
267
|
+
});
|
|
268
|
+
box = this.layout.getBox('view');
|
|
269
|
+
tree = d3.treemap().padding(1).size([box.width, box.height])(this.ret);
|
|
270
|
+
this.nodes = this.ret.leaves().filter(function(it){
|
|
271
|
+
return it.data._raw;
|
|
272
|
+
});
|
|
273
|
+
this.nodes.map(function(it){
|
|
274
|
+
return it._raw = it.data._raw;
|
|
275
|
+
});
|
|
276
|
+
return this.extent = d3.extent(this.nodes.map(function(it){
|
|
277
|
+
return it.value;
|
|
278
|
+
}));
|
|
279
|
+
},
|
|
280
|
+
render: function(){
|
|
281
|
+
var cfg, unit, binding, layout, textRenderer, tint, x$, y$, this$ = this;
|
|
282
|
+
cfg = this.cfg, unit = this.unit, binding = this.binding, layout = this.layout, textRenderer = this.textRenderer, tint = this.tint;
|
|
283
|
+
tint.set(cfg.palette);
|
|
284
|
+
this.g.unit.call(function(){
|
|
285
|
+
var node, ret;
|
|
286
|
+
node = layout.getNode('unit');
|
|
287
|
+
ret = wrapSvgText({
|
|
288
|
+
node: node,
|
|
289
|
+
useRange: true
|
|
290
|
+
});
|
|
291
|
+
this$.g.unit.node().textContent = '';
|
|
292
|
+
return this$.g.unit.node().appendChild(ret);
|
|
293
|
+
});
|
|
294
|
+
x$ = this.g.view.selectAll('rect.data').data(this.nodes, function(it){
|
|
295
|
+
return it._raw._idx;
|
|
296
|
+
});
|
|
297
|
+
x$.exit().remove();
|
|
298
|
+
x$.enter().append('rect').attr('class', 'data').attr('x', function(it){
|
|
299
|
+
return (it.x1 + it.x0) / 2 - (it.x1 - it.x0) / 4;
|
|
300
|
+
}).attr('y', function(it){
|
|
301
|
+
return (it.y1 + it.y0) / 2 - (it.y1 - it.y0) / 4;
|
|
302
|
+
}).attr('width', function(it){
|
|
303
|
+
return (it.x1 - it.x0) / 2;
|
|
304
|
+
}).attr('height', function(it){
|
|
305
|
+
return (it.y1 - it.y0) / 2;
|
|
306
|
+
}).attr('fill', function(it){
|
|
307
|
+
return tint.get(it.data.color || it.data.category);
|
|
308
|
+
}).style('opacity', 0);
|
|
309
|
+
this.g.view.selectAll('rect').transition().duration(350).attr('x', function(it){
|
|
310
|
+
return it.x0;
|
|
311
|
+
}).attr('y', function(it){
|
|
312
|
+
return it.y0;
|
|
313
|
+
}).attr('width', function(it){
|
|
314
|
+
return it.x1 - it.x0;
|
|
315
|
+
}).attr('height', function(it){
|
|
316
|
+
return it.y1 - it.y0;
|
|
317
|
+
}).attr('fill', function(it){
|
|
318
|
+
var v;
|
|
319
|
+
v = (it.value - this$.extent[0]) / (this$.extent[1] - this$.extent[0]) - 0.5;
|
|
320
|
+
return tint.get(it.data.color || it.data.category);
|
|
321
|
+
}).style('opacity', 1);
|
|
322
|
+
y$ = this.g.view.selectAll('g.label').data(this.nodes, function(it){
|
|
323
|
+
return it._raw._idx;
|
|
324
|
+
});
|
|
325
|
+
y$.exit().remove();
|
|
326
|
+
y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
|
|
327
|
+
return "translate(" + d.x0 + "," + d.y0 + ")";
|
|
328
|
+
}).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer');
|
|
329
|
+
this.g.view.selectAll('g.label').attr('font-size', '0.9em').each(function(d, i){
|
|
330
|
+
var area, ret;
|
|
331
|
+
textRenderer.style.width = (d.x1 - d.x0) + "px";
|
|
332
|
+
area = d.data.area;
|
|
333
|
+
area = d3.format('.3s')(area);
|
|
334
|
+
textRenderer.innerHTML = "<div>" + (d.data.name || '') + "</div>\n<div>" + area + unit.inner + "</div>";
|
|
335
|
+
ret = wrapSvgText({
|
|
336
|
+
node: textRenderer,
|
|
337
|
+
useRange: true
|
|
338
|
+
});
|
|
339
|
+
this.textContent = '';
|
|
340
|
+
return this.appendChild(ret);
|
|
341
|
+
}).transition().duration(350).attr('transform', function(d, i){
|
|
342
|
+
return "translate(" + d.x0 + "," + d.y0 + ")";
|
|
343
|
+
}).attr('fill', function(it){
|
|
344
|
+
return tint.text(it.data.color || it.data.category);
|
|
345
|
+
}).attr('opacity', function(d, i){
|
|
346
|
+
var box;
|
|
347
|
+
box = this.getBBox();
|
|
348
|
+
return box.width > d.x1 - d.x0 || box.height > d.y1 - d.y0 ? 0 : 1;
|
|
349
|
+
});
|
|
350
|
+
return this.legend.render();
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
return blockFactory;
|
|
355
|
+
});
|
|
356
|
+
function import$(obj, src){
|
|
357
|
+
var own = {}.hasOwnProperty;
|
|
358
|
+
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
|
359
|
+
return obj;
|
|
360
|
+
}</script></div>
|