@plotdb/chart 0.0.2 → 1.0.3
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/README.md +3 -3
- package/dist/chart.js +18 -12
- package/dist/chart.min.js +1 -1
- package/dist/index.css +8 -0
- package/dist/index.js +609 -0
- package/dist/index.min.css +1 -0
- package/dist/index.min.js +1 -0
- package/dist/utils/axis.js +6 -0
- package/dist/utils/axis.min.js +1 -1
- package/package.json +22 -11
- package/CHANGELOG.md +0 -11
- package/build +0 -39
- package/doc/charts.md +0 -58
- package/doc/config.md +0 -44
- package/doc/draft/chart.md +0 -146
- package/doc/draft/data.md +0 -8
- 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 +0 -89
- package/doc/spec.md +0 -89
- package/doc/todo.md +0 -27
- package/doc/utils/tip.md +0 -84
- package/src/chart.ls +0 -320
- package/src/chart.styl +0 -6
- package/src/data/en-US/category +0 -20
- package/src/data/en-US/fruit +0 -39
- package/src/data/en-US/movie +0 -125
- package/src/data/en-US/name +0 -58
- package/src/data/index.ls +0 -34
- package/src/data/zh-TW/category +0 -20
- package/src/data/zh-TW/fruits +0 -38
- package/src/data/zh-TW/movie +0 -125
- package/src/data/zh-TW/names +0 -105
- package/src/utils/axis.ls +0 -229
- package/src/utils/config.ls +0 -11
- package/src/utils/data.ls +0 -104
- package/src/utils/format.ls +0 -30
- package/src/utils/legend.ls +0 -134
- package/src/utils/legend.styl +0 -37
- package/src/utils/tint.ls +0 -66
- package/src/utils/tip.ls +0 -97
- package/web/src/pug/base.pug +0 -19
- package/web/src/pug/block/axis/0.0.1/index.ls +0 -38
- package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
- package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -141
- package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
- package/web/src/pug/block/bar/0.0.1/index.ls +0 -274
- package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
- package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -85
- package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
- package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -83
- package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
- package/web/src/pug/block/base/0.0.1/index.ls +0 -67
- package/web/src/pug/block/base/0.0.1/index.pug +0 -5
- package/web/src/pug/block/blank/0.0.1/index.ls +0 -25
- package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
- package/web/src/pug/block/bubble/0.0.1/index.ls +0 -220
- package/web/src/pug/block/bubble/0.0.1/index.pug +0 -28
- package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -89
- package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
- package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
- package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -90
- package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
- package/web/src/pug/block/empty/0.0.1/index.ls +0 -27
- package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
- package/web/src/pug/block/gauge/0.0.1/index.ls +0 -100
- package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
- package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
- package/web/src/pug/block/line/0.0.1/index.ls +0 -265
- package/web/src/pug/block/line/0.0.1/index.pug +0 -33
- package/web/src/pug/block/number/0.0.1/index.ls +0 -69
- package/web/src/pug/block/number/0.0.1/index.pug +0 -20
- package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -167
- package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
- package/web/src/pug/block/pie/0.0.1/index.ls +0 -125
- package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
- package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
- package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -185
- package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
- package/web/src/pug/block/radar/0.0.1/index.ls +0 -113
- package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
- package/web/src/pug/block/radar/0.0.1/xx +0 -285
- package/web/src/pug/block/scatter/0.0.1/index.ls +0 -128
- package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
- package/web/src/pug/block/sheet/0.0.1/index.ls +0 -38
- package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
- package/web/src/pug/block/table/0.0.1/index.ls +0 -40
- package/web/src/pug/block/table/0.0.1/index.pug +0 -3
- package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -48
- package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
- package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -53
- package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
- package/web/src/pug/block/treemap/0.0.1/index.ls +0 -172
- package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
- package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -174
- package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
- package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
- package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -61
- package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
- package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -83
- package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
- package/web/src/pug/index.ls +0 -72
- package/web/src/pug/index.pug +0 -52
- package/web/src/styl/index.styl +0 -0
- package/web/static/assets/block/cache.js +0 -4
- package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
- package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
- package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
- package/web/static/assets/data/countrycode.json +0 -1
- package/web/static/assets/data/world-110m.json +0 -1
- package/web/static/assets/data/zh-to-alpha2.json +0 -1
- package/web/static/assets/img/fluid.svg +0 -16
- package/web/static/block/axis/0.0.1/index.html +0 -79
- package/web/static/block/axis-bubble/0.0.1/index.html +0 -222
- package/web/static/block/bar/0.0.1/index.html +0 -581
- package/web/static/block/bar-list/0.0.1/index.html +0 -231
- package/web/static/block/bar-race/0.0.1/index.html +0 -184
- package/web/static/block/base/0.0.1/index.html +0 -197
- package/web/static/block/blank/0.0.1/index.html +0 -42
- package/web/static/block/bubble/0.0.1/index.html +0 -402
- package/web/static/block/bubble/0.0.1/test.html +0 -0
- package/web/static/block/curve-bar/0.0.1/index.html +0 -148
- package/web/static/block/dumbbell/0.0.1/index.html +0 -178
- package/web/static/block/empty/0.0.1/index.html +0 -76
- package/web/static/block/gauge/0.0.1/index.html +0 -150
- package/web/static/block/line/0.0.1/index.html +0 -540
- package/web/static/block/number/0.0.1/index.html +0 -152
- package/web/static/block/percent-list/0.0.1/index.html +0 -316
- package/web/static/block/pie/0.0.1/index.html +0 -281
- package/web/static/block/pie-bubble/0.0.1/index.html +0 -358
- package/web/static/block/radar/0.0.1/index.html +0 -149
- package/web/static/block/scatter/0.0.1/index.html +0 -251
- package/web/static/block/sheet/0.0.1/index.html +0 -103
- package/web/static/block/table/0.0.1/index.html +0 -73
- package/web/static/block/taiwantown/0.0.1/index.html +0 -210
- package/web/static/block/taiwanvillage/0.0.1/index.html +0 -220
- package/web/static/block/treemap/0.0.1/index.html +0 -360
- package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -350
- package/web/static/block/wordcloud/0.0.1/index.html +0 -92
- package/web/static/block/worldmap/0.0.1/index.html +0 -207
- 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 +0 -153
|
@@ -1,358 +0,0 @@
|
|
|
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 data-name="tip"><div ld="name"></div><div ld="value1"></div><div ld="value2"></div></div></div><style type="text/css">/*.pdl-cell { width: 100%; height: 100% }*/
|
|
2
|
-
.pdl-layout > div[data-type=layout] {
|
|
3
|
-
display: grid;
|
|
4
|
-
grid-template-columns: 1fr fit-content(10em);
|
|
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;
|
|
12
|
-
padding: 0 0.5em 0 0.5em;
|
|
13
|
-
}
|
|
14
|
-
[data-name=tip] {
|
|
15
|
-
padding: 0.4em 0.5em;
|
|
16
|
-
background: #13171a;
|
|
17
|
-
color: #fff;
|
|
18
|
-
border-radius: 3px;
|
|
19
|
-
box-shadow: 0 2px 4px rgba(0,0,0,0.3);
|
|
20
|
-
line-height: 1.2em;
|
|
21
|
-
font-size: 0.9em;
|
|
22
|
-
max-width: 10em;
|
|
23
|
-
word-break: break-all;
|
|
24
|
-
}
|
|
25
|
-
[data-name=tip] [ld=name] {
|
|
26
|
-
font-size: 0.85em;
|
|
27
|
-
}
|
|
28
|
-
[data-name=tip] [ld=value1],
|
|
29
|
-
[data-name=tip] [ld=value2] {
|
|
30
|
-
font-weight: bold;
|
|
31
|
-
font-size: 1.1em;
|
|
32
|
-
line-height: 1.2em;
|
|
33
|
-
}
|
|
34
|
-
</style><script type="@plotdb/block">(function(it){
|
|
35
|
-
return it();
|
|
36
|
-
})(function(){
|
|
37
|
-
var blockFactory, mod;
|
|
38
|
-
blockFactory = {
|
|
39
|
-
pkg: {
|
|
40
|
-
name: 'pie-bubble',
|
|
41
|
-
version: '0.0.1',
|
|
42
|
-
extend: {
|
|
43
|
-
name: "base",
|
|
44
|
-
version: "0.0.1"
|
|
45
|
-
},
|
|
46
|
-
dependencies: []
|
|
47
|
-
},
|
|
48
|
-
init: function(arg$){
|
|
49
|
-
var root, context, pubsub;
|
|
50
|
-
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
51
|
-
return pubsub.fire('init', {
|
|
52
|
-
mod: mod({
|
|
53
|
-
context: context
|
|
54
|
-
})
|
|
55
|
-
}).then(function(it){
|
|
56
|
-
return it[0];
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
mod = function(arg$){
|
|
61
|
-
var context, d3, forceBoundary, ldcolor, chart, ref$;
|
|
62
|
-
context = arg$.context;
|
|
63
|
-
d3 = context.d3, forceBoundary = context.forceBoundary, ldcolor = context.ldcolor, chart = context.chart;
|
|
64
|
-
return {
|
|
65
|
-
sample: function(){
|
|
66
|
-
return {
|
|
67
|
-
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){
|
|
68
|
-
return {
|
|
69
|
-
name: "name" + val,
|
|
70
|
-
val1: Math.random() * 100,
|
|
71
|
-
val2: Math.random() * 100
|
|
72
|
-
};
|
|
73
|
-
}),
|
|
74
|
-
binding: {
|
|
75
|
-
name: {
|
|
76
|
-
key: 'name'
|
|
77
|
-
},
|
|
78
|
-
left: {
|
|
79
|
-
key: 'val1'
|
|
80
|
-
},
|
|
81
|
-
right: {
|
|
82
|
-
key: 'val2'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
config: (ref$ = import$({}, chart.utils.config.preset['default']), ref$.color = {
|
|
88
|
-
left: {
|
|
89
|
-
type: 'color',
|
|
90
|
-
'default': '#f90'
|
|
91
|
-
},
|
|
92
|
-
right: {
|
|
93
|
-
type: 'color',
|
|
94
|
-
'default': '#09f'
|
|
95
|
-
}
|
|
96
|
-
}, ref$),
|
|
97
|
-
dimension: {
|
|
98
|
-
name: {
|
|
99
|
-
type: 'N',
|
|
100
|
-
name: "name"
|
|
101
|
-
},
|
|
102
|
-
left: {
|
|
103
|
-
type: 'R',
|
|
104
|
-
name: "size in left"
|
|
105
|
-
},
|
|
106
|
-
right: {
|
|
107
|
-
type: 'R',
|
|
108
|
-
name: "size in right"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
init: function(){
|
|
112
|
-
var tint, this$ = this;
|
|
113
|
-
this.tint = tint = new chart.utils.tint();
|
|
114
|
-
this.valid = [];
|
|
115
|
-
this.g = Object.fromEntries(['view', 'legend'].map(function(it){
|
|
116
|
-
return [it, d3.select(this$.layout.getGroup(it))];
|
|
117
|
-
}));
|
|
118
|
-
this.tip = new chart.utils.tip({
|
|
119
|
-
root: this.root,
|
|
120
|
-
node: this.root.querySelector('[data-name=tip]'),
|
|
121
|
-
view: {
|
|
122
|
-
name: function(arg$){
|
|
123
|
-
var ctx;
|
|
124
|
-
ctx = arg$.ctx;
|
|
125
|
-
if (ctx) {
|
|
126
|
-
return ctx.name;
|
|
127
|
-
} else {
|
|
128
|
-
return '';
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
value1: function(arg$){
|
|
132
|
-
var ctx;
|
|
133
|
-
ctx = arg$.ctx;
|
|
134
|
-
if (ctx) {
|
|
135
|
-
return ctx.value1;
|
|
136
|
-
} else {
|
|
137
|
-
return '';
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
value2: function(arg$){
|
|
141
|
-
var ctx;
|
|
142
|
-
ctx = arg$.ctx;
|
|
143
|
-
if (ctx) {
|
|
144
|
-
return ctx.value2;
|
|
145
|
-
} else {
|
|
146
|
-
return '';
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
accessor: function(arg$){
|
|
151
|
-
var evt, data, unit, fmt;
|
|
152
|
-
evt = arg$.evt;
|
|
153
|
-
if (!(evt.target && (data = d3.select(evt.target).datum()))) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
unit = this$.binding.left.unit || this$.binding.right.unit || '';
|
|
157
|
-
fmt = d3.format('.3s');
|
|
158
|
-
return {
|
|
159
|
-
name: data.name || '',
|
|
160
|
-
value1: this$.legendData[0].text + ": " + fmt(data.L) + unit,
|
|
161
|
-
value2: this$.legendData[1].text + ": " + fmt(data.R) + unit
|
|
162
|
-
};
|
|
163
|
-
},
|
|
164
|
-
range: function(){
|
|
165
|
-
return this$.layout.getNode('view').getBoundingClientRect();
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
this.legend = new chart.utils.legend({
|
|
169
|
-
layout: this.layout,
|
|
170
|
-
name: 'legend',
|
|
171
|
-
root: this.root,
|
|
172
|
-
shape: function(d){
|
|
173
|
-
return d3.select(this).attr('fill', tint.get(d.key));
|
|
174
|
-
},
|
|
175
|
-
cfg: {
|
|
176
|
-
selectable: true
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
return this.legend.on('select', function(){
|
|
180
|
-
this$.bind();
|
|
181
|
-
this$.resize();
|
|
182
|
-
return this$.render();
|
|
183
|
-
});
|
|
184
|
-
},
|
|
185
|
-
destroy: function(){
|
|
186
|
-
return this.tip.destroy();
|
|
187
|
-
},
|
|
188
|
-
parse: function(){
|
|
189
|
-
var this$ = this;
|
|
190
|
-
this.valid = this.data.filter(function(it){
|
|
191
|
-
return !isNaN(it.left + it.right);
|
|
192
|
-
});
|
|
193
|
-
this.legendData = ['left', 'right'].map(function(it){
|
|
194
|
-
var v;
|
|
195
|
-
v = this$.binding[it] ? this$.binding[it].name || this$.binding[it].key : it;
|
|
196
|
-
return {
|
|
197
|
-
key: v,
|
|
198
|
-
text: v
|
|
199
|
-
};
|
|
200
|
-
});
|
|
201
|
-
return this.legend.data(this.legendData);
|
|
202
|
-
},
|
|
203
|
-
resize: function(){
|
|
204
|
-
var ref$, vbox, rng, this$ = this;
|
|
205
|
-
this.sim = null;
|
|
206
|
-
this.start();
|
|
207
|
-
(ref$ = this.cfg).tip || (ref$.tip = {});
|
|
208
|
-
(ref$ = this.cfg).color || (ref$.color = {});
|
|
209
|
-
(ref$ = this.cfg).legend || (ref$.legend = {});
|
|
210
|
-
this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
|
|
211
|
-
if (this.cfg.color.left === this.cfg.color.right) {
|
|
212
|
-
this.cfg.colorRight = '#09f';
|
|
213
|
-
}
|
|
214
|
-
this.tint.set({
|
|
215
|
-
colors: [this.cfg.color.left || this.cfg.palette.colors[0] || '#09f', this.cfg.color.right || this.cfg.palette.colors[1] || '#f90'],
|
|
216
|
-
maps: this.legendData.map(function(it){
|
|
217
|
-
return it.key;
|
|
218
|
-
})
|
|
219
|
-
}, true);
|
|
220
|
-
this.legend.config((ref$ = this.cfg.legend, ref$.selectable = false, ref$));
|
|
221
|
-
this.legend.update();
|
|
222
|
-
this.layout.update(false);
|
|
223
|
-
this.vbox = vbox = this.layout.getBox('view');
|
|
224
|
-
rng = d3.randomUniform.source(d3.randomLcg(this.seed))(0, 1);
|
|
225
|
-
this.valid.map(function(obj){
|
|
226
|
-
var ref$, L, R, r, sum, rate, x, y;
|
|
227
|
-
ref$ = [(ref$ = obj.left) > 0 ? ref$ : 0, (ref$ = obj.right) > 0 ? ref$ : 0], L = ref$[0], R = ref$[1];
|
|
228
|
-
r = sum = L + R;
|
|
229
|
-
rate = !sum
|
|
230
|
-
? 0.5
|
|
231
|
-
: R / sum;
|
|
232
|
-
ref$ = [rate * vbox.width, rng() * vbox.height], x = ref$[0], y = ref$[1];
|
|
233
|
-
obj.r = r;
|
|
234
|
-
obj.sum = sum;
|
|
235
|
-
obj.rate = rate;
|
|
236
|
-
obj.L = L;
|
|
237
|
-
obj.R = R;
|
|
238
|
-
obj.cx = x;
|
|
239
|
-
if (!(obj.x != null)) {
|
|
240
|
-
obj.x = x;
|
|
241
|
-
obj.y = y;
|
|
242
|
-
}
|
|
243
|
-
if (!(obj._x != null)) {
|
|
244
|
-
obj._x = x;
|
|
245
|
-
obj._y = y;
|
|
246
|
-
}
|
|
247
|
-
return obj;
|
|
248
|
-
});
|
|
249
|
-
this.rate = 0.9 * Math.PI / (2 * Math.sqrt(3)) * Math.sqrt(vbox.width * vbox.height / this.valid.map(function(it){
|
|
250
|
-
return Math.PI * Math.pow(it.r, 2);
|
|
251
|
-
}).reduce(function(a, b){
|
|
252
|
-
return a + b;
|
|
253
|
-
}, 0));
|
|
254
|
-
return this.valid.map(function(d, i){
|
|
255
|
-
var ref$;
|
|
256
|
-
return d.rr = (ref$ = d.r * this$.rate) > 2 ? ref$ : 2;
|
|
257
|
-
});
|
|
258
|
-
},
|
|
259
|
-
render: function(){
|
|
260
|
-
var binding, tint, rate, legendData, x$, y$;
|
|
261
|
-
binding = this.binding, tint = this.tint, rate = this.rate, legendData = this.legendData;
|
|
262
|
-
x$ = this.g.view.selectAll('g.pie').data(this.valid);
|
|
263
|
-
x$.exit().remove();
|
|
264
|
-
x$.enter().append('g').attr('class', "pie data").each(function(){
|
|
265
|
-
d3.select(this).append('path');
|
|
266
|
-
return d3.select(this).append('path');
|
|
267
|
-
});
|
|
268
|
-
this.g.view.selectAll('g.pie').each(function(d, i){
|
|
269
|
-
d3.select(this).attr('transform', "translate(" + d.x + " " + d.y + ")");
|
|
270
|
-
return d3.select(this).selectAll('path').attr('fill', function(e, j){
|
|
271
|
-
return tint.get(legendData[j].key);
|
|
272
|
-
}).attr('d', function(e, j){
|
|
273
|
-
var r, rx, ry1, ry2, f;
|
|
274
|
-
r = d.rr;
|
|
275
|
-
rx = r * Math.cos(d.rate * Math.PI);
|
|
276
|
-
ry1 = -r * Math.sin(d.rate * Math.PI);
|
|
277
|
-
ry2 = r * Math.sin(d.rate * Math.PI);
|
|
278
|
-
f = d.rate > 0.5
|
|
279
|
-
? j
|
|
280
|
-
: 1 - j;
|
|
281
|
-
return ["M", rx, ry1, "A", r, r, 0, f, j, rx, ry2, "L", 0, 0, "Z"].join(" ");
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
y$ = this.g.view.selectAll('g.label').data(this.valid);
|
|
285
|
-
y$.exit().remove();
|
|
286
|
-
y$.enter().append('g').attr('class', 'label').each(function(d, i){
|
|
287
|
-
var this$ = this;
|
|
288
|
-
return [0].map(function(){
|
|
289
|
-
return d3.select(this$).append('text');
|
|
290
|
-
}).map(function(it){
|
|
291
|
-
return it.attr('text-anchor', 'middle').attr('dominant-baseline', 'middle').attr('font-size', '.7em').style('pointer-event', 'none');
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
295
|
-
return "translate(" + d.x + "," + d.y + ")";
|
|
296
|
-
}).each(function(d, i){
|
|
297
|
-
return d3.select(this).selectAll('text').attr('opacity', d.rr * 2 < (d.sum.toFixed(2) + "").length * 7 ? 0 : 1).text(function(e, i){
|
|
298
|
-
var ret;
|
|
299
|
-
ret = d3.format('.3s')(d.sum);
|
|
300
|
-
if (ret) {
|
|
301
|
-
ret = ret + "" + (binding.left.unit || binding.right.unir || '');
|
|
302
|
-
}
|
|
303
|
-
return ret;
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
return this.legend.render();
|
|
307
|
-
},
|
|
308
|
-
tick: function(){
|
|
309
|
-
var pad, kickoff, fc, this$ = this;
|
|
310
|
-
pad = this.cfg.pad || 5;
|
|
311
|
-
if (!this.sim) {
|
|
312
|
-
kickoff = true;
|
|
313
|
-
this.fc = fc = d3.forceCollide().strength(0.6).iterations(20).radius(function(it){
|
|
314
|
-
return it.rr;
|
|
315
|
-
});
|
|
316
|
-
this.fb = forceBoundary(function(it){
|
|
317
|
-
return it.rr + pad;
|
|
318
|
-
}, function(it){
|
|
319
|
-
return it.rr + pad;
|
|
320
|
-
}, function(it){
|
|
321
|
-
return this$.vbox.width - it.rr - pad;
|
|
322
|
-
}, function(it){
|
|
323
|
-
return this$.vbox.height - it.rr - pad;
|
|
324
|
-
}).strength(0.8);
|
|
325
|
-
this.fy = d3.forceY().strength(0.2);
|
|
326
|
-
this.fx = d3.forceX().strength(0.2).x(function(it){
|
|
327
|
-
return it.cx;
|
|
328
|
-
});
|
|
329
|
-
this.sim = d3.forceSimulation().force('b', this.fb).force('collide', fc).force('fx', this.fx).force('fy', this.fy);
|
|
330
|
-
this.sim.stop();
|
|
331
|
-
this.sim.alpha(0.9);
|
|
332
|
-
}
|
|
333
|
-
this.fy.y(this.vbox.height / 2);
|
|
334
|
-
this.sim.nodes(this.valid);
|
|
335
|
-
this.sim.tick(kickoff ? 10 : 1);
|
|
336
|
-
if (this.sim.alpha() < 0.01) {
|
|
337
|
-
this.stop();
|
|
338
|
-
}
|
|
339
|
-
this.valid.map(function(it){
|
|
340
|
-
it._x = it._x + (it.x - it._x) * 0.1;
|
|
341
|
-
return it._y = it._y + (it.y - it._y) * 0.1;
|
|
342
|
-
});
|
|
343
|
-
this.g.view.selectAll('g.label').attr('transform', function(d, i){
|
|
344
|
-
return "translate(" + d._x + "," + d._y + ")";
|
|
345
|
-
});
|
|
346
|
-
return this.g.view.selectAll('g.pie').attr('transform', function(d, i){
|
|
347
|
-
return "translate(" + d._x + "," + d._y + ")";
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
};
|
|
352
|
-
return blockFactory;
|
|
353
|
-
});
|
|
354
|
-
function import$(obj, src){
|
|
355
|
-
var own = {}.hasOwnProperty;
|
|
356
|
-
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
|
357
|
-
return obj;
|
|
358
|
-
}</script></div>
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
<div><script type="@plotdb/block">(function(it){
|
|
2
|
-
return it();
|
|
3
|
-
})(function(){
|
|
4
|
-
var blockFactory, mod;
|
|
5
|
-
blockFactory = {
|
|
6
|
-
pkg: {
|
|
7
|
-
name: 'radar',
|
|
8
|
-
version: '0.0.1',
|
|
9
|
-
extend: {
|
|
10
|
-
name: "base",
|
|
11
|
-
version: "0.0.1"
|
|
12
|
-
},
|
|
13
|
-
dependencies: []
|
|
14
|
-
},
|
|
15
|
-
init: function(arg$){
|
|
16
|
-
var root, context, pubsub;
|
|
17
|
-
root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
|
|
18
|
-
return pubsub.fire('init', {
|
|
19
|
-
mod: mod({
|
|
20
|
-
context: context
|
|
21
|
-
})
|
|
22
|
-
}).then(function(it){
|
|
23
|
-
return it[0];
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
mod = function(arg$){
|
|
28
|
-
var context, d3, forceBoundary, ldColor, repeatString$;
|
|
29
|
-
context = arg$.context;
|
|
30
|
-
d3 = context.d3, forceBoundary = context.forceBoundary, ldColor = context.ldColor, repeatString$ = context.repeatString$;
|
|
31
|
-
return {
|
|
32
|
-
sample: function(){
|
|
33
|
-
return {
|
|
34
|
-
raw: [0, 1, 2, 3, 4].map(function(idx){
|
|
35
|
-
return {
|
|
36
|
-
val: [0, 1, 2].map(function(){
|
|
37
|
-
return 0.5 + 0.5 * Math.random();
|
|
38
|
-
}),
|
|
39
|
-
cat: idx
|
|
40
|
-
};
|
|
41
|
-
}),
|
|
42
|
-
binding: {
|
|
43
|
-
radius: {
|
|
44
|
-
key: 'val'
|
|
45
|
-
},
|
|
46
|
-
order: {
|
|
47
|
-
key: 'cat'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
config: {},
|
|
53
|
-
dimension: {
|
|
54
|
-
radius: {
|
|
55
|
-
type: 'R',
|
|
56
|
-
name: "radius of point on radar line"
|
|
57
|
-
},
|
|
58
|
-
order: {
|
|
59
|
-
type: 'R',
|
|
60
|
-
name: "order of data point"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
init: function(){
|
|
64
|
-
var svg, gs, this$ = this;
|
|
65
|
-
svg = d3.select(this.svg);
|
|
66
|
-
this.gs = gs = {};
|
|
67
|
-
gs.all = svg.append('g');
|
|
68
|
-
return this.line = d3.line().x(function(d, i){
|
|
69
|
-
return this$.scale.r(d) * Math.cos(this$.scale.a(this$.orders[i]));
|
|
70
|
-
}).y(function(d, i){
|
|
71
|
-
return this$.scale.r(d) * -Math.sin(this$.scale.a(this$.orders[i]));
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
parse: function(){
|
|
75
|
-
this.orders = Array.from(new Set(this.data.map(function(it){
|
|
76
|
-
return it.order;
|
|
77
|
-
})));
|
|
78
|
-
this.parsed = d3.transpose(this.data.map(function(it){
|
|
79
|
-
return it.radius;
|
|
80
|
-
}));
|
|
81
|
-
this.parsed.map(function(d, i){
|
|
82
|
-
return d.idx = i;
|
|
83
|
-
});
|
|
84
|
-
this.names = ['1', '2', '3'];
|
|
85
|
-
this.radiusRange = d3.extent(this.parsed.map(function(d){
|
|
86
|
-
return d3.extent(d);
|
|
87
|
-
}).reduce(function(a, b){
|
|
88
|
-
return a.concat(b);
|
|
89
|
-
}, []));
|
|
90
|
-
if (this.radiusRange[0] === this.radiusRange[1]) {
|
|
91
|
-
return this.radiusRange[1]++;
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
bind: function(){
|
|
95
|
-
var x$, y$;
|
|
96
|
-
x$ = this.gs.all.selectAll('path.data').data(this.parsed);
|
|
97
|
-
x$.exit().attr('class', "").transition('exit').duration(500).attr('opacity', 0).remove();
|
|
98
|
-
x$.enter().append('path').attr('class', 'data').attr('opacity', 0);
|
|
99
|
-
y$ = this.gs.all.selectAll('g.data-group').data(this.parsed);
|
|
100
|
-
y$.exit().attr('class', "").transition('exit').duration(500).attr('opacity', 0).remove();
|
|
101
|
-
y$.enter().append('g').attr('class', 'data-group').attr('opacity', 0);
|
|
102
|
-
return this.gs.all.selectAll('g.data-group').each(function(d, i){
|
|
103
|
-
var x$;
|
|
104
|
-
x$ = d3.select(this).selectAll('circle.node').data(d);
|
|
105
|
-
x$.exit().attr('class', '').transition('exit').duration(500).attr('opacity', 0).remove();
|
|
106
|
-
x$.enter().append('circle').attr('class', 'node').attr('opacity', 0);
|
|
107
|
-
return x$;
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
resize: function(){
|
|
111
|
-
var size, ref$;
|
|
112
|
-
size = (ref$ = Math.min(this.box.width, this.box.height) / 2) > 10 ? ref$ : 10;
|
|
113
|
-
this.scale = {
|
|
114
|
-
r: d3.scaleLinear().domain([0, this.radiusRange[1]]).range([0, size]),
|
|
115
|
-
a: d3.scalePoint().domain(this.orders).range([0, 2 * Math.PI]),
|
|
116
|
-
c: d3.interpolateTurbo
|
|
117
|
-
};
|
|
118
|
-
if (this.cfg != null && this.cfg.palette) {
|
|
119
|
-
this.scale.c = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
|
|
120
|
-
return ldColor.web(it.value || it);
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
return this.aTicks = d3.range(this.data.length);
|
|
124
|
-
},
|
|
125
|
-
render: function(){
|
|
126
|
-
var scale, names, line, orders;
|
|
127
|
-
scale = this.scale, names = this.names, line = this.line, orders = this.orders, orders = this.orders;
|
|
128
|
-
this.gs.all.attr('transform', "translate(" + this.box.width / 2 + "," + this.box.height / 2 + ")");
|
|
129
|
-
this.gs.all.selectAll('path.data').each(function(d, i){
|
|
130
|
-
var color;
|
|
131
|
-
color = scale.c(i / (names.length - 1));
|
|
132
|
-
return d3.select(this).attr('fill', color).attr('fill-opacity', 0.2).attr('stroke', color).attr('stroke-width', 1).transition('morph').duration(350).attr('d', function(d, i){
|
|
133
|
-
return line(d, i) + "Z";
|
|
134
|
-
});
|
|
135
|
-
}).transition('opacity').duration(350).attr('opacity', 1);
|
|
136
|
-
return this.gs.all.selectAll('g.data-group').each(function(d, i){
|
|
137
|
-
var color;
|
|
138
|
-
color = scale.c(i / (names.length - 1));
|
|
139
|
-
return d3.select(this).selectAll('circle.node').attr('fill', '#fff').attr('stroke', color).attr('stroke-width', 1).transition('morph').duration(350).attr('cx', function(d, i){
|
|
140
|
-
return scale.r(d) * Math.cos(scale.a(orders[i]));
|
|
141
|
-
}).attr('cy', function(d, i){
|
|
142
|
-
return scale.r(d) * -Math.sin(scale.a(orders[i]));
|
|
143
|
-
}).attr('r', 3).attr('opacity', 1);
|
|
144
|
-
}).transition('opacity').duration(350).attr('opacity', 1);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
return blockFactory;
|
|
149
|
-
});</script></div>
|