@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,550 +25,545 @@
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: 'bar',
35
- version: '0.0.1',
36
- extend: {
37
- name: "base",
38
- version: "0.0.1"
39
- },
40
- dependencies: [],
41
- i18n: {
42
- "zh-TW": {
43
- "size": "長度"
28
+ </style><script type="@plotdb/block">var mod;
29
+ module.exports = {
30
+ pkg: {
31
+ name: 'bar',
32
+ version: '0.0.1',
33
+ extend: {
34
+ name: "base",
35
+ version: "0.0.1"
36
+ },
37
+ dependencies: [],
38
+ i18n: {
39
+ "zh-TW": {
40
+ "size": "長度"
41
+ }
42
+ }
43
+ },
44
+ init: function(arg$){
45
+ var root, context, t, pubsub;
46
+ root = arg$.root, context = arg$.context, t = arg$.t, pubsub = arg$.pubsub;
47
+ return pubsub.fire('init', {
48
+ mod: mod({
49
+ context: context,
50
+ t: t
51
+ })
52
+ });
53
+ }
54
+ };
55
+ mod = function(arg$){
56
+ var context, t, chart, d3, debounce, ref$;
57
+ context = arg$.context, t = arg$.t;
58
+ chart = context.chart, d3 = context.d3, debounce = context.debounce;
59
+ return {
60
+ sample: function(){
61
+ return {
62
+ raw: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(function(val){
63
+ var ret, i$, i;
64
+ ret = {
65
+ name: val
66
+ };
67
+ for (i$ = 1; i$ <= 4; ++i$) {
68
+ i = i$;
69
+ ret["val" + i] = Math.random();
70
+ }
71
+ return ret;
72
+ }),
73
+ binding: {
74
+ size: [1, 2, 3, 4].map(function(it){
75
+ return {
76
+ key: "val" + it,
77
+ unit: "amount"
78
+ };
79
+ }),
80
+ name: {
81
+ key: "name"
82
+ }
44
83
  }
84
+ };
85
+ },
86
+ config: (ref$ = import$({}, chart.utils.config.preset['default']), ref$.sort = {
87
+ enabled: {
88
+ type: 'boolean'
89
+ },
90
+ dir: {
91
+ type: 'choice',
92
+ values: ['asc', 'desc', 'none']
93
+ }
94
+ }, ref$.type = {
95
+ type: 'choice',
96
+ values: ['bar', 'column'],
97
+ 'default': 'column'
98
+ }, ref$),
99
+ dimension: {
100
+ size: {
101
+ type: 'R',
102
+ multiple: true,
103
+ name: "size"
104
+ },
105
+ name: {
106
+ type: 'NO',
107
+ name: "name"
45
108
  }
46
109
  },
47
- init: function(arg$){
48
- var root, context, t, pubsub;
49
- root = arg$.root, context = arg$.context, t = arg$.t, pubsub = arg$.pubsub;
50
- return pubsub.fire('init', {
51
- mod: mod({
52
- context: context,
53
- t: t
54
- })
110
+ init: function(){
111
+ var tint, brush, scale, this$ = this;
112
+ this.tint = tint = new chart.utils.tint();
113
+ [['multiple', 'stack'], ['percent', false], ['dancing', true]].map(function(arg$){
114
+ var k, v;
115
+ k = arg$[0], v = arg$[1];
116
+ if (!(this$.cfg[k] != null)) {
117
+ return this$.cfg[k] = v;
118
+ }
55
119
  });
56
- }
57
- };
58
- mod = function(arg$){
59
- var context, t, chart, d3, debounce, ref$;
60
- context = arg$.context, t = arg$.t;
61
- chart = context.chart, d3 = context.d3, debounce = context.debounce;
62
- return {
63
- sample: function(){
64
- return {
65
- raw: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(function(val){
66
- var ret, i$, i;
67
- ret = {
68
- name: val
69
- };
70
- for (i$ = 1; i$ <= 4; ++i$) {
71
- i = i$;
72
- ret["val" + i] = Math.random();
120
+ this.svg.addEventListener('click', function(){
121
+ if (!this$.cfg.dancing || this$.cfg.percent) {
122
+ return;
123
+ }
124
+ this$.alignIdx = ((this$.alignIdx || 0) + 1) % (this$.binding.size.length + 1);
125
+ this$.resize();
126
+ return this$.render();
127
+ });
128
+ this.brush = d3.brushX();
129
+ this.g = Object.fromEntries(['view', 'xaxis', 'yaxis', 'legend'].map(function(it){
130
+ return [it, d3.select(this$.layout.getGroup(it))];
131
+ }));
132
+ this.range = "null";
133
+ brush = debounce(150, function(e){
134
+ var ref$, range, _range, domain, bandwidth;
135
+ if (((ref$ = this$.cfg).brush || (ref$.brush = {})).enabled != null && !this$.cfg.brush.enabled) {
136
+ return;
137
+ }
138
+ range = e.selection;
139
+ if ((_range = JSON.stringify(range)) === this$.range) {
140
+ return;
141
+ } else {
142
+ this$.range = _range;
143
+ }
144
+ if (!range) {
145
+ return this$.filter({
146
+ name: undefined
147
+ }, true);
148
+ } else {
149
+ domain = this$.scale.x.domain();
150
+ bandwidth = this$.scale.x.bandwidth();
151
+ range = range.map(function(it){
152
+ var ref$, ref1$, ref2$;
153
+ return (ref$ = (ref2$ = Math.floor(it / bandwidth)) > 0 ? ref2$ : 0) < (ref1$ = domain.length - 1) ? ref$ : ref1$;
154
+ });
155
+ range = (function(){
156
+ var i$, to$, results$ = [];
157
+ for (i$ = range[0], to$ = range[1]; i$ <= to$; ++i$) {
158
+ results$.push(i$);
73
159
  }
74
- return ret;
75
- }),
76
- binding: {
77
- size: [1, 2, 3, 4].map(function(it){
78
- return {
79
- key: "val" + it,
80
- unit: "amount"
81
- };
82
- }),
160
+ return results$;
161
+ }()).map(function(it){
162
+ return domain[it];
163
+ });
164
+ return this$.filter({
83
165
  name: {
84
- key: "name"
166
+ type: 'index',
167
+ value: range
85
168
  }
86
- }
87
- };
88
- },
89
- config: (ref$ = import$({}, chart.utils.config.preset['default']), ref$.sort = {
90
- enabled: {
91
- type: 'boolean'
92
- },
93
- dir: {
94
- type: 'choice',
95
- values: ['asc', 'desc', 'none']
169
+ }, true);
96
170
  }
97
- }, ref$.type = {
98
- type: 'choice',
99
- values: ['bar', 'column'],
100
- 'default': 'column'
101
- }, ref$),
102
- dimension: {
103
- size: {
104
- type: 'R',
105
- multiple: true,
106
- name: "size"
107
- },
108
- name: {
109
- type: 'NO',
110
- name: "name"
171
+ });
172
+ this.brush.on('end', brush);
173
+ this.brush.on('brush', brush);
174
+ this.scale = scale = {};
175
+ this.yaxis = new chart.utils.axis({
176
+ layout: this.layout,
177
+ name: 'yaxis',
178
+ direction: 'left'
179
+ });
180
+ this.xaxis = new chart.utils.axis({
181
+ layout: this.layout,
182
+ name: 'xaxis',
183
+ direction: 'bottom'
184
+ });
185
+ return this.legend = new chart.utils.legend({
186
+ layout: this.layout,
187
+ name: 'legend',
188
+ root: this.root,
189
+ shape: function(d){
190
+ return d3.select(this).attr('fill', tint.get(d.key));
111
191
  }
112
- },
113
- init: function(){
114
- var tint, brush, scale, this$ = this;
115
- this.tint = tint = new chart.utils.tint();
116
- [['multiple', 'stack'], ['percent', false], ['dancing', true]].map(function(arg$){
117
- var k, v;
118
- k = arg$[0], v = arg$[1];
119
- if (!(this$.cfg[k] != null)) {
120
- return this$.cfg[k] = v;
121
- }
122
- });
123
- this.svg.addEventListener('click', function(){
124
- if (!this$.cfg.dancing || this$.cfg.percent) {
125
- return;
192
+ });
193
+ },
194
+ destroy: function(){
195
+ if (this.tip) {
196
+ return this.tip.destroy();
197
+ }
198
+ },
199
+ filter: function(filters, internal){
200
+ var this$ = this;
201
+ internal == null && (internal = false);
202
+ this.render();
203
+ if (internal) {
204
+ return;
205
+ }
206
+ return this.brush.move(this.g.view, filters.name ? filters.name.map(function(it){
207
+ return this$.scale.x(it);
208
+ }) : null);
209
+ },
210
+ parse: function(){
211
+ this.data.map(function(d){
212
+ return d.size = d.size.map(function(it){
213
+ if (isNaN(it)) {
214
+ return 0;
215
+ } else {
216
+ return it;
126
217
  }
127
- this$.alignIdx = ((this$.alignIdx || 0) + 1) % (this$.binding.size.length + 1);
128
- this$.resize();
129
- return this$.render();
130
218
  });
131
- this.brush = d3.brushX();
132
- this.g = Object.fromEntries(['view', 'xaxis', 'yaxis', 'legend'].map(function(it){
133
- return [it, d3.select(this$.layout.getGroup(it))];
219
+ });
220
+ return this.alignIdx = undefined;
221
+ },
222
+ resize: function(){
223
+ var alignIdx, ref$, ref1$, delta, max, i, box, maxTick, yticks, v, xticks, i$, w, h, r, this$ = this;
224
+ this.type = this.cfg.type || 'column';
225
+ this.legend.config(this.cfg.legend);
226
+ this.legend.update();
227
+ this.layout.update(false);
228
+ this.maxPerGroup = this.binding.size.map(function(d, i){
229
+ return Math.max.apply(Math, this$.data.map(function(it){
230
+ return it.size[i];
134
231
  }));
135
- this.range = "null";
136
- brush = debounce(150, function(e){
137
- var ref$, range, _range, domain, bandwidth;
138
- if (((ref$ = this$.cfg).brush || (ref$.brush = {})).enabled != null && !this$.cfg.brush.enabled) {
139
- return;
140
- }
141
- range = e.selection;
142
- if ((_range = JSON.stringify(range)) === this$.range) {
143
- return;
144
- } else {
145
- this$.range = _range;
232
+ });
233
+ if (this.cfg.alignIdx && !this.alignIdx) {
234
+ this.alignIdx = this.cfg.alignIdx;
235
+ }
236
+ alignIdx = (ref$ = this.cfg.percent
237
+ ? 0
238
+ : this.alignIdx || 0) < (ref1$ = this.binding.size.length) ? ref$ : ref1$;
239
+ this.baseOffset = this.data.map(function(d){
240
+ return (function(){
241
+ var i$, to$, results$ = [];
242
+ for (i$ = 0, to$ = alignIdx; i$ < to$; ++i$) {
243
+ results$.push(i$);
146
244
  }
147
- if (!range) {
148
- return this$.filter({
149
- name: undefined
150
- }, true);
151
- } else {
152
- domain = this$.scale.x.domain();
153
- bandwidth = this$.scale.x.bandwidth();
154
- range = range.map(function(it){
155
- var ref$, ref1$, ref2$;
156
- return (ref$ = (ref2$ = Math.floor(it / bandwidth)) > 0 ? ref2$ : 0) < (ref1$ = domain.length - 1) ? ref$ : ref1$;
157
- });
158
- range = (function(){
245
+ return results$;
246
+ }()).reduce(function(a, b){
247
+ return a + d.size[b];
248
+ }, 0) || 0;
249
+ });
250
+ this.delta = delta = Math.max.apply(Math, this.baseOffset);
251
+ if (this.cfg.multiple === 'stack') {
252
+ if (this.cfg.percent) {
253
+ max = 1;
254
+ } else {
255
+ max = Math.max.apply(Math, this.data.map(function(d){
256
+ return (function(){
159
257
  var i$, to$, results$ = [];
160
- for (i$ = range[0], to$ = range[1]; i$ <= to$; ++i$) {
258
+ for (i$ = alignIdx, to$ = d.size.length; i$ < to$; ++i$) {
161
259
  results$.push(i$);
162
260
  }
163
261
  return results$;
164
- }()).map(function(it){
165
- return domain[it];
166
- });
167
- return this$.filter({
168
- name: {
169
- type: 'index',
170
- value: range
171
- }
172
- }, true);
173
- }
174
- });
175
- this.brush.on('end', brush);
176
- this.brush.on('brush', brush);
177
- this.scale = scale = {};
178
- this.yaxis = new chart.utils.axis({
179
- layout: this.layout,
180
- name: 'yaxis',
181
- direction: 'left'
182
- });
183
- this.xaxis = new chart.utils.axis({
184
- layout: this.layout,
185
- name: 'xaxis',
186
- direction: 'bottom'
187
- });
188
- return this.legend = new chart.utils.legend({
189
- layout: this.layout,
190
- name: 'legend',
191
- root: this.root,
192
- shape: function(d){
193
- return d3.select(this).attr('fill', tint.get(d.key));
194
- }
195
- });
196
- },
197
- destroy: function(){
198
- if (this.tip) {
199
- return this.tip.destroy();
262
+ }()).reduce(function(a, b){
263
+ return a + d.size[b];
264
+ }, 0);
265
+ })) + (delta || 0);
200
266
  }
201
- },
202
- filter: function(filters, internal){
203
- var this$ = this;
204
- internal == null && (internal = false);
205
- this.render();
206
- if (internal) {
207
- return;
267
+ } else if (this.cfg.multiple === 'group') {
268
+ max = Math.max.apply(Math, this.data.map(function(d){
269
+ return Math.max.apply(Math, d.size);
270
+ }));
271
+ } else if (this.cfg.multiple === 'split') {
272
+ max = this.maxPerGroup.reduce(function(a, b){
273
+ return a + b;
274
+ }, 0);
275
+ }
276
+ this.order = this.data.map(function(d, i){
277
+ return {
278
+ key: d._idx,
279
+ idx: i,
280
+ name: d.name
281
+ };
282
+ });
283
+ this.data.map(function(d, i){
284
+ return d.sum = d.size.reduce(function(a, b){
285
+ return a + b;
286
+ }, 0);
287
+ });
288
+ if (((ref$ = this.cfg).sort || (ref$.sort = {})).enabled) {
289
+ this.order.sort(function(a, b){
290
+ return (this$.cfg.sort.dir === 'asc'
291
+ ? 1
292
+ : -1) * (this$.data[a.idx].sum - this$.data[b.idx].sum);
293
+ });
294
+ }
295
+ console.log(this.cfg);
296
+ if (this.cfg.palette) {
297
+ this.tint.set(this.cfg.palette.colors.map(function(it){
298
+ return it.value || it;
299
+ }));
300
+ }
301
+ this.legend.data((function(){
302
+ var i$, results$ = [];
303
+ for (i$ = this.binding.size.length - 1; i$ >= 0; --i$) {
304
+ i = i$;
305
+ results$.push({
306
+ key: i,
307
+ text: this.binding.size[i].name || this.binding.size[i].key
308
+ });
208
309
  }
209
- return this.brush.move(this.g.view, filters.name ? filters.name.map(function(it){
210
- return this$.scale.x(it);
211
- }) : null);
212
- },
213
- parse: function(){
214
- this.data.map(function(d){
215
- return d.size = d.size.map(function(it){
216
- if (isNaN(it)) {
217
- return 0;
218
- } else {
219
- return it;
310
+ return results$;
311
+ }.call(this)));
312
+ this.layout.update(false);
313
+ box = this.layout.getBox('view');
314
+ if (this.type === 'column') {
315
+ ref$ = this.scale;
316
+ ref$.y = d3.scaleLinear().domain([0, max]).range([box.height, 0]);
317
+ ref$.x = d3.scaleBand().domain(this.order.map(function(it){
318
+ return it.name || it.key;
319
+ })).range([0, box.width]);
320
+ maxTick = (ref$ = Math.ceil(this.layout.getBox('yaxis').height / 40)) > 2 ? ref$ : 2;
321
+ yticks = this.cfg.bump
322
+ ? (function(){
323
+ var i$, to$, ref$, results$ = [];
324
+ for (i$ = 1, to$ = (ref$ = this.parsed.length || 1) > 1 ? ref$ : 1; i$ <= to$; ++i$) {
325
+ results$.push(i$);
220
326
  }
221
- });
222
- });
223
- return this.alignIdx = undefined;
224
- },
225
- resize: function(){
226
- var alignIdx, ref$, ref1$, delta, max, i, box, maxTick, yticks, v, xticks, i$, w, h, r, this$ = this;
227
- this.type = this.cfg.type || 'column';
228
- this.legend.config(this.cfg.legend);
229
- this.legend.update();
230
- this.layout.update(false);
231
- this.maxPerGroup = this.binding.size.map(function(d, i){
232
- return Math.max.apply(Math, this$.data.map(function(it){
233
- return it.size[i];
234
- }));
235
- });
236
- if (this.cfg.alignIdx && !this.alignIdx) {
237
- this.alignIdx = this.cfg.alignIdx;
327
+ return results$;
328
+ }.call(this))
329
+ : this.scale.y.ticks((ref$ = ((ref1$ = this.cfg).yaxis || (ref1$.yaxis = {})).tickCount || 4) < maxTick ? ref$ : maxTick);
330
+ this.yaxis.config(this.cfg.yaxis);
331
+ v = this.binding.size[0] || {};
332
+ if (this.binding.size.length > 1) {
333
+ this.yaxis.caption(v.unit ? v.unit + "" : '');
334
+ } else {
335
+ this.yaxis.caption((v.name || v.key || '') + (v.unit ? "(" + v.unit + ")" : ''));
238
336
  }
239
- alignIdx = (ref$ = this.cfg.percent
240
- ? 0
241
- : this.alignIdx || 0) < (ref1$ = this.binding.size.length) ? ref$ : ref1$;
242
- this.baseOffset = this.data.map(function(d){
243
- return (function(){
244
- var i$, to$, results$ = [];
245
- for (i$ = 0, to$ = alignIdx; i$ < to$; ++i$) {
337
+ this.yaxis.ticks(yticks);
338
+ this.yaxis.scale(this.scale.y);
339
+ this.xaxis.config((ref$ = this.cfg).xaxis || (ref$.xaxis = {}));
340
+ this.xaxis.ticks(this.data.map(function(it){
341
+ return it.name;
342
+ }));
343
+ this.xaxis.scale(this.scale.x);
344
+ this.xaxis.caption((this.binding.name.name || this.binding.name.key) + (this.binding.name.unit ? "(" + this.binding.name.unit + ")" : ''));
345
+ } else {
346
+ ref$ = this.scale;
347
+ ref$.x = d3.scaleLinear().domain([0, max]).range([box.width, 0]);
348
+ ref$.y = d3.scaleBand().domain(this.order.map(function(it){
349
+ return it.name || it.key;
350
+ })).range([0, box.height]);
351
+ maxTick = (ref$ = Math.ceil(this.layout.getBox('xaxis').width / 80)) > 2 ? ref$ : 2;
352
+ xticks = this.cfg.bump
353
+ ? (function(){
354
+ var i$, to$, ref$, results$ = [];
355
+ for (i$ = 1, to$ = (ref$ = this.parsed.length || 1) > 1 ? ref$ : 1; i$ <= to$; ++i$) {
246
356
  results$.push(i$);
247
357
  }
248
358
  return results$;
249
- }()).reduce(function(a, b){
250
- return a + d.size[b];
251
- }, 0) || 0;
252
- });
253
- this.delta = delta = Math.max.apply(Math, this.baseOffset);
254
- if (this.cfg.multiple === 'stack') {
255
- if (this.cfg.percent) {
256
- max = 1;
257
- } else {
258
- max = Math.max.apply(Math, this.data.map(function(d){
259
- return (function(){
260
- var i$, to$, results$ = [];
261
- for (i$ = alignIdx, to$ = d.size.length; i$ < to$; ++i$) {
262
- results$.push(i$);
263
- }
264
- return results$;
265
- }()).reduce(function(a, b){
266
- return a + d.size[b];
267
- }, 0);
268
- })) + (delta || 0);
269
- }
270
- } else if (this.cfg.multiple === 'group') {
271
- max = Math.max.apply(Math, this.data.map(function(d){
272
- return Math.max.apply(Math, d.size);
273
- }));
274
- } else if (this.cfg.multiple === 'split') {
275
- max = this.maxPerGroup.reduce(function(a, b){
276
- return a + b;
277
- }, 0);
359
+ }.call(this))
360
+ : this.scale.x.ticks((ref$ = ((ref1$ = this.cfg).xaxis || (ref1$.xaxis = {})).tickCount || 4) < maxTick ? ref$ : maxTick);
361
+ this.xaxis.config(this.cfg.xaxis);
362
+ v = this.binding.size[0] || {};
363
+ if (this.binding.size.length > 1) {
364
+ this.xaxis.caption(v.unit ? v.unit + "" : '');
365
+ } else {
366
+ this.xaxis.caption((v.name || v.key || '') + (v.unit ? "(" + v.unit + ")" : ''));
278
367
  }
279
- this.order = this.data.map(function(d, i){
280
- return {
281
- key: d._idx,
282
- idx: i,
283
- name: d.name
284
- };
285
- });
286
- this.data.map(function(d, i){
287
- return d.sum = d.size.reduce(function(a, b){
368
+ this.xaxis.ticks(xticks);
369
+ this.xaxis.scale(this.scale.x);
370
+ this.yaxis.config((ref$ = this.cfg).yaxis || (ref$.yaxis = {}));
371
+ this.yaxis.ticks(this.data.map(function(it){
372
+ return it.name;
373
+ }));
374
+ this.yaxis.scale(this.scale.y);
375
+ this.yaxis.caption((this.binding.name.name || this.binding.name.key) + (this.binding.name.unit ? "(" + this.binding.name.unit + ")" : ''));
376
+ }
377
+ for (i$ = 0; i$ < 2; ++i$) {
378
+ i = i$;
379
+ this.layout.update(false);
380
+ box = this.layout.getBox('view');
381
+ ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
382
+ this.tint.set(this.cfg.palette);
383
+ r = this.cfg.dotSize || 3;
384
+ this.scale.x.range([0, w - r]);
385
+ this.scale.y.range([h, r]);
386
+ this.xaxis.render();
387
+ this.yaxis.render();
388
+ }
389
+ box = this.layout.getBox('view');
390
+ return this.brush.extent([[0, 1], [box.width, box.height - 1]]);
391
+ },
392
+ render: function(){
393
+ var binding, scale, range, delta, baseOffset, maxPerGroup, cfg, tint, data, type, x$, ref$, this$ = this;
394
+ binding = this.binding, scale = this.scale, range = this.range, delta = this.delta, baseOffset = this.baseOffset, maxPerGroup = this.maxPerGroup, cfg = this.cfg, tint = this.tint, data = this.data, type = this.type;
395
+ x$ = this.g.view.selectAll('g.bar').data(this.data);
396
+ x$.exit().remove();
397
+ x$.enter().append('g').attr('class', 'bar');
398
+ this.g.view.selectAll('g.bar').attr('transform', function(d, i){
399
+ if (this$.type === 'column') {
400
+ return "translate(" + scale.x(d.name) + ",0)";
401
+ } else {
402
+ return "translate(0," + scale.y(d.name) + ")";
403
+ }
404
+ }).each(function(item, j){
405
+ var ref$, bars, offset, sum, i$, to$, idx, size, key, x$, y$, tran;
406
+ ref$ = [[], 0], bars = ref$[0], offset = ref$[1];
407
+ offset = delta - baseOffset[j];
408
+ sum = 1;
409
+ if (cfg.percent === true) {
410
+ sum = (ref$ = item.size.reduce(function(a, b){
288
411
  return a + b;
289
- }, 0);
412
+ }, 0)) > 1 ? ref$ : 1;
413
+ }
414
+ for (i$ = 0, to$ = item.size.length; i$ < to$; ++i$) {
415
+ idx = i$;
416
+ size = item.size[idx];
417
+ key = idx;
418
+ bars.push({
419
+ size: size / sum,
420
+ offset: offset / sum,
421
+ key: key,
422
+ group: item.name,
423
+ name: binding.size[key].name || binding.size[key].key,
424
+ unit: binding.size[key].unit || ''
425
+ });
426
+ if (cfg.multiple === 'split') {
427
+ offset += maxPerGroup[idx];
428
+ } else if (cfg.multiple === 'stack') {
429
+ offset += size;
430
+ }
431
+ }
432
+ x$ = d3.select(this).selectAll('rect').data(bars, function(d, i){
433
+ return d.key;
290
434
  });
291
- if (((ref$ = this.cfg).sort || (ref$.sort = {})).enabled) {
292
- this.order.sort(function(a, b){
293
- return (this$.cfg.sort.dir === 'asc'
294
- ? 1
295
- : -1) * (this$.data[a.idx].sum - this$.data[b.idx].sum);
435
+ x$.exit().remove();
436
+ y$ = x$.enter().append('rect');
437
+ if (type === 'column') {
438
+ y$.attr('width', function(d, i){
439
+ var ref$;
440
+ return (ref$ = scale.x.bandwidth() - 2) > 1 ? ref$ : 1;
296
441
  });
297
442
  }
298
- console.log(this.cfg);
299
- if (this.cfg.palette) {
300
- this.tint.set(this.cfg.palette.colors.map(function(it){
301
- return it.value || it;
302
- }));
443
+ if (type === 'column') {
444
+ y$.attr('y', function(d, i){
445
+ return scale.y(0);
446
+ });
303
447
  }
304
- this.legend.data((function(){
305
- var i$, results$ = [];
306
- for (i$ = this.binding.size.length - 1; i$ >= 0; --i$) {
307
- i = i$;
308
- results$.push({
309
- key: i,
310
- text: this.binding.size[i].name || this.binding.size[i].key
448
+ if (type !== 'column') {
449
+ y$.attr('height', function(d, i){
450
+ var ref$;
451
+ return (ref$ = scale.y.bandwidth() - 2) > 1 ? ref$ : 1;
452
+ });
453
+ }
454
+ if (type !== 'column') {
455
+ y$.attr('x', function(d, i){
456
+ return scale.x(0);
457
+ });
458
+ }
459
+ tran = d3.select(this).selectAll('rect').transition().duration(350).call(function(sel){
460
+ var x$;
461
+ if (cfg.multiple !== 'group') {
462
+ return;
463
+ }
464
+ x$ = sel;
465
+ if (type === 'column') {
466
+ x$.attr('x', function(d, i){
467
+ return 1 + i * (scale.x.bandwidth() - 2) / bars.length;
311
468
  });
312
469
  }
313
- return results$;
314
- }.call(this)));
315
- this.layout.update(false);
316
- box = this.layout.getBox('view');
317
- if (this.type === 'column') {
318
- ref$ = this.scale;
319
- ref$.y = d3.scaleLinear().domain([0, max]).range([box.height, 0]);
320
- ref$.x = d3.scaleBand().domain(this.order.map(function(it){
321
- return it.name || it.key;
322
- })).range([0, box.width]);
323
- maxTick = (ref$ = Math.ceil(this.layout.getBox('yaxis').height / 40)) > 2 ? ref$ : 2;
324
- yticks = this.cfg.bump
325
- ? (function(){
326
- var i$, to$, ref$, results$ = [];
327
- for (i$ = 1, to$ = (ref$ = this.parsed.length || 1) > 1 ? ref$ : 1; i$ <= to$; ++i$) {
328
- results$.push(i$);
329
- }
330
- return results$;
331
- }.call(this))
332
- : this.scale.y.ticks((ref$ = ((ref1$ = this.cfg).yaxis || (ref1$.yaxis = {})).tickCount || 4) < maxTick ? ref$ : maxTick);
333
- this.yaxis.config(this.cfg.yaxis);
334
- v = this.binding.size[0] || {};
335
- if (this.binding.size.length > 1) {
336
- this.yaxis.caption(v.unit ? v.unit + "" : '');
337
- } else {
338
- this.yaxis.caption((v.name || v.key || '') + (v.unit ? "(" + v.unit + ")" : ''));
470
+ if (type === 'column') {
471
+ x$.attr('width', function(d, i){
472
+ return (scale.x.bandwidth() - 2) / bars.length;
473
+ });
339
474
  }
340
- this.yaxis.ticks(yticks);
341
- this.yaxis.scale(this.scale.y);
342
- this.xaxis.config((ref$ = this.cfg).xaxis || (ref$.xaxis = {}));
343
- this.xaxis.ticks(this.data.map(function(it){
344
- return it.name;
345
- }));
346
- this.xaxis.scale(this.scale.x);
347
- this.xaxis.caption((this.binding.name.name || this.binding.name.key) + (this.binding.name.unit ? "(" + this.binding.name.unit + ")" : ''));
348
- } else {
349
- ref$ = this.scale;
350
- ref$.x = d3.scaleLinear().domain([0, max]).range([box.width, 0]);
351
- ref$.y = d3.scaleBand().domain(this.order.map(function(it){
352
- return it.name || it.key;
353
- })).range([0, box.height]);
354
- maxTick = (ref$ = Math.ceil(this.layout.getBox('xaxis').width / 80)) > 2 ? ref$ : 2;
355
- xticks = this.cfg.bump
356
- ? (function(){
357
- var i$, to$, ref$, results$ = [];
358
- for (i$ = 1, to$ = (ref$ = this.parsed.length || 1) > 1 ? ref$ : 1; i$ <= to$; ++i$) {
359
- results$.push(i$);
360
- }
361
- return results$;
362
- }.call(this))
363
- : this.scale.x.ticks((ref$ = ((ref1$ = this.cfg).xaxis || (ref1$.xaxis = {})).tickCount || 4) < maxTick ? ref$ : maxTick);
364
- this.xaxis.config(this.cfg.xaxis);
365
- v = this.binding.size[0] || {};
366
- if (this.binding.size.length > 1) {
367
- this.xaxis.caption(v.unit ? v.unit + "" : '');
368
- } else {
369
- this.xaxis.caption((v.name || v.key || '') + (v.unit ? "(" + v.unit + ")" : ''));
475
+ if (type === 'column') {
476
+ x$.attr('y', function(d, i){
477
+ return Math.round(Math.min(scale.y(0), scale.y(d.size)));
478
+ });
370
479
  }
371
- this.xaxis.ticks(xticks);
372
- this.xaxis.scale(this.scale.x);
373
- this.yaxis.config((ref$ = this.cfg).yaxis || (ref$.yaxis = {}));
374
- this.yaxis.ticks(this.data.map(function(it){
375
- return it.name;
376
- }));
377
- this.yaxis.scale(this.scale.y);
378
- this.yaxis.caption((this.binding.name.name || this.binding.name.key) + (this.binding.name.unit ? "(" + this.binding.name.unit + ")" : ''));
379
- }
380
- for (i$ = 0; i$ < 2; ++i$) {
381
- i = i$;
382
- this.layout.update(false);
383
- box = this.layout.getBox('view');
384
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
385
- this.tint.set(this.cfg.palette);
386
- r = this.cfg.dotSize || 3;
387
- this.scale.x.range([0, w - r]);
388
- this.scale.y.range([h, r]);
389
- this.xaxis.render();
390
- this.yaxis.render();
391
- }
392
- box = this.layout.getBox('view');
393
- return this.brush.extent([[0, 1], [box.width, box.height - 1]]);
394
- },
395
- render: function(){
396
- var binding, scale, range, delta, baseOffset, maxPerGroup, cfg, tint, data, type, x$, ref$, this$ = this;
397
- binding = this.binding, scale = this.scale, range = this.range, delta = this.delta, baseOffset = this.baseOffset, maxPerGroup = this.maxPerGroup, cfg = this.cfg, tint = this.tint, data = this.data, type = this.type;
398
- x$ = this.g.view.selectAll('g.bar').data(this.data);
399
- x$.exit().remove();
400
- x$.enter().append('g').attr('class', 'bar');
401
- this.g.view.selectAll('g.bar').attr('transform', function(d, i){
402
- if (this$.type === 'column') {
403
- return "translate(" + scale.x(d.name) + ",0)";
404
- } else {
405
- return "translate(0," + scale.y(d.name) + ")";
480
+ if (type !== 'column') {
481
+ x$.attr('y', function(d, i){
482
+ return 1 + i * (scale.y.bandwidth() - 2) / bars.length;
483
+ });
406
484
  }
407
- }).each(function(item, j){
408
- var ref$, bars, offset, sum, i$, to$, idx, size, key, x$, y$, tran;
409
- ref$ = [[], 0], bars = ref$[0], offset = ref$[1];
410
- offset = delta - baseOffset[j];
411
- sum = 1;
412
- if (cfg.percent === true) {
413
- sum = (ref$ = item.size.reduce(function(a, b){
414
- return a + b;
415
- }, 0)) > 1 ? ref$ : 1;
485
+ if (type !== 'column') {
486
+ x$.attr('height', function(d, i){
487
+ return (scale.y.bandwidth() - 2) / bars.length;
488
+ });
416
489
  }
417
- for (i$ = 0, to$ = item.size.length; i$ < to$; ++i$) {
418
- idx = i$;
419
- size = item.size[idx];
420
- key = idx;
421
- bars.push({
422
- size: size / sum,
423
- offset: offset / sum,
424
- key: key,
425
- group: item.name,
426
- name: binding.size[key].name || binding.size[key].key,
427
- unit: binding.size[key].unit || ''
490
+ if (type !== 'column') {
491
+ x$.attr('x', function(d, i){
492
+ return Math.round(Math.min(scale.x(0), scale.x(d.size)));
428
493
  });
429
- if (cfg.multiple === 'split') {
430
- offset += maxPerGroup[idx];
431
- } else if (cfg.multiple === 'stack') {
432
- offset += size;
433
- }
434
494
  }
435
- x$ = d3.select(this).selectAll('rect').data(bars, function(d, i){
436
- return d.key;
437
- });
438
- x$.exit().remove();
439
- y$ = x$.enter().append('rect');
495
+ return x$;
496
+ }).call(function(sel){
497
+ var x$;
498
+ if (cfg.multiple !== 'stack') {
499
+ return;
500
+ }
501
+ x$ = sel;
440
502
  if (type === 'column') {
441
- y$.attr('width', function(d, i){
442
- var ref$;
443
- return (ref$ = scale.x.bandwidth() - 2) > 1 ? ref$ : 1;
503
+ x$.attr('x', 1);
504
+ }
505
+ if (type === 'column') {
506
+ x$.attr('width', function(d, i){
507
+ return scale.x.bandwidth() - 2;
444
508
  });
445
509
  }
446
510
  if (type === 'column') {
447
- y$.attr('y', function(d, i){
448
- return scale.y(0);
511
+ x$.attr('y', function(d, i){
512
+ return Math.round(Math.min(scale.y(d.offset), scale.y(d.offset + d.size)));
449
513
  });
450
514
  }
451
515
  if (type !== 'column') {
452
- y$.attr('height', function(d, i){
453
- var ref$;
454
- return (ref$ = scale.y.bandwidth() - 2) > 1 ? ref$ : 1;
516
+ x$.attr('y', 1);
517
+ }
518
+ if (type !== 'column') {
519
+ x$.attr('height', function(d, i){
520
+ return scale.y.bandwidth() - 2;
455
521
  });
456
522
  }
457
523
  if (type !== 'column') {
458
- y$.attr('x', function(d, i){
459
- return scale.x(0);
524
+ x$.attr('x', function(d, i){
525
+ return Math.round(Math.min(scale.x(d.offset), scale.x(d.offset + d.size)));
460
526
  });
461
527
  }
462
- tran = d3.select(this).selectAll('rect').transition().duration(350).call(function(sel){
463
- var x$;
464
- if (cfg.multiple !== 'group') {
465
- return;
466
- }
467
- x$ = sel;
468
- if (type === 'column') {
469
- x$.attr('x', function(d, i){
470
- return 1 + i * (scale.x.bandwidth() - 2) / bars.length;
471
- });
472
- }
473
- if (type === 'column') {
474
- x$.attr('width', function(d, i){
475
- return (scale.x.bandwidth() - 2) / bars.length;
476
- });
477
- }
478
- if (type === 'column') {
479
- x$.attr('y', function(d, i){
480
- return Math.round(Math.min(scale.y(0), scale.y(d.size)));
481
- });
482
- }
483
- if (type !== 'column') {
484
- x$.attr('y', function(d, i){
485
- return 1 + i * (scale.y.bandwidth() - 2) / bars.length;
486
- });
487
- }
488
- if (type !== 'column') {
489
- x$.attr('height', function(d, i){
490
- return (scale.y.bandwidth() - 2) / bars.length;
491
- });
492
- }
493
- if (type !== 'column') {
494
- x$.attr('x', function(d, i){
495
- return Math.round(Math.min(scale.x(0), scale.x(d.size)));
496
- });
497
- }
498
- return x$;
499
- }).call(function(sel){
500
- var x$;
501
- if (cfg.multiple !== 'stack') {
502
- return;
503
- }
504
- x$ = sel;
505
- if (type === 'column') {
506
- x$.attr('x', 1);
507
- }
508
- if (type === 'column') {
509
- x$.attr('width', function(d, i){
510
- return scale.x.bandwidth() - 2;
511
- });
512
- }
513
- if (type === 'column') {
514
- x$.attr('y', function(d, i){
515
- return Math.round(Math.min(scale.y(d.offset), scale.y(d.offset + d.size)));
516
- });
517
- }
518
- if (type !== 'column') {
519
- x$.attr('y', 1);
520
- }
521
- if (type !== 'column') {
522
- x$.attr('height', function(d, i){
523
- return scale.y.bandwidth() - 2;
524
- });
525
- }
526
- if (type !== 'column') {
527
- x$.attr('x', function(d, i){
528
- return Math.round(Math.min(scale.x(d.offset), scale.x(d.offset + d.size)));
529
- });
530
- }
531
- return x$;
528
+ return x$;
529
+ });
530
+ if (type === 'column') {
531
+ tran.attr('height', function(d, i){
532
+ return Math.round(Math.abs(scale.y(0) - scale.y(d.size)));
532
533
  });
533
- if (type === 'column') {
534
- tran.attr('height', function(d, i){
535
- return Math.round(Math.abs(scale.y(0) - scale.y(d.size)));
536
- });
534
+ } else {
535
+ tran.attr('width', function(d, i){
536
+ return Math.round(Math.abs(scale.x(0) - scale.x(d.size)));
537
+ });
538
+ }
539
+ return tran.attr('fill', function(d, i){
540
+ return tint.get(i, cfg.colorVariant ? j / data.length - 0.5 : 0);
541
+ }).attr('fill-opacity', function(d, i){
542
+ var filter, range;
543
+ if (!(binding.name && (filter = binding.name.filter))) {
544
+ return 1;
545
+ }
546
+ if (!(range = filter.value)) {
547
+ return 1;
548
+ }
549
+ if (in$(item.name, range)) {
550
+ return 1;
537
551
  } else {
538
- tran.attr('width', function(d, i){
539
- return Math.round(Math.abs(scale.x(0) - scale.x(d.size)));
540
- });
552
+ return 0.2;
541
553
  }
542
- return tran.attr('fill', function(d, i){
543
- return tint.get(i, cfg.colorVariant ? j / data.length - 0.5 : 0);
544
- }).attr('fill-opacity', function(d, i){
545
- var filter, range;
546
- if (!(binding.name && (filter = binding.name.filter))) {
547
- return 1;
548
- }
549
- if (!(range = filter.value)) {
550
- return 1;
551
- }
552
- if (in$(item.name, range)) {
553
- return 1;
554
- } else {
555
- return 0.2;
556
- }
557
- });
558
554
  });
559
- if (!(((ref$ = this.cfg).brush || (ref$.brush = {})).enabled != null && !this.cfg.brush.enabled)) {
560
- this.g.view.call(this.brush);
561
- }
562
- this.g.view.selectAll('rect.selection').attr('shape-rendering', 'auto');
563
- this.legend.render();
564
- this.yaxis.render();
565
- return this.xaxis.render();
566
- },
567
- tick: function(){}
568
- };
555
+ });
556
+ if (!(((ref$ = this.cfg).brush || (ref$.brush = {})).enabled != null && !this.cfg.brush.enabled)) {
557
+ this.g.view.call(this.brush);
558
+ }
559
+ this.g.view.selectAll('rect.selection').attr('shape-rendering', 'auto');
560
+ this.legend.render();
561
+ this.yaxis.render();
562
+ return this.xaxis.render();
563
+ },
564
+ tick: function(){}
569
565
  };
570
- return blockFactory;
571
- });
566
+ };
572
567
  function import$(obj, src){
573
568
  var own = {}.hasOwnProperty;
574
569
  for (var key in src) if (own.call(src, key)) obj[key] = src[key];