@plotdb/chart 0.0.3 → 2.0.0

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 (194) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +3 -3
  3. package/{dist/data → data}/index.js +0 -0
  4. package/{dist/chart.css → index.css} +0 -0
  5. package/{dist/chart.js → index.js} +3 -1
  6. package/{dist/chart.min.css → index.min.css} +0 -0
  7. package/index.min.js +1 -0
  8. package/package.json +1 -89
  9. package/{dist/utils → utils}/axis.js +6 -0
  10. package/utils/axis.min.js +1 -0
  11. package/{dist/utils → utils}/config.js +0 -0
  12. package/utils/config.min.js +1 -0
  13. package/{dist/utils → utils}/data.js +0 -0
  14. package/utils/data.min.js +1 -0
  15. package/{dist/utils → utils}/format.js +0 -0
  16. package/utils/format.min.js +1 -0
  17. package/{dist/utils → utils}/legend.css +0 -0
  18. package/{dist/utils → utils}/legend.js +0 -0
  19. package/{dist/utils → utils}/legend.min.css +0 -0
  20. package/utils/legend.min.js +1 -0
  21. package/{dist/utils → utils}/tint.js +0 -0
  22. package/utils/tint.min.js +1 -0
  23. package/{dist/utils → utils}/tip.js +0 -0
  24. package/utils/tip.min.js +1 -0
  25. package/build +0 -39
  26. package/dist/chart.min.js +0 -1
  27. package/dist/utils/axis.min.js +0 -1
  28. package/dist/utils/config.min.js +0 -1
  29. package/dist/utils/data.min.js +0 -1
  30. package/dist/utils/format.min.js +0 -1
  31. package/dist/utils/legend.min.js +0 -1
  32. package/dist/utils/tint.min.js +0 -1
  33. package/dist/utils/tip.min.js +0 -1
  34. package/doc/charts.md +0 -58
  35. package/doc/config.md +0 -44
  36. package/doc/draft/chart.md +0 -146
  37. package/doc/draft/data.md +0 -8
  38. package/doc/draft/definition.md +0 -0
  39. package/doc/draft/events.md +0 -0
  40. package/doc/draft/filter.md +0 -0
  41. package/doc/draft/lifecycle.md +0 -89
  42. package/doc/spec.md +0 -89
  43. package/doc/todo.md +0 -27
  44. package/doc/utils/tip.md +0 -84
  45. package/src/chart.ls +0 -323
  46. package/src/chart.styl +0 -6
  47. package/src/data/en-US/category +0 -20
  48. package/src/data/en-US/fruit +0 -39
  49. package/src/data/en-US/movie +0 -125
  50. package/src/data/en-US/name +0 -58
  51. package/src/data/index.ls +0 -34
  52. package/src/data/zh-TW/category +0 -20
  53. package/src/data/zh-TW/fruits +0 -38
  54. package/src/data/zh-TW/movie +0 -125
  55. package/src/data/zh-TW/names +0 -105
  56. package/src/utils/axis.ls +0 -229
  57. package/src/utils/config.ls +0 -11
  58. package/src/utils/data.ls +0 -104
  59. package/src/utils/format.ls +0 -30
  60. package/src/utils/legend.ls +0 -134
  61. package/src/utils/legend.styl +0 -37
  62. package/src/utils/tint.ls +0 -66
  63. package/src/utils/tip.ls +0 -97
  64. package/web/src/pug/base.pug +0 -20
  65. package/web/src/pug/block/axis/0.0.1/index.ls +0 -38
  66. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  67. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -141
  68. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  69. package/web/src/pug/block/bar/0.0.1/index.ls +0 -274
  70. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  71. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -85
  72. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  73. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -83
  74. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  75. package/web/src/pug/block/base/0.0.1/index.ls +0 -67
  76. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  77. package/web/src/pug/block/blank/0.0.1/index.ls +0 -25
  78. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  79. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -220
  80. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -28
  81. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -89
  82. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  83. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  84. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -90
  85. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  86. package/web/src/pug/block/empty/0.0.1/index.ls +0 -27
  87. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  88. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -100
  89. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  90. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  91. package/web/src/pug/block/line/0.0.1/index.ls +0 -302
  92. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  93. package/web/src/pug/block/number/0.0.1/index.ls +0 -69
  94. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  95. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -167
  96. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  97. package/web/src/pug/block/pie/0.0.1/index.ls +0 -125
  98. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  99. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  100. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -185
  101. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  102. package/web/src/pug/block/radar/0.0.1/index.ls +0 -113
  103. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  104. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  105. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -128
  106. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  107. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -38
  108. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  109. package/web/src/pug/block/table/0.0.1/index.ls +0 -40
  110. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  111. package/web/src/pug/block/taiwancounty/0.0.1/index.ls +0 -74
  112. package/web/src/pug/block/taiwancounty/0.0.1/index.pug +0 -64
  113. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -48
  114. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  115. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -53
  116. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  117. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -172
  118. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  119. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -174
  120. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  121. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  122. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -61
  123. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  124. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -81
  125. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  126. package/web/src/pug/index.ls +0 -72
  127. package/web/src/pug/index.pug +0 -51
  128. package/web/src/styl/index.styl +0 -0
  129. package/web/static/assets/block/cache.js +0 -4
  130. package/web/static/assets/custom-lib/d3/d3-array.v2.js +0 -1182
  131. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  132. package/web/static/assets/custom-lib/d3/d3-array.v3.js +0 -1273
  133. package/web/static/assets/custom-lib/d3/d3-array.v3.min.js +0 -1273
  134. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  135. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  136. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  137. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  138. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  139. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  140. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  141. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  142. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  143. package/web/static/assets/custom-lib/d3/d3-geo.v2.js +0 -3127
  144. package/web/static/assets/custom-lib/d3/d3-geo.v2.min.js +0 -2
  145. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  146. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  147. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  148. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  149. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  150. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  151. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  152. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  153. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  154. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  155. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  156. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  157. package/web/static/assets/custom-lib/d3/d3.v6.js +0 -19708
  158. package/web/static/assets/data/countrycode.json +0 -1
  159. package/web/static/assets/data/world-110m.json +0 -1
  160. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  161. package/web/static/assets/img/fluid.svg +0 -16
  162. package/web/static/block/axis/0.0.1/index.html +0 -79
  163. package/web/static/block/axis-bubble/0.0.1/index.html +0 -222
  164. package/web/static/block/bar/0.0.1/index.html +0 -581
  165. package/web/static/block/bar-list/0.0.1/index.html +0 -231
  166. package/web/static/block/bar-race/0.0.1/index.html +0 -184
  167. package/web/static/block/base/0.0.1/index.html +0 -197
  168. package/web/static/block/blank/0.0.1/index.html +0 -42
  169. package/web/static/block/bubble/0.0.1/index.html +0 -402
  170. package/web/static/block/bubble/0.0.1/test.html +0 -0
  171. package/web/static/block/curve-bar/0.0.1/index.html +0 -148
  172. package/web/static/block/dumbbell/0.0.1/index.html +0 -178
  173. package/web/static/block/empty/0.0.1/index.html +0 -76
  174. package/web/static/block/gauge/0.0.1/index.html +0 -150
  175. package/web/static/block/line/0.0.1/index.html +0 -571
  176. package/web/static/block/number/0.0.1/index.html +0 -152
  177. package/web/static/block/percent-list/0.0.1/index.html +0 -316
  178. package/web/static/block/pie/0.0.1/index.html +0 -281
  179. package/web/static/block/pie-bubble/0.0.1/index.html +0 -358
  180. package/web/static/block/radar/0.0.1/index.html +0 -149
  181. package/web/static/block/scatter/0.0.1/index.html +0 -251
  182. package/web/static/block/sheet/0.0.1/index.html +0 -103
  183. package/web/static/block/table/0.0.1/index.html +0 -73
  184. package/web/static/block/taiwancounty/0.0.1/index.html +0 -202
  185. package/web/static/block/taiwantown/0.0.1/index.html +0 -210
  186. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -220
  187. package/web/static/block/treemap/0.0.1/index.html +0 -360
  188. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -350
  189. package/web/static/block/wordcloud/0.0.1/index.html +0 -92
  190. package/web/static/block/worldmap/0.0.1/index.html +0 -207
  191. package/web/static/css/index.css +0 -0
  192. package/web/static/css/index.min.css +0 -0
  193. package/web/static/favicon.ico +0 -0
  194. package/web/static/index.html +0 -153
@@ -1,281 +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
- .pdl-layout > div[data-type=layout] > [data-name=legend] {
11
- min-width: 6em;
12
- }
13
- </style><script type="@plotdb/block">(function(it){
14
- return it();
15
- })(function(){
16
- var blockFactory, mod;
17
- blockFactory = {
18
- pkg: {
19
- name: 'pie',
20
- version: '0.0.1',
21
- extend: {
22
- name: "base",
23
- version: "0.0.1"
24
- },
25
- dependencies: [],
26
- i18n: {
27
- "zh-TW": {
28
- value: "數值",
29
- name: "名稱",
30
- other: "其它"
31
- }
32
- }
33
- },
34
- init: function(arg$){
35
- var root, context, pubsub, t;
36
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
37
- return pubsub.fire('init', {
38
- mod: mod({
39
- context: context,
40
- t: t
41
- })
42
- });
43
- }
44
- };
45
- mod = function(arg$){
46
- var context, t, chart, d3;
47
- context = arg$.context, t = arg$.t;
48
- chart = context.chart, d3 = context.d3;
49
- return {
50
- sample: function(){
51
- return {
52
- raw: [1, 2, 3, 4, 5].map(function(val){
53
- return {
54
- val: (10 * Math.random()).toFixed(2),
55
- name: val
56
- };
57
- }),
58
- binding: {
59
- name: {
60
- key: 'name'
61
- },
62
- value: {
63
- key: 'val'
64
- }
65
- }
66
- };
67
- },
68
- config: {},
69
- dimension: {
70
- value: {
71
- type: 'R',
72
- name: "value",
73
- priority: 20
74
- },
75
- name: {
76
- type: 'NO',
77
- name: "name",
78
- priority: 10
79
- }
80
- },
81
- init: function(){
82
- var tint, this$ = this;
83
- this.g = Object.fromEntries(['view', 'legend'].map(function(it){
84
- return [it, d3.select(this$.layout.getGroup(it)).append('g')];
85
- }));
86
- this.tint = tint = new chart.utils.tint();
87
- this.tip = new chart.utils.tip({
88
- root: this.root,
89
- accessor: function(arg$){
90
- var evt, data, v;
91
- evt = arg$.evt;
92
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
93
- return null;
94
- }
95
- v = isNaN(data.value)
96
- ? '-'
97
- : data.value.toFixed(2) + "" + (this$.binding.value.unit || '');
98
- return {
99
- name: data.name,
100
- value: v
101
- };
102
- },
103
- range: function(){
104
- return this$.layout.getNode('view').getBoundingClientRect();
105
- }
106
- });
107
- this.legend = new chart.utils.legend({
108
- layout: this.layout,
109
- name: 'legend',
110
- root: this.root,
111
- shape: function(d){
112
- return d3.select(this).attr('fill', tint.get(d.text));
113
- },
114
- cfg: {
115
- selectable: true
116
- }
117
- });
118
- this.legend.on('select', function(){
119
- this$.bind();
120
- this$.resize();
121
- return this$.render();
122
- });
123
- this.arc = d3.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(Math.PI / 2);
124
- return this.total = {};
125
- },
126
- destroy: function(){
127
- return this.tip.destroy();
128
- },
129
- parse: function(){
130
- var other, ref$, total, sum, i$, to$, idx;
131
- this.tint.reset();
132
- this.parsed = this.data.map(function(it){
133
- var ret;
134
- ret = import$({}, it);
135
- if (isNaN(ret.value)) {
136
- ret.value = 0;
137
- }
138
- return ret;
139
- });
140
- this.parsed.sort(function(a, b){
141
- return b.value - a.value;
142
- });
143
- if (this.cfg.collapse != null && this.cfg.collapse.enabled) {
144
- if (this.cfg.collapse.method === 'count') {
145
- other = this.parsed.splice(this.cfg.collapse.threshold || 7);
146
- if (other.length) {
147
- this.parsed.push({
148
- name: t("other"),
149
- value: other.reduce(function(a, b){
150
- return a + b.value;
151
- }, 0)
152
- });
153
- }
154
- } else {
155
- ref$ = [
156
- this.parsed.reduce(function(a, b){
157
- return a + b.value;
158
- }, 0), 0
159
- ], total = ref$[0], sum = ref$[1];
160
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
161
- idx = i$;
162
- sum += this.parsed[idx].value;
163
- if (sum / total > (this.cfg.collapse.threshold || 0.75)) {
164
- break;
165
- }
166
- }
167
- other = this.parsed.splice(idx + 1);
168
- if (other.length) {
169
- this.parsed.push({
170
- name: t("other"),
171
- value: other.reduce(function(a, b){
172
- return a + b.value;
173
- }, 0)
174
- });
175
- }
176
- }
177
- }
178
- return this.legend.data(this.parsed.map(function(it){
179
- return {
180
- text: it.name,
181
- key: it.name
182
- };
183
- }));
184
- },
185
- bind: function(){
186
- var offset, i$, to$, i, obj, that, this$ = this, results$ = [];
187
- this.parsed.map(function(it){
188
- return it.picked = this$.legend.isSelected(it.name);
189
- });
190
- this.total.old = this.total.cur;
191
- this.total.cur = this.parsed.reduce(function(a, b){
192
- return a + (b.picked ? b.value : 0);
193
- }, 0) || 1;
194
- if (!this.total.old) {
195
- this.total.old = this.total.cur;
196
- }
197
- offset = 0;
198
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
199
- i = i$;
200
- obj = this.parsed[i];
201
- if (!obj.old) {
202
- obj.old = {
203
- s: (that = this.parsed[i - 1]) ? that.old.e : 0,
204
- e: 0
205
- };
206
- }
207
- if (obj.cur) {
208
- obj.old = obj.cur;
209
- }
210
- obj.cur = {
211
- s: offset,
212
- e: offset + (obj.picked ? obj.value : 0)
213
- };
214
- obj.angle = {
215
- old: {
216
- s: 2 * Math.PI * obj.old.s / this.total.old,
217
- e: 2 * Math.PI * obj.old.e / this.total.old
218
- },
219
- cur: {
220
- s: 2 * Math.PI * obj.cur.s / this.total.cur,
221
- e: 2 * Math.PI * obj.cur.e / this.total.cur
222
- }
223
- };
224
- if (obj.picked) {
225
- results$.push(offset += obj.value);
226
- }
227
- }
228
- return results$;
229
- },
230
- resize: function(){
231
- var box, ref$, w, h, size;
232
- this.layout.update(false);
233
- box = this.layout.getBox('view');
234
- this.layout.getNode('view').style.width = box.height + "px";
235
- this.layout.update(false);
236
- box = this.layout.getBox('view');
237
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
238
- size = Math.min(w, h);
239
- return this.arc.innerRadius((this.cfg.donutPercent || 0.7) * size / 2).outerRadius(size / 2);
240
- },
241
- render: function(){
242
- var tint, interpolateArc, box, x$, this$ = this;
243
- tint = this.tint;
244
- interpolateArc = function(a1, a2){
245
- return function(t){
246
- var ref$, s, e;
247
- ref$ = ['s', 'e'].map(function(i){
248
- return (a2[i] - a1[i]) * t + a1[i];
249
- }), s = ref$[0], e = ref$[1];
250
- this$.arc.startAngle(s).endAngle(e);
251
- return this$.arc();
252
- };
253
- };
254
- if (this.cfg != null && this.cfg.palette) {
255
- this.tint.set(this.cfg.palette.colors.map(function(it){
256
- return it.value || it;
257
- }));
258
- }
259
- box = this.layout.getBox('view');
260
- this.g.view.attr('transform', "translate(" + box.width / 2 + "," + box.height / 2 + ")");
261
- x$ = this.g.view.selectAll('path.data').data(this.parsed, function(it){
262
- return it.name || it._idx;
263
- });
264
- x$.exit().remove();
265
- x$.enter().append('path').attr('class', 'data');
266
- this.g.view.selectAll('path.data').attr('fill', function(d, i){
267
- return this$.tint.get(d.name || d._idx);
268
- }).transition().duration(350).attrTween('d', function(d, i){
269
- return interpolateArc(d.angle.old, d.angle.cur);
270
- });
271
- return this.legend.render();
272
- }
273
- };
274
- };
275
- return blockFactory;
276
- });
277
- function import$(obj, src){
278
- var own = {}.hasOwnProperty;
279
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
280
- return obj;
281
- }</script></div>
@@ -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>