@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.
Files changed (164) hide show
  1. package/README.md +3 -3
  2. package/dist/chart.js +18 -12
  3. package/dist/chart.min.js +1 -1
  4. package/dist/index.css +8 -0
  5. package/dist/index.js +609 -0
  6. package/dist/index.min.css +1 -0
  7. package/dist/index.min.js +1 -0
  8. package/dist/utils/axis.js +6 -0
  9. package/dist/utils/axis.min.js +1 -1
  10. package/package.json +22 -11
  11. package/CHANGELOG.md +0 -11
  12. package/build +0 -39
  13. package/doc/charts.md +0 -58
  14. package/doc/config.md +0 -44
  15. package/doc/draft/chart.md +0 -146
  16. package/doc/draft/data.md +0 -8
  17. package/doc/draft/definition.md +0 -0
  18. package/doc/draft/events.md +0 -0
  19. package/doc/draft/filter.md +0 -0
  20. package/doc/draft/lifecycle.md +0 -89
  21. package/doc/spec.md +0 -89
  22. package/doc/todo.md +0 -27
  23. package/doc/utils/tip.md +0 -84
  24. package/src/chart.ls +0 -320
  25. package/src/chart.styl +0 -6
  26. package/src/data/en-US/category +0 -20
  27. package/src/data/en-US/fruit +0 -39
  28. package/src/data/en-US/movie +0 -125
  29. package/src/data/en-US/name +0 -58
  30. package/src/data/index.ls +0 -34
  31. package/src/data/zh-TW/category +0 -20
  32. package/src/data/zh-TW/fruits +0 -38
  33. package/src/data/zh-TW/movie +0 -125
  34. package/src/data/zh-TW/names +0 -105
  35. package/src/utils/axis.ls +0 -229
  36. package/src/utils/config.ls +0 -11
  37. package/src/utils/data.ls +0 -104
  38. package/src/utils/format.ls +0 -30
  39. package/src/utils/legend.ls +0 -134
  40. package/src/utils/legend.styl +0 -37
  41. package/src/utils/tint.ls +0 -66
  42. package/src/utils/tip.ls +0 -97
  43. package/web/src/pug/base.pug +0 -19
  44. package/web/src/pug/block/axis/0.0.1/index.ls +0 -38
  45. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  46. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -141
  47. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  48. package/web/src/pug/block/bar/0.0.1/index.ls +0 -274
  49. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  50. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -85
  51. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  52. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -83
  53. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  54. package/web/src/pug/block/base/0.0.1/index.ls +0 -67
  55. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  56. package/web/src/pug/block/blank/0.0.1/index.ls +0 -25
  57. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  58. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -220
  59. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -28
  60. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -89
  61. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  62. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  63. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -90
  64. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  65. package/web/src/pug/block/empty/0.0.1/index.ls +0 -27
  66. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  67. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -100
  68. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  69. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  70. package/web/src/pug/block/line/0.0.1/index.ls +0 -265
  71. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  72. package/web/src/pug/block/number/0.0.1/index.ls +0 -69
  73. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  74. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -167
  75. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  76. package/web/src/pug/block/pie/0.0.1/index.ls +0 -125
  77. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  78. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  79. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -185
  80. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  81. package/web/src/pug/block/radar/0.0.1/index.ls +0 -113
  82. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  83. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  84. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -128
  85. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  86. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -38
  87. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  88. package/web/src/pug/block/table/0.0.1/index.ls +0 -40
  89. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  90. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -48
  91. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  92. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -53
  93. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  94. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -172
  95. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  96. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -174
  97. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  98. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  99. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -61
  100. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  101. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -83
  102. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  103. package/web/src/pug/index.ls +0 -72
  104. package/web/src/pug/index.pug +0 -52
  105. package/web/src/styl/index.styl +0 -0
  106. package/web/static/assets/block/cache.js +0 -4
  107. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  108. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  109. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  110. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  111. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  112. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  113. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  114. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  115. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  116. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  117. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  118. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  119. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  120. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  121. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  122. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  123. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  124. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  125. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  126. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  127. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  128. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  129. package/web/static/assets/data/countrycode.json +0 -1
  130. package/web/static/assets/data/world-110m.json +0 -1
  131. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  132. package/web/static/assets/img/fluid.svg +0 -16
  133. package/web/static/block/axis/0.0.1/index.html +0 -79
  134. package/web/static/block/axis-bubble/0.0.1/index.html +0 -222
  135. package/web/static/block/bar/0.0.1/index.html +0 -581
  136. package/web/static/block/bar-list/0.0.1/index.html +0 -231
  137. package/web/static/block/bar-race/0.0.1/index.html +0 -184
  138. package/web/static/block/base/0.0.1/index.html +0 -197
  139. package/web/static/block/blank/0.0.1/index.html +0 -42
  140. package/web/static/block/bubble/0.0.1/index.html +0 -402
  141. package/web/static/block/bubble/0.0.1/test.html +0 -0
  142. package/web/static/block/curve-bar/0.0.1/index.html +0 -148
  143. package/web/static/block/dumbbell/0.0.1/index.html +0 -178
  144. package/web/static/block/empty/0.0.1/index.html +0 -76
  145. package/web/static/block/gauge/0.0.1/index.html +0 -150
  146. package/web/static/block/line/0.0.1/index.html +0 -540
  147. package/web/static/block/number/0.0.1/index.html +0 -152
  148. package/web/static/block/percent-list/0.0.1/index.html +0 -316
  149. package/web/static/block/pie/0.0.1/index.html +0 -281
  150. package/web/static/block/pie-bubble/0.0.1/index.html +0 -358
  151. package/web/static/block/radar/0.0.1/index.html +0 -149
  152. package/web/static/block/scatter/0.0.1/index.html +0 -251
  153. package/web/static/block/sheet/0.0.1/index.html +0 -103
  154. package/web/static/block/table/0.0.1/index.html +0 -73
  155. package/web/static/block/taiwantown/0.0.1/index.html +0 -210
  156. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -220
  157. package/web/static/block/treemap/0.0.1/index.html +0 -360
  158. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -350
  159. package/web/static/block/wordcloud/0.0.1/index.html +0 -92
  160. package/web/static/block/worldmap/0.0.1/index.html +0 -207
  161. package/web/static/css/index.css +0 -0
  162. package/web/static/css/index.min.css +0 -0
  163. package/web/static/favicon.ico +0 -0
  164. package/web/static/index.html +0 -153
@@ -1,402 +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="unit"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></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
- grid-template-rows: 1fr fit-content(1em);
6
- }
7
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
8
- grid-area: 1/1;
9
- }
10
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
11
- grid-column: 2;
12
- grid-row: 1/span 2;
13
- padding: 0 0.5em 0 0.5em;
14
- }
15
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=unit] {
16
- grid-column: 1;
17
- grid-row: 2;
18
- line-height: 1em;
19
- text-align: right;
20
- padding: 0.25em 0;
21
- }
22
- </style><script type="@plotdb/block">(function(it){
23
- return it();
24
- })(function(){
25
- var blockFactory, mod;
26
- blockFactory = {
27
- pkg: {
28
- name: 'bubble',
29
- version: '0.0.1',
30
- extend: {
31
- name: "base",
32
- version: "0.0.1"
33
- },
34
- dependencies: [],
35
- i18n: {
36
- "zh-TW": {
37
- "K": '千',
38
- "M": '百萬'
39
- }
40
- }
41
- },
42
- init: function(arg$){
43
- var root, context, pubsub, t;
44
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
45
- return pubsub.fire('init', {
46
- mod: mod({
47
- context: context,
48
- t: t
49
- })
50
- }).then(function(it){
51
- return it[0];
52
- });
53
- }
54
- };
55
- mod = function(arg$){
56
- var context, t, d3, forceBoundary, ldcolor, chart;
57
- context = arg$.context, t = arg$.t;
58
- d3 = context.d3, forceBoundary = context.forceBoundary, ldcolor = context.ldcolor, chart = context.chart;
59
- return {
60
- sample: function(){
61
- return {
62
- 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){
63
- return {
64
- val: val,
65
- cat: Math.floor(Math.random() * 5),
66
- name: val
67
- };
68
- }),
69
- binding: {
70
- group: {
71
- key: 'cat'
72
- },
73
- name: {
74
- key: 'name'
75
- },
76
- color: {
77
- key: 'cat'
78
- },
79
- area: {
80
- key: 'val'
81
- }
82
- }
83
- };
84
- },
85
- config: {},
86
- dimension: {
87
- group: {
88
- type: 'C',
89
- name: "group",
90
- priority: 2
91
- },
92
- color: {
93
- type: 'NR',
94
- name: "color",
95
- priority: 4
96
- },
97
- area: {
98
- type: 'R',
99
- name: "area",
100
- priority: 1
101
- },
102
- name: {
103
- type: 'NC',
104
- name: "name",
105
- priority: 3
106
- }
107
- },
108
- init: function(){
109
- var tint, node, this$ = this;
110
- this.tint = tint = new chart.utils.tint();
111
- this.parsed = this.parsed || [];
112
- this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
113
- return [it, d3.select(this$.layout.getGroup(it))];
114
- }));
115
- node = this.root.querySelector('[ld=tip]');
116
- this.tip = new chart.utils.tip({
117
- root: this.root,
118
- accessor: function(arg$){
119
- var evt, data;
120
- evt = arg$.evt;
121
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
122
- return null;
123
- }
124
- return {
125
- name: data.name,
126
- value: data.area + "" + (this$.binding.area.unit || '')
127
- };
128
- },
129
- range: function(){
130
- return this$.layout.getNode('view').getBoundingClientRect();
131
- }
132
- });
133
- this.legend = new chart.utils.legend({
134
- layout: this.layout,
135
- name: 'legend',
136
- root: this.root,
137
- shape: function(d){
138
- return d3.select(this).attr('fill', tint.get(d.key));
139
- },
140
- cfg: {
141
- selectable: true
142
- }
143
- });
144
- return this.legend.on('select', function(){
145
- this$.bind();
146
- this$.resize();
147
- return this$.render();
148
- });
149
- },
150
- destroy: function(){
151
- return this.tip.destroy();
152
- },
153
- parse: function(){
154
- this.valid = this.data.filter(function(it){
155
- return !isNaN(it.area);
156
- });
157
- this.groups = Array.from(new Set(this.valid.map(function(it){
158
- return it.group;
159
- }))).filter(function(it){
160
- return it;
161
- });
162
- this.sim = null;
163
- return this.legend.data(this.groups.map(function(it){
164
- return {
165
- key: it,
166
- text: it
167
- };
168
- }));
169
- },
170
- resize: function(){
171
- var ref$, list, ret, box, pack, this$ = this;
172
- this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
173
- (ref$ = this.cfg).legend || (ref$.legend = {});
174
- this.random = d3.randomUniform.source(d3.randomLcg(+Date.now()))(0, 1);
175
- list = [{
176
- key: 'root',
177
- root: true
178
- }].concat(this.groups.map(function(it){
179
- return {
180
- key: "group-" + it
181
- };
182
- }), this.valid.filter(function(it){
183
- return !this$.cfg.legend.enabled || this$.legend.isSelected(it.group);
184
- }));
185
- if (this.legend.enabled()) {
186
- list = list.filter(function(it){
187
- return !it._raw || this$.legend.isSelected(it.group);
188
- });
189
- }
190
- this.legend.config(this.cfg.legend);
191
- this.legend.update();
192
- this.layout.update(false);
193
- ret = d3.hierarchy(d3.stratify().id(function(it){
194
- if (it._idx != null) {
195
- return it._idx;
196
- } else {
197
- return it.key;
198
- }
199
- }).parentId(function(it){
200
- var that;
201
- if (it.root) {
202
- return '';
203
- } else if (that = it.group) {
204
- return "group-" + that;
205
- } else {
206
- return 'root';
207
- }
208
- })(list)).sum(function(it){
209
- return it.data.area;
210
- }).sort(function(a, b){
211
- return b.value - a.value;
212
- });
213
- box = this.vbox = this.layout.getBox('view');
214
- pack = d3.pack().size([box.width, box.height])(ret);
215
- this.parsed = ret.leaves().map(function(d){
216
- var ddata, pos, od, p, x, y;
217
- d._raw = d.data.data._raw;
218
- ddata = d.data.data;
219
- pos = !(this$.cfg.grouping != null) && this$.cfg.grouping
220
- ? d
221
- : {
222
- x: Math.random() * box.width * 0.8 + box.width * 0.1,
223
- y: Math.random() * box.height * 0.8 + box.height * 0.1
224
- };
225
- od = this$.parsed ? (p = this$.parsed.filter(function(p){
226
- if (p.name != null || ddata.name != null) {
227
- return p.name === ddata.name;
228
- } else {
229
- return p._idx === ddata._idx;
230
- }
231
- })[0], p ? p : d) : d;
232
- x = d.x, y = d.y;
233
- d.radius = Math.pow(ddata.area, 0.5);
234
- d.x = x;
235
- d.y = y;
236
- d._idx = ddata._idx;
237
- d.name = ddata.name;
238
- d.color = ddata.color;
239
- d.group = ddata.group;
240
- d.area = ddata.area;
241
- if (od._x) {
242
- d._x = od._x;
243
- } else if (!d._x) {
244
- d._x = d.x;
245
- }
246
- if (od._y) {
247
- d._y = od._y;
248
- } else if (!d._y) {
249
- d._y = d.y;
250
- }
251
- return d;
252
- }).filter(function(it){
253
- return it.area != null;
254
- });
255
- this.sim = null;
256
- return this.start();
257
- },
258
- render: function(){
259
- var binding, tint, box, rate, x$, y$, this$ = this;
260
- binding = this.binding, tint = this.tint;
261
- box = this.vbox;
262
- this.rate = rate = 0.85 * Math.PI / (2 * Math.sqrt(3)) * Math.sqrt(box.width * box.height / this.parsed.map(function(it){
263
- return Math.PI * Math.pow(it.r, 2);
264
- }).reduce(function(a, b){
265
- return a + b;
266
- }, 0));
267
- this.parsed.map(function(d, i){
268
- var ref$;
269
- return d.rr = (ref$ = d.r * this$.rate) > 2 ? ref$ : 2;
270
- });
271
- tint.set(this.cfg.palette);
272
- x$ = this.g.view.selectAll('circle.bubble').data(this.parsed, function(it){
273
- return it.name || it._idx;
274
- });
275
- x$.exit().remove();
276
- x$.enter().append('circle').attr('class', 'bubble data').attr('r', function(d, i){
277
- return 0;
278
- }).attr('fill', function(d, i){
279
- return tint.get(d.color || d.group || d.name);
280
- }).attr('cx', function(d, i){
281
- return d._x;
282
- }).attr('cy', function(d, i){
283
- return d._y;
284
- });
285
- this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
286
- return d._x;
287
- }).attr('cy', function(d, i){
288
- return d._y;
289
- }).transition().duration(350).attr('fill', function(d, i){
290
- return tint.get(d.color || d.group || d.name);
291
- }).attr('r', function(d, i){
292
- return d.rr;
293
- });
294
- y$ = this.g.view.selectAll('g.label').data(this.parsed, function(it){
295
- return it.name || it._idx;
296
- });
297
- y$.exit().remove();
298
- y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
299
- return "translate(" + d.x + "," + d.y + ")";
300
- }).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer').each(function(d, i){
301
- var this$ = this;
302
- return [0, 1].map(function(){
303
- return d3.select(this$).append('text');
304
- }).map(function(it){
305
- return it.attr('dy', '-.28em').attr('text-anchor', 'middle').style('pointer-event', 'none');
306
- });
307
- });
308
- this.g.view.selectAll('g.label').attr('transform', function(d, i){
309
- return "translate(" + d._x + "," + d._y + ")";
310
- }).each(function(d, i){
311
- return d3.select(this).selectAll('text').attr('dy', function(e, i){
312
- if (i === 0) {
313
- return '-.28em';
314
- } else {
315
- return '.88em';
316
- }
317
- }).text(function(e, i){
318
- var area, ret;
319
- if (i === 0) {
320
- area = d3.format('.3s')(d.area);
321
- /*
322
- ret = if area > 1000000 => (area/1000000).toFixed(1) + t(\M)
323
- else if area > 1000 => (area/1000).toFixed(1) + t(\K)
324
- else (area).toFixed(0)
325
- */
326
- ret = area;
327
- if (ret) {
328
- ret = ret + "" + (binding.area.unit || '');
329
- }
330
- return ret;
331
- } else {
332
- return d.name || '';
333
- }
334
- }).attr('font-size', function(d, i){
335
- return i ? '0.9em' : '1.1em';
336
- }).transition().duration(350).attr('fill', function(){
337
- var hcl;
338
- hcl = ldcolor.hcl(tint.get(d.color) || d.group || d.name);
339
- if (hcl.l < 50) {
340
- return '#fff';
341
- } else {
342
- return '#000';
343
- }
344
- });
345
- });
346
- this.g.view.selectAll('g.label').transition().duration(350).attr('opacity', function(d, i){
347
- var box, ref$, w, h;
348
- box = this.getBoundingClientRect();
349
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
350
- if (2 * d.rr < w || 2 * d.rr < h) {
351
- return 0;
352
- } else {
353
- return 1;
354
- }
355
- });
356
- return this.legend.render();
357
- },
358
- tick: function(){
359
- var cfg, pad, box, kickoff, fc, this$ = this;
360
- cfg = this.cfg;
361
- pad = cfg.pad || 5;
362
- box = this.vbox;
363
- if (!this.sim) {
364
- kickoff = true;
365
- this.fc = fc = d3.forceCollide().strength(0.5).iterations(20).radius(function(it){
366
- return this$.rate * it.r;
367
- });
368
- this.fg = d3.forceCenter().strength(0.5);
369
- this.fb = forceBoundary(function(it){
370
- return it.rr + pad;
371
- }, function(it){
372
- return it.rr + pad;
373
- }, function(it){
374
- return box.width - it.rr - pad;
375
- }, function(it){
376
- return box.height - it.rr - pad;
377
- }).strength(0.5);
378
- this.sim = d3.forceSimulation().force('b', this.fb).force('collide', this.fc);
379
- this.sim.stop();
380
- this.sim.alpha(0.9);
381
- }
382
- this.fg.x(box.width / 2);
383
- this.fg.y(box.height / 2);
384
- this.sim.nodes(this.parsed);
385
- this.sim.tick(kickoff ? 10 : 1);
386
- this.parsed.map(function(it){
387
- it._x = it._x + (it.x - it._x) * 0.1;
388
- return it._y = it._y + (it.y - it._y) * 0.1;
389
- });
390
- this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
391
- return d._x;
392
- }).attr('cy', function(d, i){
393
- return d._y;
394
- });
395
- return this.g.view.selectAll('g.label').attr('transform', function(d, i){
396
- return "translate(" + d._x + "," + d._y + ")";
397
- });
398
- }
399
- };
400
- };
401
- return blockFactory;
402
- });</script></div>
File without changes
@@ -1,148 +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><style type="text/css">.pdl-layout > div[data-type=layout] {
2
- display: flex;
3
- justify-content: center;
4
- align-items: center;
5
- }
6
- .pdl-layout > div[data-type=layout] [data-name=view] {
7
- height: 100%;
8
- margin-right: 1em;
9
- }
10
- </style><script type="@plotdb/block">(function(it){
11
- return it();
12
- })(function(){
13
- var blockFactory, mod;
14
- blockFactory = {
15
- pkg: {
16
- name: 'curve-bar',
17
- version: '0.0.1',
18
- extend: {
19
- name: "base",
20
- version: "0.0.1"
21
- },
22
- dependencies: []
23
- },
24
- init: function(arg$){
25
- var root, context, pubsub;
26
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
27
- return pubsub.fire('init', {
28
- mod: mod({
29
- context: context
30
- })
31
- });
32
- }
33
- };
34
- mod = function(arg$){
35
- var context, d3, legend, chart;
36
- context = arg$.context;
37
- d3 = context.d3, legend = context.legend, chart = context.chart;
38
- return {
39
- sample: function(){
40
- return {
41
- raw: [1, 2, 3, 4, 5].map(function(val){
42
- return {
43
- val: Math.random(),
44
- name: val
45
- };
46
- }),
47
- binding: {
48
- name: {
49
- key: 'name'
50
- },
51
- value: {
52
- key: 'val'
53
- }
54
- }
55
- };
56
- },
57
- config: {},
58
- dimension: {
59
- value: {
60
- type: 'R',
61
- name: "value"
62
- },
63
- name: {
64
- type: 'N',
65
- name: "name"
66
- }
67
- },
68
- init: function(){
69
- var tint;
70
- this.gview = d3.select(this.layout.getGroup('view'));
71
- this.g = this.gview.append('g');
72
- this.tint = tint = new chart.utils.tint();
73
- this.arc = d3.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(Math.PI / 2);
74
- return this.legend = new chart.utils.legend({
75
- root: this.root,
76
- name: 'legend',
77
- shape: function(d){
78
- return d3.select(this).attr('fill', tint.get(d.text));
79
- },
80
- layout: this.layout
81
- });
82
- },
83
- parse: function(){
84
- this.tint.reset();
85
- this.extent = {
86
- v: d3.extent(this.data.map(function(it){
87
- return it.value;
88
- }))
89
- };
90
- this.data.sort(function(a, b){
91
- return a.value - b.value;
92
- });
93
- return this.legend.data(this.data.map(function(it){
94
- return {
95
- key: it.name,
96
- text: it.name
97
- };
98
- }));
99
- },
100
- resize: function(){
101
- var box, ref$, w, h, size;
102
- box = this.layout.getBox('view');
103
- this.layout.getNode('view').style.width = box.height + "px";
104
- this.layout.update(false);
105
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
106
- size = Math.min(w, h);
107
- return this.scale = {
108
- v: d3.scaleLinear().domain([0, this.extent.v[1]]).range([0, Math.PI * 3 / 2]),
109
- r: d3.scaleBand().domain(this.data.map(function(d, i){
110
- return i;
111
- })).range([24, size / 2])
112
- };
113
- },
114
- render: function(){
115
- var scale, bw, box, x$, y$, this$ = this;
116
- scale = this.scale;
117
- bw = this.scale.r.bandwidth();
118
- this.arc.cornerRadius(bw / 2);
119
- if (this.cfg != null && this.cfg.palette) {
120
- this.tint.set(this.cfg.palette.colors.map(function(it){
121
- return it.value || it;
122
- }));
123
- }
124
- this.legend.render();
125
- box = this.layout.getBox('view');
126
- this.g.attr('transform', "translate(" + box.width / 2 + "," + box.height / 2 + ")");
127
- x$ = this.g.selectAll('path.data').data(this.data);
128
- x$.exit().remove();
129
- x$.enter().append('path').attr('class', 'data');
130
- this.g.selectAll('path.data').attr('d', function(d, i){
131
- this$.arc.startAngle(0).endAngle(scale.v(d.value)).innerRadius(scale.r(i)).outerRadius(scale.r(i) + bw - 2);
132
- return this$.arc();
133
- }).attr('fill', function(d, i){
134
- return this$.tint.get(d.name) || d._idx;
135
- });
136
- y$ = this.g.selectAll('text.label').data(this.data);
137
- y$.exit().remove();
138
- y$.enter().append('text').attr('class', 'label');
139
- return this.g.selectAll('text.label').attr('dominant-baseline', 'center').attr('text-anchor', 'end').attr('x', '-.5em').attr('y', function(d, i){
140
- return -scale.r(i);
141
- }).attr('dy', -bw * 1 / 4).text(function(d, i){
142
- return d.name;
143
- });
144
- }
145
- };
146
- };
147
- return blockFactory;
148
- });</script></div>