@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,350 @@
|
|
|
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="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
|
+
}
|
|
5
|
+
.pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
|
|
6
|
+
grid-column: 1;
|
|
7
|
+
}
|
|
8
|
+
.pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
|
|
9
|
+
grid-column: 2;
|
|
10
|
+
padding: 0 0.5em 0 0.5em;
|
|
11
|
+
}
|
|
12
|
+
</style><script type="@plotdb/block">(function(it){
|
|
13
|
+
return it();
|
|
14
|
+
})(function(){
|
|
15
|
+
var blockFactory, mod;
|
|
16
|
+
blockFactory = {
|
|
17
|
+
pkg: {
|
|
18
|
+
name: 'voronoi-treemap',
|
|
19
|
+
version: '0.0.1',
|
|
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
|
+
}]
|
|
29
|
+
},
|
|
30
|
+
init: function(arg$){
|
|
31
|
+
var root, context, pubsub;
|
|
32
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
33
|
+
return pubsub.fire('init', {
|
|
34
|
+
mod: mod({
|
|
35
|
+
context: context
|
|
36
|
+
})
|
|
37
|
+
}).then(function(it){
|
|
38
|
+
return it[0];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
mod = function(arg$){
|
|
43
|
+
var context, d3, ldcolor, voronoi, chart;
|
|
44
|
+
context = arg$.context;
|
|
45
|
+
d3 = context.d3, ldcolor = context.ldcolor, voronoi = context.voronoi, chart = context.chart;
|
|
46
|
+
return {
|
|
47
|
+
sample: function(){
|
|
48
|
+
return {
|
|
49
|
+
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){
|
|
50
|
+
return {
|
|
51
|
+
val: Math.random() * 10,
|
|
52
|
+
cat: Math.floor(1 + 10 * Math.random()),
|
|
53
|
+
name: val
|
|
54
|
+
};
|
|
55
|
+
}),
|
|
56
|
+
binding: {
|
|
57
|
+
name: {
|
|
58
|
+
key: 'name'
|
|
59
|
+
},
|
|
60
|
+
area: {
|
|
61
|
+
key: 'val'
|
|
62
|
+
},
|
|
63
|
+
category: {
|
|
64
|
+
key: 'cat'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
config: {},
|
|
70
|
+
dimension: {
|
|
71
|
+
area: {
|
|
72
|
+
type: 'R',
|
|
73
|
+
name: "area"
|
|
74
|
+
},
|
|
75
|
+
name: {
|
|
76
|
+
type: 'N',
|
|
77
|
+
desc: "name"
|
|
78
|
+
},
|
|
79
|
+
category: {
|
|
80
|
+
type: 'N',
|
|
81
|
+
desc: "category"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
init: function(){
|
|
85
|
+
var tint, g, this$ = this;
|
|
86
|
+
this.tint = tint = new chart.utils.tint();
|
|
87
|
+
this.g = Object.fromEntries(['view', 'legend'].map(function(it){
|
|
88
|
+
return [it, d3.select(this$.layout.getGroup(it))];
|
|
89
|
+
}));
|
|
90
|
+
this.layout.getGroup('view').appendChild(g = document.createElementNS("http://www.w3.org/2000/svg", "g"));
|
|
91
|
+
this.g.shape = d3.select(g);
|
|
92
|
+
this.siteBoxes = [];
|
|
93
|
+
this.legend = new chart.utils.legend({
|
|
94
|
+
layout: this.layout,
|
|
95
|
+
name: 'legend',
|
|
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
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
this.legend.on('select', function(){
|
|
105
|
+
this$.bind();
|
|
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;
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(data)) {
|
|
118
|
+
if (!this$._sites) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!(data.idx != null)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!(data = this$._sites[data.idx])) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
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
|
+
}
|
|
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
|
+
return {
|
|
151
|
+
key: it,
|
|
152
|
+
text: it
|
|
153
|
+
};
|
|
154
|
+
}));
|
|
155
|
+
},
|
|
156
|
+
bind: function(){
|
|
157
|
+
var data, box, ref$, w, h, sites, x$, y$, this$ = this;
|
|
158
|
+
data = this.data.filter(function(it){
|
|
159
|
+
return this$.legend.isSelected(it.category);
|
|
160
|
+
});
|
|
161
|
+
this.parsed = {
|
|
162
|
+
children: d3.nest().key(function(it){
|
|
163
|
+
return it.category;
|
|
164
|
+
}).entries(data).map(function(it){
|
|
165
|
+
return it.children = it.values, it;
|
|
166
|
+
})
|
|
167
|
+
};
|
|
168
|
+
box = this.box || this.svg.getBoundingClientRect();
|
|
169
|
+
ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
|
|
170
|
+
w = h = Math.min(w, h);
|
|
171
|
+
this.treemap = new voronoi.Treemap(this.parsed, voronoi.Polygon.create(w, h, 60), w, h);
|
|
172
|
+
sites = this.treemap.getSites();
|
|
173
|
+
x$ = this.g.shape.selectAll('path.data').data(this.treemap.getPolygons());
|
|
174
|
+
x$.exit().remove();
|
|
175
|
+
x$.enter().append('path').attr('class', 'data').each(function(d, i){
|
|
176
|
+
return d.idx = i;
|
|
177
|
+
});
|
|
178
|
+
this.g.shape.selectAll('path.data').attr('class', function(d, i){
|
|
179
|
+
if (sites[i].lv <= 0) {
|
|
180
|
+
return 'data group';
|
|
181
|
+
} else {
|
|
182
|
+
return 'data';
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
this.polygons = this.g.shape.selectAll('path.data');
|
|
186
|
+
y$ = this.g.shape.selectAll('g.label').data(sites);
|
|
187
|
+
y$.exit().remove();
|
|
188
|
+
y$.enter().append('g').attr('class', 'label').each(function(d, i){
|
|
189
|
+
var x$;
|
|
190
|
+
x$ = d3.select(this);
|
|
191
|
+
x$.append('text').attr('class', 'name').attr('font-size', '.8em');
|
|
192
|
+
x$.append('text').attr('class', 'value');
|
|
193
|
+
return x$;
|
|
194
|
+
});
|
|
195
|
+
this.sites = this.g.shape.selectAll('g.label');
|
|
196
|
+
return this.sites.each(function(d, i){
|
|
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);
|
|
268
|
+
}
|
|
269
|
+
siteBoxes = this.siteBoxes;
|
|
270
|
+
boxes = [];
|
|
271
|
+
this.polygons.data(polygons).attr('d', function(d, i){
|
|
272
|
+
var ret, ref$, min, max, i$, to$, idx, x, y;
|
|
273
|
+
d.idx = i;
|
|
274
|
+
if (!(d && d.length)) {
|
|
275
|
+
boxes.push({});
|
|
276
|
+
return "";
|
|
277
|
+
}
|
|
278
|
+
ret = [['M', d[0].x, d[0].y]];
|
|
279
|
+
ref$ = [
|
|
280
|
+
{
|
|
281
|
+
x: d[0].x,
|
|
282
|
+
y: d[0].y
|
|
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]);
|
|
304
|
+
}
|
|
305
|
+
ret.push(['L', d[0].x, d[0].y]);
|
|
306
|
+
boxes.push({
|
|
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();
|
|
322
|
+
}
|
|
323
|
+
return d3.select(this).attr('transform', function(){
|
|
324
|
+
var x, y;
|
|
325
|
+
x = box.x + box.width / 2;
|
|
326
|
+
y = box.y + box.height / 2;
|
|
327
|
+
if (isNaN(x)) {
|
|
328
|
+
x = -10000;
|
|
329
|
+
}
|
|
330
|
+
if (isNaN(y)) {
|
|
331
|
+
y = -10000;
|
|
332
|
+
}
|
|
333
|
+
return "translate(" + x + ", " + y + ")";
|
|
334
|
+
}).attr('opacity', function(){
|
|
335
|
+
var ref$, ref1$, ref2$;
|
|
336
|
+
return (ref$ = 1 - 6 * ((ref1$ = mybox.width / ((ref2$ = box.width) > 0 ? ref2$ : 0) - 1) > 0 ? ref1$ : 0)) > 0 ? ref$ : 0;
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
tick: function(){
|
|
341
|
+
this.count = (this.count || 0) + 1;
|
|
342
|
+
if (this.count < 100) {
|
|
343
|
+
this.treemap.compute();
|
|
344
|
+
return this.render(true);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
return blockFactory;
|
|
350
|
+
});</script></div>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<div><script type="@plotdb/block">(function(it){
|
|
2
|
+
return it();
|
|
3
|
+
})(function(){
|
|
4
|
+
var blockFactory, mod;
|
|
5
|
+
blockFactory = {
|
|
6
|
+
pkg: {
|
|
7
|
+
name: 'wordcloud',
|
|
8
|
+
version: '0.0.1',
|
|
9
|
+
extend: {
|
|
10
|
+
name: "base",
|
|
11
|
+
version: "0.0.1"
|
|
12
|
+
},
|
|
13
|
+
dependencies: [{
|
|
14
|
+
url: "https://unpkg.com/d3-cloud@1.2.5/build/d3.layout.cloud.js"
|
|
15
|
+
}]
|
|
16
|
+
},
|
|
17
|
+
init: function(arg$){
|
|
18
|
+
var root, context, pubsub;
|
|
19
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
20
|
+
return pubsub.fire('init', {
|
|
21
|
+
mod: mod({
|
|
22
|
+
context: context
|
|
23
|
+
})
|
|
24
|
+
}).then(function(it){
|
|
25
|
+
return it[0];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
mod = function(arg$){
|
|
30
|
+
var context, root, d3, forceBoundary, ldColor, repeatString$;
|
|
31
|
+
context = arg$.context, root = arg$.root;
|
|
32
|
+
d3 = context.d3, forceBoundary = context.forceBoundary, ldColor = context.ldColor, repeatString$ = context.repeatString$;
|
|
33
|
+
return {
|
|
34
|
+
sample: function(){
|
|
35
|
+
return {
|
|
36
|
+
raw: [],
|
|
37
|
+
binding: {}
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
config: {},
|
|
41
|
+
dimension: {},
|
|
42
|
+
init: function(){
|
|
43
|
+
var this$ = this;
|
|
44
|
+
this.dd = ['cover', 'scandal', 'seem', 'consumption', 'garbage', 'hunter', 'pepper', 'west', 'guilt', 'conspiracy', 'pupil', 'boat', 'muscle', 'nightmare', 'gene', 'royalty', 'salon', 'difficult', 'management', 'brainstorm', 'aid', 'moving', 'plaster', 'cake', 'issue', 'realism', 'subject', 'speed', 'railcar', 'break', 'grass', 'collapse', 'is', 'leave', 'retiree', 'looting', 'transaction', 'copyright', 'serve', 'guard', 'colony', 'spell', 'ask', 'ranch', 'cell', 'sensation', 'name', 'default', 'reflection'].map(function(d, i){
|
|
45
|
+
return {
|
|
46
|
+
text: d,
|
|
47
|
+
value: 1.5 * i + 10
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
this.cloud = d3.layout.cloud();
|
|
51
|
+
return this.cloud.font('arial').padding(2).fontSize(function(it){
|
|
52
|
+
return it.value;
|
|
53
|
+
}).on('end', function(){
|
|
54
|
+
return this$.render();
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
parse: function(){},
|
|
58
|
+
resize: function(){
|
|
59
|
+
return this.cloud.size([this.box.width, this.box.height].map(function(it){
|
|
60
|
+
return Math.round(it);
|
|
61
|
+
})).words(this.dd).start();
|
|
62
|
+
},
|
|
63
|
+
render: function(){
|
|
64
|
+
var color, vext, vscale, x$, this$ = this;
|
|
65
|
+
color = d3.interpolateTurbo;
|
|
66
|
+
if (this.cfg != null && this.cfg.palette) {
|
|
67
|
+
color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
|
|
68
|
+
return ldColor.web(it.value || it);
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
vext = d3.extent(this.dd.map(function(it){
|
|
72
|
+
return it.value;
|
|
73
|
+
}));
|
|
74
|
+
vscale = d3.scaleLinear().domain(vext).range([0, 1]);
|
|
75
|
+
x$ = d3.select(this.svg).selectAll('text').data(this.dd);
|
|
76
|
+
x$.exit().remove();
|
|
77
|
+
x$.enter().append('text');
|
|
78
|
+
return d3.select(this.svg).selectAll('text').attr('transform', function(it){
|
|
79
|
+
return "translate(" + (it.x + this$.box.width / 2) + " " + (it.y + this$.box.height / 2) + ") rotate(" + it.rotate + ")";
|
|
80
|
+
}).attr('text-anchor', 'middle').attr('font-size', function(it){
|
|
81
|
+
return it.size;
|
|
82
|
+
}).attr('font-family', 'arial').attr('fill', function(it){
|
|
83
|
+
return color(vscale(it.value));
|
|
84
|
+
}).text(function(it){
|
|
85
|
+
return it.text;
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
tick: function(){}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
return blockFactory;
|
|
92
|
+
});</script></div>
|
|
@@ -0,0 +1,207 @@
|
|
|
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="legend">123</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(5em);
|
|
4
|
+
}
|
|
5
|
+
</style><script type="@plotdb/block">(function(it){
|
|
6
|
+
return it();
|
|
7
|
+
})(function(){
|
|
8
|
+
var blockFactory, mod;
|
|
9
|
+
blockFactory = {
|
|
10
|
+
pkg: {
|
|
11
|
+
name: 'worldmap',
|
|
12
|
+
version: '0.0.1',
|
|
13
|
+
extend: {
|
|
14
|
+
name: "base",
|
|
15
|
+
version: "0.0.1"
|
|
16
|
+
},
|
|
17
|
+
dependencies: [
|
|
18
|
+
{
|
|
19
|
+
url: "https://d3js.org/d3-geo.v2.min.js",
|
|
20
|
+
async: false
|
|
21
|
+
}, {
|
|
22
|
+
url: "https://d3js.org/topojson.v2.min.js",
|
|
23
|
+
async: false
|
|
24
|
+
}, {
|
|
25
|
+
url: "/assets/lib/@plotdb/pdmap-world/main/index.js"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
init: function(arg$){
|
|
30
|
+
var root, context, pubsub;
|
|
31
|
+
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
32
|
+
return pubsub.fire('init', {
|
|
33
|
+
mod: mod({
|
|
34
|
+
context: context
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
mod = function(arg$){
|
|
40
|
+
var context, chart, d3, ldcolor, pdmapWorld, topojson;
|
|
41
|
+
context = arg$.context;
|
|
42
|
+
chart = context.chart, d3 = context.d3, ldcolor = context.ldcolor, pdmapWorld = context.pdmapWorld, topojson = context.topojson;
|
|
43
|
+
return {
|
|
44
|
+
sample: function(){
|
|
45
|
+
return {
|
|
46
|
+
raw: pdmapWorld.meta.alpha2.map(function(it){
|
|
47
|
+
return {
|
|
48
|
+
country: it,
|
|
49
|
+
val: Math.random()
|
|
50
|
+
};
|
|
51
|
+
}),
|
|
52
|
+
binding: {
|
|
53
|
+
color: {
|
|
54
|
+
key: 'val'
|
|
55
|
+
},
|
|
56
|
+
name: {
|
|
57
|
+
key: 'country'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
config: {},
|
|
63
|
+
dimension: {
|
|
64
|
+
name: {
|
|
65
|
+
type: 'N',
|
|
66
|
+
name: "國家"
|
|
67
|
+
},
|
|
68
|
+
color: {
|
|
69
|
+
type: 'R',
|
|
70
|
+
name: "顏色"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
init: function(){
|
|
74
|
+
var scale, this$ = this;
|
|
75
|
+
this.g = this.layout.getGroup('view');
|
|
76
|
+
this.obj = new pdmapWorld({
|
|
77
|
+
root: this.g
|
|
78
|
+
});
|
|
79
|
+
this.scale = scale = {
|
|
80
|
+
color: d3.interpolateTurbo
|
|
81
|
+
};
|
|
82
|
+
this.legend = new chart.utils.legend({
|
|
83
|
+
root: this.root,
|
|
84
|
+
name: 'legend',
|
|
85
|
+
layout: this.layout,
|
|
86
|
+
shape: function(d){
|
|
87
|
+
return d3.select(this).attr('fill', scale.color(d.key));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
this.tip = new chart.utils.tip({
|
|
91
|
+
root: this.root,
|
|
92
|
+
accessor: function(arg$){
|
|
93
|
+
var evt, data, ret, k, v, name;
|
|
94
|
+
evt = arg$.evt;
|
|
95
|
+
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
ret = (function(){
|
|
99
|
+
var ref$, results$ = [];
|
|
100
|
+
for (k in ref$ = pdmapWorld.meta.zhalpha2) {
|
|
101
|
+
v = ref$[k];
|
|
102
|
+
results$.push([k, v]);
|
|
103
|
+
}
|
|
104
|
+
return results$;
|
|
105
|
+
}()).filter(function(it){
|
|
106
|
+
return it[1].toLowerCase() === data.properties.alpha2;
|
|
107
|
+
})[0];
|
|
108
|
+
name = ret
|
|
109
|
+
? ret[0]
|
|
110
|
+
: data.properties.shortname || data.data.name;
|
|
111
|
+
v = isNaN(data.data.color)
|
|
112
|
+
? '-'
|
|
113
|
+
: data.data.color.toFixed(2) + "" + (this$.binding.color.unit || '');
|
|
114
|
+
return {
|
|
115
|
+
name: name,
|
|
116
|
+
value: v
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
range: function(){
|
|
120
|
+
return this$.layout.getNode('view').getBoundingClientRect();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return this.obj.init().then(function(){
|
|
124
|
+
return this$.obj.fit();
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
destroy: function(){
|
|
128
|
+
return this.tip.destroy();
|
|
129
|
+
},
|
|
130
|
+
parse: function(){
|
|
131
|
+
var geoData, this$ = this;
|
|
132
|
+
geoData = d3.select(this.g).selectAll('path').data();
|
|
133
|
+
geoData.map(function(d){
|
|
134
|
+
d.data = null;
|
|
135
|
+
d.properties.value = 0;
|
|
136
|
+
return d.properties.data = {};
|
|
137
|
+
});
|
|
138
|
+
this.data.map(function(it){
|
|
139
|
+
return {
|
|
140
|
+
c: this$.obj.findCountry(it.name),
|
|
141
|
+
v: it
|
|
142
|
+
};
|
|
143
|
+
}).filter(function(it){
|
|
144
|
+
return it.c;
|
|
145
|
+
}).map(function(it){
|
|
146
|
+
var ref$;
|
|
147
|
+
return ref$ = it.c, ref$.value = it.v.color, ref$.data = it.v, ref$;
|
|
148
|
+
});
|
|
149
|
+
geoData.map(function(d){
|
|
150
|
+
return d.data = d.properties.data || {};
|
|
151
|
+
});
|
|
152
|
+
return this.extent = {
|
|
153
|
+
c: d3.extent(geoData, function(it){
|
|
154
|
+
return it.properties.value;
|
|
155
|
+
})
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
resize: function(){
|
|
159
|
+
var ref$, pal, len, this$ = this;
|
|
160
|
+
this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
|
|
161
|
+
this.obj.fit(this.layout.getBox('view'));
|
|
162
|
+
pal = this.cfg.palette
|
|
163
|
+
? this.cfg.palette.colors
|
|
164
|
+
: ['#f00', '#999', '#00f'];
|
|
165
|
+
len = pal.length;
|
|
166
|
+
this.ticks = d3.quantize(function(it){
|
|
167
|
+
return (1 - it) * (this$.extent.c[1] - this$.extent.c[0]) + this$.extent.c[0];
|
|
168
|
+
}, len).map(function(it){
|
|
169
|
+
var that;
|
|
170
|
+
return {
|
|
171
|
+
key: it,
|
|
172
|
+
text: d3.format(this$.cfg.legendFormat || '.2f')(it) + ((that = this$.binding.color.unit) ? that : '')
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
this.ticks.sort(function(a, b){
|
|
176
|
+
return a.key - b.key;
|
|
177
|
+
});
|
|
178
|
+
if (this.cfg.palette) {
|
|
179
|
+
this.scale.color = d3.scaleLinear().domain(this.ticks.map(function(it){
|
|
180
|
+
return it.key;
|
|
181
|
+
})).range(pal.map(function(it){
|
|
182
|
+
return ldcolor.web(it.value || it);
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
return this.legend.data(this.ticks);
|
|
186
|
+
},
|
|
187
|
+
render: function(){
|
|
188
|
+
var this$ = this;
|
|
189
|
+
this.legend.render();
|
|
190
|
+
return d3.select(this.g).selectAll('path').transition().duration(350).attr('fill', function(d, i){
|
|
191
|
+
return this$.scale.color(d.properties.value);
|
|
192
|
+
}).attr('fill-opacity', function(d, i){
|
|
193
|
+
if (this$.cfg.dimEmpty) {
|
|
194
|
+
if (d.properties.value) {
|
|
195
|
+
return 1;
|
|
196
|
+
} else {
|
|
197
|
+
return 0.2;
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
return 1;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
return blockFactory;
|
|
207
|
+
});</script></div>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|