@plotdb/chart 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/package.json +3 -1
  2. package/CHANGELOG.md +0 -29
  3. package/build +0 -45
  4. package/doc/charts.md +0 -58
  5. package/doc/config.md +0 -44
  6. package/doc/draft/chart.md +0 -146
  7. package/doc/draft/data.md +0 -8
  8. package/doc/draft/definition.md +0 -0
  9. package/doc/draft/events.md +0 -0
  10. package/doc/draft/filter.md +0 -0
  11. package/doc/draft/lifecycle.md +0 -89
  12. package/doc/spec.md +0 -89
  13. package/doc/todo.md +0 -27
  14. package/doc/utils/tip.md +0 -84
  15. package/src/data/en-US/category +0 -20
  16. package/src/data/en-US/fruit +0 -39
  17. package/src/data/en-US/movie +0 -125
  18. package/src/data/en-US/name +0 -58
  19. package/src/data/index.ls +0 -34
  20. package/src/data/zh-TW/category +0 -20
  21. package/src/data/zh-TW/fruits +0 -38
  22. package/src/data/zh-TW/movie +0 -125
  23. package/src/data/zh-TW/names +0 -105
  24. package/src/index.ls +0 -323
  25. package/src/index.styl +0 -6
  26. package/src/utils/axis.ls +0 -229
  27. package/src/utils/config.ls +0 -11
  28. package/src/utils/data.ls +0 -104
  29. package/src/utils/format.ls +0 -30
  30. package/src/utils/legend.ls +0 -134
  31. package/src/utils/legend.styl +0 -37
  32. package/src/utils/tint.ls +0 -66
  33. package/src/utils/tip.ls +0 -97
  34. package/web/src/pug/base.pug +0 -21
  35. package/web/src/pug/block/axis/0.0.1/index.ls +0 -32
  36. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  37. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -137
  38. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  39. package/web/src/pug/block/bar/0.0.1/index.ls +0 -270
  40. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  41. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -81
  42. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  43. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -79
  44. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  45. package/web/src/pug/block/base/0.0.1/index.ls +0 -66
  46. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  47. package/web/src/pug/block/blank/0.0.1/index.ls +0 -21
  48. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  49. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -218
  50. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -42
  51. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -85
  52. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  53. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  54. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -86
  55. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  56. package/web/src/pug/block/empty/0.0.1/index.ls +0 -28
  57. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  58. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -96
  59. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  60. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  61. package/web/src/pug/block/line/0.0.1/index.ls +0 -297
  62. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  63. package/web/src/pug/block/number/0.0.1/index.ls +0 -65
  64. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  65. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -161
  66. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  67. package/web/src/pug/block/pie/0.0.1/index.ls +0 -121
  68. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  69. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  70. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -181
  71. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  72. package/web/src/pug/block/radar/0.0.1/index.ls +0 -109
  73. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  74. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  75. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -124
  76. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  77. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -34
  78. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  79. package/web/src/pug/block/table/0.0.1/index.ls +0 -36
  80. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  81. package/web/src/pug/block/taiwancounty/0.0.1/index.ls +0 -70
  82. package/web/src/pug/block/taiwancounty/0.0.1/index.pug +0 -64
  83. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -44
  84. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  85. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -49
  86. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  87. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -168
  88. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  89. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -170
  90. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  91. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  92. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -57
  93. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  94. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -77
  95. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  96. package/web/src/pug/index.ls +0 -72
  97. package/web/src/pug/index.pug +0 -51
  98. package/web/src/styl/index.styl +0 -6
  99. package/web/static/assets/block/cache.js +0 -4
  100. package/web/static/assets/custom-lib/d3/d3-array.v2.js +0 -1182
  101. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  102. package/web/static/assets/custom-lib/d3/d3-array.v3.js +0 -1273
  103. package/web/static/assets/custom-lib/d3/d3-array.v3.min.js +0 -1273
  104. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  105. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  106. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  107. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  108. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  109. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  110. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  111. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  112. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  113. package/web/static/assets/custom-lib/d3/d3-geo.v2.js +0 -3127
  114. package/web/static/assets/custom-lib/d3/d3-geo.v2.min.js +0 -2
  115. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  116. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  117. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  118. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  119. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  120. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  121. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  122. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  123. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  124. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  125. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  126. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  127. package/web/static/assets/custom-lib/d3/d3.v6.js +0 -19708
  128. package/web/static/assets/data/countrycode.json +0 -1
  129. package/web/static/assets/data/world-110m.json +0 -1
  130. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  131. package/web/static/assets/img/fluid.svg +0 -16
  132. package/web/static/block/axis/0.0.1/index.html +0 -74
  133. package/web/static/block/axis-bubble/0.0.1/index.html +0 -217
  134. package/web/static/block/bar/0.0.1/index.html +0 -576
  135. package/web/static/block/bar-list/0.0.1/index.html +0 -226
  136. package/web/static/block/bar-race/0.0.1/index.html +0 -179
  137. package/web/static/block/base/0.0.1/index.html +0 -197
  138. package/web/static/block/blank/0.0.1/index.html +0 -37
  139. package/web/static/block/bubble/0.0.1/index.html +0 -422
  140. package/web/static/block/bubble/0.0.1/test.html +0 -0
  141. package/web/static/block/curve-bar/0.0.1/index.html +0 -143
  142. package/web/static/block/dumbbell/0.0.1/index.html +0 -173
  143. package/web/static/block/empty/0.0.1/index.html +0 -76
  144. package/web/static/block/gauge/0.0.1/index.html +0 -145
  145. package/web/static/block/line/0.0.1/index.html +0 -566
  146. package/web/static/block/number/0.0.1/index.html +0 -147
  147. package/web/static/block/percent-list/0.0.1/index.html +0 -311
  148. package/web/static/block/pie/0.0.1/index.html +0 -276
  149. package/web/static/block/pie-bubble/0.0.1/index.html +0 -353
  150. package/web/static/block/radar/0.0.1/index.html +0 -144
  151. package/web/static/block/scatter/0.0.1/index.html +0 -246
  152. package/web/static/block/sheet/0.0.1/index.html +0 -98
  153. package/web/static/block/table/0.0.1/index.html +0 -67
  154. package/web/static/block/taiwancounty/0.0.1/index.html +0 -197
  155. package/web/static/block/taiwantown/0.0.1/index.html +0 -205
  156. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -215
  157. package/web/static/block/treemap/0.0.1/index.html +0 -355
  158. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -345
  159. package/web/static/block/wordcloud/0.0.1/index.html +0 -87
  160. package/web/static/block/worldmap/0.0.1/index.html +0 -202
  161. package/web/static/css/index.css +0 -6
  162. package/web/static/css/index.min.css +0 -1
  163. package/web/static/favicon.ico +0 -0
  164. package/web/static/index.html +0 -153
@@ -1,422 +0,0 @@
1
- <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="unit"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">/*.pdl-cell { width: 100%; height: 100% }*/
2
- .pdl-layout > div[data-type=layout] {
3
- display: grid;
4
- grid-template-columns: 1fr fit-content(10em);
5
- grid-template-rows: 1fr fit-content(1em);
6
- }
7
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
8
- grid-area: 1/1;
9
- }
10
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
11
- grid-column: 2;
12
- grid-row: 1/span 2;
13
- padding: 0 0.5em 0 0.5em;
14
- }
15
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=unit] {
16
- grid-column: 1;
17
- grid-row: 2;
18
- line-height: 1em;
19
- text-align: right;
20
- padding: 0.25em 0;
21
- }
22
- .pdl-layout.legend-bottom > div[data-type=layout] {
23
- grid-template-columns: 1fr fit-content(1em);
24
- grid-template-rows: 1fr fit-content(3em);
25
- }
26
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=view] {
27
- grid-column: 1/span 2;
28
- grid-row: 1;
29
- }
30
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=legend] {
31
- padding-top: 1em;
32
- grid-column: 1;
33
- grid-row: 2;
34
- }
35
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=unit] {
36
- padding-top: 1em;
37
- grid-column: 2;
38
- grid-row: 2;
39
- }
40
- </style><script type="@plotdb/block">var mod;
41
- module.exports = {
42
- pkg: {
43
- name: 'bubble',
44
- version: '0.0.1',
45
- extend: {
46
- name: "base",
47
- version: "0.0.1"
48
- },
49
- dependencies: [],
50
- i18n: {
51
- "zh-TW": {
52
- "K": '千',
53
- "M": '百萬'
54
- }
55
- }
56
- },
57
- init: function(arg$){
58
- var root, context, pubsub, t;
59
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
60
- return pubsub.fire('init', {
61
- mod: mod({
62
- context: context,
63
- t: t
64
- })
65
- }).then(function(it){
66
- return it[0];
67
- });
68
- }
69
- };
70
- mod = function(arg$){
71
- var context, t, d3, forceBoundary, ldcolor, chart;
72
- context = arg$.context, t = arg$.t;
73
- d3 = context.d3, forceBoundary = context.forceBoundary, ldcolor = context.ldcolor, chart = context.chart;
74
- return {
75
- sample: function(){
76
- return {
77
- 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100].map(function(val){
78
- return {
79
- val: val,
80
- cat: Math.floor(Math.random() * 5),
81
- name: val
82
- };
83
- }),
84
- binding: {
85
- group: {
86
- key: 'cat'
87
- },
88
- name: {
89
- key: 'name'
90
- },
91
- color: {
92
- key: 'cat'
93
- },
94
- area: {
95
- key: 'val'
96
- }
97
- }
98
- };
99
- },
100
- config: import$({}, chart.utils.config.preset['default']),
101
- dimension: {
102
- group: {
103
- type: 'C',
104
- name: "group",
105
- priority: 2
106
- },
107
- color: {
108
- type: 'NR',
109
- name: "color",
110
- priority: 4
111
- },
112
- area: {
113
- type: 'R',
114
- name: "area",
115
- priority: 1
116
- },
117
- name: {
118
- type: 'NC',
119
- name: "name",
120
- priority: 3
121
- }
122
- },
123
- init: function(){
124
- var tint, node, ref$, this$ = this;
125
- this.tint = tint = new chart.utils.tint();
126
- this.parsed = this.parsed || [];
127
- this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
128
- return [it, d3.select(this$.layout.getGroup(it))];
129
- }));
130
- node = this.root.querySelector('[ld=tip]');
131
- this.tip = new chart.utils.tip({
132
- root: this.root,
133
- accessor: function(arg$){
134
- var evt, data;
135
- evt = arg$.evt;
136
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
137
- return null;
138
- }
139
- return {
140
- name: data.name,
141
- value: data.area + "" + (this$.binding.area.unit || '')
142
- };
143
- },
144
- range: function(){
145
- return this$.layout.getNode('view').getBoundingClientRect();
146
- }
147
- });
148
- this.legend = new chart.utils.legend({
149
- layout: this.layout,
150
- name: 'legend',
151
- root: this.root,
152
- shape: function(d){
153
- return d3.select(this).attr('fill', tint.get(d.key));
154
- },
155
- direction: ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom' ? 'horizontal' : 'vertical',
156
- cfg: {
157
- selectable: true
158
- }
159
- });
160
- return this.legend.on('select', function(){
161
- this$.bind();
162
- this$.resize();
163
- return this$.render();
164
- });
165
- },
166
- destroy: function(){
167
- return this.tip.destroy();
168
- },
169
- parse: function(){
170
- this.valid = this.data.filter(function(it){
171
- return !isNaN(it.area);
172
- });
173
- this.groups = Array.from(new Set(this.valid.map(function(it){
174
- return it.group;
175
- }))).filter(function(it){
176
- return it;
177
- });
178
- this.sim = null;
179
- return this.legend.data(this.groups.map(function(it){
180
- return {
181
- key: it,
182
- text: it
183
- };
184
- }));
185
- },
186
- resize: function(){
187
- var ref$, list, ret, box, pack, this$ = this;
188
- this.root.querySelector('.pdl-layout').classList.toggle('legend-bottom', ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom');
189
- this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
190
- (ref$ = this.cfg).legend || (ref$.legend = {});
191
- this.random = d3.randomUniform.source(d3.randomLcg(+Date.now()))(0, 1);
192
- list = [{
193
- key: 'root',
194
- root: true
195
- }].concat(this.groups.map(function(it){
196
- return {
197
- key: "group-" + it
198
- };
199
- }), this.valid.filter(function(it){
200
- return !this$.cfg.legend.enabled || this$.legend.isSelected(it.group);
201
- }));
202
- if (this.legend.enabled()) {
203
- list = list.filter(function(it){
204
- return !it._raw || this$.legend.isSelected(it.group);
205
- });
206
- }
207
- this.legend.config(this.cfg.legend);
208
- this.legend.update();
209
- this.layout.update(false);
210
- ret = d3.hierarchy(d3.stratify().id(function(it){
211
- if (it._idx != null) {
212
- return it._idx;
213
- } else {
214
- return it.key;
215
- }
216
- }).parentId(function(it){
217
- var that;
218
- if (it.root) {
219
- return '';
220
- } else if (that = it.group) {
221
- return "group-" + that;
222
- } else {
223
- return 'root';
224
- }
225
- })(list)).sum(function(it){
226
- return it.data.area;
227
- }).sort(function(a, b){
228
- return b.value - a.value;
229
- });
230
- box = this.vbox = this.layout.getBox('view');
231
- pack = d3.pack().size([box.width, box.height])(ret);
232
- this.parsed = ret.leaves().map(function(d){
233
- var ddata, pos, od, p, x, y;
234
- d._raw = d.data.data._raw;
235
- ddata = d.data.data;
236
- pos = !(this$.cfg.grouping != null) && this$.cfg.grouping
237
- ? d
238
- : {
239
- x: Math.random() * box.width * 0.8 + box.width * 0.1,
240
- y: Math.random() * box.height * 0.8 + box.height * 0.1
241
- };
242
- od = this$.parsed ? (p = this$.parsed.filter(function(p){
243
- if (p.name != null || ddata.name != null) {
244
- return p.name === ddata.name;
245
- } else {
246
- return p._idx === ddata._idx;
247
- }
248
- })[0], p ? p : d) : d;
249
- x = d.x, y = d.y;
250
- d.radius = Math.pow(ddata.area, 0.5);
251
- d.x = x;
252
- d.y = y;
253
- d._idx = ddata._idx;
254
- d.name = ddata.name;
255
- d.color = ddata.color;
256
- d.group = ddata.group;
257
- d.area = ddata.area;
258
- if (od._x) {
259
- d._x = od._x;
260
- } else if (!d._x) {
261
- d._x = d.x;
262
- }
263
- if (od._y) {
264
- d._y = od._y;
265
- } else if (!d._y) {
266
- d._y = d.y;
267
- }
268
- return d;
269
- }).filter(function(it){
270
- return it.area != null;
271
- });
272
- this.sim = null;
273
- return this.start();
274
- },
275
- render: function(){
276
- var binding, tint, box, rate, x$, y$, this$ = this;
277
- binding = this.binding, tint = this.tint;
278
- box = this.vbox;
279
- this.rate = rate = 0.85 * Math.PI / (2 * Math.sqrt(3)) * Math.sqrt(box.width * box.height / this.parsed.map(function(it){
280
- return Math.PI * Math.pow(it.r, 2);
281
- }).reduce(function(a, b){
282
- return a + b;
283
- }, 0));
284
- this.parsed.map(function(d, i){
285
- var ref$;
286
- return d.rr = (ref$ = d.r * this$.rate) > 2 ? ref$ : 2;
287
- });
288
- tint.set(this.cfg.palette);
289
- x$ = this.g.view.selectAll('circle.bubble').data(this.parsed, function(it){
290
- return it.name || it._idx;
291
- });
292
- x$.exit().remove();
293
- x$.enter().append('circle').attr('class', 'bubble data').attr('r', function(d, i){
294
- return 0;
295
- }).attr('fill', function(d, i){
296
- return tint.get(d.color || d.group || d.name);
297
- }).attr('cx', function(d, i){
298
- return d._x;
299
- }).attr('cy', function(d, i){
300
- return d._y;
301
- });
302
- this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
303
- return d._x;
304
- }).attr('cy', function(d, i){
305
- return d._y;
306
- }).transition().duration(350).attr('fill', function(d, i){
307
- return tint.get(d.color || d.group || d.name);
308
- }).attr('r', function(d, i){
309
- return d.rr;
310
- });
311
- y$ = this.g.view.selectAll('g.label').data(this.parsed, function(it){
312
- return it.name || it._idx;
313
- });
314
- y$.exit().remove();
315
- y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
316
- return "translate(" + d.x + "," + d.y + ")";
317
- }).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer').each(function(d, i){
318
- var this$ = this;
319
- return [0, 1].map(function(){
320
- return d3.select(this$).append('text');
321
- }).map(function(it){
322
- return it.attr('dy', '-.28em').attr('text-anchor', 'middle').style('pointer-event', 'none');
323
- });
324
- });
325
- this.g.view.selectAll('g.label').attr('transform', function(d, i){
326
- return "translate(" + d._x + "," + d._y + ")";
327
- }).each(function(d, i){
328
- return d3.select(this).selectAll('text').attr('dy', function(e, i){
329
- if (i === 0) {
330
- return '-.28em';
331
- } else {
332
- return '.88em';
333
- }
334
- }).text(function(e, i){
335
- var area, ret;
336
- if (i === 0) {
337
- area = d3.format('.3s')(d.area);
338
- /*
339
- ret = if area > 1000000 => (area/1000000).toFixed(1) + t(\M)
340
- else if area > 1000 => (area/1000).toFixed(1) + t(\K)
341
- else (area).toFixed(0)
342
- */
343
- ret = area;
344
- if (ret) {
345
- ret = ret + "" + (binding.area.unit || '');
346
- }
347
- return ret;
348
- } else {
349
- return d.name || '';
350
- }
351
- }).attr('font-size', function(d, i){
352
- return i ? '0.9em' : '1.1em';
353
- }).transition().duration(350).attr('fill', function(){
354
- var hcl;
355
- hcl = ldcolor.hcl(tint.get(d.color) || d.group || d.name);
356
- if (hcl.l < 50) {
357
- return '#fff';
358
- } else {
359
- return '#000';
360
- }
361
- });
362
- });
363
- this.g.view.selectAll('g.label').transition().duration(350).attr('opacity', function(d, i){
364
- var box, ref$, w, h;
365
- box = this.getBoundingClientRect();
366
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
367
- if (2 * d.rr < w || 2 * d.rr < h) {
368
- return 0;
369
- } else {
370
- return 1;
371
- }
372
- });
373
- return this.legend.render();
374
- },
375
- tick: function(){
376
- var cfg, pad, box, kickoff, fc, this$ = this;
377
- cfg = this.cfg;
378
- pad = cfg.pad || 5;
379
- box = this.vbox;
380
- if (!this.sim) {
381
- kickoff = true;
382
- this.fc = fc = d3.forceCollide().strength(0.5).iterations(20).radius(function(it){
383
- return this$.rate * it.r;
384
- });
385
- this.fg = d3.forceCenter().strength(0.5);
386
- this.fb = forceBoundary(function(it){
387
- return it.rr + pad;
388
- }, function(it){
389
- return it.rr + pad;
390
- }, function(it){
391
- return box.width - it.rr - pad;
392
- }, function(it){
393
- return box.height - it.rr - pad;
394
- }).strength(0.5);
395
- this.sim = d3.forceSimulation().force('b', this.fb).force('collide', this.fc);
396
- this.sim.stop();
397
- this.sim.alpha(0.9);
398
- }
399
- this.fg.x(box.width / 2);
400
- this.fg.y(box.height / 2);
401
- this.sim.nodes(this.parsed);
402
- this.sim.tick(kickoff ? 10 : 1);
403
- this.parsed.map(function(it){
404
- it._x = it._x + (it.x - it._x) * 0.1;
405
- return it._y = it._y + (it.y - it._y) * 0.1;
406
- });
407
- this.g.view.selectAll('circle.bubble').attr('cx', function(d, i){
408
- return d._x;
409
- }).attr('cy', function(d, i){
410
- return d._y;
411
- });
412
- return this.g.view.selectAll('g.label').attr('transform', function(d, i){
413
- return "translate(" + d._x + "," + d._y + ")";
414
- });
415
- }
416
- };
417
- };
418
- function import$(obj, src){
419
- var own = {}.hasOwnProperty;
420
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
421
- return obj;
422
- }</script></div>
File without changes
@@ -1,143 +0,0 @@
1
- <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout > div[data-type=layout] {
2
- display: flex;
3
- justify-content: center;
4
- align-items: center;
5
- }
6
- .pdl-layout > div[data-type=layout] [data-name=view] {
7
- height: 100%;
8
- margin-right: 1em;
9
- }
10
- </style><script type="@plotdb/block">var mod;
11
- module.exports = {
12
- pkg: {
13
- name: 'curve-bar',
14
- version: '0.0.1',
15
- extend: {
16
- name: "base",
17
- version: "0.0.1"
18
- },
19
- dependencies: []
20
- },
21
- init: function(arg$){
22
- var root, context, pubsub;
23
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
24
- return pubsub.fire('init', {
25
- mod: mod({
26
- context: context
27
- })
28
- });
29
- }
30
- };
31
- mod = function(arg$){
32
- var context, d3, legend, chart;
33
- context = arg$.context;
34
- d3 = context.d3, legend = context.legend, chart = context.chart;
35
- return {
36
- sample: function(){
37
- return {
38
- raw: [1, 2, 3, 4, 5].map(function(val){
39
- return {
40
- val: Math.random(),
41
- name: val
42
- };
43
- }),
44
- binding: {
45
- name: {
46
- key: 'name'
47
- },
48
- value: {
49
- key: 'val'
50
- }
51
- }
52
- };
53
- },
54
- config: {},
55
- dimension: {
56
- value: {
57
- type: 'R',
58
- name: "value"
59
- },
60
- name: {
61
- type: 'N',
62
- name: "name"
63
- }
64
- },
65
- init: function(){
66
- var tint;
67
- this.gview = d3.select(this.layout.getGroup('view'));
68
- this.g = this.gview.append('g');
69
- this.tint = tint = new chart.utils.tint();
70
- this.arc = d3.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(Math.PI / 2);
71
- return this.legend = new chart.utils.legend({
72
- root: this.root,
73
- name: 'legend',
74
- shape: function(d){
75
- return d3.select(this).attr('fill', tint.get(d.text));
76
- },
77
- layout: this.layout
78
- });
79
- },
80
- parse: function(){
81
- this.tint.reset();
82
- this.extent = {
83
- v: d3.extent(this.data.map(function(it){
84
- return it.value;
85
- }))
86
- };
87
- this.data.sort(function(a, b){
88
- return a.value - b.value;
89
- });
90
- return this.legend.data(this.data.map(function(it){
91
- return {
92
- key: it.name,
93
- text: it.name
94
- };
95
- }));
96
- },
97
- resize: function(){
98
- var box, ref$, w, h, size;
99
- box = this.layout.getBox('view');
100
- this.layout.getNode('view').style.width = box.height + "px";
101
- this.layout.update(false);
102
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
103
- size = Math.min(w, h);
104
- return this.scale = {
105
- v: d3.scaleLinear().domain([0, this.extent.v[1]]).range([0, Math.PI * 3 / 2]),
106
- r: d3.scaleBand().domain(this.data.map(function(d, i){
107
- return i;
108
- })).range([24, size / 2])
109
- };
110
- },
111
- render: function(){
112
- var scale, bw, box, x$, y$, this$ = this;
113
- scale = this.scale;
114
- bw = this.scale.r.bandwidth();
115
- this.arc.cornerRadius(bw / 2);
116
- if (this.cfg != null && this.cfg.palette) {
117
- this.tint.set(this.cfg.palette.colors.map(function(it){
118
- return it.value || it;
119
- }));
120
- }
121
- this.legend.render();
122
- box = this.layout.getBox('view');
123
- this.g.attr('transform', "translate(" + box.width / 2 + "," + box.height / 2 + ")");
124
- x$ = this.g.selectAll('path.data').data(this.data);
125
- x$.exit().remove();
126
- x$.enter().append('path').attr('class', 'data');
127
- this.g.selectAll('path.data').attr('d', function(d, i){
128
- this$.arc.startAngle(0).endAngle(scale.v(d.value)).innerRadius(scale.r(i)).outerRadius(scale.r(i) + bw - 2);
129
- return this$.arc();
130
- }).attr('fill', function(d, i){
131
- return this$.tint.get(d.name) || d._idx;
132
- });
133
- y$ = this.g.selectAll('text.label').data(this.data);
134
- y$.exit().remove();
135
- y$.enter().append('text').attr('class', 'label');
136
- return this.g.selectAll('text.label').attr('dominant-baseline', 'center').attr('text-anchor', 'end').attr('x', '-.5em').attr('y', function(d, i){
137
- return -scale.r(i);
138
- }).attr('dy', -bw * 1 / 4).text(function(d, i){
139
- return d.name;
140
- });
141
- }
142
- };
143
- };</script></div>