@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,540 @@
1
+ <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="yaxis">&nbsp;</div><div class="pdl-cell" data-name="view"></div><div class="pdl-cell"></div><div class="pdl-cell" data-name="xaxis">&nbsp;</div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">[data-name=xaxis] {
2
+ font-size: 0.8em;
3
+ }
4
+ [data-name=yaxis] {
5
+ font-size: 0.8em;
6
+ }
7
+ .pdl-layout > div[data-type=layout] {
8
+ display: grid;
9
+ grid-template-columns: fit-content(2em) 1fr fit-content(7em);
10
+ grid-template-rows: 1fr fit-content(1em);
11
+ /* 0.5em for axis label at the boundary */
12
+ padding: 0 0.5em;
13
+ }
14
+ .pdl-layout > div[data-type=layout] .pdl-cell[data-name=legend] {
15
+ padding-left: 1em;
16
+ grid-column: 3;
17
+ grid-row: 1/span 2;
18
+ }
19
+ .pdl-layout.legend-below > div[data-type=layout] {
20
+ grid-template-columns: 2em 1fr;
21
+ grid-template-rows: 1fr fit-content(2em) fit-content(3em);
22
+ }
23
+ .pdl-layout.legend-below > div[data-type=layout] .pdl-cell[data-name=legend] {
24
+ padding-top: 1em;
25
+ grid-column: 1/span 2;
26
+ grid-row: 3;
27
+ }
28
+ </style><script type="@plotdb/block">(function(it){
29
+ return it();
30
+ })(function(){
31
+ var blockFactory, mod;
32
+ blockFactory = {
33
+ pkg: {
34
+ name: 'line',
35
+ version: '0.0.1',
36
+ extend: {
37
+ name: "base",
38
+ version: "0.0.1"
39
+ },
40
+ dependencies: [],
41
+ i18n: {
42
+ "zh-TW": {
43
+ "y axis": "Y軸",
44
+ "x axis": "X軸",
45
+ "rank": "順位"
46
+ }
47
+ }
48
+ },
49
+ init: function(arg$){
50
+ var root, context, pubsub, t;
51
+ root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
52
+ return pubsub.fire('init', {
53
+ mod: mod({
54
+ context: context,
55
+ t: t
56
+ })
57
+ });
58
+ }
59
+ };
60
+ mod = function(arg$){
61
+ var context, t, d3, chart, axis, format, sampleCount;
62
+ context = arg$.context, t = arg$.t;
63
+ d3 = context.d3, chart = context.chart, axis = context.axis, format = context.format;
64
+ sampleCount = 4;
65
+ return {
66
+ sample: function(){
67
+ return {
68
+ 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){
69
+ var ret;
70
+ ret = {};
71
+ (function(){
72
+ var i$, to$, results$ = [];
73
+ for (i$ = 1, to$ = sampleCount; i$ <= to$; ++i$) {
74
+ results$.push(i$);
75
+ }
76
+ return results$;
77
+ }()).map(function(i){
78
+ return ret["val" + i] = Math.random() * (10 - Math.abs(10 - val)) + val;
79
+ });
80
+ ret.order = val;
81
+ return ret;
82
+ }),
83
+ binding: {
84
+ value: (function(){
85
+ var i$, to$, results$ = [];
86
+ for (i$ = 1, to$ = sampleCount; i$ <= to$; ++i$) {
87
+ results$.push(i$);
88
+ }
89
+ return results$;
90
+ }()).map(function(it){
91
+ return {
92
+ key: "val" + it
93
+ };
94
+ }),
95
+ order: {
96
+ key: 'order'
97
+ }
98
+ }
99
+ };
100
+ },
101
+ config: {},
102
+ dimension: {
103
+ value: {
104
+ type: 'R',
105
+ name: "y axis",
106
+ multiple: true
107
+ },
108
+ order: {
109
+ type: 'ON',
110
+ name: "x axis"
111
+ }
112
+ },
113
+ init: function(){
114
+ var svg, tint, this$ = this;
115
+ svg = d3.select(this.svg);
116
+ ['view', 'yaxis', 'xaxis', 'legend'].map(function(it){
117
+ return (this$.g || (this$.g = {}))[it] = d3.select(this$.layout.getGroup(it));
118
+ });
119
+ this.tint = tint = new chart.utils.tint();
120
+ this.line = d3.line().defined(function(it){
121
+ return !isNaN(it.y1);
122
+ }).x(function(it){
123
+ return this$.scale.x(it.x);
124
+ }).y(function(it){
125
+ return this$.scale.y(it.y1);
126
+ });
127
+ this.area = d3.area().defined(function(it){
128
+ return !isNaN(it.y1) && !isNaN(it.y0);
129
+ }).x(function(it){
130
+ return this$.scale.x(it.x);
131
+ }).y0(function(it){
132
+ return this$.scale.y(it.y0);
133
+ }).y1(function(it){
134
+ return this$.scale.y(it.y1);
135
+ });
136
+ this.xaxis = new chart.utils.axis({
137
+ layout: this.layout,
138
+ name: 'xaxis',
139
+ direction: 'bottom'
140
+ });
141
+ this.yaxis = new chart.utils.axis({
142
+ layout: this.layout,
143
+ name: 'yaxis',
144
+ direction: 'left'
145
+ });
146
+ this.tip = new chart.utils.tip({
147
+ root: this.root,
148
+ range: function(){
149
+ return this$.layout.getNode('view').getBoundingClientRect();
150
+ }
151
+ });
152
+ this._evthdr = {};
153
+ this.root.addEventListener('mouseout', this._evthdr.out = function(evt){
154
+ return this$.tip.hide().now();
155
+ });
156
+ this.root.addEventListener('mousemove', this._evthdr.move = function(evt){
157
+ var x, y, min, i$, to$, i, series, j$, to1$, j, p, dx, dy, d, bind, pt, data, box;
158
+ x = evt.clientX - this$.layout.getNode('view').getBoundingClientRect().x;
159
+ y = evt.clientY - this$.layout.getNode('view').getBoundingClientRect().y;
160
+ min = {
161
+ d: -1,
162
+ p: null,
163
+ series: null
164
+ };
165
+ for (i$ = 0, to$ = this$.parsed.length; i$ < to$; ++i$) {
166
+ i = i$;
167
+ series = this$.parsed[i];
168
+ for (j$ = 0, to1$ = series.pts.length; j$ < to1$; ++j$) {
169
+ j = j$;
170
+ p = series.pts[j];
171
+ if (isNaN(p.y1) || isNaN(p.x)) {
172
+ continue;
173
+ }
174
+ dx = Math.abs(this$.scale.x(p.x) - x);
175
+ dy = Math.abs(this$.scale.y(p.y1) - y);
176
+ d = Math.pow(dx, 2) + Math.pow(dy, 2);
177
+ if (min.d < 0 || min.d > d) {
178
+ min.d = d;
179
+ min.p = p;
180
+ min.series = series;
181
+ }
182
+ }
183
+ }
184
+ if (!(min.p && min.d && min.series)) {
185
+ return;
186
+ }
187
+ bind = min.series.bind;
188
+ pt = min.p;
189
+ data = {
190
+ name: (bind ? bind.name || bind.key || '' : void 8) + " /\n" + (pt.data.orderText || pt.data.order || pt.x) + (this$.binding.order.unit || ''),
191
+ value: isNaN(pt.v)
192
+ ? '-'
193
+ : pt.v.toFixed(2) + "" + (bind ? bind.unit || '' : '')
194
+ };
195
+ box = {
196
+ x: this$.scale.x(pt.x),
197
+ y: this$.scale.y(pt.y)
198
+ };
199
+ return this$.tip.render({
200
+ data: data,
201
+ evt: evt,
202
+ box: box
203
+ });
204
+ });
205
+ this.legend = new chart.utils.legend({
206
+ layout: this.layout,
207
+ root: this.root,
208
+ name: 'legend',
209
+ shape: function(d){
210
+ return d3.select(this).attr('fill', tint.get(d.text));
211
+ },
212
+ direction: 'vertical',
213
+ cfg: {
214
+ selectable: true
215
+ }
216
+ });
217
+ this.legend.on('select', function(){
218
+ this$.bind();
219
+ this$.resize();
220
+ return this$.render();
221
+ });
222
+ return this.scale = {
223
+ x: d3.scaleLinear(),
224
+ y: d3.scaleLinear()
225
+ };
226
+ },
227
+ destroy: function(){
228
+ this.root.removeEventListener('mouseout', this._evthdr.out);
229
+ this.root.removeEventListener('mousemove', this._evthdr.move);
230
+ return this.tip.destroy();
231
+ },
232
+ parse: function(){
233
+ this.data.map(function(d, i){
234
+ d.orderText = '' + (!(d.order != null)
235
+ ? i
236
+ : d.order);
237
+ return d._order = !(d.order != null) || isNaN(+d.order)
238
+ ? i
239
+ : +d.order;
240
+ });
241
+ this.data.sort(function(a, b){
242
+ if (a._order > b._order) {
243
+ return 1;
244
+ } else if (a._order === b._order) {
245
+ return 0;
246
+ } else {
247
+ return -1;
248
+ }
249
+ });
250
+ return this.legend.data(this.binding.value.map(function(it){
251
+ return {
252
+ key: it.key,
253
+ text: it.key
254
+ };
255
+ }));
256
+ },
257
+ bind: function(){
258
+ var binds, dd, ys, i$, to$, i, b, last, this$ = this, results$ = [];
259
+ binds = this.binding.value;
260
+ binds = this.binding.value.map(function(b, i){
261
+ return {
262
+ b: b,
263
+ i: i
264
+ };
265
+ }).filter(function(d, i){
266
+ return this$.legend.isSelected(d.b.key);
267
+ });
268
+ if (this.cfg.bump) {
269
+ this.parsed = [];
270
+ dd = this.data.map(function(d){
271
+ var ret, v;
272
+ ret = import$({}, d);
273
+ v = ret.value.map(function(d, i){
274
+ return {
275
+ i: i,
276
+ v: this$.legend.isSelected(this$.binding.value[i].key) ? d : NaN
277
+ };
278
+ });
279
+ v.sort(function(a, b){
280
+ if (isNaN(a.v) && isNaN(b.v)) {
281
+ return 0;
282
+ } else if (isNaN(b.v)) {
283
+ return -1;
284
+ } else if (isNaN(a.v)) {
285
+ return 1;
286
+ }
287
+ return b.v - a.v;
288
+ });
289
+ v.map(function(d, i){
290
+ return d.r = i + 1;
291
+ });
292
+ v.sort(function(a, b){
293
+ return a.i - b.i;
294
+ });
295
+ ret.value = v.map(function(it){
296
+ if (isNaN(it.v)) {
297
+ return NaN;
298
+ } else {
299
+ return it.r;
300
+ }
301
+ });
302
+ ret.originalValue = v.map(function(it){
303
+ return it.v;
304
+ });
305
+ return ret;
306
+ });
307
+ }
308
+ this.parsed = binds.map(function(b, i){
309
+ return {
310
+ pts: (dd || this$.data).map(function(d, j){
311
+ return {
312
+ data: d,
313
+ y0: 0,
314
+ y1: d.value[b.i],
315
+ x: d._order,
316
+ v: d.originalValue
317
+ ? d.originalValue[i]
318
+ : d.value[i]
319
+ };
320
+ }),
321
+ bind: b.b,
322
+ color: b.b.name || b.b.key
323
+ };
324
+ });
325
+ if (this.cfg.stack) {
326
+ ys = this.data.map(function(it){
327
+ return it.value.reduce(function(a, b){
328
+ return a + b;
329
+ }, 0);
330
+ });
331
+ this.parsed = [];
332
+ for (i$ = 0, to$ = binds.length; i$ < to$; ++i$) {
333
+ i = i$;
334
+ b = binds[i].b;
335
+ last = this.parsed[i - 1] || null;
336
+ results$.push(this.parsed.push({
337
+ pts: this.data.map(fn$),
338
+ bind: b,
339
+ color: b.name || b.key
340
+ }));
341
+ }
342
+ return results$;
343
+ }
344
+ function fn$(d, j){
345
+ return {
346
+ y1: d.value[i] + (!last
347
+ ? 0
348
+ : last.pts[j].y1),
349
+ y0: !last
350
+ ? 0
351
+ : last.pts[j].y1,
352
+ x: d._order,
353
+ v: d.originalValue
354
+ ? d.originalValue[i]
355
+ : d.value[i]
356
+ };
357
+ }
358
+ },
359
+ resize: function(){
360
+ var ref$, miny, maxy, i$, to$, i, j$, to1$, j, p, w, h, maxTick, yticks, ref1$, yfmt, units, v, box, r, results$ = [];
361
+ this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
362
+ ref$ = [0, 0], miny = ref$[0], maxy = ref$[1];
363
+ for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
364
+ i = i$;
365
+ for (j$ = 0, to1$ = this.parsed[i].pts.length; j$ < to1$; ++j$) {
366
+ j = j$;
367
+ p = this.parsed[i].pts[j];
368
+ if (!isNaN(p.y0) && miny > p.y0) {
369
+ miny = p.y0;
370
+ }
371
+ if (!isNaN(p.y1) && miny > p.y1) {
372
+ miny = p.y1;
373
+ }
374
+ if (!isNaN(p.y0) && maxy < p.y0) {
375
+ maxy = p.y0;
376
+ }
377
+ if (!isNaN(p.y1) && maxy < p.y1) {
378
+ maxy = p.y1;
379
+ }
380
+ }
381
+ }
382
+ this.extent = {
383
+ x: d3.extent(this.data, function(it){
384
+ return it._order;
385
+ }),
386
+ y: [this.cfg.bump ? miny > 1 ? miny : 1 : miny, maxy === miny ? miny + 1 : maxy]
387
+ };
388
+ this.scale.x.domain(this.extent.x);
389
+ this.scale.y.domain(this.cfg.bump
390
+ ? [this.extent.y[1], this.extent.y[0]]
391
+ : this.extent.y);
392
+ ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
393
+ maxTick = (ref$ = Math.ceil(this.layout.getBox('yaxis').height / 40)) > 2 ? ref$ : 2;
394
+ yticks = this.cfg.bump
395
+ ? (function(){
396
+ var i$, to$, ref$, results$ = [];
397
+ for (i$ = 1, to$ = (ref$ = this.parsed.length || 1) > 1 ? ref$ : 1; i$ <= to$; ++i$) {
398
+ results$.push(i$);
399
+ }
400
+ return results$;
401
+ }.call(this))
402
+ : this.scale.y.ticks((ref$ = ((ref1$ = this.cfg).yaxis || (ref1$.yaxis = {})).tickCount || 4) < maxTick ? ref$ : maxTick);
403
+ yfmt = chart.utils.format.auto(yticks);
404
+ this.legend.config(this.cfg.legend);
405
+ this.legend.update();
406
+ this.yaxis.config(this.cfg.yaxis);
407
+ this.yaxis.ticks(yticks);
408
+ this.yaxis.scale(this.scale.y);
409
+ if (this.cfg.bump) {
410
+ this.yaxis.caption(t('rank'));
411
+ } else {
412
+ if (this.parsed.length > 1) {
413
+ units = Array.from(new Set(this.parsed.map(function(it){
414
+ return it.bind.unit;
415
+ }))).filter(function(it){
416
+ return it;
417
+ });
418
+ if (units.length > 1) {
419
+ this.yaxis.caption('');
420
+ } else {
421
+ this.yaxis.caption(units[0] || '');
422
+ }
423
+ } else {
424
+ v = (this.parsed[0] || {}).bind || {};
425
+ this.yaxis.caption((v.name || v.key || '') + (v.unit ? "(" + v.unit + ")" : ''));
426
+ }
427
+ }
428
+ this.xaxis.config(this.cfg.xaxis);
429
+ this.xaxis.ticks(this.data.map(function(it){
430
+ return {
431
+ v: it._order,
432
+ t: it.orderText
433
+ };
434
+ }));
435
+ this.xaxis.scale(this.scale.x);
436
+ this.xaxis.caption((this.binding.order.name || this.binding.order.key) + (this.binding.order.unit ? "(" + this.binding.order.unit + ")" : ''));
437
+ for (i$ = 0; i$ < 2; ++i$) {
438
+ i = i$;
439
+ this.layout.update(false);
440
+ box = this.layout.getBox('view');
441
+ ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
442
+ this.tint.set(this.cfg.palette);
443
+ r = this.cfg.dotSize || 3;
444
+ this.scale.x.range([0, w - r]);
445
+ this.scale.y.range([h, r]);
446
+ this.xaxis.render();
447
+ results$.push(this.yaxis.render());
448
+ }
449
+ return results$;
450
+ },
451
+ render: function(){
452
+ var scale, tint, extent, r, vbox, lbox, x$, y$, this$ = this;
453
+ scale = this.scale, tint = this.tint, extent = this.extent;
454
+ r = this.cfg.dotSize || 3;
455
+ vbox = this.layout.getBox('view');
456
+ lbox = this.layout.getBox('yaxis');
457
+ x$ = this.g.view.selectAll('path.data').data(this.parsed, function(it){
458
+ return it.bind.key;
459
+ });
460
+ x$.exit().remove();
461
+ x$.enter().append('path').attr('class', 'data').attr('fill', 'none').attr('d', function(d, i){
462
+ if (this$.cfg.stack || this$.cfg.area) {
463
+ return this$.area(d.pts);
464
+ } else {
465
+ return this$.line(d.pts);
466
+ }
467
+ }).attr('stroke', function(d, i){
468
+ return this$.tint.get(d.color);
469
+ }).attr('stroke-width', 1);
470
+ this.g.view.selectAll('path.data').transition().duration(150).style('opacity', function(d, i){
471
+ if (this$.legend.isSelected(d.bind.key)) {
472
+ return 1;
473
+ } else {
474
+ return 0.3;
475
+ }
476
+ }).attr('d', function(d, i){
477
+ if (this$.cfg.stack || this$.cfg.area) {
478
+ return this$.area(d.pts);
479
+ } else {
480
+ return this$.line(d.pts);
481
+ }
482
+ }).attr('stroke', function(d, i){
483
+ return this$.tint.get(d.color);
484
+ }).attr('fill', function(d, i){
485
+ if (this$.cfg.stack || this$.cfg.area) {
486
+ return this$.tint.get(d.color);
487
+ } else {
488
+ return 'none';
489
+ }
490
+ }).attr('fill-opacity', function(){
491
+ return '0.5';
492
+ });
493
+ y$ = this.g.view.selectAll('g.dot').data(this.parsed, function(it){
494
+ return it.bind.key;
495
+ });
496
+ y$.exit().remove();
497
+ y$.enter().append('g').attr('class', 'dot');
498
+ this.g.view.selectAll('g.dot').style('opacity', function(d, i){
499
+ if (this$.legend.isSelected(d.bind.key)) {
500
+ return 1;
501
+ } else {
502
+ return 0.3;
503
+ }
504
+ }).each(function(d, i){
505
+ var x$;
506
+ x$ = d3.select(this).selectAll('circle.dot').data(d.pts);
507
+ x$.exit().remove();
508
+ x$.enter().append('circle').attr('class', 'dot').attr('r', r).attr('fill', '#fff').attr('stroke', tint.get(d.bind.name || d.bind.key));
509
+ d3.select(this).selectAll('circle.dot').filter(function(d, i){
510
+ return isNaN(d.y1);
511
+ }).attr('cx', function(d, i){
512
+ if (isNaN(scale.x(d.x))) {
513
+ return scale.x(extent.x[0]);
514
+ } else {
515
+ return scale.x(d.x);
516
+ }
517
+ }).attr('cy', function(d, i){
518
+ return scale.y(extent.y[0]);
519
+ }).transition(150).attr('opacity', 0);
520
+ return d3.select(this).selectAll('circle.dot').filter(function(d, i){
521
+ return !isNaN(d.y1);
522
+ }).attr('cx', function(d, i){
523
+ return scale.x(d.x);
524
+ }).attr('cy', function(d, i){
525
+ return scale.y(d.y1);
526
+ }).attr('r', r).attr('fill', tint.get(d.color)).attr('stroke', tint.get(d.color)).transition(150).attr('opacity', 1);
527
+ });
528
+ this.legend.render();
529
+ this.xaxis.render();
530
+ return this.yaxis.render();
531
+ }
532
+ };
533
+ };
534
+ return blockFactory;
535
+ });
536
+ function import$(obj, src){
537
+ var own = {}.hasOwnProperty;
538
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
539
+ return obj;
540
+ }</script></div>
@@ -0,0 +1,152 @@
1
+ <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="number"></div><div class="pdl-cell" data-name="unit"></div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout > [data-type=layout] {
2
+ flex-direction: column;
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ }
7
+ .pdl-layout > [data-type=layout] .pdl-cell {
8
+ line-height: 1em;
9
+ white-space: nowrap;
10
+ }
11
+ .pdl-layout > [data-type=layout] .pdl-cell[data-name=number] {
12
+ font-weight: bold;
13
+ }
14
+ </style><script type="@plotdb/block">(function(it){
15
+ return it();
16
+ })(function(){
17
+ var blockFactory, mod;
18
+ blockFactory = {
19
+ pkg: {
20
+ name: 'number',
21
+ version: '0.0.1',
22
+ extend: {
23
+ name: "base",
24
+ version: "0.0.1"
25
+ },
26
+ dependencies: []
27
+ },
28
+ init: function(arg$){
29
+ var root, context, pubsub;
30
+ root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
31
+ return pubsub.fire('init', {
32
+ mod: mod({
33
+ context: context
34
+ })
35
+ }).then(function(it){
36
+ return it[0];
37
+ });
38
+ }
39
+ };
40
+ mod = function(arg$){
41
+ var context, d3, ldcolor, repeatString$, infinite;
42
+ context = arg$.context;
43
+ d3 = context.d3, ldcolor = context.ldcolor, repeatString$ = context.repeatString$, infinite = context.infinite;
44
+ return {
45
+ sample: function(){
46
+ return {
47
+ raw: [{
48
+ val: 12777216,
49
+ name: "票房",
50
+ unit: "新臺幣"
51
+ }],
52
+ binding: {
53
+ name: {
54
+ key: 'name'
55
+ },
56
+ value: {
57
+ key: 'val',
58
+ unit: '百萬元新臺幣'
59
+ }
60
+ }
61
+ };
62
+ },
63
+ config: {
64
+ enlarge: {
65
+ type: 'boolean',
66
+ 'default': false
67
+ }
68
+ },
69
+ dimension: {
70
+ value: {
71
+ type: 'R',
72
+ name: "value"
73
+ },
74
+ name: {
75
+ type: 'N',
76
+ name: "name"
77
+ }
78
+ },
79
+ init: function(){
80
+ var this$ = this;
81
+ this.n = Object.fromEntries(['number', 'unit'].map(function(it){
82
+ return [it, this$.layout.getNode(it)];
83
+ }));
84
+ this.g = Object.fromEntries(['number', 'unit'].map(function(it){
85
+ return [it, d3.select(this$.layout.getGroup(it))];
86
+ }));
87
+ this.g.number.append('text');
88
+ this.g.unit.append('text');
89
+ return this.v = {
90
+ number: 0,
91
+ unit: '',
92
+ run: 0
93
+ };
94
+ },
95
+ resize: function(){
96
+ var ref$, w, h, x$, y$, r, this$ = this;
97
+ ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
98
+ this.sizeRate = {
99
+ number: this.cfg.numberSizeRate || 3,
100
+ unit: this.cfg.unitSizeRate || 1
101
+ };
102
+ import$(this.v, {
103
+ number: (this.data[0] || {
104
+ value: 0
105
+ }).value,
106
+ unit: this.binding.value.unit || (this.data[0] || {
107
+ unit: ''
108
+ }).unit || ''
109
+ });
110
+ x$ = this.n.number;
111
+ x$.style.fontSize = this.sizeRate.number + "em";
112
+ x$.textContent = this.v.number;
113
+ y$ = this.n.unit;
114
+ y$.style.fontSize = '1em';
115
+ y$.textContent = this.v.unit;
116
+ this.r = r = Object.fromEntries(['number', 'unit'].map(function(it){
117
+ return [it, w / (this$.n[it].getBoundingClientRect().width || 1)];
118
+ }));
119
+ (!this.cfg.enlarge
120
+ ? ['number', 'unit']
121
+ : ['unit']).map(function(it){
122
+ var ref$;
123
+ return this$.r[it] = (ref$ = r[it]) < 1 ? ref$ : 1;
124
+ });
125
+ this.n.number.style.fontSize = this.sizeRate.number * r.number + "em";
126
+ this.n.unit.style.fontSize = this.sizeRate.unit * r.unit + "em";
127
+ return this.layout.update(false);
128
+ },
129
+ tick: function(){
130
+ var this$ = this;
131
+ return this.g.number.select('text').text(function(){
132
+ this$.v.run = (this$.v.number - this$.v.run) * 0.1 + this$.v.run;
133
+ if (this$.v.run === this$.v.number) {
134
+ this$.stop();
135
+ }
136
+ return Math.round(this$.v.run);
137
+ });
138
+ },
139
+ render: function(){
140
+ this.g.number.select('text').attr('x', this.n.number.getBoundingClientRect().width / 2).attr('font-size', this.sizeRate.number * this.r.number + "em").attr('font-weight', 'bold').attr('dominant-baseline', 'hanging').attr('text-anchor', 'middle').text(this.v.run);
141
+ this.g.unit.select('text').attr('font-size', this.sizeRate.unit * this.r.unit + "em").attr('dominant-baseline', 'hanging').text(this.v.unit);
142
+ return this.start();
143
+ }
144
+ };
145
+ };
146
+ return blockFactory;
147
+ });
148
+ function import$(obj, src){
149
+ var own = {}.hasOwnProperty;
150
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
151
+ return obj;
152
+ }</script></div>