@plotdb/chart 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +50 -0
  3. package/build +39 -0
  4. package/dist/chart.css +8 -0
  5. package/dist/chart.js +603 -0
  6. package/dist/chart.min.css +1 -0
  7. package/dist/chart.min.js +1 -0
  8. package/dist/data/index.js +73 -0
  9. package/dist/utils/axis.js +357 -0
  10. package/dist/utils/axis.min.js +1 -0
  11. package/dist/utils/config.js +33 -0
  12. package/dist/utils/config.min.js +1 -0
  13. package/dist/utils/data.js +238 -0
  14. package/dist/utils/data.min.js +1 -0
  15. package/dist/utils/format.js +70 -0
  16. package/dist/utils/format.min.js +1 -0
  17. package/dist/utils/legend.css +40 -0
  18. package/dist/utils/legend.js +263 -0
  19. package/dist/utils/legend.min.css +1 -0
  20. package/dist/utils/legend.min.js +1 -0
  21. package/dist/utils/tint.js +138 -0
  22. package/dist/utils/tint.min.js +1 -0
  23. package/dist/utils/tip.js +148 -0
  24. package/dist/utils/tip.min.js +1 -0
  25. package/doc/charts.md +58 -0
  26. package/doc/config.md +44 -0
  27. package/doc/draft/chart.md +146 -0
  28. package/doc/draft/data.md +8 -0
  29. package/doc/draft/definition.md +0 -0
  30. package/doc/draft/events.md +0 -0
  31. package/doc/draft/filter.md +0 -0
  32. package/doc/draft/lifecycle.md +89 -0
  33. package/doc/spec.md +89 -0
  34. package/doc/todo.md +27 -0
  35. package/doc/utils/tip.md +84 -0
  36. package/package.json +83 -0
  37. package/src/chart.ls +320 -0
  38. package/src/chart.styl +6 -0
  39. package/src/data/en-US/category +20 -0
  40. package/src/data/en-US/fruit +39 -0
  41. package/src/data/en-US/movie +125 -0
  42. package/src/data/en-US/name +58 -0
  43. package/src/data/index.ls +34 -0
  44. package/src/data/zh-TW/category +20 -0
  45. package/src/data/zh-TW/fruits +38 -0
  46. package/src/data/zh-TW/movie +125 -0
  47. package/src/data/zh-TW/names +105 -0
  48. package/src/utils/axis.ls +229 -0
  49. package/src/utils/config.ls +11 -0
  50. package/src/utils/data.ls +104 -0
  51. package/src/utils/format.ls +30 -0
  52. package/src/utils/legend.ls +134 -0
  53. package/src/utils/legend.styl +37 -0
  54. package/src/utils/tint.ls +66 -0
  55. package/src/utils/tip.ls +97 -0
  56. package/web/src/pug/base.pug +19 -0
  57. package/web/src/pug/block/axis/0.0.1/index.ls +38 -0
  58. package/web/src/pug/block/axis/0.0.1/index.pug +1 -0
  59. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +141 -0
  60. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +1 -0
  61. package/web/src/pug/block/bar/0.0.1/index.ls +274 -0
  62. package/web/src/pug/block/bar/0.0.1/index.pug +35 -0
  63. package/web/src/pug/block/bar-list/0.0.1/index.ls +85 -0
  64. package/web/src/pug/block/bar-list/0.0.1/index.pug +30 -0
  65. package/web/src/pug/block/bar-race/0.0.1/index.ls +83 -0
  66. package/web/src/pug/block/bar-race/0.0.1/index.pug +21 -0
  67. package/web/src/pug/block/base/0.0.1/index.ls +67 -0
  68. package/web/src/pug/block/base/0.0.1/index.pug +5 -0
  69. package/web/src/pug/block/blank/0.0.1/index.ls +25 -0
  70. package/web/src/pug/block/blank/0.0.1/index.pug +1 -0
  71. package/web/src/pug/block/bubble/0.0.1/index.ls +220 -0
  72. package/web/src/pug/block/bubble/0.0.1/index.pug +28 -0
  73. package/web/src/pug/block/curve-bar/0.0.1/index.ls +89 -0
  74. package/web/src/pug/block/curve-bar/0.0.1/index.pug +16 -0
  75. package/web/src/pug/block/curve-bar/0.0.1/sample.js +338 -0
  76. package/web/src/pug/block/dumbbell/0.0.1/index.ls +90 -0
  77. package/web/src/pug/block/dumbbell/0.0.1/index.pug +1 -0
  78. package/web/src/pug/block/empty/0.0.1/index.ls +27 -0
  79. package/web/src/pug/block/empty/0.0.1/index.pug +2 -0
  80. package/web/src/pug/block/gauge/0.0.1/index.ls +100 -0
  81. package/web/src/pug/block/gauge/0.0.1/index.pug +31 -0
  82. package/web/src/pug/block/gauge/0.0.1/sample.js +338 -0
  83. package/web/src/pug/block/line/0.0.1/index.ls +265 -0
  84. package/web/src/pug/block/line/0.0.1/index.pug +33 -0
  85. package/web/src/pug/block/number/0.0.1/index.ls +69 -0
  86. package/web/src/pug/block/number/0.0.1/index.pug +20 -0
  87. package/web/src/pug/block/percent-list/0.0.1/index.ls +167 -0
  88. package/web/src/pug/block/percent-list/0.0.1/index.pug +34 -0
  89. package/web/src/pug/block/pie/0.0.1/index.ls +125 -0
  90. package/web/src/pug/block/pie/0.0.1/index.pug +19 -0
  91. package/web/src/pug/block/pie/0.0.1/sample.js +338 -0
  92. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +185 -0
  93. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +40 -0
  94. package/web/src/pug/block/radar/0.0.1/index.ls +113 -0
  95. package/web/src/pug/block/radar/0.0.1/index.pug +1 -0
  96. package/web/src/pug/block/radar/0.0.1/xx +285 -0
  97. package/web/src/pug/block/scatter/0.0.1/index.ls +128 -0
  98. package/web/src/pug/block/scatter/0.0.1/index.pug +30 -0
  99. package/web/src/pug/block/sheet/0.0.1/index.ls +38 -0
  100. package/web/src/pug/block/sheet/0.0.1/index.pug +5 -0
  101. package/web/src/pug/block/table/0.0.1/index.ls +40 -0
  102. package/web/src/pug/block/table/0.0.1/index.pug +3 -0
  103. package/web/src/pug/block/taiwantown/0.0.1/index.ls +48 -0
  104. package/web/src/pug/block/taiwantown/0.0.1/index.pug +52 -0
  105. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +53 -0
  106. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +52 -0
  107. package/web/src/pug/block/treemap/0.0.1/index.ls +172 -0
  108. package/web/src/pug/block/treemap/0.0.1/index.pug +42 -0
  109. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +174 -0
  110. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +17 -0
  111. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +241 -0
  112. package/web/src/pug/block/wordcloud/0.0.1/index.ls +61 -0
  113. package/web/src/pug/block/wordcloud/0.0.1/index.pug +1 -0
  114. package/web/src/pug/block/worldmap/0.0.1/index.ls +83 -0
  115. package/web/src/pug/block/worldmap/0.0.1/index.pug +12 -0
  116. package/web/src/pug/index.ls +72 -0
  117. package/web/src/pug/index.pug +52 -0
  118. package/web/src/styl/index.styl +0 -0
  119. package/web/static/assets/block/cache.js +4 -0
  120. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +2 -0
  121. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +2 -0
  122. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +2 -0
  123. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +2 -0
  124. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +2 -0
  125. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +2 -0
  126. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +2 -0
  127. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +2 -0
  128. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +2 -0
  129. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +2 -0
  130. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +2 -0
  131. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +2 -0
  132. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +2 -0
  133. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +2 -0
  134. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +2 -0
  135. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +2 -0
  136. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +2 -0
  137. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +2 -0
  138. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +2 -0
  139. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +2 -0
  140. package/web/static/assets/custom-lib/d3/d3.v4.js +17178 -0
  141. package/web/static/assets/custom-lib/d3/d3.v4.min.js +2 -0
  142. package/web/static/assets/data/countrycode.json +1 -0
  143. package/web/static/assets/data/world-110m.json +1 -0
  144. package/web/static/assets/data/zh-to-alpha2.json +1 -0
  145. package/web/static/assets/img/fluid.svg +16 -0
  146. package/web/static/block/axis/0.0.1/index.html +79 -0
  147. package/web/static/block/axis-bubble/0.0.1/index.html +222 -0
  148. package/web/static/block/bar/0.0.1/index.html +581 -0
  149. package/web/static/block/bar-list/0.0.1/index.html +231 -0
  150. package/web/static/block/bar-race/0.0.1/index.html +184 -0
  151. package/web/static/block/base/0.0.1/index.html +197 -0
  152. package/web/static/block/blank/0.0.1/index.html +42 -0
  153. package/web/static/block/bubble/0.0.1/index.html +402 -0
  154. package/web/static/block/bubble/0.0.1/test.html +0 -0
  155. package/web/static/block/curve-bar/0.0.1/index.html +148 -0
  156. package/web/static/block/dumbbell/0.0.1/index.html +178 -0
  157. package/web/static/block/empty/0.0.1/index.html +76 -0
  158. package/web/static/block/gauge/0.0.1/index.html +150 -0
  159. package/web/static/block/line/0.0.1/index.html +540 -0
  160. package/web/static/block/number/0.0.1/index.html +152 -0
  161. package/web/static/block/percent-list/0.0.1/index.html +316 -0
  162. package/web/static/block/pie/0.0.1/index.html +281 -0
  163. package/web/static/block/pie-bubble/0.0.1/index.html +358 -0
  164. package/web/static/block/radar/0.0.1/index.html +149 -0
  165. package/web/static/block/scatter/0.0.1/index.html +251 -0
  166. package/web/static/block/sheet/0.0.1/index.html +103 -0
  167. package/web/static/block/table/0.0.1/index.html +73 -0
  168. package/web/static/block/taiwantown/0.0.1/index.html +210 -0
  169. package/web/static/block/taiwanvillage/0.0.1/index.html +220 -0
  170. package/web/static/block/treemap/0.0.1/index.html +360 -0
  171. package/web/static/block/voronoi-treemap/0.0.1/index.html +350 -0
  172. package/web/static/block/wordcloud/0.0.1/index.html +92 -0
  173. package/web/static/block/worldmap/0.0.1/index.html +207 -0
  174. package/web/static/css/index.css +0 -0
  175. package/web/static/css/index.min.css +0 -0
  176. package/web/static/favicon.ico +0 -0
  177. package/web/static/index.html +153 -0
@@ -0,0 +1,581 @@
1
+ <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="yaxis">&nbsp;</div><div class="pdl-cell" data-name="view"></div><div class="pdl-cell"></div><div class="pdl-cell" data-name="xaxis">&nbsp;</div><div class="pdl-cell" data-name="legend">&nbsp;</div></div><div data-type="render"></div></div></div><style type="text/css">[data-name=xaxis] {
2
+ font-size: 0.8em;
3
+ }
4
+ [data-name=yaxis] {
5
+ font-size: 0.8em;
6
+ }
7
+ .pdl-layout > div[data-type=layout] {
8
+ display: grid;
9
+ grid-template-columns: fit-content(2em) 1fr fit-content(10em);
10
+ grid-template-rows: 1fr fit-content(1em);
11
+ /* 0.5em for axis label at the boundary */
12
+ padding: 0 0.5em;
13
+ }
14
+ .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
15
+ grid-column: 3;
16
+ grid-row: 1/span 2;
17
+ padding-left: 1em;
18
+ }
19
+ .pdl-layout.legend-below > div[data-type=layout] {
20
+ grid-template-columns: 2em 1fr;
21
+ grid-template-rows: 1fr fit-content(2em) fit-content(3em);
22
+ }
23
+ .pdl-layout.legend-below > div[data-type=layout] .pdl-cell[data-name=legend] {
24
+ padding-top: 1em;
25
+ grid-column: 1/span 2;
26
+ grid-row: 3;
27
+ }
28
+ </style><script type="@plotdb/block">(function(it){
29
+ return it();
30
+ })(function(){
31
+ var blockFactory, mod;
32
+ blockFactory = {
33
+ pkg: {
34
+ name: '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": "長度"
44
+ }
45
+ }
46
+ },
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
+ })
55
+ });
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();
73
+ }
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
+ }),
83
+ name: {
84
+ key: "name"
85
+ }
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']
96
+ }
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"
111
+ }
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;
126
+ }
127
+ this$.alignIdx = ((this$.alignIdx || 0) + 1) % (this$.binding.size.length + 1);
128
+ this$.resize();
129
+ return this$.render();
130
+ });
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))];
134
+ }));
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;
146
+ }
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(){
159
+ var i$, to$, results$ = [];
160
+ for (i$ = range[0], to$ = range[1]; i$ <= to$; ++i$) {
161
+ results$.push(i$);
162
+ }
163
+ 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();
200
+ }
201
+ },
202
+ filter: function(filters, internal){
203
+ var this$ = this;
204
+ internal == null && (internal = false);
205
+ this.render();
206
+ if (internal) {
207
+ return;
208
+ }
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;
220
+ }
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;
238
+ }
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$) {
246
+ results$.push(i$);
247
+ }
248
+ 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);
278
+ }
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){
288
+ return a + b;
289
+ }, 0);
290
+ });
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);
296
+ });
297
+ }
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
+ }));
303
+ }
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
311
+ });
312
+ }
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 + ")" : ''));
339
+ }
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 + ")" : ''));
370
+ }
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) + ")";
406
+ }
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;
416
+ }
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 || ''
428
+ });
429
+ if (cfg.multiple === 'split') {
430
+ offset += maxPerGroup[idx];
431
+ } else if (cfg.multiple === 'stack') {
432
+ offset += size;
433
+ }
434
+ }
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');
440
+ if (type === 'column') {
441
+ y$.attr('width', function(d, i){
442
+ var ref$;
443
+ return (ref$ = scale.x.bandwidth() - 2) > 1 ? ref$ : 1;
444
+ });
445
+ }
446
+ if (type === 'column') {
447
+ y$.attr('y', function(d, i){
448
+ return scale.y(0);
449
+ });
450
+ }
451
+ if (type !== 'column') {
452
+ y$.attr('height', function(d, i){
453
+ var ref$;
454
+ return (ref$ = scale.y.bandwidth() - 2) > 1 ? ref$ : 1;
455
+ });
456
+ }
457
+ if (type !== 'column') {
458
+ y$.attr('x', function(d, i){
459
+ return scale.x(0);
460
+ });
461
+ }
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$;
532
+ });
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
+ });
537
+ } else {
538
+ tran.attr('width', function(d, i){
539
+ return Math.round(Math.abs(scale.x(0) - scale.x(d.size)));
540
+ });
541
+ }
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
+ });
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
+ };
569
+ };
570
+ return blockFactory;
571
+ });
572
+ function import$(obj, src){
573
+ var own = {}.hasOwnProperty;
574
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
575
+ return obj;
576
+ }
577
+ function in$(x, xs){
578
+ var i = -1, l = xs.length >>> 0;
579
+ while (++i < l) if (x === xs[i]) return true;
580
+ return false;
581
+ }</script></div>