@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.
Files changed (177) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +50 -0
  3. package/build +39 -0
  4. package/dist/chart.css +8 -0
  5. package/dist/chart.js +603 -0
  6. package/dist/chart.min.css +1 -0
  7. package/dist/chart.min.js +1 -0
  8. package/dist/data/index.js +73 -0
  9. package/dist/utils/axis.js +357 -0
  10. package/dist/utils/axis.min.js +1 -0
  11. package/dist/utils/config.js +33 -0
  12. package/dist/utils/config.min.js +1 -0
  13. package/dist/utils/data.js +238 -0
  14. package/dist/utils/data.min.js +1 -0
  15. package/dist/utils/format.js +70 -0
  16. package/dist/utils/format.min.js +1 -0
  17. package/dist/utils/legend.css +40 -0
  18. package/dist/utils/legend.js +263 -0
  19. package/dist/utils/legend.min.css +1 -0
  20. package/dist/utils/legend.min.js +1 -0
  21. package/dist/utils/tint.js +138 -0
  22. package/dist/utils/tint.min.js +1 -0
  23. package/dist/utils/tip.js +148 -0
  24. package/dist/utils/tip.min.js +1 -0
  25. package/doc/charts.md +58 -0
  26. package/doc/config.md +44 -0
  27. package/doc/draft/chart.md +146 -0
  28. package/doc/draft/data.md +8 -0
  29. package/doc/draft/definition.md +0 -0
  30. package/doc/draft/events.md +0 -0
  31. package/doc/draft/filter.md +0 -0
  32. package/doc/draft/lifecycle.md +89 -0
  33. package/doc/spec.md +89 -0
  34. package/doc/todo.md +27 -0
  35. package/doc/utils/tip.md +84 -0
  36. package/package.json +83 -0
  37. package/src/chart.ls +320 -0
  38. package/src/chart.styl +6 -0
  39. package/src/data/en-US/category +20 -0
  40. package/src/data/en-US/fruit +39 -0
  41. package/src/data/en-US/movie +125 -0
  42. package/src/data/en-US/name +58 -0
  43. package/src/data/index.ls +34 -0
  44. package/src/data/zh-TW/category +20 -0
  45. package/src/data/zh-TW/fruits +38 -0
  46. package/src/data/zh-TW/movie +125 -0
  47. package/src/data/zh-TW/names +105 -0
  48. package/src/utils/axis.ls +229 -0
  49. package/src/utils/config.ls +11 -0
  50. package/src/utils/data.ls +104 -0
  51. package/src/utils/format.ls +30 -0
  52. package/src/utils/legend.ls +134 -0
  53. package/src/utils/legend.styl +37 -0
  54. package/src/utils/tint.ls +66 -0
  55. package/src/utils/tip.ls +97 -0
  56. package/web/src/pug/base.pug +19 -0
  57. package/web/src/pug/block/axis/0.0.1/index.ls +38 -0
  58. package/web/src/pug/block/axis/0.0.1/index.pug +1 -0
  59. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +141 -0
  60. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +1 -0
  61. package/web/src/pug/block/bar/0.0.1/index.ls +274 -0
  62. package/web/src/pug/block/bar/0.0.1/index.pug +35 -0
  63. package/web/src/pug/block/bar-list/0.0.1/index.ls +85 -0
  64. package/web/src/pug/block/bar-list/0.0.1/index.pug +30 -0
  65. package/web/src/pug/block/bar-race/0.0.1/index.ls +83 -0
  66. package/web/src/pug/block/bar-race/0.0.1/index.pug +21 -0
  67. package/web/src/pug/block/base/0.0.1/index.ls +67 -0
  68. package/web/src/pug/block/base/0.0.1/index.pug +5 -0
  69. package/web/src/pug/block/blank/0.0.1/index.ls +25 -0
  70. package/web/src/pug/block/blank/0.0.1/index.pug +1 -0
  71. package/web/src/pug/block/bubble/0.0.1/index.ls +220 -0
  72. package/web/src/pug/block/bubble/0.0.1/index.pug +28 -0
  73. package/web/src/pug/block/curve-bar/0.0.1/index.ls +89 -0
  74. package/web/src/pug/block/curve-bar/0.0.1/index.pug +16 -0
  75. package/web/src/pug/block/curve-bar/0.0.1/sample.js +338 -0
  76. package/web/src/pug/block/dumbbell/0.0.1/index.ls +90 -0
  77. package/web/src/pug/block/dumbbell/0.0.1/index.pug +1 -0
  78. package/web/src/pug/block/empty/0.0.1/index.ls +27 -0
  79. package/web/src/pug/block/empty/0.0.1/index.pug +2 -0
  80. package/web/src/pug/block/gauge/0.0.1/index.ls +100 -0
  81. package/web/src/pug/block/gauge/0.0.1/index.pug +31 -0
  82. package/web/src/pug/block/gauge/0.0.1/sample.js +338 -0
  83. package/web/src/pug/block/line/0.0.1/index.ls +265 -0
  84. package/web/src/pug/block/line/0.0.1/index.pug +33 -0
  85. package/web/src/pug/block/number/0.0.1/index.ls +69 -0
  86. package/web/src/pug/block/number/0.0.1/index.pug +20 -0
  87. package/web/src/pug/block/percent-list/0.0.1/index.ls +167 -0
  88. package/web/src/pug/block/percent-list/0.0.1/index.pug +34 -0
  89. package/web/src/pug/block/pie/0.0.1/index.ls +125 -0
  90. package/web/src/pug/block/pie/0.0.1/index.pug +19 -0
  91. package/web/src/pug/block/pie/0.0.1/sample.js +338 -0
  92. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +185 -0
  93. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +40 -0
  94. package/web/src/pug/block/radar/0.0.1/index.ls +113 -0
  95. package/web/src/pug/block/radar/0.0.1/index.pug +1 -0
  96. package/web/src/pug/block/radar/0.0.1/xx +285 -0
  97. package/web/src/pug/block/scatter/0.0.1/index.ls +128 -0
  98. package/web/src/pug/block/scatter/0.0.1/index.pug +30 -0
  99. package/web/src/pug/block/sheet/0.0.1/index.ls +38 -0
  100. package/web/src/pug/block/sheet/0.0.1/index.pug +5 -0
  101. package/web/src/pug/block/table/0.0.1/index.ls +40 -0
  102. package/web/src/pug/block/table/0.0.1/index.pug +3 -0
  103. package/web/src/pug/block/taiwantown/0.0.1/index.ls +48 -0
  104. package/web/src/pug/block/taiwantown/0.0.1/index.pug +52 -0
  105. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +53 -0
  106. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +52 -0
  107. package/web/src/pug/block/treemap/0.0.1/index.ls +172 -0
  108. package/web/src/pug/block/treemap/0.0.1/index.pug +42 -0
  109. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +174 -0
  110. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +17 -0
  111. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +241 -0
  112. package/web/src/pug/block/wordcloud/0.0.1/index.ls +61 -0
  113. package/web/src/pug/block/wordcloud/0.0.1/index.pug +1 -0
  114. package/web/src/pug/block/worldmap/0.0.1/index.ls +83 -0
  115. package/web/src/pug/block/worldmap/0.0.1/index.pug +12 -0
  116. package/web/src/pug/index.ls +72 -0
  117. package/web/src/pug/index.pug +52 -0
  118. package/web/src/styl/index.styl +0 -0
  119. package/web/static/assets/block/cache.js +4 -0
  120. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +2 -0
  121. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +2 -0
  122. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +2 -0
  123. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +2 -0
  124. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +2 -0
  125. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +2 -0
  126. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +2 -0
  127. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +2 -0
  128. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +2 -0
  129. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +2 -0
  130. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +2 -0
  131. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +2 -0
  132. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +2 -0
  133. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +2 -0
  134. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +2 -0
  135. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +2 -0
  136. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +2 -0
  137. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +2 -0
  138. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +2 -0
  139. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +2 -0
  140. package/web/static/assets/custom-lib/d3/d3.v4.js +17178 -0
  141. package/web/static/assets/custom-lib/d3/d3.v4.min.js +2 -0
  142. package/web/static/assets/data/countrycode.json +1 -0
  143. package/web/static/assets/data/world-110m.json +1 -0
  144. package/web/static/assets/data/zh-to-alpha2.json +1 -0
  145. package/web/static/assets/img/fluid.svg +16 -0
  146. package/web/static/block/axis/0.0.1/index.html +79 -0
  147. package/web/static/block/axis-bubble/0.0.1/index.html +222 -0
  148. package/web/static/block/bar/0.0.1/index.html +581 -0
  149. package/web/static/block/bar-list/0.0.1/index.html +231 -0
  150. package/web/static/block/bar-race/0.0.1/index.html +184 -0
  151. package/web/static/block/base/0.0.1/index.html +197 -0
  152. package/web/static/block/blank/0.0.1/index.html +42 -0
  153. package/web/static/block/bubble/0.0.1/index.html +402 -0
  154. package/web/static/block/bubble/0.0.1/test.html +0 -0
  155. package/web/static/block/curve-bar/0.0.1/index.html +148 -0
  156. package/web/static/block/dumbbell/0.0.1/index.html +178 -0
  157. package/web/static/block/empty/0.0.1/index.html +76 -0
  158. package/web/static/block/gauge/0.0.1/index.html +150 -0
  159. package/web/static/block/line/0.0.1/index.html +540 -0
  160. package/web/static/block/number/0.0.1/index.html +152 -0
  161. package/web/static/block/percent-list/0.0.1/index.html +316 -0
  162. package/web/static/block/pie/0.0.1/index.html +281 -0
  163. package/web/static/block/pie-bubble/0.0.1/index.html +358 -0
  164. package/web/static/block/radar/0.0.1/index.html +149 -0
  165. package/web/static/block/scatter/0.0.1/index.html +251 -0
  166. package/web/static/block/sheet/0.0.1/index.html +103 -0
  167. package/web/static/block/table/0.0.1/index.html +73 -0
  168. package/web/static/block/taiwantown/0.0.1/index.html +210 -0
  169. package/web/static/block/taiwanvillage/0.0.1/index.html +220 -0
  170. package/web/static/block/treemap/0.0.1/index.html +360 -0
  171. package/web/static/block/voronoi-treemap/0.0.1/index.html +350 -0
  172. package/web/static/block/wordcloud/0.0.1/index.html +92 -0
  173. package/web/static/block/worldmap/0.0.1/index.html +207 -0
  174. package/web/static/css/index.css +0 -0
  175. package/web/static/css/index.min.css +0 -0
  176. package/web/static/favicon.ico +0 -0
  177. package/web/static/index.html +153 -0
@@ -0,0 +1,358 @@
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>
@@ -0,0 +1,149 @@
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>