@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,540 +0,0 @@
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>
@@ -1,152 +0,0 @@
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>