@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,316 +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="link"></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
- padding: 0.5em;
6
- }
7
- .pdl-layout > div[data-type=layout] > [data-name=view] {
8
- height: 100%;
9
- min-width: 2.5em;
10
- margin-right: 0.5em;
11
- flex: 1 0 2.5em;
12
- }
13
- .pdl-layout > div[data-type=layout] > [data-name=link] {
14
- height: 100%;
15
- width: 2.5em;
16
- margin-right: 0.5em;
17
- flex: 0 0 auto;
18
- }
19
- .pdl-layout > div[data-type=layout] > [data-name=legend] {
20
- flex: 1 0 auto;
21
- width: fit-content;
22
- max-width: 60%;
23
- height: 100%;
24
- display: flex;
25
- flex-direction: column;
26
- justify-content: start;
27
- align-items: start;
28
- }
29
- </style><script type="@plotdb/block">(function(it){
30
- return it();
31
- })(function(){
32
- var blockFactory, mod;
33
- blockFactory = {
34
- pkg: {
35
- name: 'percent-list',
36
- version: '0.0.1',
37
- extend: {
38
- name: "base",
39
- version: "0.0.1"
40
- },
41
- dependencies: [],
42
- i18n: {
43
- "zh-TW": {
44
- "other": "其它"
45
- }
46
- }
47
- },
48
- init: function(arg$){
49
- var root, context, pubsub, t;
50
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
51
- return pubsub.fire('init', {
52
- mod: mod({
53
- context: context,
54
- t: t
55
- })
56
- });
57
- }
58
- };
59
- mod = function(arg$){
60
- var context, t, chart, d3, wrapSvgText, debounce;
61
- context = arg$.context, t = arg$.t;
62
- chart = context.chart, d3 = context.d3, wrapSvgText = context.wrapSvgText, debounce = context.debounce;
63
- return {
64
- sample: function(){
65
- return {
66
- raw: ["Bachchan Pandey", "The Good Maharaja", "Ramprasad Ki Tehrvi", "Madam Chief Minister", "Satya Sai Baba", "Lahore Confidential", "Sandeep Aur Pinky Faraar", "Silence... Can You Hear It?", "Hum Bhi Akele Tum Bhi Akele", "Radhe", "Shaadisthan", "Chandigarh Kare Aashiqui", "Gangubai Kathiawadi", "Attack", "The Battle of Bhima Koregaon", "Tadap", "Looop Lapeta"].map(function(val){
67
- return {
68
- val: Math.random(),
69
- name: val
70
- };
71
- }),
72
- binding: {
73
- name: {
74
- key: 'name'
75
- },
76
- value: {
77
- key: 'val'
78
- }
79
- }
80
- };
81
- },
82
- config: {},
83
- dimension: {
84
- value: {
85
- type: 'R',
86
- name: "value",
87
- priority: 20
88
- },
89
- name: {
90
- type: 'N',
91
- name: "name",
92
- priority: 10
93
- }
94
- },
95
- init: function(){
96
- var tint, this$ = this;
97
- this.g = {
98
- view: d3.select(this.layout.getGroup('view')),
99
- link: d3.select(this.layout.getGroup('link')),
100
- legend: d3.select(this.layout.getGroup('legend'))
101
- };
102
- this.tint = tint = new chart.utils.tint();
103
- this.scale = {
104
- y: d3.scaleLinear()
105
- };
106
- this.layout.getGroup('view').addEventListener('mousemove', function(evt){
107
- var n;
108
- if (!((n = evt.target) && n.nodeName.toLowerCase() === 'rect')) {
109
- return;
110
- }
111
- this$.idx = Array.from(n.parentNode.childNodes).indexOf(n);
112
- return this$.renderDebounced();
113
- });
114
- return this.renderDebounced = debounce(350, function(){
115
- return this$.render();
116
- });
117
- },
118
- parse: function(){
119
- var ref$, other, total, sum, i$, to$, idx, offset, i, ret, this$ = this;
120
- ((ref$ = this.cfg).collapse || (ref$.collapse = {})).enabled = false;
121
- this.parsed = this.data.map(function(it){
122
- return import$({}, it);
123
- });
124
- this.parsed.sort(function(a, b){
125
- return b.value - a.value;
126
- });
127
- if (this.cfg.collapse.enabled) {
128
- if (this.cfg.collapse.method === 'count') {
129
- other = this.parsed.splice(this.cfg.collapse.threshold || 7);
130
- if (other.length) {
131
- this.parsed.push({
132
- name: t("other"),
133
- value: other.reduce(function(a, b){
134
- return a + b.value;
135
- }, 0)
136
- });
137
- }
138
- } else {
139
- ref$ = [
140
- this.parsed.reduce(function(a, b){
141
- return a + b.value;
142
- }, 0), 0
143
- ], total = ref$[0], sum = ref$[1];
144
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
145
- idx = i$;
146
- sum += this.parsed[idx].value;
147
- if (sum / total > (this.cfg.collapse.threshold || 0.75)) {
148
- break;
149
- }
150
- }
151
- other = this.parsed.splice(idx + 1);
152
- if (other.length) {
153
- this.parsed.push({
154
- name: t("other"),
155
- value: other.reduce(function(a, b){
156
- return a + b.value;
157
- }, 0)
158
- });
159
- }
160
- }
161
- }
162
- this.tint.reset();
163
- this.parsed.map(function(it){
164
- return this$.tint.get(it.name || it._idx);
165
- });
166
- offset = 0;
167
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
168
- i = i$;
169
- ret = this.parsed[i];
170
- ret.offset = offset;
171
- offset += ret.value;
172
- }
173
- return this.total = offset || 1;
174
- },
175
- resize: function(){
176
- var node, box, ref$, w, h, size, this$ = this;
177
- this.layout.update(false);
178
- node = this.layout.getNode('legend');
179
- node.textContent = "";
180
- this.parsed.map(function(it){
181
- var div, p;
182
- div = document.createElement('div');
183
- p = (100 * (it.value / this$.total)).toFixed(1);
184
- div.textContent = it.text = it.name + " / " + p + "%";
185
- return node.appendChild(div);
186
- });
187
- this.nboxes = this.parsed.map(function(d, i){
188
- return this$.layout.getNode('legend').childNodes[i].getBoundingClientRect();
189
- });
190
- this.rbox = this.layout.getNode('legend').getBoundingClientRect();
191
- this.lbox = this.layout.getBox('link');
192
- box = this.layout.getBox('view');
193
- this.layout.update(false);
194
- box = this.layout.getBox('view');
195
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
196
- size = Math.min(w, h);
197
- return this.scale.y.range([0, box.height]).domain([0, this.total]);
198
- },
199
- render: function(){
200
- var total, cfg, layout, tint, scale, nboxes, rbox, lbox, box, offset, ref$, ref1$, ref2$, last, x$, y$, z$, z1$;
201
- total = this.total, cfg = this.cfg, layout = this.layout, tint = this.tint, scale = this.scale, nboxes = this.nboxes, rbox = this.rbox, lbox = this.lbox;
202
- if (this.cfg != null && this.cfg.palette) {
203
- this.tint.set(this.cfg.palette.colors.map(function(it){
204
- return it.value || it;
205
- }));
206
- }
207
- box = this.layout.getBox('view');
208
- offset = 0;
209
- if (this.idx != null && nboxes.length) {
210
- this.idx = (ref$ = (ref1$ = this.idx) < (ref2$ = this.nboxes.length - 1) ? ref1$ : ref2$) > 0 ? ref$ : 0;
211
- offset = nboxes[this.idx].y - rbox.y;
212
- last = nboxes[nboxes.length - 1].y + nboxes[nboxes.length - 1].height - rbox.y;
213
- if (last - offset < rbox.height) {
214
- offset = last - rbox.height;
215
- }
216
- }
217
- x$ = this.g.view.selectAll('rect').data(this.parsed);
218
- x$.exit().remove();
219
- x$.enter().append('rect');
220
- y$ = this.g.view.selectAll('rect');
221
- y$.attr('x', function(){
222
- return 0;
223
- });
224
- y$.attr('y', function(d, i){
225
- return scale.y(d.offset);
226
- });
227
- y$.attr('width', function(){
228
- return box.width;
229
- });
230
- y$.attr('height', function(d, i){
231
- var ref$;
232
- return (ref$ = scale.y(d.offset + d.value) - scale.y(d.offset) - 1) > 1 ? ref$ : 1;
233
- });
234
- y$.attr('fill', function(d, i){
235
- var ret, nbox, y1;
236
- return tint.get(Math.ceil(((d.offset + d.value / 2) / total) * 5));
237
- ret = tint.get(0, (i % 3 - 1) / 5);
238
- if (cfg.collapse.enabled) {
239
- nbox = nboxes[i];
240
- y1 = (nbox.y - rbox.y) + nbox.height / 2;
241
- if (y1 < rbox.height) {
242
- return ret;
243
- }
244
- ret = ldcolor.hcl(ret);
245
- ret.c = ret.c * 0.1;
246
- ret.l = ret.l * 1.1;
247
- }
248
- return ldcolor.web(ret);
249
- });
250
- z$ = this.g.legend.selectAll('g.label').data(this.parsed);
251
- z$.exit().remove();
252
- z$.enter().append('g').attr('class', 'label');
253
- this.g.legend.selectAll('g.label').each(function(d, i){
254
- var n, ret;
255
- if (this._text !== d.text) {
256
- this._text = d.text;
257
- n = layout.getNode('legend').childNodes[i];
258
- ret = wrapSvgText({
259
- node: n,
260
- useRange: true
261
- });
262
- this.textContent = "";
263
- return this.appendChild(ret);
264
- }
265
- }).transition().duration(350).attr('opacity', function(d, i){
266
- var nbox, y;
267
- nbox = nboxes[i];
268
- y = nbox.y - rbox.y - offset;
269
- if (y < 0 || y > rbox.height - nbox.height / 2) {
270
- return 0;
271
- } else {
272
- return 1;
273
- }
274
- }).attr('transform', function(d, i){
275
- var nbox;
276
- nbox = nboxes[i];
277
- return "translate(" + (nbox.x - rbox.x) + ", " + (nbox.y - rbox.y - offset) + ")";
278
- });
279
- z1$ = this.g.link.selectAll('path').data(this.parsed);
280
- z1$.exit().remove();
281
- z1$.enter().append('path').attr('fill', 'none').attr('stroke-width', 1);
282
- return this.g.link.selectAll('path').attr('stroke', function(d, i){
283
- return tint.get(Math.ceil(((d.offset + d.value / 2) / total) * 5));
284
- }).transition().duration(350).attr('d', function(d, i){
285
- var x0, x1, x2, x3, y0, nbox, y1;
286
- x0 = 0;
287
- x1 = lbox.width / 10;
288
- x2 = 9 * lbox.width / 10;
289
- x3 = lbox.width;
290
- y0 = scale.y(d.offset + d.value / 2);
291
- nbox = nboxes[i];
292
- y1 = (nbox.y - rbox.y) + nbox.height / 2 - offset;
293
- if (Math.abs(y1 - y0) < 2) {
294
- y1 = y0;
295
- }
296
- return "M" + x0 + " " + y0 + " L" + x1 + " " + y0 + " L" + x2 + " " + y1 + " L" + x3 + " " + y1;
297
- }).attr('opacity', function(d, i){
298
- var nbox, y0, y1;
299
- nbox = nboxes[i];
300
- y0 = scale.y(d.offset + d.value / 2);
301
- y1 = (nbox.y - rbox.y) + nbox.height / 2 - offset;
302
- if (Math.abs(y1 - y0) < 2) {
303
- y1 = y0;
304
- }
305
- return y1 > rbox.height || y1 < 0 ? 0 : 1;
306
- });
307
- }
308
- };
309
- };
310
- return blockFactory;
311
- });
312
- function import$(obj, src){
313
- var own = {}.hasOwnProperty;
314
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
315
- return obj;
316
- }</script></div>
@@ -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>