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