@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,316 @@
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>
@@ -0,0 +1,281 @@
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>