@plotdb/chart 0.0.3 → 1.0.1

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