@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
@@ -10,270 +10,265 @@
10
10
  .pdl-layout > div[data-type=layout] > [data-name=legend] {
11
11
  min-width: 6em;
12
12
  }
13
- </style><script type="@plotdb/block">(function(it){
14
- return it();
15
- })(function(){
16
- var blockFactory, mod;
17
- blockFactory = {
18
- pkg: {
19
- name: 'pie',
20
- version: '0.0.1',
21
- extend: {
22
- name: "base",
23
- version: "0.0.1"
24
- },
25
- dependencies: [],
26
- i18n: {
27
- "zh-TW": {
28
- value: "數值",
29
- name: "名稱",
30
- other: "其它"
31
- }
32
- }
13
+ </style><script type="@plotdb/block">var mod;
14
+ module.exports = {
15
+ pkg: {
16
+ name: 'pie',
17
+ version: '0.0.1',
18
+ extend: {
19
+ name: "base",
20
+ version: "0.0.1"
33
21
  },
34
- init: function(arg$){
35
- var root, context, pubsub, t;
36
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
37
- return pubsub.fire('init', {
38
- mod: mod({
39
- context: context,
40
- t: t
41
- })
42
- });
22
+ dependencies: [],
23
+ i18n: {
24
+ "zh-TW": {
25
+ value: "數值",
26
+ name: "名稱",
27
+ other: "其它"
28
+ }
43
29
  }
44
- };
45
- mod = function(arg$){
46
- var context, t, chart, d3;
47
- context = arg$.context, t = arg$.t;
48
- chart = context.chart, d3 = context.d3;
49
- return {
50
- sample: function(){
51
- return {
52
- raw: [1, 2, 3, 4, 5].map(function(val){
53
- return {
54
- val: (10 * Math.random()).toFixed(2),
55
- name: val
56
- };
57
- }),
58
- binding: {
59
- name: {
60
- key: 'name'
61
- },
62
- value: {
63
- key: 'val'
64
- }
65
- }
66
- };
67
- },
68
- config: {},
69
- dimension: {
70
- value: {
71
- type: 'R',
72
- name: "value",
73
- priority: 20
74
- },
75
- name: {
76
- type: 'NO',
77
- name: "name",
78
- priority: 10
79
- }
80
- },
81
- init: function(){
82
- var tint, this$ = this;
83
- this.g = Object.fromEntries(['view', 'legend'].map(function(it){
84
- return [it, d3.select(this$.layout.getGroup(it)).append('g')];
85
- }));
86
- this.tint = tint = new chart.utils.tint();
87
- this.tip = new chart.utils.tip({
88
- root: this.root,
89
- accessor: function(arg$){
90
- var evt, data, v;
91
- evt = arg$.evt;
92
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
93
- return null;
94
- }
95
- v = isNaN(data.value)
96
- ? '-'
97
- : data.value.toFixed(2) + "" + (this$.binding.value.unit || '');
98
- return {
99
- name: data.name,
100
- value: v
101
- };
102
- },
103
- range: function(){
104
- return this$.layout.getNode('view').getBoundingClientRect();
105
- }
106
- });
107
- this.legend = new chart.utils.legend({
108
- layout: this.layout,
109
- name: 'legend',
110
- root: this.root,
111
- shape: function(d){
112
- return d3.select(this).attr('fill', tint.get(d.text));
30
+ },
31
+ init: function(arg$){
32
+ var root, context, pubsub, t;
33
+ root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
34
+ return pubsub.fire('init', {
35
+ mod: mod({
36
+ context: context,
37
+ t: t
38
+ })
39
+ });
40
+ }
41
+ };
42
+ mod = function(arg$){
43
+ var context, t, chart, d3;
44
+ context = arg$.context, t = arg$.t;
45
+ chart = context.chart, d3 = context.d3;
46
+ return {
47
+ sample: function(){
48
+ return {
49
+ raw: [1, 2, 3, 4, 5].map(function(val){
50
+ return {
51
+ val: (10 * Math.random()).toFixed(2),
52
+ name: val
53
+ };
54
+ }),
55
+ binding: {
56
+ name: {
57
+ key: 'name'
113
58
  },
114
- cfg: {
115
- selectable: true
59
+ value: {
60
+ key: 'val'
116
61
  }
117
- });
118
- this.legend.on('select', function(){
119
- this$.bind();
120
- this$.resize();
121
- return this$.render();
122
- });
123
- this.arc = d3.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(Math.PI / 2);
124
- return this.total = {};
125
- },
126
- destroy: function(){
127
- return this.tip.destroy();
62
+ }
63
+ };
64
+ },
65
+ config: {},
66
+ dimension: {
67
+ value: {
68
+ type: 'R',
69
+ name: "value",
70
+ priority: 20
128
71
  },
129
- parse: function(){
130
- var other, ref$, total, sum, i$, to$, idx;
131
- this.tint.reset();
132
- this.parsed = this.data.map(function(it){
133
- var ret;
134
- ret = import$({}, it);
135
- if (isNaN(ret.value)) {
136
- ret.value = 0;
137
- }
138
- return ret;
139
- });
140
- this.parsed.sort(function(a, b){
141
- return b.value - a.value;
142
- });
143
- if (this.cfg.collapse != null && this.cfg.collapse.enabled) {
144
- if (this.cfg.collapse.method === 'count') {
145
- other = this.parsed.splice(this.cfg.collapse.threshold || 7);
146
- if (other.length) {
147
- this.parsed.push({
148
- name: t("other"),
149
- value: other.reduce(function(a, b){
150
- return a + b.value;
151
- }, 0)
152
- });
153
- }
154
- } else {
155
- ref$ = [
156
- this.parsed.reduce(function(a, b){
157
- return a + b.value;
158
- }, 0), 0
159
- ], total = ref$[0], sum = ref$[1];
160
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
161
- idx = i$;
162
- sum += this.parsed[idx].value;
163
- if (sum / total > (this.cfg.collapse.threshold || 0.75)) {
164
- break;
165
- }
166
- }
167
- other = this.parsed.splice(idx + 1);
168
- if (other.length) {
169
- this.parsed.push({
170
- name: t("other"),
171
- value: other.reduce(function(a, b){
172
- return a + b.value;
173
- }, 0)
174
- });
175
- }
72
+ name: {
73
+ type: 'NO',
74
+ name: "name",
75
+ priority: 10
76
+ }
77
+ },
78
+ init: function(){
79
+ var tint, this$ = this;
80
+ this.g = Object.fromEntries(['view', 'legend'].map(function(it){
81
+ return [it, d3.select(this$.layout.getGroup(it)).append('g')];
82
+ }));
83
+ this.tint = tint = new chart.utils.tint();
84
+ this.tip = new chart.utils.tip({
85
+ root: this.root,
86
+ accessor: function(arg$){
87
+ var evt, data, v;
88
+ evt = arg$.evt;
89
+ if (!(evt.target && (data = d3.select(evt.target).datum()))) {
90
+ return null;
176
91
  }
177
- }
178
- return this.legend.data(this.parsed.map(function(it){
92
+ v = isNaN(data.value)
93
+ ? '-'
94
+ : data.value.toFixed(2) + "" + (this$.binding.value.unit || '');
179
95
  return {
180
- text: it.name,
181
- key: it.name
96
+ name: data.name,
97
+ value: v
182
98
  };
183
- }));
184
- },
185
- bind: function(){
186
- var offset, i$, to$, i, obj, that, this$ = this, results$ = [];
187
- this.parsed.map(function(it){
188
- return it.picked = this$.legend.isSelected(it.name);
189
- });
190
- this.total.old = this.total.cur;
191
- this.total.cur = this.parsed.reduce(function(a, b){
192
- return a + (b.picked ? b.value : 0);
193
- }, 0) || 1;
194
- if (!this.total.old) {
195
- this.total.old = this.total.cur;
99
+ },
100
+ range: function(){
101
+ return this$.layout.getNode('view').getBoundingClientRect();
196
102
  }
197
- offset = 0;
198
- for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
199
- i = i$;
200
- obj = this.parsed[i];
201
- if (!obj.old) {
202
- obj.old = {
203
- s: (that = this.parsed[i - 1]) ? that.old.e : 0,
204
- e: 0
205
- };
206
- }
207
- if (obj.cur) {
208
- obj.old = obj.cur;
103
+ });
104
+ this.legend = new chart.utils.legend({
105
+ layout: this.layout,
106
+ name: 'legend',
107
+ root: this.root,
108
+ shape: function(d){
109
+ return d3.select(this).attr('fill', tint.get(d.text));
110
+ },
111
+ cfg: {
112
+ selectable: true
113
+ }
114
+ });
115
+ this.legend.on('select', function(){
116
+ this$.bind();
117
+ this$.resize();
118
+ return this$.render();
119
+ });
120
+ this.arc = d3.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(Math.PI / 2);
121
+ return this.total = {};
122
+ },
123
+ destroy: function(){
124
+ return this.tip.destroy();
125
+ },
126
+ parse: function(){
127
+ var other, ref$, total, sum, i$, to$, idx;
128
+ this.tint.reset();
129
+ this.parsed = this.data.map(function(it){
130
+ var ret;
131
+ ret = import$({}, it);
132
+ if (isNaN(ret.value)) {
133
+ ret.value = 0;
134
+ }
135
+ return ret;
136
+ });
137
+ this.parsed.sort(function(a, b){
138
+ return b.value - a.value;
139
+ });
140
+ if (this.cfg.collapse != null && this.cfg.collapse.enabled) {
141
+ if (this.cfg.collapse.method === 'count') {
142
+ other = this.parsed.splice(this.cfg.collapse.threshold || 7);
143
+ if (other.length) {
144
+ this.parsed.push({
145
+ name: t("other"),
146
+ value: other.reduce(function(a, b){
147
+ return a + b.value;
148
+ }, 0)
149
+ });
209
150
  }
210
- obj.cur = {
211
- s: offset,
212
- e: offset + (obj.picked ? obj.value : 0)
213
- };
214
- obj.angle = {
215
- old: {
216
- s: 2 * Math.PI * obj.old.s / this.total.old,
217
- e: 2 * Math.PI * obj.old.e / this.total.old
218
- },
219
- cur: {
220
- s: 2 * Math.PI * obj.cur.s / this.total.cur,
221
- e: 2 * Math.PI * obj.cur.e / this.total.cur
151
+ } else {
152
+ ref$ = [
153
+ this.parsed.reduce(function(a, b){
154
+ return a + b.value;
155
+ }, 0), 0
156
+ ], total = ref$[0], sum = ref$[1];
157
+ for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
158
+ idx = i$;
159
+ sum += this.parsed[idx].value;
160
+ if (sum / total > (this.cfg.collapse.threshold || 0.75)) {
161
+ break;
222
162
  }
223
- };
224
- if (obj.picked) {
225
- results$.push(offset += obj.value);
163
+ }
164
+ other = this.parsed.splice(idx + 1);
165
+ if (other.length) {
166
+ this.parsed.push({
167
+ name: t("other"),
168
+ value: other.reduce(function(a, b){
169
+ return a + b.value;
170
+ }, 0)
171
+ });
226
172
  }
227
173
  }
228
- return results$;
229
- },
230
- resize: function(){
231
- var box, ref$, w, h, size;
232
- this.layout.update(false);
233
- box = this.layout.getBox('view');
234
- this.layout.getNode('view').style.width = box.height + "px";
235
- this.layout.update(false);
236
- box = this.layout.getBox('view');
237
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
238
- size = Math.min(w, h);
239
- return this.arc.innerRadius((this.cfg.donutPercent || 0.7) * size / 2).outerRadius(size / 2);
240
- },
241
- render: function(){
242
- var tint, interpolateArc, box, x$, this$ = this;
243
- tint = this.tint;
244
- interpolateArc = function(a1, a2){
245
- return function(t){
246
- var ref$, s, e;
247
- ref$ = ['s', 'e'].map(function(i){
248
- return (a2[i] - a1[i]) * t + a1[i];
249
- }), s = ref$[0], e = ref$[1];
250
- this$.arc.startAngle(s).endAngle(e);
251
- return this$.arc();
174
+ }
175
+ return this.legend.data(this.parsed.map(function(it){
176
+ return {
177
+ text: it.name,
178
+ key: it.name
179
+ };
180
+ }));
181
+ },
182
+ bind: function(){
183
+ var offset, i$, to$, i, obj, that, this$ = this, results$ = [];
184
+ this.parsed.map(function(it){
185
+ return it.picked = this$.legend.isSelected(it.name);
186
+ });
187
+ this.total.old = this.total.cur;
188
+ this.total.cur = this.parsed.reduce(function(a, b){
189
+ return a + (b.picked ? b.value : 0);
190
+ }, 0) || 1;
191
+ if (!this.total.old) {
192
+ this.total.old = this.total.cur;
193
+ }
194
+ offset = 0;
195
+ for (i$ = 0, to$ = this.parsed.length; i$ < to$; ++i$) {
196
+ i = i$;
197
+ obj = this.parsed[i];
198
+ if (!obj.old) {
199
+ obj.old = {
200
+ s: (that = this.parsed[i - 1]) ? that.old.e : 0,
201
+ e: 0
252
202
  };
203
+ }
204
+ if (obj.cur) {
205
+ obj.old = obj.cur;
206
+ }
207
+ obj.cur = {
208
+ s: offset,
209
+ e: offset + (obj.picked ? obj.value : 0)
210
+ };
211
+ obj.angle = {
212
+ old: {
213
+ s: 2 * Math.PI * obj.old.s / this.total.old,
214
+ e: 2 * Math.PI * obj.old.e / this.total.old
215
+ },
216
+ cur: {
217
+ s: 2 * Math.PI * obj.cur.s / this.total.cur,
218
+ e: 2 * Math.PI * obj.cur.e / this.total.cur
219
+ }
253
220
  };
254
- if (this.cfg != null && this.cfg.palette) {
255
- this.tint.set(this.cfg.palette.colors.map(function(it){
256
- return it.value || it;
257
- }));
221
+ if (obj.picked) {
222
+ results$.push(offset += obj.value);
258
223
  }
259
- box = this.layout.getBox('view');
260
- this.g.view.attr('transform', "translate(" + box.width / 2 + "," + box.height / 2 + ")");
261
- x$ = this.g.view.selectAll('path.data').data(this.parsed, function(it){
262
- return it.name || it._idx;
263
- });
264
- x$.exit().remove();
265
- x$.enter().append('path').attr('class', 'data');
266
- this.g.view.selectAll('path.data').attr('fill', function(d, i){
267
- return this$.tint.get(d.name || d._idx);
268
- }).transition().duration(350).attrTween('d', function(d, i){
269
- return interpolateArc(d.angle.old, d.angle.cur);
270
- });
271
- return this.legend.render();
272
224
  }
273
- };
225
+ return results$;
226
+ },
227
+ resize: function(){
228
+ var box, ref$, w, h, size;
229
+ this.layout.update(false);
230
+ box = this.layout.getBox('view');
231
+ this.layout.getNode('view').style.width = box.height + "px";
232
+ this.layout.update(false);
233
+ box = this.layout.getBox('view');
234
+ ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
235
+ size = Math.min(w, h);
236
+ return this.arc.innerRadius((this.cfg.donutPercent || 0.7) * size / 2).outerRadius(size / 2);
237
+ },
238
+ render: function(){
239
+ var tint, interpolateArc, box, x$, this$ = this;
240
+ tint = this.tint;
241
+ interpolateArc = function(a1, a2){
242
+ return function(t){
243
+ var ref$, s, e;
244
+ ref$ = ['s', 'e'].map(function(i){
245
+ return (a2[i] - a1[i]) * t + a1[i];
246
+ }), s = ref$[0], e = ref$[1];
247
+ this$.arc.startAngle(s).endAngle(e);
248
+ return this$.arc();
249
+ };
250
+ };
251
+ if (this.cfg != null && this.cfg.palette) {
252
+ this.tint.set(this.cfg.palette.colors.map(function(it){
253
+ return it.value || it;
254
+ }));
255
+ }
256
+ box = this.layout.getBox('view');
257
+ this.g.view.attr('transform', "translate(" + box.width / 2 + "," + box.height / 2 + ")");
258
+ x$ = this.g.view.selectAll('path.data').data(this.parsed, function(it){
259
+ return it.name || it._idx;
260
+ });
261
+ x$.exit().remove();
262
+ x$.enter().append('path').attr('class', 'data');
263
+ this.g.view.selectAll('path.data').attr('fill', function(d, i){
264
+ return this$.tint.get(d.name || d._idx);
265
+ }).transition().duration(350).attrTween('d', function(d, i){
266
+ return interpolateArc(d.angle.old, d.angle.cur);
267
+ });
268
+ return this.legend.render();
269
+ }
274
270
  };
275
- return blockFactory;
276
- });
271
+ };
277
272
  function import$(obj, src){
278
273
  var own = {}.hasOwnProperty;
279
274
  for (var key in src) if (own.call(src, key)) obj[key] = src[key];