@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,355 +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-layout > div[data-type=layout] {
2
- display: grid;
3
- grid-template-columns: 1fr fit-content(10em);
4
- grid-template-rows: 1fr fit-content(1em);
5
- }
6
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=view] {
7
- grid-area: 1/1;
8
- }
9
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=legend] {
10
- grid-column: 2;
11
- grid-row: 1/span 2;
12
- padding: 0 0.5em 0 0.5em;
13
- }
14
- .pdl-layout > div[data-type=layout] > .pdl-cell[data-name=unit] {
15
- grid-column: 1;
16
- grid-row: 2;
17
- line-height: 1em;
18
- text-align: right;
19
- padding: 0.25em 0;
20
- }
21
- .pdl-layout.legend-bottom > div[data-type=layout] {
22
- grid-template-columns: 1fr fit-content(1em);
23
- grid-template-rows: 1fr fit-content(3em);
24
- }
25
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=view] {
26
- grid-column: 1/span 2;
27
- grid-row: 1;
28
- }
29
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=legend] {
30
- padding-top: 1em;
31
- grid-column: 1;
32
- grid-row: 2;
33
- }
34
- .pdl-layout.legend-bottom > div[data-type=layout] .pdl-cell[data-name=unit] {
35
- padding-top: 1em;
36
- grid-column: 2;
37
- grid-row: 2;
38
- }
39
- </style><script type="@plotdb/block">var mod;
40
- module.exports = {
41
- pkg: {
42
- name: 'treemap',
43
- version: '0.0.1',
44
- extend: {
45
- name: "base",
46
- version: "0.0.1"
47
- },
48
- dependencies: [],
49
- i18n: {
50
- "zh-TW": {
51
- "other": "其它",
52
- "unit": "單位"
53
- }
54
- }
55
- },
56
- init: function(arg$){
57
- var root, context, pubsub, t;
58
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub, t = arg$.t;
59
- return pubsub.fire('init', {
60
- mod: mod({
61
- root: root,
62
- context: context,
63
- t: t
64
- })
65
- });
66
- }
67
- };
68
- mod = function(arg$){
69
- var root, context, t, chart, d3, ldcolor, wrapSvgText;
70
- root = arg$.root, context = arg$.context, t = arg$.t;
71
- chart = context.chart, d3 = context.d3, ldcolor = context.ldcolor, wrapSvgText = context.wrapSvgText;
72
- return {
73
- sample: function(){
74
- return {
75
- 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].map(function(val){
76
- return {
77
- val: Math.random().toFixed(2),
78
- cat: Math.floor(1 + 6 * Math.random())
79
- };
80
- }),
81
- binding: {
82
- color: {
83
- key: 'cat'
84
- },
85
- area: {
86
- key: 'val',
87
- unit: 'MB'
88
- },
89
- name: {
90
- key: 'cat'
91
- },
92
- category: {
93
- key: 'cat'
94
- }
95
- }
96
- };
97
- },
98
- config: {
99
- unitPosition: {
100
- type: 'choice',
101
- values: ['inner', 'outside', 'none']
102
- }
103
- },
104
- dimension: {
105
- color: {
106
- type: 'RC',
107
- name: "顏色",
108
- priority: 4
109
- },
110
- area: {
111
- type: 'R',
112
- name: "面積",
113
- priority: 1
114
- },
115
- name: {
116
- type: 'NC',
117
- name: "名稱",
118
- priority: 2
119
- },
120
- category: {
121
- type: 'C',
122
- name: "分類",
123
- priority: 3
124
- }
125
- },
126
- init: function(){
127
- var tint, textRenderer, ref$, this$ = this;
128
- this.tint = tint = new chart.utils.tint();
129
- this.g = Object.fromEntries(['view', 'unit', 'legend'].map(function(it){
130
- return [it, d3.select(this$.layout.getGroup(it))];
131
- }));
132
- this.textRenderer = textRenderer = document.createElement('div');
133
- import$(textRenderer.style, {
134
- textAlign: 'right',
135
- fontSize: '0.9em',
136
- padding: ".5em .5em",
137
- lineHeight: '1.1em',
138
- whiteSpace: "pre-line",
139
- display: 'inline-block',
140
- position: 'absolute',
141
- top: 0,
142
- left: 0,
143
- opacity: 0,
144
- pointerEvents: 'none',
145
- userSelect: 'none',
146
- zIndex: 0
147
- });
148
- root.appendChild(textRenderer);
149
- this.legend = new chart.utils.legend({
150
- layout: this.layout,
151
- name: 'legend',
152
- root: this.root,
153
- shape: function(d){
154
- return d3.select(this).attr('fill', tint.get(d.key));
155
- },
156
- direction: ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom' ? 'horizontal' : 'vertical',
157
- cfg: {
158
- selectable: true
159
- }
160
- });
161
- this.legend.on('select', function(){
162
- this$.bind();
163
- this$.resize();
164
- return this$.render();
165
- });
166
- return this.tip = new chart.utils.tip({
167
- root: this.root,
168
- accessor: function(arg$){
169
- var evt, data, v;
170
- evt = arg$.evt;
171
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
172
- return null;
173
- }
174
- v = isNaN(data.data.area)
175
- ? '-'
176
- : data.data.area.toFixed(2) + "" + (this$.binding.area.unit || '');
177
- return {
178
- name: data.data.name,
179
- value: v
180
- };
181
- },
182
- range: function(){
183
- return this$.layout.getNode('view').getBoundingClientRect();
184
- }
185
- });
186
- },
187
- destroy: function(){
188
- return this.tip.destroy();
189
- },
190
- parse: function(){
191
- var hash, k, v;
192
- this.tint.reset();
193
- hash = {};
194
- this.data.map(function(d, i){
195
- d.id = "name-" + i;
196
- if (!d.category || d.category === "") {
197
- return d.category = t("other");
198
- }
199
- });
200
- if (!this.binding.category) {
201
- this.data.map(function(d){
202
- return d.category = 'root-1';
203
- });
204
- }
205
- this.data.map(function(it){
206
- return hash[it.category] = {
207
- id: it.category,
208
- category: 'root'
209
- };
210
- });
211
- this.cats = Array.from(new Set(this.data.map(function(it){
212
- return it.category;
213
- }))).filter(function(it){
214
- return it !== 'root-1';
215
- });
216
- this.data = this.data.concat((function(){
217
- var ref$, results$ = [];
218
- for (k in ref$ = hash) {
219
- v = ref$[k];
220
- results$.push(v);
221
- }
222
- return results$;
223
- }()), [{
224
- id: 'root'
225
- }]);
226
- return this.legend.data(this.cats.map(function(it){
227
- return {
228
- key: it,
229
- text: it
230
- };
231
- }));
232
- },
233
- bind: function(){
234
- var data, s, this$ = this;
235
- data = this.data.filter(function(it){
236
- var ref$;
237
- return it.id === 'root' || ((ref$ = it.category) === 'root' || ref$ === 'root-1') || this$.legend.isSelected(it.category);
238
- });
239
- s = d3.stratify().id(function(it){
240
- return it.id;
241
- }).parentId(function(it){
242
- return it.category;
243
- });
244
- return this.ret = s(data);
245
- },
246
- resize: function(){
247
- var ref$, ref1$, x$, box, tree;
248
- this.root.querySelector('.pdl-layout').classList.toggle('legend-bottom', ((ref$ = this.cfg).legend || (ref$.legend = {})).position === 'bottom');
249
- this.tip.toggle(((ref$ = this.cfg).tip || (ref$.tip = {})).enabled != null ? this.cfg.tip.enabled : true);
250
- this.unit = {
251
- inner: ((ref$ = this.cfg).unit || (ref$.unit = {})).position === 'inner' ? this.binding.area.unit || '' : '',
252
- outer: (ref$ = ((ref1$ = this.cfg).unit || (ref1$.unit = {})).position) === 'inner' || ref$ === 'none'
253
- ? ''
254
- : this.binding.area.unit ? t('unit') + ": " + (this.binding.area.unit || '') : ''
255
- };
256
- x$ = this.layout.getNode('unit');
257
- x$.style.display = !this.unit.outer ? 'none' : '';
258
- x$.textContent = this.unit.outer;
259
- this.legend.config(this.cfg.legend);
260
- this.legend.update();
261
- this.layout.update(false);
262
- this.ret.sum(function(it){
263
- return it.area;
264
- });
265
- box = this.layout.getBox('view');
266
- tree = d3.treemap().padding(1).size([box.width, box.height])(this.ret);
267
- this.nodes = this.ret.leaves().filter(function(it){
268
- return it.data._raw;
269
- });
270
- this.nodes.map(function(it){
271
- return it._raw = it.data._raw;
272
- });
273
- return this.extent = d3.extent(this.nodes.map(function(it){
274
- return it.value;
275
- }));
276
- },
277
- render: function(){
278
- var cfg, unit, binding, layout, textRenderer, tint, x$, y$, this$ = this;
279
- cfg = this.cfg, unit = this.unit, binding = this.binding, layout = this.layout, textRenderer = this.textRenderer, tint = this.tint;
280
- tint.set(cfg.palette);
281
- this.g.unit.call(function(){
282
- var node, ret;
283
- node = layout.getNode('unit');
284
- ret = wrapSvgText({
285
- node: node,
286
- useRange: true
287
- });
288
- this$.g.unit.node().textContent = '';
289
- return this$.g.unit.node().appendChild(ret);
290
- });
291
- x$ = this.g.view.selectAll('rect.data').data(this.nodes, function(it){
292
- return it._raw._idx;
293
- });
294
- x$.exit().remove();
295
- x$.enter().append('rect').attr('class', 'data').attr('x', function(it){
296
- return (it.x1 + it.x0) / 2 - (it.x1 - it.x0) / 4;
297
- }).attr('y', function(it){
298
- return (it.y1 + it.y0) / 2 - (it.y1 - it.y0) / 4;
299
- }).attr('width', function(it){
300
- return (it.x1 - it.x0) / 2;
301
- }).attr('height', function(it){
302
- return (it.y1 - it.y0) / 2;
303
- }).attr('fill', function(it){
304
- return tint.get(it.data.color || it.data.category);
305
- }).style('opacity', 0);
306
- this.g.view.selectAll('rect').transition().duration(350).attr('x', function(it){
307
- return it.x0;
308
- }).attr('y', function(it){
309
- return it.y0;
310
- }).attr('width', function(it){
311
- return it.x1 - it.x0;
312
- }).attr('height', function(it){
313
- return it.y1 - it.y0;
314
- }).attr('fill', function(it){
315
- var v;
316
- v = (it.value - this$.extent[0]) / (this$.extent[1] - this$.extent[0]) - 0.5;
317
- return tint.get(it.data.color || it.data.category);
318
- }).style('opacity', 1);
319
- y$ = this.g.view.selectAll('g.label').data(this.nodes, function(it){
320
- return it._raw._idx;
321
- });
322
- y$.exit().remove();
323
- y$.enter().append('g').attr('class', 'label data').attr('transform', function(d, i){
324
- return "translate(" + d.x0 + "," + d.y0 + ")";
325
- }).attr('opacity', 0).style('pointer-events', 'none').style('cursor', 'pointer');
326
- this.g.view.selectAll('g.label').attr('font-size', '0.9em').each(function(d, i){
327
- var area, ret;
328
- textRenderer.style.width = (d.x1 - d.x0) + "px";
329
- area = d.data.area;
330
- area = d3.format('.3s')(area);
331
- textRenderer.innerHTML = "<div>" + (d.data.name || '') + "</div>\n<div>" + area + unit.inner + "</div>";
332
- ret = wrapSvgText({
333
- node: textRenderer,
334
- useRange: true
335
- });
336
- this.textContent = '';
337
- return this.appendChild(ret);
338
- }).transition().duration(350).attr('transform', function(d, i){
339
- return "translate(" + d.x0 + "," + d.y0 + ")";
340
- }).attr('fill', function(it){
341
- return tint.text(it.data.color || it.data.category);
342
- }).attr('opacity', function(d, i){
343
- var box;
344
- box = this.getBBox();
345
- return box.width > d.x1 - d.x0 || box.height > d.y1 - d.y0 ? 0 : 1;
346
- });
347
- return this.legend.render();
348
- }
349
- };
350
- };
351
- function import$(obj, src){
352
- var own = {}.hasOwnProperty;
353
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
354
- return obj;
355
- }</script></div>
@@ -1,345 +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">var mod;
13
- module.exports = {
14
- pkg: {
15
- name: 'voronoi-treemap',
16
- version: '0.0.1',
17
- extend: {
18
- name: "base",
19
- version: "0.0.1"
20
- },
21
- dependencies: [{
22
- name: "@zbryikt/voronoijs",
23
- version: "main",
24
- path: "voronoi.min.js"
25
- }]
26
- },
27
- init: function(arg$){
28
- var root, context, pubsub;
29
- root = arg$.root, context = arg$.context, pubsub = arg$.pubsub;
30
- return pubsub.fire('init', {
31
- mod: mod({
32
- context: context
33
- })
34
- }).then(function(it){
35
- return it[0];
36
- });
37
- }
38
- };
39
- mod = function(arg$){
40
- var context, d3, ldcolor, voronoi, chart;
41
- context = arg$.context;
42
- d3 = context.d3, ldcolor = context.ldcolor, voronoi = context.voronoi, chart = context.chart;
43
- return {
44
- sample: function(){
45
- return {
46
- 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){
47
- return {
48
- val: Math.random() * 10,
49
- cat: Math.floor(1 + 10 * Math.random()),
50
- name: val
51
- };
52
- }),
53
- binding: {
54
- name: {
55
- key: 'name'
56
- },
57
- area: {
58
- key: 'val'
59
- },
60
- category: {
61
- key: 'cat'
62
- }
63
- }
64
- };
65
- },
66
- config: {},
67
- dimension: {
68
- area: {
69
- type: 'R',
70
- name: "area"
71
- },
72
- name: {
73
- type: 'N',
74
- desc: "name"
75
- },
76
- category: {
77
- type: 'N',
78
- desc: "category"
79
- }
80
- },
81
- init: function(){
82
- var tint, g, this$ = this;
83
- this.tint = tint = new chart.utils.tint();
84
- this.g = Object.fromEntries(['view', 'legend'].map(function(it){
85
- return [it, d3.select(this$.layout.getGroup(it))];
86
- }));
87
- this.layout.getGroup('view').appendChild(g = document.createElementNS("http://www.w3.org/2000/svg", "g"));
88
- this.g.shape = d3.select(g);
89
- this.siteBoxes = [];
90
- this.legend = new chart.utils.legend({
91
- layout: this.layout,
92
- name: 'legend',
93
- root: this.root,
94
- shape: function(d){
95
- return d3.select(this).attr('fill', tint.get(d.key));
96
- },
97
- cfg: {
98
- selectable: true
99
- }
100
- });
101
- this.legend.on('select', function(){
102
- this$.bind();
103
- this$.resize();
104
- return this$.render();
105
- });
106
- this.tip = new chart.utils.tip({
107
- root: this.root,
108
- accessor: function(arg$){
109
- var evt, data;
110
- evt = arg$.evt;
111
- if (!(evt.target && (data = d3.select(evt.target).datum()))) {
112
- return null;
113
- }
114
- if (Array.isArray(data)) {
115
- if (!this$._sites) {
116
- return;
117
- }
118
- if (!(data.idx != null)) {
119
- return;
120
- }
121
- if (!(data = this$._sites[data.idx])) {
122
- return;
123
- }
124
- }
125
- return {
126
- name: data.name,
127
- value: data.area.toFixed(2) + "" + (this$.binding.area.unit || '')
128
- };
129
- },
130
- range: function(){
131
- return this$.layout.getNode('view').getBoundingClientRect();
132
- }
133
- });
134
- return this.start();
135
- },
136
- parse: function(){
137
- this.data.map(function(it){
138
- return it.key = it.name, it.value = it.area, it;
139
- });
140
- this.total = this.data.reduce(function(a, b){
141
- return a + b.area;
142
- }, 0);
143
- this.cats = Array.from(new Set(this.data.map(function(d){
144
- return d.category;
145
- })));
146
- return this.legend.data(this.cats.map(function(it){
147
- return {
148
- key: it,
149
- text: it
150
- };
151
- }));
152
- },
153
- bind: function(){
154
- var data, box, ref$, w, h, sites, x$, y$, this$ = this;
155
- data = this.data.filter(function(it){
156
- return this$.legend.isSelected(it.category);
157
- });
158
- this.parsed = {
159
- children: d3.nest().key(function(it){
160
- return it.category;
161
- }).entries(data).map(function(it){
162
- return it.children = it.values, it;
163
- })
164
- };
165
- box = this.box || this.svg.getBoundingClientRect();
166
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
167
- w = h = Math.min(w, h);
168
- this.treemap = new voronoi.Treemap(this.parsed, voronoi.Polygon.create(w, h, 60), w, h);
169
- sites = this.treemap.getSites();
170
- x$ = this.g.shape.selectAll('path.data').data(this.treemap.getPolygons());
171
- x$.exit().remove();
172
- x$.enter().append('path').attr('class', 'data').each(function(d, i){
173
- return d.idx = i;
174
- });
175
- this.g.shape.selectAll('path.data').attr('class', function(d, i){
176
- if (sites[i].lv <= 0) {
177
- return 'data group';
178
- } else {
179
- return 'data';
180
- }
181
- });
182
- this.polygons = this.g.shape.selectAll('path.data');
183
- y$ = this.g.shape.selectAll('g.label').data(sites);
184
- y$.exit().remove();
185
- y$.enter().append('g').attr('class', 'label').each(function(d, i){
186
- var x$;
187
- x$ = d3.select(this);
188
- x$.append('text').attr('class', 'name').attr('font-size', '.8em');
189
- x$.append('text').attr('class', 'value');
190
- return x$;
191
- });
192
- this.sites = this.g.shape.selectAll('g.label');
193
- return this.sites.each(function(d, i){
194
- return d3.select(this).selectAll('text').data([d, d]).attr('text-anchor', 'middle').attr('dominant-baseline', 'center');
195
- });
196
- },
197
- resize: function(){
198
- var box, ref$, w, h, s, sites;
199
- box = this.layout.getBox('view');
200
- ref$ = [box.width, box.height], w = ref$[0], h = ref$[1];
201
- s = Math.min(w, h);
202
- this.legend.config(this.cfg.legend);
203
- this.legend.update();
204
- this.layout.update(false);
205
- this.g.shape.attr('transform', "translate(" + (w / 2 - s / 2) + "," + (h / 2 - s / 2) + ")");
206
- this.scale = {
207
- x: d3.scaleLinear().domain([0, w]).range([0, w]),
208
- y: d3.scaleLinear().domain([0, h]).range([0, h]),
209
- color: d3.interpolateTurbo
210
- };
211
- if (this.cfg != null && this.cfg.palette) {
212
- this.scale.color = d3.interpolateDiscrete(this.cfg.palette.colors.map(function(it){
213
- return ldcolor.web(it.value || it);
214
- }));
215
- }
216
- this.tint.set(this.cfg.palette);
217
- sites = this.treemap.getSites();
218
- this.count = 0;
219
- return this.gbox = this.svg.getBoundingClientRect();
220
- },
221
- render: function(tick){
222
- var sites, polygons, ref$, w, h, siteBoxes, boxes, this$ = this;
223
- tick == null && (tick = false);
224
- this._sites = sites = this.treemap.getSites();
225
- polygons = this.treemap.getPolygons();
226
- ref$ = [this.box.width, this.box.height], w = ref$[0], h = ref$[1];
227
- if (!tick) {
228
- this.legend.render();
229
- this.sites.selectAll('.name').attr('dy', '0.88em').text(function(it){
230
- var n;
231
- n = (it.name || '') + "";
232
- return n;
233
- if (it.lv > 0) {
234
- return n.substring(0, 7) + (n.length > 7 ? '...' : '');
235
- } else {
236
- return '';
237
- }
238
- }).attr('fill', function(d, i){
239
- if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
240
- return '#000';
241
- } else {
242
- return '#eee';
243
- }
244
- }).style('pointer-events', 'none');
245
- this.sites.selectAll('.value').attr('dy', '-0.28em').text(function(it){
246
- if (it.lv > 0) {
247
- return (it.value || 0).toFixed(2);
248
- } else {
249
- return '';
250
- }
251
- }).attr('fill', function(d, i){
252
- if (ldcolor.hcl(this$.tint.get(d.category)).l > 60) {
253
- return '#000';
254
- } else {
255
- return '#eee';
256
- }
257
- }).style('pointer-events', 'none');
258
- this.siteBoxes = siteBoxes = [];
259
- this.sites.each(function(d, i){
260
- return siteBoxes.push(this.getBoundingClientRect());
261
- });
262
- this.polygons.attr('fill', function(d, i){
263
- return this$.tint.get(sites[i].category);
264
- }).attr('stroke', '#fff').attr('stroke-width', 1);
265
- }
266
- siteBoxes = this.siteBoxes;
267
- boxes = [];
268
- this.polygons.data(polygons).attr('d', function(d, i){
269
- var ret, ref$, min, max, i$, to$, idx, x, y;
270
- d.idx = i;
271
- if (!(d && d.length)) {
272
- boxes.push({});
273
- return "";
274
- }
275
- ret = [['M', d[0].x, d[0].y]];
276
- ref$ = [
277
- {
278
- x: d[0].x,
279
- y: d[0].y
280
- }, {
281
- x: d[0].x,
282
- y: d[0].y
283
- }
284
- ], min = ref$[0], max = ref$[1];
285
- for (i$ = 0, to$ = d.length; i$ < to$; ++i$) {
286
- idx = i$;
287
- ref$ = [d[idx].x, d[idx].y], x = ref$[0], y = ref$[1];
288
- if (min.x > x) {
289
- min.x = x;
290
- }
291
- if (max.x < x) {
292
- max.x = x;
293
- }
294
- if (min.y > y) {
295
- min.y = y;
296
- }
297
- if (max.y < y) {
298
- max.y = y;
299
- }
300
- ret.push(['L', x, y]);
301
- }
302
- ret.push(['L', d[0].x, d[0].y]);
303
- boxes.push({
304
- x: min.x,
305
- y: min.y,
306
- width: max.x - min.x,
307
- height: max.y - min.y
308
- });
309
- return ret.map(function(it){
310
- return it.join(' ');
311
- }).join(' ');
312
- });
313
- return this.sites.each(function(d, i){
314
- var box, mybox;
315
- box = boxes[i];
316
- mybox = siteBoxes[i];
317
- if (!mybox) {
318
- mybox = this.getBoundingClientRect();
319
- }
320
- return d3.select(this).attr('transform', function(){
321
- var x, y;
322
- x = box.x + box.width / 2;
323
- y = box.y + box.height / 2;
324
- if (isNaN(x)) {
325
- x = -10000;
326
- }
327
- if (isNaN(y)) {
328
- y = -10000;
329
- }
330
- return "translate(" + x + ", " + y + ")";
331
- }).attr('opacity', function(){
332
- var ref$, ref1$, ref2$;
333
- return (ref$ = 1 - 6 * ((ref1$ = mybox.width / ((ref2$ = box.width) > 0 ? ref2$ : 0) - 1) > 0 ? ref1$ : 0)) > 0 ? ref$ : 0;
334
- });
335
- });
336
- },
337
- tick: function(){
338
- this.count = (this.count || 0) + 1;
339
- if (this.count < 100) {
340
- this.treemap.compute();
341
- return this.render(true);
342
- }
343
- }
344
- };
345
- };</script></div>