@plotdb/chart 0.0.2 → 1.0.3

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/README.md +3 -3
  2. package/dist/chart.js +18 -12
  3. package/dist/chart.min.js +1 -1
  4. package/dist/index.css +8 -0
  5. package/dist/index.js +609 -0
  6. package/dist/index.min.css +1 -0
  7. package/dist/index.min.js +1 -0
  8. package/dist/utils/axis.js +6 -0
  9. package/dist/utils/axis.min.js +1 -1
  10. package/package.json +22 -11
  11. package/CHANGELOG.md +0 -11
  12. package/build +0 -39
  13. package/doc/charts.md +0 -58
  14. package/doc/config.md +0 -44
  15. package/doc/draft/chart.md +0 -146
  16. package/doc/draft/data.md +0 -8
  17. package/doc/draft/definition.md +0 -0
  18. package/doc/draft/events.md +0 -0
  19. package/doc/draft/filter.md +0 -0
  20. package/doc/draft/lifecycle.md +0 -89
  21. package/doc/spec.md +0 -89
  22. package/doc/todo.md +0 -27
  23. package/doc/utils/tip.md +0 -84
  24. package/src/chart.ls +0 -320
  25. package/src/chart.styl +0 -6
  26. package/src/data/en-US/category +0 -20
  27. package/src/data/en-US/fruit +0 -39
  28. package/src/data/en-US/movie +0 -125
  29. package/src/data/en-US/name +0 -58
  30. package/src/data/index.ls +0 -34
  31. package/src/data/zh-TW/category +0 -20
  32. package/src/data/zh-TW/fruits +0 -38
  33. package/src/data/zh-TW/movie +0 -125
  34. package/src/data/zh-TW/names +0 -105
  35. package/src/utils/axis.ls +0 -229
  36. package/src/utils/config.ls +0 -11
  37. package/src/utils/data.ls +0 -104
  38. package/src/utils/format.ls +0 -30
  39. package/src/utils/legend.ls +0 -134
  40. package/src/utils/legend.styl +0 -37
  41. package/src/utils/tint.ls +0 -66
  42. package/src/utils/tip.ls +0 -97
  43. package/web/src/pug/base.pug +0 -19
  44. package/web/src/pug/block/axis/0.0.1/index.ls +0 -38
  45. package/web/src/pug/block/axis/0.0.1/index.pug +0 -1
  46. package/web/src/pug/block/axis-bubble/0.0.1/index.ls +0 -141
  47. package/web/src/pug/block/axis-bubble/0.0.1/index.pug +0 -1
  48. package/web/src/pug/block/bar/0.0.1/index.ls +0 -274
  49. package/web/src/pug/block/bar/0.0.1/index.pug +0 -35
  50. package/web/src/pug/block/bar-list/0.0.1/index.ls +0 -85
  51. package/web/src/pug/block/bar-list/0.0.1/index.pug +0 -30
  52. package/web/src/pug/block/bar-race/0.0.1/index.ls +0 -83
  53. package/web/src/pug/block/bar-race/0.0.1/index.pug +0 -21
  54. package/web/src/pug/block/base/0.0.1/index.ls +0 -67
  55. package/web/src/pug/block/base/0.0.1/index.pug +0 -5
  56. package/web/src/pug/block/blank/0.0.1/index.ls +0 -25
  57. package/web/src/pug/block/blank/0.0.1/index.pug +0 -1
  58. package/web/src/pug/block/bubble/0.0.1/index.ls +0 -220
  59. package/web/src/pug/block/bubble/0.0.1/index.pug +0 -28
  60. package/web/src/pug/block/curve-bar/0.0.1/index.ls +0 -89
  61. package/web/src/pug/block/curve-bar/0.0.1/index.pug +0 -16
  62. package/web/src/pug/block/curve-bar/0.0.1/sample.js +0 -338
  63. package/web/src/pug/block/dumbbell/0.0.1/index.ls +0 -90
  64. package/web/src/pug/block/dumbbell/0.0.1/index.pug +0 -1
  65. package/web/src/pug/block/empty/0.0.1/index.ls +0 -27
  66. package/web/src/pug/block/empty/0.0.1/index.pug +0 -2
  67. package/web/src/pug/block/gauge/0.0.1/index.ls +0 -100
  68. package/web/src/pug/block/gauge/0.0.1/index.pug +0 -31
  69. package/web/src/pug/block/gauge/0.0.1/sample.js +0 -338
  70. package/web/src/pug/block/line/0.0.1/index.ls +0 -265
  71. package/web/src/pug/block/line/0.0.1/index.pug +0 -33
  72. package/web/src/pug/block/number/0.0.1/index.ls +0 -69
  73. package/web/src/pug/block/number/0.0.1/index.pug +0 -20
  74. package/web/src/pug/block/percent-list/0.0.1/index.ls +0 -167
  75. package/web/src/pug/block/percent-list/0.0.1/index.pug +0 -34
  76. package/web/src/pug/block/pie/0.0.1/index.ls +0 -125
  77. package/web/src/pug/block/pie/0.0.1/index.pug +0 -19
  78. package/web/src/pug/block/pie/0.0.1/sample.js +0 -338
  79. package/web/src/pug/block/pie-bubble/0.0.1/index.ls +0 -185
  80. package/web/src/pug/block/pie-bubble/0.0.1/index.pug +0 -40
  81. package/web/src/pug/block/radar/0.0.1/index.ls +0 -113
  82. package/web/src/pug/block/radar/0.0.1/index.pug +0 -1
  83. package/web/src/pug/block/radar/0.0.1/xx +0 -285
  84. package/web/src/pug/block/scatter/0.0.1/index.ls +0 -128
  85. package/web/src/pug/block/scatter/0.0.1/index.pug +0 -30
  86. package/web/src/pug/block/sheet/0.0.1/index.ls +0 -38
  87. package/web/src/pug/block/sheet/0.0.1/index.pug +0 -5
  88. package/web/src/pug/block/table/0.0.1/index.ls +0 -40
  89. package/web/src/pug/block/table/0.0.1/index.pug +0 -3
  90. package/web/src/pug/block/taiwantown/0.0.1/index.ls +0 -48
  91. package/web/src/pug/block/taiwantown/0.0.1/index.pug +0 -52
  92. package/web/src/pug/block/taiwanvillage/0.0.1/index.ls +0 -53
  93. package/web/src/pug/block/taiwanvillage/0.0.1/index.pug +0 -52
  94. package/web/src/pug/block/treemap/0.0.1/index.ls +0 -172
  95. package/web/src/pug/block/treemap/0.0.1/index.pug +0 -42
  96. package/web/src/pug/block/voronoi-treemap/0.0.1/index.ls +0 -174
  97. package/web/src/pug/block/voronoi-treemap/0.0.1/index.pug +0 -17
  98. package/web/src/pug/block/voronoi-treemap/0.0.1/sample.js +0 -241
  99. package/web/src/pug/block/wordcloud/0.0.1/index.ls +0 -61
  100. package/web/src/pug/block/wordcloud/0.0.1/index.pug +0 -1
  101. package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -83
  102. package/web/src/pug/block/worldmap/0.0.1/index.pug +0 -12
  103. package/web/src/pug/index.ls +0 -72
  104. package/web/src/pug/index.pug +0 -52
  105. package/web/src/styl/index.styl +0 -0
  106. package/web/static/assets/block/cache.js +0 -4
  107. package/web/static/assets/custom-lib/d3/d3-array.v2.min.js +0 -2
  108. package/web/static/assets/custom-lib/d3/d3-axis.v2.min.js +0 -2
  109. package/web/static/assets/custom-lib/d3/d3-brush.v2.min.js +0 -2
  110. package/web/static/assets/custom-lib/d3/d3-color.v2.min.js +0 -2
  111. package/web/static/assets/custom-lib/d3/d3-dispatch.v2.min.js +0 -2
  112. package/web/static/assets/custom-lib/d3/d3-drag.v2.min.js +0 -2
  113. package/web/static/assets/custom-lib/d3/d3-ease.v2.min.js +0 -2
  114. package/web/static/assets/custom-lib/d3/d3-force-boundary.v0.0.1.min.js +0 -2
  115. package/web/static/assets/custom-lib/d3/d3-force.v2.min.js +0 -2
  116. package/web/static/assets/custom-lib/d3/d3-format.v2.min.js +0 -2
  117. package/web/static/assets/custom-lib/d3/d3-hierarchy.v2.min.js +0 -2
  118. package/web/static/assets/custom-lib/d3/d3-interpolate.v2.min.js +0 -2
  119. package/web/static/assets/custom-lib/d3/d3-path.v2.min.js +0 -2
  120. package/web/static/assets/custom-lib/d3/d3-quadtree.v2.min.js +0 -2
  121. package/web/static/assets/custom-lib/d3/d3-random.v2.min.js +0 -2
  122. package/web/static/assets/custom-lib/d3/d3-scale-chromatic.v1.min.js +0 -2
  123. package/web/static/assets/custom-lib/d3/d3-selection.v2.min.js +0 -2
  124. package/web/static/assets/custom-lib/d3/d3-shape.v2.min.js +0 -2
  125. package/web/static/assets/custom-lib/d3/d3-timer.v2.min.js +0 -2
  126. package/web/static/assets/custom-lib/d3/d3-transition.v2.min.js +0 -2
  127. package/web/static/assets/custom-lib/d3/d3.v4.js +0 -17178
  128. package/web/static/assets/custom-lib/d3/d3.v4.min.js +0 -2
  129. package/web/static/assets/data/countrycode.json +0 -1
  130. package/web/static/assets/data/world-110m.json +0 -1
  131. package/web/static/assets/data/zh-to-alpha2.json +0 -1
  132. package/web/static/assets/img/fluid.svg +0 -16
  133. package/web/static/block/axis/0.0.1/index.html +0 -79
  134. package/web/static/block/axis-bubble/0.0.1/index.html +0 -222
  135. package/web/static/block/bar/0.0.1/index.html +0 -581
  136. package/web/static/block/bar-list/0.0.1/index.html +0 -231
  137. package/web/static/block/bar-race/0.0.1/index.html +0 -184
  138. package/web/static/block/base/0.0.1/index.html +0 -197
  139. package/web/static/block/blank/0.0.1/index.html +0 -42
  140. package/web/static/block/bubble/0.0.1/index.html +0 -402
  141. package/web/static/block/bubble/0.0.1/test.html +0 -0
  142. package/web/static/block/curve-bar/0.0.1/index.html +0 -148
  143. package/web/static/block/dumbbell/0.0.1/index.html +0 -178
  144. package/web/static/block/empty/0.0.1/index.html +0 -76
  145. package/web/static/block/gauge/0.0.1/index.html +0 -150
  146. package/web/static/block/line/0.0.1/index.html +0 -540
  147. package/web/static/block/number/0.0.1/index.html +0 -152
  148. package/web/static/block/percent-list/0.0.1/index.html +0 -316
  149. package/web/static/block/pie/0.0.1/index.html +0 -281
  150. package/web/static/block/pie-bubble/0.0.1/index.html +0 -358
  151. package/web/static/block/radar/0.0.1/index.html +0 -149
  152. package/web/static/block/scatter/0.0.1/index.html +0 -251
  153. package/web/static/block/sheet/0.0.1/index.html +0 -103
  154. package/web/static/block/table/0.0.1/index.html +0 -73
  155. package/web/static/block/taiwantown/0.0.1/index.html +0 -210
  156. package/web/static/block/taiwanvillage/0.0.1/index.html +0 -220
  157. package/web/static/block/treemap/0.0.1/index.html +0 -360
  158. package/web/static/block/voronoi-treemap/0.0.1/index.html +0 -350
  159. package/web/static/block/wordcloud/0.0.1/index.html +0 -92
  160. package/web/static/block/worldmap/0.0.1/index.html +0 -207
  161. package/web/static/css/index.css +0 -0
  162. package/web/static/css/index.min.css +0 -0
  163. package/web/static/favicon.ico +0 -0
  164. package/web/static/index.html +0 -153
@@ -1,350 +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: grid;
3
- grid-template-columns: 1fr fit-content(10em);
4
- }
5
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
6
- grid-column: 1;
7
- }
8
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
9
- grid-column: 2;
10
- padding: 0 0.5em 0 0.5em;
11
- }
12
- </style><script type="@plotdb/block">(function(it){
13
- return it();
14
- })(function(){
15
- var blockFactory, mod;
16
- blockFactory = {
17
- pkg: {
18
- name: 'voronoi-treemap',
19
- version: '0.0.1',
20
- extend: {
21
- name: "base",
22
- version: "0.0.1"
23
- },
24
- dependencies: [{
25
- name: "@zbryikt/voronoijs",
26
- version: "main",
27
- path: "voronoi.min.js"
28
- }]
29
- },
30
- init: function(arg$){
31
- var root, context, pubsub;
32
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
33
- return pubsub.fire('init', {
34
- mod: mod({
35
- context: context
36
- })
37
- }).then(function(it){
38
- return it[0];
39
- });
40
- }
41
- };
42
- mod = function(arg$){
43
- var context, d3, ldcolor, voronoi, chart;
44
- context = arg$.context;
45
- d3 = context.d3, ldcolor = context.ldcolor, voronoi = context.voronoi, chart = context.chart;
46
- return {
47
- sample: function(){
48
- return {
49
- 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){
50
- return {
51
- val: Math.random() * 10,
52
- cat: Math.floor(1 + 10 * Math.random()),
53
- name: val
54
- };
55
- }),
56
- binding: {
57
- name: {
58
- key: 'name'
59
- },
60
- area: {
61
- key: 'val'
62
- },
63
- category: {
64
- key: 'cat'
65
- }
66
- }
67
- };
68
- },
69
- config: {},
70
- dimension: {
71
- area: {
72
- type: 'R',
73
- name: "area"
74
- },
75
- name: {
76
- type: 'N',
77
- desc: "name"
78
- },
79
- category: {
80
- type: 'N',
81
- desc: "category"
82
- }
83
- },
84
- init: function(){
85
- var tint, g, this$ = this;
86
- this.tint = tint = new chart.utils.tint();
87
- this.g = Object.fromEntries(['view', 'legend'].map(function(it){
88
- return [it, d3.select(this$.layout.getGroup(it))];
89
- }));
90
- this.layout.getGroup('view').appendChild(g = document.createElementNS("http://www.w3.org/2000/svg", "g"));
91
- this.g.shape = d3.select(g);
92
- this.siteBoxes = [];
93
- this.legend = new chart.utils.legend({
94
- layout: this.layout,
95
- name: 'legend',
96
- root: this.root,
97
- shape: function(d){
98
- return d3.select(this).attr('fill', tint.get(d.key));
99
- },
100
- cfg: {
101
- selectable: true
102
- }
103
- });
104
- this.legend.on('select', function(){
105
- this$.bind();
106
- this$.resize();
107
- return this$.render();
108
- });
109
- this.tip = new chart.utils.tip({
110
- root: this.root,
111
- accessor: function(arg$){
112
- var evt, data;
113
- evt = arg$.evt;
114
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
115
- return null;
116
- }
117
- if (Array.isArray(data)) {
118
- if (!this$._sites) {
119
- return;
120
- }
121
- if (!(data.idx != null)) {
122
- return;
123
- }
124
- if (!(data = this$._sites[data.idx])) {
125
- return;
126
- }
127
- }
128
- return {
129
- name: data.name,
130
- value: data.area.toFixed(2) + "" + (this$.binding.area.unit || '')
131
- };
132
- },
133
- range: function(){
134
- return this$.layout.getNode('view').getBoundingClientRect();
135
- }
136
- });
137
- return this.start();
138
- },
139
- parse: function(){
140
- this.data.map(function(it){
141
- return it.key = it.name, it.value = it.area, it;
142
- });
143
- this.total = this.data.reduce(function(a, b){
144
- return a + b.area;
145
- }, 0);
146
- this.cats = Array.from(new Set(this.data.map(function(d){
147
- return d.category;
148
- })));
149
- return this.legend.data(this.cats.map(function(it){
150
- return {
151
- key: it,
152
- text: it
153
- };
154
- }));
155
- },
156
- bind: function(){
157
- var data, box, ref$, w, h, sites, x$, y$, this$ = this;
158
- data = this.data.filter(function(it){
159
- return this$.legend.isSelected(it.category);
160
- });
161
- this.parsed = {
162
- children: d3.nest().key(function(it){
163
- return it.category;
164
- }).entries(data).map(function(it){
165
- return it.children = it.values, it;
166
- })
167
- };
168
- box = this.box || this.svg.getBoundingClientRect();
169
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
170
- w = h = Math.min(w, h);
171
- this.treemap = new voronoi.Treemap(this.parsed, voronoi.Polygon.create(w, h, 60), w, h);
172
- sites = this.treemap.getSites();
173
- x$ = this.g.shape.selectAll('path.data').data(this.treemap.getPolygons());
174
- x$.exit().remove();
175
- x$.enter().append('path').attr('class', 'data').each(function(d, i){
176
- return d.idx = i;
177
- });
178
- this.g.shape.selectAll('path.data').attr('class', function(d, i){
179
- if (sites[i].lv <= 0) {
180
- return 'data group';
181
- } else {
182
- return 'data';
183
- }
184
- });
185
- this.polygons = this.g.shape.selectAll('path.data');
186
- y$ = this.g.shape.selectAll('g.label').data(sites);
187
- y$.exit().remove();
188
- y$.enter().append('g').attr('class', 'label').each(function(d, i){
189
- var x$;
190
- x$ = d3.select(this);
191
- x$.append('text').attr('class', 'name').attr('font-size', '.8em');
192
- x$.append('text').attr('class', 'value');
193
- return x$;
194
- });
195
- this.sites = this.g.shape.selectAll('g.label');
196
- return this.sites.each(function(d, i){
197
- return d3.select(this).selectAll('text').data([d, d]).attr('text-anchor', 'middle').attr('dominant-baseline', 'center');
198
- });
199
- },
200
- resize: function(){
201
- var box, ref$, w, h, s, sites;
202
- box = this.layout.getBox('view');
203
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
204
- s = Math.min(w, h);
205
- this.legend.config(this.cfg.legend);
206
- this.legend.update();
207
- this.layout.update(false);
208
- this.g.shape.attr('transform', "translate(" + (w / 2 - s / 2) + "," + (h / 2 - s / 2) + ")");
209
- this.scale = {
210
- x: d3.scaleLinear().domain([0, w]).range([0, w]),
211
- y: d3.scaleLinear().domain([0, h]).range([0, h]),
212
- color: d3.interpolateTurbo
213
- };
214
- if (this.cfg != null && this.cfg.palette) {
215
- this.scale.color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
216
- return ldcolor.web(it.value || it);
217
- }));
218
- }
219
- this.tint.set(this.cfg.palette);
220
- sites = this.treemap.getSites();
221
- this.count = 0;
222
- return this.gbox = this.svg.getBoundingClientRect();
223
- },
224
- render: function(tick){
225
- var sites, polygons, ref$, w, h, siteBoxes, boxes, this$ = this;
226
- tick == null && (tick = false);
227
- this._sites = sites = this.treemap.getSites();
228
- polygons = this.treemap.getPolygons();
229
- ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
230
- if (!tick) {
231
- this.legend.render();
232
- this.sites.selectAll('.name').attr('dy', '0.88em').text(function(it){
233
- var n;
234
- n = (it.name || '') + "";
235
- return n;
236
- if (it.lv > 0) {
237
- return n.substring(0, 7) + (n.length > 7 ? '...' : '');
238
- } else {
239
- return '';
240
- }
241
- }).attr('fill', function(d, i){
242
- if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
243
- return '#000';
244
- } else {
245
- return '#eee';
246
- }
247
- }).style('pointer-events', 'none');
248
- this.sites.selectAll('.value').attr('dy', '-0.28em').text(function(it){
249
- if (it.lv > 0) {
250
- return (it.value || 0).toFixed(2);
251
- } else {
252
- return '';
253
- }
254
- }).attr('fill', function(d, i){
255
- if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
256
- return '#000';
257
- } else {
258
- return '#eee';
259
- }
260
- }).style('pointer-events', 'none');
261
- this.siteBoxes = siteBoxes = [];
262
- this.sites.each(function(d, i){
263
- return siteBoxes.push(this.getBoundingClientRect());
264
- });
265
- this.polygons.attr('fill', function(d, i){
266
- return this$.tint.get(sites[i].category);
267
- }).attr('stroke', '#fff').attr('stroke-width', 1);
268
- }
269
- siteBoxes = this.siteBoxes;
270
- boxes = [];
271
- this.polygons.data(polygons).attr('d', function(d, i){
272
- var ret, ref$, min, max, i$, to$, idx, x, y;
273
- d.idx = i;
274
- if (!(d && d.length)) {
275
- boxes.push({});
276
- return "";
277
- }
278
- ret = [['M', d[0].x, d[0].y]];
279
- ref$ = [
280
- {
281
- x: d[0].x,
282
- y: d[0].y
283
- }, {
284
- x: d[0].x,
285
- y: d[0].y
286
- }
287
- ], min = ref$[0], max = ref$[1];
288
- for (i$ = 0, to$ = d.length; i$ < to$; ++i$) {
289
- idx = i$;
290
- ref$ = [d[idx].x, d[idx].y], x = ref$[0], y = ref$[1];
291
- if (min.x > x) {
292
- min.x = x;
293
- }
294
- if (max.x < x) {
295
- max.x = x;
296
- }
297
- if (min.y > y) {
298
- min.y = y;
299
- }
300
- if (max.y < y) {
301
- max.y = y;
302
- }
303
- ret.push(['L', x, y]);
304
- }
305
- ret.push(['L', d[0].x, d[0].y]);
306
- boxes.push({
307
- x: min.x,
308
- y: min.y,
309
- width: max.x - min.x,
310
- height: max.y - min.y
311
- });
312
- return ret.map(function(it){
313
- return it.join(' ');
314
- }).join(' ');
315
- });
316
- return this.sites.each(function(d, i){
317
- var box, mybox;
318
- box = boxes[i];
319
- mybox = siteBoxes[i];
320
- if (!mybox) {
321
- mybox = this.getBoundingClientRect();
322
- }
323
- return d3.select(this).attr('transform', function(){
324
- var x, y;
325
- x = box.x + box.width / 2;
326
- y = box.y + box.height / 2;
327
- if (isNaN(x)) {
328
- x = -10000;
329
- }
330
- if (isNaN(y)) {
331
- y = -10000;
332
- }
333
- return "translate(" + x + ", " + y + ")";
334
- }).attr('opacity', function(){
335
- var ref$, ref1$, ref2$;
336
- return (ref$ = 1 - 6 * ((ref1$ = mybox.width / ((ref2$ = box.width) > 0 ? ref2$ : 0) - 1) > 0 ? ref1$ : 0)) > 0 ? ref$ : 0;
337
- });
338
- });
339
- },
340
- tick: function(){
341
- this.count = (this.count || 0) + 1;
342
- if (this.count < 100) {
343
- this.treemap.compute();
344
- return this.render(true);
345
- }
346
- }
347
- };
348
- };
349
- return blockFactory;
350
- });</script></div>
@@ -1,92 +0,0 @@
1
- <div><script type="@plotdb/block">(function(it){
2
- return it();
3
- })(function(){
4
- var blockFactory, mod;
5
- blockFactory = {
6
- pkg: {
7
- name: 'wordcloud',
8
- version: '0.0.1',
9
- extend: {
10
- name: "base",
11
- version: "0.0.1"
12
- },
13
- dependencies: [{
14
- url: "https://unpkg.com/d3-cloud@1.2.5/build/d3.layout.cloud.js"
15
- }]
16
- },
17
- init: function(arg$){
18
- var root, context, pubsub;
19
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
20
- return pubsub.fire('init', {
21
- mod: mod({
22
- context: context
23
- })
24
- }).then(function(it){
25
- return it[0];
26
- });
27
- }
28
- };
29
- mod = function(arg$){
30
- var context, root, d3, forceBoundary, ldColor, repeatString$;
31
- context = arg$.context, root = arg$.root;
32
- d3 = context.d3, forceBoundary = context.forceBoundary, ldColor = context.ldColor, repeatString$ = context.repeatString$;
33
- return {
34
- sample: function(){
35
- return {
36
- raw: [],
37
- binding: {}
38
- };
39
- },
40
- config: {},
41
- dimension: {},
42
- init: function(){
43
- var this$ = this;
44
- this.dd = ['cover', 'scandal', 'seem', 'consumption', 'garbage', 'hunter', 'pepper', 'west', 'guilt', 'conspiracy', 'pupil', 'boat', 'muscle', 'nightmare', 'gene', 'royalty', 'salon', 'difficult', 'management', 'brainstorm', 'aid', 'moving', 'plaster', 'cake', 'issue', 'realism', 'subject', 'speed', 'railcar', 'break', 'grass', 'collapse', 'is', 'leave', 'retiree', 'looting', 'transaction', 'copyright', 'serve', 'guard', 'colony', 'spell', 'ask', 'ranch', 'cell', 'sensation', 'name', 'default', 'reflection'].map(function(d, i){
45
- return {
46
- text: d,
47
- value: 1.5 * i + 10
48
- };
49
- });
50
- this.cloud = d3.layout.cloud();
51
- return this.cloud.font('arial').padding(2).fontSize(function(it){
52
- return it.value;
53
- }).on('end', function(){
54
- return this$.render();
55
- });
56
- },
57
- parse: function(){},
58
- resize: function(){
59
- return this.cloud.size([this.box.width, this.box.height].map(function(it){
60
- return Math.round(it);
61
- })).words(this.dd).start();
62
- },
63
- render: function(){
64
- var color, vext, vscale, x$, this$ = this;
65
- color = d3.interpolateTurbo;
66
- if (this.cfg != null && this.cfg.palette) {
67
- color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
68
- return ldColor.web(it.value || it);
69
- }));
70
- }
71
- vext = d3.extent(this.dd.map(function(it){
72
- return it.value;
73
- }));
74
- vscale = d3.scaleLinear().domain(vext).range([0, 1]);
75
- x$ = d3.select(this.svg).selectAll('text').data(this.dd);
76
- x$.exit().remove();
77
- x$.enter().append('text');
78
- return d3.select(this.svg).selectAll('text').attr('transform', function(it){
79
- return "translate(" + (it.x + this$.box.width / 2) + " " + (it.y + this$.box.height / 2) + ") rotate(" + it.rotate + ")";
80
- }).attr('text-anchor', 'middle').attr('font-size', function(it){
81
- return it.size;
82
- }).attr('font-family', 'arial').attr('fill', function(it){
83
- return color(vscale(it.value));
84
- }).text(function(it){
85
- return it.text;
86
- });
87
- },
88
- tick: function(){}
89
- };
90
- };
91
- return blockFactory;
92
- });</script></div>
@@ -1,207 +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">123</div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout > div[data-type=layout] {
2
- display: grid;
3
- grid-template-columns: 1fr fit-content(5em);
4
- }
5
- </style><script type="@plotdb/block">(function(it){
6
- return it();
7
- })(function(){
8
- var blockFactory, mod;
9
- blockFactory = {
10
- pkg: {
11
- name: 'worldmap',
12
- version: '0.0.1',
13
- extend: {
14
- name: "base",
15
- version: "0.0.1"
16
- },
17
- dependencies: [
18
- {
19
- url: "https://d3js.org/d3-geo.v2.min.js",
20
- async: false
21
- }, {
22
- url: "https://d3js.org/topojson.v2.min.js",
23
- async: false
24
- }, {
25
- url: "/assets/lib/@plotdb/pdmap-world/main/index.js"
26
- }
27
- ]
28
- },
29
- init: function(arg$){
30
- var root, context, pubsub;
31
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
32
- return pubsub.fire('init', {
33
- mod: mod({
34
- context: context
35
- })
36
- });
37
- }
38
- };
39
- mod = function(arg$){
40
- var context, chart, d3, ldcolor, pdmapWorld, topojson;
41
- context = arg$.context;
42
- chart = context.chart, d3 = context.d3, ldcolor = context.ldcolor, pdmapWorld = context.pdmapWorld, topojson = context.topojson;
43
- return {
44
- sample: function(){
45
- return {
46
- raw: pdmapWorld.meta.alpha2.map(function(it){
47
- return {
48
- country: it,
49
- val: Math.random()
50
- };
51
- }),
52
- binding: {
53
- color: {
54
- key: 'val'
55
- },
56
- name: {
57
- key: 'country'
58
- }
59
- }
60
- };
61
- },
62
- config: {},
63
- dimension: {
64
- name: {
65
- type: 'N',
66
- name: "國家"
67
- },
68
- color: {
69
- type: 'R',
70
- name: "顏色"
71
- }
72
- },
73
- init: function(){
74
- var scale, this$ = this;
75
- this.g = this.layout.getGroup('view');
76
- this.obj = new pdmapWorld({
77
- root: this.g
78
- });
79
- this.scale = scale = {
80
- color: d3.interpolateTurbo
81
- };
82
- this.legend = new chart.utils.legend({
83
- root: this.root,
84
- name: 'legend',
85
- layout: this.layout,
86
- shape: function(d){
87
- return d3.select(this).attr('fill', scale.color(d.key));
88
- }
89
- });
90
- this.tip = new chart.utils.tip({
91
- root: this.root,
92
- accessor: function(arg$){
93
- var evt, data, ret, k, v, name;
94
- evt = arg$.evt;
95
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
96
- return null;
97
- }
98
- ret = (function(){
99
- var ref$, results$ = [];
100
- for (k in ref$ = pdmapWorld.meta.zhalpha2) {
101
- v = ref$[k];
102
- results$.push([k, v]);
103
- }
104
- return results$;
105
- }()).filter(function(it){
106
- return it[1].toLowerCase() === data.properties.alpha2;
107
- })[0];
108
- name = ret
109
- ? ret[0]
110
- : data.properties.shortname || data.data.name;
111
- v = isNaN(data.data.color)
112
- ? '-'
113
- : data.data.color.toFixed(2) + "" + (this$.binding.color.unit || '');
114
- return {
115
- name: name,
116
- value: v
117
- };
118
- },
119
- range: function(){
120
- return this$.layout.getNode('view').getBoundingClientRect();
121
- }
122
- });
123
- return this.obj.init().then(function(){
124
- return this$.obj.fit();
125
- });
126
- },
127
- destroy: function(){
128
- return this.tip.destroy();
129
- },
130
- parse: function(){
131
- var geoData, this$ = this;
132
- geoData = d3.select(this.g).selectAll('path').data();
133
- geoData.map(function(d){
134
- d.data = null;
135
- d.properties.value = 0;
136
- return d.properties.data = {};
137
- });
138
- this.data.map(function(it){
139
- return {
140
- c: this$.obj.findCountry(it.name),
141
- v: it
142
- };
143
- }).filter(function(it){
144
- return it.c;
145
- }).map(function(it){
146
- var ref$;
147
- return ref$ = it.c, ref$.value = it.v.color, ref$.data = it.v, ref$;
148
- });
149
- geoData.map(function(d){
150
- return d.data = d.properties.data || {};
151
- });
152
- return this.extent = {
153
- c: d3.extent(geoData, function(it){
154
- return it.properties.value;
155
- })
156
- };
157
- },
158
- resize: function(){
159
- var ref$, pal, len, this$ = this;
160
- this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
161
- this.obj.fit(this.layout.getBox('view'));
162
- pal = this.cfg.palette
163
- ? this.cfg.palette.colors
164
- : ['#f00', '#999', '#00f'];
165
- len = pal.length;
166
- this.ticks = d3.quantize(function(it){
167
- return (1 - it) * (this$.extent.c[1] - this$.extent.c[0]) + this$.extent.c[0];
168
- }, len).map(function(it){
169
- var that;
170
- return {
171
- key: it,
172
- text: d3.format(this$.cfg.legendFormat || '.2f')(it) + ((that = this$.binding.color.unit) ? that : '')
173
- };
174
- });
175
- this.ticks.sort(function(a, b){
176
- return a.key - b.key;
177
- });
178
- if (this.cfg.palette) {
179
- this.scale.color = d3.scaleLinear().domain(this.ticks.map(function(it){
180
- return it.key;
181
- })).range(pal.map(function(it){
182
- return ldcolor.web(it.value || it);
183
- }));
184
- }
185
- return this.legend.data(this.ticks);
186
- },
187
- render: function(){
188
- var this$ = this;
189
- this.legend.render();
190
- return d3.select(this.g).selectAll('path').transition().duration(350).attr('fill', function(d, i){
191
- return this$.scale.color(d.properties.value);
192
- }).attr('fill-opacity', function(d, i){
193
- if (this$.cfg.dimEmpty) {
194
- if (d.properties.value) {
195
- return 1;
196
- } else {
197
- return 0.2;
198
- }
199
- } else {
200
- return 1;
201
- }
202
- });
203
- }
204
- };
205
- };
206
- return blockFactory;
207
- });</script></div>
File without changes
File without changes
File without changes