@visactor/vgrammar-plot 0.6.0

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 (173) hide show
  1. package/README.md +3 -0
  2. package/README.zh-CN.md +0 -0
  3. package/cjs/area.d.ts +14 -0
  4. package/cjs/area.js +83 -0
  5. package/cjs/area.js.map +1 -0
  6. package/cjs/cell.d.ts +14 -0
  7. package/cjs/cell.js +51 -0
  8. package/cjs/cell.js.map +1 -0
  9. package/cjs/circle-packing.d.ts +17 -0
  10. package/cjs/circle-packing.js +76 -0
  11. package/cjs/circle-packing.js.map +1 -0
  12. package/cjs/enums.d.ts +24 -0
  13. package/cjs/enums.js +17 -0
  14. package/cjs/enums.js.map +1 -0
  15. package/cjs/image.d.ts +13 -0
  16. package/cjs/image.js +77 -0
  17. package/cjs/image.js.map +1 -0
  18. package/cjs/index.d.ts +1 -0
  19. package/cjs/index.js +15 -0
  20. package/cjs/index.js.map +1 -0
  21. package/cjs/interval.d.ts +19 -0
  22. package/cjs/interval.js +102 -0
  23. package/cjs/interval.js.map +1 -0
  24. package/cjs/line.d.ts +14 -0
  25. package/cjs/line.js +52 -0
  26. package/cjs/line.js.map +1 -0
  27. package/cjs/path.d.ts +11 -0
  28. package/cjs/path.js +25 -0
  29. package/cjs/path.js.map +1 -0
  30. package/cjs/plot-all.d.ts +2 -0
  31. package/cjs/plot-all.js +19 -0
  32. package/cjs/plot-all.js.map +1 -0
  33. package/cjs/plot.d.ts +46 -0
  34. package/cjs/plot.js +265 -0
  35. package/cjs/plot.js.map +1 -0
  36. package/cjs/polygon.d.ts +12 -0
  37. package/cjs/polygon.js +44 -0
  38. package/cjs/polygon.js.map +1 -0
  39. package/cjs/rect-x.d.ts +13 -0
  40. package/cjs/rect-x.js +67 -0
  41. package/cjs/rect-x.js.map +1 -0
  42. package/cjs/rect-y.d.ts +13 -0
  43. package/cjs/rect-y.js +67 -0
  44. package/cjs/rect-y.js.map +1 -0
  45. package/cjs/rect.d.ts +13 -0
  46. package/cjs/rect.js +82 -0
  47. package/cjs/rect.js.map +1 -0
  48. package/cjs/rule-x.d.ts +12 -0
  49. package/cjs/rule-x.js +37 -0
  50. package/cjs/rule-x.js.map +1 -0
  51. package/cjs/rule-y.d.ts +12 -0
  52. package/cjs/rule-y.js +36 -0
  53. package/cjs/rule-y.js.map +1 -0
  54. package/cjs/rule.d.ts +12 -0
  55. package/cjs/rule.js +45 -0
  56. package/cjs/rule.js.map +1 -0
  57. package/cjs/sankey.d.ts +46 -0
  58. package/cjs/sankey.js +139 -0
  59. package/cjs/sankey.js.map +1 -0
  60. package/cjs/semantic-mark.d.ts +88 -0
  61. package/cjs/semantic-mark.js +846 -0
  62. package/cjs/semantic-mark.js.map +1 -0
  63. package/cjs/sunburst.d.ts +45 -0
  64. package/cjs/sunburst.js +134 -0
  65. package/cjs/sunburst.js.map +1 -0
  66. package/cjs/symbol.d.ts +13 -0
  67. package/cjs/symbol.js +53 -0
  68. package/cjs/symbol.js.map +1 -0
  69. package/cjs/text.d.ts +12 -0
  70. package/cjs/text.js +32 -0
  71. package/cjs/text.js.map +1 -0
  72. package/cjs/tree.d.ts +20 -0
  73. package/cjs/tree.js +128 -0
  74. package/cjs/tree.js.map +1 -0
  75. package/cjs/treemap.d.ts +41 -0
  76. package/cjs/treemap.js +109 -0
  77. package/cjs/treemap.js.map +1 -0
  78. package/cjs/util.d.ts +3 -0
  79. package/cjs/util.js +11 -0
  80. package/cjs/util.js.map +1 -0
  81. package/cjs/wordcloud-shape.d.ts +13 -0
  82. package/cjs/wordcloud-shape.js +85 -0
  83. package/cjs/wordcloud-shape.js.map +1 -0
  84. package/cjs/wordcloud.d.ts +13 -0
  85. package/cjs/wordcloud.js +81 -0
  86. package/cjs/wordcloud.js.map +1 -0
  87. package/dist/index.js +3291 -0
  88. package/dist/index.min.js +1 -0
  89. package/es/area.d.ts +14 -0
  90. package/es/area.js +83 -0
  91. package/es/area.js.map +1 -0
  92. package/es/cell.d.ts +14 -0
  93. package/es/cell.js +49 -0
  94. package/es/cell.js.map +1 -0
  95. package/es/circle-packing.d.ts +17 -0
  96. package/es/circle-packing.js +75 -0
  97. package/es/circle-packing.js.map +1 -0
  98. package/es/enums.d.ts +24 -0
  99. package/es/enums.js +13 -0
  100. package/es/enums.js.map +1 -0
  101. package/es/image.d.ts +13 -0
  102. package/es/image.js +74 -0
  103. package/es/image.js.map +1 -0
  104. package/es/index.d.ts +1 -0
  105. package/es/index.js +2 -0
  106. package/es/index.js.map +1 -0
  107. package/es/interval.d.ts +19 -0
  108. package/es/interval.js +103 -0
  109. package/es/interval.js.map +1 -0
  110. package/es/line.d.ts +14 -0
  111. package/es/line.js +50 -0
  112. package/es/line.js.map +1 -0
  113. package/es/path.d.ts +11 -0
  114. package/es/path.js +23 -0
  115. package/es/path.js.map +1 -0
  116. package/es/plot-all.d.ts +2 -0
  117. package/es/plot-all.js +50 -0
  118. package/es/plot-all.js.map +1 -0
  119. package/es/plot.d.ts +46 -0
  120. package/es/plot.js +263 -0
  121. package/es/plot.js.map +1 -0
  122. package/es/polygon.d.ts +12 -0
  123. package/es/polygon.js +43 -0
  124. package/es/polygon.js.map +1 -0
  125. package/es/rect-x.d.ts +13 -0
  126. package/es/rect-x.js +69 -0
  127. package/es/rect-x.js.map +1 -0
  128. package/es/rect-y.d.ts +13 -0
  129. package/es/rect-y.js +69 -0
  130. package/es/rect-y.js.map +1 -0
  131. package/es/rect.d.ts +13 -0
  132. package/es/rect.js +84 -0
  133. package/es/rect.js.map +1 -0
  134. package/es/rule-x.d.ts +12 -0
  135. package/es/rule-x.js +35 -0
  136. package/es/rule-x.js.map +1 -0
  137. package/es/rule-y.d.ts +12 -0
  138. package/es/rule-y.js +34 -0
  139. package/es/rule-y.js.map +1 -0
  140. package/es/rule.d.ts +12 -0
  141. package/es/rule.js +45 -0
  142. package/es/rule.js.map +1 -0
  143. package/es/sankey.d.ts +46 -0
  144. package/es/sankey.js +137 -0
  145. package/es/sankey.js.map +1 -0
  146. package/es/semantic-mark.d.ts +88 -0
  147. package/es/semantic-mark.js +833 -0
  148. package/es/semantic-mark.js.map +1 -0
  149. package/es/sunburst.d.ts +45 -0
  150. package/es/sunburst.js +133 -0
  151. package/es/sunburst.js.map +1 -0
  152. package/es/symbol.d.ts +13 -0
  153. package/es/symbol.js +51 -0
  154. package/es/symbol.js.map +1 -0
  155. package/es/text.d.ts +12 -0
  156. package/es/text.js +30 -0
  157. package/es/text.js.map +1 -0
  158. package/es/tree.d.ts +20 -0
  159. package/es/tree.js +127 -0
  160. package/es/tree.js.map +1 -0
  161. package/es/treemap.d.ts +41 -0
  162. package/es/treemap.js +108 -0
  163. package/es/treemap.js.map +1 -0
  164. package/es/util.d.ts +3 -0
  165. package/es/util.js +3 -0
  166. package/es/util.js.map +1 -0
  167. package/es/wordcloud-shape.d.ts +13 -0
  168. package/es/wordcloud-shape.js +84 -0
  169. package/es/wordcloud-shape.js.map +1 -0
  170. package/es/wordcloud.d.ts +13 -0
  171. package/es/wordcloud.js +80 -0
  172. package/es/wordcloud.js.map +1 -0
  173. package/package.json +73 -0
package/dist/index.js ADDED
@@ -0,0 +1,3291 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vgrammar-util'), require('@visactor/vutils'), require('@visactor/vgrammar')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@visactor/vgrammar-util', '@visactor/vutils', '@visactor/vgrammar'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VGrammar = global.VGrammar || {}, global.VGrammar.Projection = {}), global.VGrammar.Util, global.VUtils, global.VGrammar));
5
+ })(this, (function (exports, vgrammarUtil, vutils, vgrammar) { 'use strict';
6
+
7
+ var ScaleEnum;
8
+ !function (ScaleEnum) {
9
+ ScaleEnum.Linear = "linear", ScaleEnum.Log = "log", ScaleEnum.Pow = "pow", ScaleEnum.Sqrt = "sqrt", ScaleEnum.Symlog = "symlog", ScaleEnum.Time = "time", ScaleEnum.Quantile = "quantile", ScaleEnum.Quantize = "quantize", ScaleEnum.Threshold = "threshold", ScaleEnum.Ordinal = "ordinal", ScaleEnum.Point = "point", ScaleEnum.Band = "band";
10
+ }(ScaleEnum || (ScaleEnum = {}));
11
+ function isContinuous(type) {
12
+ switch (type) {
13
+ case ScaleEnum.Linear:
14
+ case ScaleEnum.Log:
15
+ case ScaleEnum.Pow:
16
+ case ScaleEnum.Sqrt:
17
+ case ScaleEnum.Symlog:
18
+ case ScaleEnum.Time:
19
+ return !0;
20
+ default:
21
+ return !1;
22
+ }
23
+ }
24
+ function isDiscrete(type) {
25
+ switch (type) {
26
+ case ScaleEnum.Ordinal:
27
+ case ScaleEnum.Point:
28
+ case ScaleEnum.Band:
29
+ return !0;
30
+ default:
31
+ return !1;
32
+ }
33
+ }
34
+
35
+ const defaultTheme = vgrammar.getTheme('default');
36
+ let semanticMarkId = -1;
37
+ class SemanticMark {
38
+ constructor(type, id) {
39
+ this.type = type;
40
+ this.uid = ++semanticMarkId;
41
+ this._logger = vutils.Logger.getInstance();
42
+ this.spec = { id: id !== null && id !== void 0 ? id : `${this.type}-${this.uid}` };
43
+ }
44
+ parseSpec(spec) {
45
+ if (vutils.isNil(spec.id)) {
46
+ spec.id = this.spec.id;
47
+ }
48
+ this.spec = spec;
49
+ return this;
50
+ }
51
+ coordinate(option) {
52
+ this._coordinate = option;
53
+ return this;
54
+ }
55
+ data(values, transform, id) {
56
+ if (vutils.isNil(values)) {
57
+ return this;
58
+ }
59
+ this.spec.data = { values, transform, id };
60
+ return this;
61
+ }
62
+ encode(channel, option) {
63
+ if (!this.spec.encode) {
64
+ this.spec.encode = {};
65
+ }
66
+ this.spec.encode[channel] = option;
67
+ return this;
68
+ }
69
+ scale(channel, option) {
70
+ if (!this.spec.scale) {
71
+ this.spec.scale = {};
72
+ }
73
+ this.spec.scale[channel] = option;
74
+ return this;
75
+ }
76
+ style(style) {
77
+ this.spec.style = style;
78
+ return this;
79
+ }
80
+ transform(option) {
81
+ this.spec.transform = vutils.array(option);
82
+ return this;
83
+ }
84
+ state(state, option) {
85
+ if ([
86
+ vgrammar.BuiltInEncodeNames.enter,
87
+ vgrammar.BuiltInEncodeNames.update,
88
+ vgrammar.BuiltInEncodeNames.exit,
89
+ vgrammar.BuiltInEncodeNames.group
90
+ ].includes(state)) {
91
+ this._logger.warn(`[VGrammar]: ${state} is a reserved keyword to specify the encode of different data state,
92
+ don't use this keyword`);
93
+ return;
94
+ }
95
+ if (!this.spec.state) {
96
+ this.spec.state = {};
97
+ }
98
+ this.spec.state[state] = option;
99
+ return this;
100
+ }
101
+ animate(state, option) {
102
+ if (state === 'state') {
103
+ this._logger.warn(`[VGrammar]: ${state} is a keyword use to specify state animation config, don't use this keyword`);
104
+ return this;
105
+ }
106
+ if (!this.spec.animation) {
107
+ this.spec.animation = {};
108
+ }
109
+ this.spec.animation[state] = option;
110
+ return this;
111
+ }
112
+ axis(channel, option = true, layout) {
113
+ if (!this.spec.axis) {
114
+ this.spec.axis = {};
115
+ }
116
+ this.spec.axis[channel] = { option, layout };
117
+ return this;
118
+ }
119
+ legend(channel, option = true, layout) {
120
+ if (!this.spec.legend) {
121
+ this.spec.legend = {};
122
+ }
123
+ this.spec.legend[channel] = { option, layout };
124
+ return this;
125
+ }
126
+ crosshair(channel, option) {
127
+ if (!this.spec.crosshair) {
128
+ this.spec.crosshair = {};
129
+ }
130
+ this.spec.crosshair[channel] = option;
131
+ return this;
132
+ }
133
+ tooltip(option) {
134
+ this.spec.tooltip = option;
135
+ return this;
136
+ }
137
+ slider(channel, option, layout) {
138
+ if (!this.spec.slider) {
139
+ this.spec.slider = {};
140
+ }
141
+ this.spec.slider[channel] = { option, layout };
142
+ return this;
143
+ }
144
+ datazoom(channel, option, layout) {
145
+ if (!this.spec.datazoom) {
146
+ this.spec.datazoom = {};
147
+ }
148
+ this.spec.datazoom[channel] = { option, layout };
149
+ return this;
150
+ }
151
+ label(channel, option) {
152
+ if (!this.spec.label) {
153
+ this.spec.label = {};
154
+ }
155
+ this.spec.label[channel] = option;
156
+ return this;
157
+ }
158
+ player(data, option, layout) {
159
+ this.spec.player = { data, option, layout };
160
+ return this;
161
+ }
162
+ setDefaultDataTransform() {
163
+ return [];
164
+ }
165
+ setMultipleData() {
166
+ return null;
167
+ }
168
+ setDefaultMarkTransform() {
169
+ return [];
170
+ }
171
+ convertMarkTransform(userTransform, defaultTransform = []) {
172
+ if (defaultTransform && defaultTransform.length) {
173
+ if (userTransform && userTransform.length) {
174
+ let transforms = [];
175
+ const excludeIndex = [];
176
+ for (let i = 0, len = userTransform.length; i < len; i++) {
177
+ const customizedSpec = userTransform[i];
178
+ const index = defaultTransform.findIndex(entry => entry.type === customizedSpec.type);
179
+ if (index >= 0) {
180
+ transforms.push(Object.assign({}, defaultTransform[index], customizedSpec));
181
+ excludeIndex.push(index);
182
+ }
183
+ else {
184
+ transforms.push(customizedSpec);
185
+ }
186
+ }
187
+ for (let j = 0, dlen = defaultTransform.length; j < dlen; j++) {
188
+ if (!excludeIndex.includes(j)) {
189
+ transforms = [defaultTransform[j]].concat(transforms);
190
+ }
191
+ }
192
+ return transforms;
193
+ }
194
+ return defaultTransform;
195
+ }
196
+ return userTransform;
197
+ }
198
+ convertMarkAnimation() {
199
+ if (!this.spec.animation) {
200
+ return null;
201
+ }
202
+ return this.spec.animation;
203
+ }
204
+ convertSimpleMarkEncode(encode) {
205
+ if (!encode) {
206
+ return {};
207
+ }
208
+ const markEncoder = {};
209
+ Object.keys(encode).map(channel => {
210
+ markEncoder[channel] = { field: encode[channel], scale: this.getScaleId(channel) };
211
+ });
212
+ return markEncoder;
213
+ }
214
+ getDataIdOfFiltered() {
215
+ var _a, _b;
216
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-data-filtered`;
217
+ }
218
+ getDataIdOfMain() {
219
+ var _a, _b;
220
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-data`;
221
+ }
222
+ getDataIdOfPlayer() {
223
+ var _a, _b;
224
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-player`;
225
+ }
226
+ getDataZoomScaleId(channel) {
227
+ return {
228
+ x: `datazoom-scale-${channel}-x`,
229
+ y: `datazoom-scale-${channel}-y`
230
+ };
231
+ }
232
+ getScaleId(channel) {
233
+ var _a, _b, _c;
234
+ return (_c = (_b = (_a = this.spec.scale) === null || _a === void 0 ? void 0 : _a[channel]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : `scale-${channel}`;
235
+ }
236
+ getMarkId() {
237
+ return `${this.spec.id}-mark`;
238
+ }
239
+ getScaleSpec(scaleId) {
240
+ var _a, _b, _c;
241
+ return (_c = (_b = (_a = this.viewSpec) === null || _a === void 0 ? void 0 : _a.scales) === null || _b === void 0 ? void 0 : _b.find) === null || _c === void 0 ? void 0 : _c.call(_b, scale => scale.id === scaleId);
242
+ }
243
+ parseScaleOfEncodeX(option) {
244
+ return {
245
+ type: 'band',
246
+ id: this.getScaleId('x'),
247
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
248
+ domain: {
249
+ data: this.getDataIdOfFiltered(),
250
+ field: option
251
+ },
252
+ range: this._coordinate
253
+ ? { coordinate: this._coordinate.id, dimension: 'x' }
254
+ : (scale, params) => {
255
+ return [0, params.viewBox.width()];
256
+ }
257
+ };
258
+ }
259
+ parseScaleOfEncodeY(option) {
260
+ return {
261
+ type: 'linear',
262
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
263
+ id: this.getScaleId('y'),
264
+ domain: {
265
+ data: this.getDataIdOfFiltered(),
266
+ field: option
267
+ },
268
+ range: this._coordinate
269
+ ? { coordinate: this._coordinate.id, dimension: 'y' }
270
+ : (scale, params) => {
271
+ return [params.viewBox.height(), 0];
272
+ }
273
+ };
274
+ }
275
+ parseScaleOfEncodeColor(option) {
276
+ return {
277
+ type: 'ordinal',
278
+ id: this.getScaleId('color'),
279
+ domain: {
280
+ data: this.getDataIdOfMain(),
281
+ field: option
282
+ },
283
+ range: vgrammar.getPalette()
284
+ };
285
+ }
286
+ parseScaleOfEncodeGroup(option) {
287
+ return {
288
+ type: 'ordinal',
289
+ id: this.getScaleId('group'),
290
+ domain: {
291
+ data: this.getDataIdOfMain(),
292
+ field: option
293
+ },
294
+ range: vgrammar.getPalette()
295
+ };
296
+ }
297
+ parseScaleOfCommonEncode(channel, option) {
298
+ if (channel === 'x') {
299
+ return this.parseScaleOfEncodeX(option);
300
+ }
301
+ if (channel === 'y') {
302
+ return this.parseScaleOfEncodeY(option);
303
+ }
304
+ if (channel === 'color') {
305
+ return this.parseScaleOfEncodeColor(option);
306
+ }
307
+ if (channel === 'group') {
308
+ return this.parseScaleOfEncodeGroup(option);
309
+ }
310
+ return null;
311
+ }
312
+ setDefaultAxis() {
313
+ return {};
314
+ }
315
+ parseAxisSpec() {
316
+ const axis = this.spec.axis;
317
+ const res = [];
318
+ if (axis) {
319
+ Object.keys(axis).forEach(channel => {
320
+ const { option, layout } = this.parseOption(axis[channel]);
321
+ if (option) {
322
+ const axisMarkSpec = {
323
+ type: 'component',
324
+ componentType: vgrammar.ComponentEnum.axis,
325
+ scale: this.getScaleId(channel),
326
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
327
+ tickCount: option.tickCount,
328
+ encode: {
329
+ update: (datum, elment, params) => {
330
+ const positionAttrs = this._coordinate
331
+ ? {}
332
+ : channel === 'x'
333
+ ? {
334
+ x: 0,
335
+ y: params.viewBox.height(),
336
+ start: { x: 0, y: 0 },
337
+ end: { x: params.viewBox.width(), y: 0 }
338
+ }
339
+ : {
340
+ x: 0,
341
+ y: params.viewBox.height(),
342
+ start: { x: 0, y: 0 },
343
+ verticalFactor: -1,
344
+ end: { x: 0, y: -params.viewBox.height() }
345
+ };
346
+ return vutils.isPlainObject(option) ? Object.assign(positionAttrs, option) : positionAttrs;
347
+ }
348
+ }
349
+ };
350
+ axisMarkSpec.layout = layout !== null && layout !== void 0 ? layout : {
351
+ position: this._coordinate
352
+ ? 'auto'
353
+ : vutils.isPlainObject(layout) && !vutils.isNil(layout.orient)
354
+ ? layout.orient
355
+ : channel === 'x'
356
+ ? 'bottom'
357
+ : 'left'
358
+ };
359
+ res.push(axisMarkSpec);
360
+ }
361
+ });
362
+ }
363
+ return res;
364
+ }
365
+ parseOption(spec) {
366
+ let option;
367
+ let layout;
368
+ if (vutils.isPlainObject(spec)) {
369
+ if (vutils.isNil(spec.option)) {
370
+ option = spec;
371
+ }
372
+ else {
373
+ option = spec.option;
374
+ layout = spec.layout;
375
+ }
376
+ }
377
+ else {
378
+ option = spec;
379
+ }
380
+ return { option, layout };
381
+ }
382
+ setDefaultLegend() {
383
+ return {};
384
+ }
385
+ parseLegendSpec() {
386
+ const legend = this.spec.legend;
387
+ const res = [];
388
+ if (legend) {
389
+ Object.keys(legend).forEach(channel => {
390
+ var _a;
391
+ const { option, layout } = this.parseOption(legend[channel]);
392
+ if (option) {
393
+ const markLayout = layout !== null && layout !== void 0 ? layout : (vutils.isPlainObject(option) && !vutils.isNil(option.layout)
394
+ ? option.layout === 'horizontal'
395
+ ? { position: 'top', align: 'center' }
396
+ : option.layout === 'vertical'
397
+ ? { position: 'right', align: 'middle' }
398
+ : { position: 'top', align: 'center' }
399
+ : { position: 'top', align: 'center' });
400
+ const markSpec = {
401
+ type: 'component',
402
+ componentType: vgrammar.ComponentEnum.legend,
403
+ scale: this.getScaleId(channel),
404
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
405
+ target: {
406
+ data: this.getDataIdOfFiltered(),
407
+ filter: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a[channel]
408
+ },
409
+ encode: {
410
+ update: (datum, element, params) => {
411
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
412
+ const calculatedAttrs = markLayout.position === 'left'
413
+ ? {
414
+ layout: 'vertical',
415
+ x: (_c = (_b = (_a = element.mark) === null || _a === void 0 ? void 0 : _a.relativePosition) === null || _b === void 0 ? void 0 : _b.left) !== null && _c !== void 0 ? _c : 0,
416
+ y: (_f = (_e = (_d = element.mark) === null || _d === void 0 ? void 0 : _d.relativePosition) === null || _e === void 0 ? void 0 : _e.top) !== null && _f !== void 0 ? _f : 0
417
+ }
418
+ : markLayout.position === 'right'
419
+ ? {
420
+ layout: 'vertical',
421
+ x: (_j = (_h = (_g = element.mark) === null || _g === void 0 ? void 0 : _g.relativePosition) === null || _h === void 0 ? void 0 : _h.left) !== null && _j !== void 0 ? _j : params.viewBox.width(),
422
+ y: (_m = (_l = (_k = element.mark) === null || _k === void 0 ? void 0 : _k.relativePosition) === null || _l === void 0 ? void 0 : _l.top) !== null && _m !== void 0 ? _m : 0
423
+ }
424
+ : markLayout.position === 'bottom'
425
+ ? {
426
+ layout: 'horizontal',
427
+ x: (_q = (_p = (_o = element.mark) === null || _o === void 0 ? void 0 : _o.relativePosition) === null || _p === void 0 ? void 0 : _p.left) !== null && _q !== void 0 ? _q : 0,
428
+ y: (_t = (_s = (_r = element.mark) === null || _r === void 0 ? void 0 : _r.relativePosition) === null || _s === void 0 ? void 0 : _s.top) !== null && _t !== void 0 ? _t : params.viewBox.height()
429
+ }
430
+ : {
431
+ layout: 'horizontal',
432
+ x: (_w = (_v = (_u = element.mark) === null || _u === void 0 ? void 0 : _u.relativePosition) === null || _v === void 0 ? void 0 : _v.left) !== null && _w !== void 0 ? _w : 0,
433
+ y: (_z = (_y = (_x = element.mark) === null || _x === void 0 ? void 0 : _x.relativePosition) === null || _y === void 0 ? void 0 : _y.top) !== null && _z !== void 0 ? _z : 0
434
+ };
435
+ const attrs = vutils.isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
436
+ return attrs;
437
+ }
438
+ }
439
+ };
440
+ markSpec.layout = markLayout;
441
+ res.push(markSpec);
442
+ }
443
+ });
444
+ }
445
+ return res;
446
+ }
447
+ setDefaultCrosshair() {
448
+ return {};
449
+ }
450
+ getVisualChannel(channel) {
451
+ var _a, _b;
452
+ if (((_a = this._coordinate) === null || _a === void 0 ? void 0 : _a.type) === 'polar') {
453
+ return this._coordinate.transpose ? (channel === 'x' ? 'radius' : 'angle') : channel === 'x' ? 'angle' : 'radius';
454
+ }
455
+ return (((_b = this._coordinate) === null || _b === void 0 ? void 0 : _b.transpose) ? (channel === 'x' ? 'y' : 'x') : channel);
456
+ }
457
+ parseCrosshairSpec() {
458
+ const defaultCrosshair = this.setDefaultCrosshair();
459
+ const defaultKeys = Object.keys(defaultCrosshair);
460
+ const crosshairKeys = this.spec.crosshair
461
+ ? Object.keys(this.spec.crosshair).reduce((res, key) => {
462
+ if (!res.includes(key)) {
463
+ res.push(key);
464
+ }
465
+ return res;
466
+ }, defaultKeys)
467
+ : defaultKeys;
468
+ const res = [];
469
+ if (crosshairKeys.length) {
470
+ crosshairKeys.forEach(channel => {
471
+ var _a, _b;
472
+ const userOption = (_a = this.spec.crosshair) === null || _a === void 0 ? void 0 : _a[channel];
473
+ const option = userOption !== null && userOption !== void 0 ? userOption : defaultCrosshair[channel];
474
+ if (option) {
475
+ const scaleId = this.getScaleId(channel);
476
+ const scaleSpec = this.getScaleSpec(scaleId);
477
+ const markSpec = {
478
+ type: 'component',
479
+ componentType: vgrammar.ComponentEnum.crosshair,
480
+ scale: this.getScaleId(channel),
481
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
482
+ crosshairShape: vutils.isBoolean(option)
483
+ ? (scaleSpec === null || scaleSpec === void 0 ? void 0 : scaleSpec.type) === 'band'
484
+ ? 'rect'
485
+ : 'line'
486
+ : (_b = option.crosshairShape) !== null && _b !== void 0 ? _b : ((scaleSpec === null || scaleSpec === void 0 ? void 0 : scaleSpec.type) === 'band' ? 'rect' : 'line'),
487
+ crosshairType: this.getVisualChannel(channel)
488
+ };
489
+ if (vutils.isPlainObject(userOption)) {
490
+ markSpec.encode = {
491
+ update: userOption
492
+ };
493
+ if (userOption.type === 'polygon') {
494
+ markSpec.crosshairType = 'radius-polygon';
495
+ const anotherDimScaleId = this.getScaleId(channel === 'x' ? 'y' : 'x');
496
+ markSpec.dependency.push(anotherDimScaleId);
497
+ markSpec.encode.update.sides = (datum, el, params) => {
498
+ const scale = params[anotherDimScaleId];
499
+ return scale && isDiscrete(scale.type) ? scale.domain().length : undefined;
500
+ };
501
+ markSpec.encode.update.startAngle = (datum, el, params) => {
502
+ var _a, _b;
503
+ const scale = params[anotherDimScaleId];
504
+ return scale && isDiscrete(scale.type) ? scale.range()[0] + ((_b = (_a = scale === null || scale === void 0 ? void 0 : scale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(scale)) !== null && _b !== void 0 ? _b : 0) / 2 : undefined;
505
+ };
506
+ markSpec.encode.update.endAngle = (datum, el, params) => {
507
+ var _a, _b;
508
+ const scale = params[anotherDimScaleId];
509
+ return scale && isDiscrete(scale.type) ? scale.range()[1] + ((_b = (_a = scale === null || scale === void 0 ? void 0 : scale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(scale)) !== null && _b !== void 0 ? _b : 0) / 2 : undefined;
510
+ };
511
+ }
512
+ }
513
+ res.push(markSpec);
514
+ }
515
+ });
516
+ }
517
+ return res;
518
+ }
519
+ setDefaultTooltip() {
520
+ return null;
521
+ }
522
+ parseTooltipSpec() {
523
+ var _a;
524
+ const defaultTooltipSpec = this.setDefaultTooltip();
525
+ const userTooltipSpec = this.spec.tooltip;
526
+ if (userTooltipSpec !== false && userTooltipSpec !== null && defaultTooltipSpec !== null) {
527
+ const res = [];
528
+ const tooltipSpec = Object.assign({}, defaultTooltipSpec, userTooltipSpec === true ? {} : userTooltipSpec);
529
+ const colorChannel = vutils.isNil(this.spec.encode.color) ? 'group' : 'color';
530
+ const colorEncode = this.spec.encode[colorChannel];
531
+ const dependency = colorEncode ? [this.getScaleId(colorChannel)] : [];
532
+ const colorAccessor = colorEncode ? vgrammarUtil.field(colorEncode) : null;
533
+ const title = {
534
+ visible: !!tooltipSpec.title || !!tooltipSpec.staticTitle,
535
+ key: 'title',
536
+ value: !vutils.isNil(tooltipSpec.staticTitle)
537
+ ? tooltipSpec.staticTitle
538
+ : {
539
+ field: (datum, el, params) => {
540
+ return tooltipSpec.title && (datum === null || datum === void 0 ? void 0 : datum.length) ? vgrammarUtil.field(tooltipSpec.title)(datum[0]) : undefined;
541
+ }
542
+ }
543
+ };
544
+ const content = vutils.isArray(tooltipSpec.content) && tooltipSpec.content.length
545
+ ? tooltipSpec.content.map((entry, index) => {
546
+ return {
547
+ key: entry.key
548
+ ? { field: entry.key }
549
+ : !vutils.isNil(tooltipSpec.staticContentKey)
550
+ ? vutils.isArray(tooltipSpec.staticContentKey)
551
+ ? tooltipSpec.staticContentKey[index]
552
+ : tooltipSpec.staticContentKey
553
+ : (datum, el, params) => {
554
+ return colorAccessor ? colorAccessor(datum) : undefined;
555
+ },
556
+ value: { field: entry.value },
557
+ symbol: (datum, el, params) => {
558
+ var _a;
559
+ const scale = params[this.getScaleId(colorChannel)];
560
+ return {
561
+ symbolType: entry.symbol ? (_a = vgrammarUtil.field(entry.symbol)(datum)) !== null && _a !== void 0 ? _a : 'circle' : 'circle',
562
+ fill: scale && colorAccessor ? scale.scale(colorAccessor(datum)) : vgrammar.getPalette()[0]
563
+ };
564
+ }
565
+ };
566
+ })
567
+ : null;
568
+ if (tooltipSpec.disableGraphicTooltip !== true) {
569
+ res.push({
570
+ type: 'component',
571
+ componentType: vgrammar.ComponentEnum.tooltip,
572
+ target: this.getMarkId(),
573
+ dependency,
574
+ title,
575
+ content,
576
+ zIndex: 1000
577
+ });
578
+ }
579
+ if (tooltipSpec.disableDimensionTooltip !== true) {
580
+ res.push({
581
+ type: 'component',
582
+ componentType: vgrammar.ComponentEnum.dimensionTooltip,
583
+ tooltipType: this.getVisualChannel('x'),
584
+ scale: this.getScaleId('x'),
585
+ dependency,
586
+ target: { data: this.getDataIdOfFiltered(), filter: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.x },
587
+ title,
588
+ content,
589
+ avoidMark: tooltipSpec.disableGraphicTooltip ? [] : [this.getMarkId()],
590
+ zIndex: 1000
591
+ });
592
+ }
593
+ return res;
594
+ }
595
+ return [];
596
+ }
597
+ setDefaultSlider() {
598
+ return {};
599
+ }
600
+ parseSliderSpec() {
601
+ const slider = this.spec.slider;
602
+ const res = [];
603
+ if (slider) {
604
+ Object.keys(slider).forEach(channel => {
605
+ var _a, _b;
606
+ const { option, layout } = this.parseOption(slider[channel]);
607
+ if (option) {
608
+ const scaleId = this.getScaleId(channel);
609
+ const scaleSpec = this.getScaleSpec(scaleId);
610
+ const dataId = this.getDataIdOfMain();
611
+ if (!scaleSpec || !isContinuous(scaleSpec.type)) {
612
+ this._logger.warn(`[VGrammar]: Don't use slider in a channel which has scale type = ${scaleSpec === null || scaleSpec === void 0 ? void 0 : scaleSpec.type}`);
613
+ return;
614
+ }
615
+ const getter = vgrammarUtil.field((_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a[channel]);
616
+ const markLayout = layout !== null && layout !== void 0 ? layout : (vutils.isPlainObject(option) && !vutils.isNil(option.layout)
617
+ ? option.layout === 'horizontal'
618
+ ? { position: 'top', align: 'center' }
619
+ : option.layout === 'vertical'
620
+ ? { position: 'right', align: 'middle' }
621
+ : { position: 'top', align: 'center' }
622
+ : { position: 'top', align: 'center' });
623
+ const markSpec = {
624
+ type: 'component',
625
+ componentType: vgrammar.ComponentEnum.slider,
626
+ dependency: [vgrammar.SIGNAL_VIEW_BOX, dataId],
627
+ min: (datum, elment, params) => {
628
+ const data = params[dataId];
629
+ return Math.min.apply(null, data.map(getter));
630
+ },
631
+ max: (datum, elment, params) => {
632
+ const data = params[dataId];
633
+ return Math.max.apply(null, data.map(getter));
634
+ },
635
+ target: {
636
+ data: this.getDataIdOfFiltered(),
637
+ filter: (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b[channel]
638
+ },
639
+ encode: {
640
+ update: (datum, elment, params) => {
641
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
642
+ const calculatedAttrs = markLayout.position === 'left'
643
+ ? {
644
+ layout: 'vertical',
645
+ x: (_c = (_b = (_a = elment.mark) === null || _a === void 0 ? void 0 : _a.relativePosition) === null || _b === void 0 ? void 0 : _b.left) !== null && _c !== void 0 ? _c : 0,
646
+ y: (_f = (_e = (_d = elment.mark) === null || _d === void 0 ? void 0 : _d.relativePosition) === null || _e === void 0 ? void 0 : _e.top) !== null && _f !== void 0 ? _f : 0,
647
+ railWidth: defaultTheme.slider.railHeight,
648
+ railHeight: params.viewBox.height()
649
+ }
650
+ : markLayout.position === 'right'
651
+ ? {
652
+ layout: 'vertical',
653
+ x: (_j = (_h = (_g = elment.mark) === null || _g === void 0 ? void 0 : _g.relativePosition) === null || _h === void 0 ? void 0 : _h.left) !== null && _j !== void 0 ? _j : params.viewBox.width(),
654
+ y: (_m = (_l = (_k = elment.mark) === null || _k === void 0 ? void 0 : _k.relativePosition) === null || _l === void 0 ? void 0 : _l.top) !== null && _m !== void 0 ? _m : 0,
655
+ railWidth: defaultTheme.slider.railHeight,
656
+ railHeight: params.viewBox.height()
657
+ }
658
+ : markLayout.position === 'bottom'
659
+ ? {
660
+ layout: 'horizontal',
661
+ x: (_q = (_p = (_o = elment.mark) === null || _o === void 0 ? void 0 : _o.relativePosition) === null || _p === void 0 ? void 0 : _p.left) !== null && _q !== void 0 ? _q : 0,
662
+ y: (_t = (_s = (_r = elment.mark) === null || _r === void 0 ? void 0 : _r.relativePosition) === null || _s === void 0 ? void 0 : _s.top) !== null && _t !== void 0 ? _t : params.viewBox.height(),
663
+ railHeight: defaultTheme.slider.railHeight,
664
+ railWidth: params.viewBox.width()
665
+ }
666
+ : {
667
+ layout: 'horizontal',
668
+ x: (_w = (_v = (_u = elment.mark) === null || _u === void 0 ? void 0 : _u.relativePosition) === null || _v === void 0 ? void 0 : _v.left) !== null && _w !== void 0 ? _w : 0,
669
+ y: (_z = (_y = (_x = elment.mark) === null || _x === void 0 ? void 0 : _x.relativePosition) === null || _y === void 0 ? void 0 : _y.top) !== null && _z !== void 0 ? _z : 0,
670
+ railHeight: defaultTheme.slider.railHeight,
671
+ railWidth: params.viewBox.width()
672
+ };
673
+ const attrs = vutils.isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
674
+ return attrs;
675
+ }
676
+ }
677
+ };
678
+ markSpec.layout = markLayout;
679
+ res.push(markSpec);
680
+ }
681
+ });
682
+ }
683
+ return res;
684
+ }
685
+ setDefaultDataZoom() {
686
+ return {};
687
+ }
688
+ getVisiualPositionByDimension(channel) {
689
+ return channel === 'y' ? 'left' : 'bottom';
690
+ }
691
+ parseDataZoomSpec() {
692
+ const datazoom = this.spec.datazoom;
693
+ const res = [];
694
+ if (datazoom) {
695
+ Object.keys(datazoom).forEach(channel => {
696
+ var _a, _b, _c, _d, _e;
697
+ const { option, layout } = this.parseOption(datazoom[channel]);
698
+ if (option) {
699
+ const dataId = this.getDataIdOfMain();
700
+ const markLayout = layout !== null && layout !== void 0 ? layout : (vutils.isPlainObject(option) && !vutils.isNil(option.orient)
701
+ ? { position: option.orient }
702
+ : { position: this.getVisiualPositionByDimension(channel) });
703
+ const preview = {
704
+ data: dataId
705
+ };
706
+ const { x, y } = this.getDataZoomScaleId(channel);
707
+ if (channel === 'x') {
708
+ preview.x = { scale: x, field: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a[channel] };
709
+ preview.y = { scale: y, field: (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b.y };
710
+ }
711
+ else {
712
+ preview[markLayout.position === 'top' || markLayout.position === 'bottom' ? 'x' : 'y'] = {
713
+ scale: x,
714
+ field: (_d = (_c = this.spec.encode) === null || _c === void 0 ? void 0 : _c[channel]) !== null && _d !== void 0 ? _d : channel
715
+ };
716
+ }
717
+ const markSpec = {
718
+ type: 'component',
719
+ componentType: vgrammar.ComponentEnum.datazoom,
720
+ dependency: [vgrammar.SIGNAL_VIEW_BOX, dataId],
721
+ target: {
722
+ data: this.getDataIdOfFiltered(),
723
+ filter: (_e = this.spec.encode) === null || _e === void 0 ? void 0 : _e[channel]
724
+ },
725
+ preview,
726
+ encode: {
727
+ update: (datum, elment, params) => {
728
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
729
+ const calculatedAttrs = markLayout.position === 'left'
730
+ ? {
731
+ orient: markLayout.position,
732
+ x: (_c = (_b = (_a = elment.mark) === null || _a === void 0 ? void 0 : _a.relativePosition) === null || _b === void 0 ? void 0 : _b.left) !== null && _c !== void 0 ? _c : 0,
733
+ y: (_f = (_e = (_d = elment.mark) === null || _d === void 0 ? void 0 : _d.relativePosition) === null || _e === void 0 ? void 0 : _e.top) !== null && _f !== void 0 ? _f : 0,
734
+ size: { height: params.viewBox.height(), width: defaultTheme.datazoom.size.height }
735
+ }
736
+ : markLayout.position === 'right'
737
+ ? {
738
+ orient: markLayout.position,
739
+ x: (_j = (_h = (_g = elment.mark) === null || _g === void 0 ? void 0 : _g.relativePosition) === null || _h === void 0 ? void 0 : _h.left) !== null && _j !== void 0 ? _j : params.viewBox.width(),
740
+ y: (_m = (_l = (_k = elment.mark) === null || _k === void 0 ? void 0 : _k.relativePosition) === null || _l === void 0 ? void 0 : _l.top) !== null && _m !== void 0 ? _m : 0,
741
+ size: { height: params.viewBox.height(), width: defaultTheme.datazoom.size.height }
742
+ }
743
+ : markLayout.position === 'bottom'
744
+ ? {
745
+ orient: markLayout.position,
746
+ x: (_q = (_p = (_o = elment.mark) === null || _o === void 0 ? void 0 : _o.relativePosition) === null || _p === void 0 ? void 0 : _p.left) !== null && _q !== void 0 ? _q : 0,
747
+ y: (_t = (_s = (_r = elment.mark) === null || _r === void 0 ? void 0 : _r.relativePosition) === null || _s === void 0 ? void 0 : _s.top) !== null && _t !== void 0 ? _t : params.viewBox.height(),
748
+ size: { width: params.viewBox.width(), height: defaultTheme.datazoom.size.height }
749
+ }
750
+ : {
751
+ orient: markLayout.position,
752
+ x: (_w = (_v = (_u = elment.mark) === null || _u === void 0 ? void 0 : _u.relativePosition) === null || _v === void 0 ? void 0 : _v.left) !== null && _w !== void 0 ? _w : 0,
753
+ y: (_z = (_y = (_x = elment.mark) === null || _x === void 0 ? void 0 : _x.relativePosition) === null || _y === void 0 ? void 0 : _y.top) !== null && _z !== void 0 ? _z : 0,
754
+ size: { width: params.viewBox.width(), height: defaultTheme.datazoom.size.height }
755
+ };
756
+ const attrs = vutils.isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
757
+ return attrs;
758
+ }
759
+ }
760
+ };
761
+ markSpec.layout = markLayout;
762
+ res.push(markSpec);
763
+ }
764
+ });
765
+ }
766
+ return res;
767
+ }
768
+ setDefaultLabel() {
769
+ return {};
770
+ }
771
+ getLabelPosition() {
772
+ var _a, _b;
773
+ if (((_a = this._coordinate) === null || _a === void 0 ? void 0 : _a.type) === 'polar') {
774
+ return this._coordinate.transpose ? 'endAngle' : 'outer';
775
+ }
776
+ return ((_b = this._coordinate) === null || _b === void 0 ? void 0 : _b.transpose) ? 'right' : 'top';
777
+ }
778
+ setLabelTextGetter(channel, option) {
779
+ return null;
780
+ }
781
+ parseLabelSpec() {
782
+ const label = this.spec.label;
783
+ const res = [];
784
+ if (label) {
785
+ Object.keys(label).forEach(channel => {
786
+ const option = label[channel];
787
+ if (option) {
788
+ const markSpec = {
789
+ type: 'component',
790
+ componentType: vgrammar.ComponentEnum.label,
791
+ target: this.getMarkId(),
792
+ layout: {
793
+ position: 'content',
794
+ skipBeforeLayouted: true
795
+ },
796
+ labelStyle: vutils.isPlainObject(option)
797
+ ? Object.assign({
798
+ position: this.getLabelPosition()
799
+ }, option)
800
+ : { position: this.getLabelPosition() },
801
+ encode: {
802
+ update: {
803
+ text: this.spec.encode[channel]
804
+ ? { field: this.spec.encode[channel] }
805
+ : this.setLabelTextGetter(channel, option)
806
+ }
807
+ }
808
+ };
809
+ res.push(markSpec);
810
+ }
811
+ });
812
+ }
813
+ return res;
814
+ }
815
+ setDefaultPlayer() {
816
+ return {};
817
+ }
818
+ parsePlayerSpec() {
819
+ var _a;
820
+ const player = this.spec.player;
821
+ const res = [];
822
+ if (player) {
823
+ const option = player === null || player === void 0 ? void 0 : player.option;
824
+ const layout = player === null || player === void 0 ? void 0 : player.layout;
825
+ if (option) {
826
+ const markLayout = layout !== null && layout !== void 0 ? layout : (vutils.isPlainObject(option) && !vutils.isNil(option.orient)
827
+ ? { position: option.orient }
828
+ : { position: 'bottom' });
829
+ const markSpec = {
830
+ type: 'component',
831
+ componentType: vgrammar.ComponentEnum.player,
832
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
833
+ target: {
834
+ data: this.getDataIdOfMain(),
835
+ source: this.getDataIdOfPlayer()
836
+ },
837
+ playerType: vutils.isPlainObject(option) ? (_a = option.type) !== null && _a !== void 0 ? _a : 'auto' : 'auto',
838
+ encode: {
839
+ update: (datum, elment, params) => {
840
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
841
+ const calculatedAttrs = markLayout.position === 'left'
842
+ ? {
843
+ x: (_c = (_b = (_a = elment.mark) === null || _a === void 0 ? void 0 : _a.relativePosition) === null || _b === void 0 ? void 0 : _b.left) !== null && _c !== void 0 ? _c : 0,
844
+ y: (_f = (_e = (_d = elment.mark) === null || _d === void 0 ? void 0 : _d.relativePosition) === null || _e === void 0 ? void 0 : _e.top) !== null && _f !== void 0 ? _f : 0,
845
+ size: { height: params.viewBox.height(), width: 20 }
846
+ }
847
+ : markLayout.position === 'right'
848
+ ? {
849
+ x: (_j = (_h = (_g = elment.mark) === null || _g === void 0 ? void 0 : _g.relativePosition) === null || _h === void 0 ? void 0 : _h.left) !== null && _j !== void 0 ? _j : params.viewBox.width(),
850
+ y: (_m = (_l = (_k = elment.mark) === null || _k === void 0 ? void 0 : _k.relativePosition) === null || _l === void 0 ? void 0 : _l.top) !== null && _m !== void 0 ? _m : 0,
851
+ size: { height: params.viewBox.height(), width: 20 }
852
+ }
853
+ : markLayout.position === 'bottom'
854
+ ? {
855
+ x: (_q = (_p = (_o = elment.mark) === null || _o === void 0 ? void 0 : _o.relativePosition) === null || _p === void 0 ? void 0 : _p.left) !== null && _q !== void 0 ? _q : 0,
856
+ y: (_t = (_s = (_r = elment.mark) === null || _r === void 0 ? void 0 : _r.relativePosition) === null || _s === void 0 ? void 0 : _s.top) !== null && _t !== void 0 ? _t : params.viewBox.height(),
857
+ size: { width: params.viewBox.width(), height: 20 }
858
+ }
859
+ : {
860
+ x: (_w = (_v = (_u = elment.mark) === null || _u === void 0 ? void 0 : _u.relativePosition) === null || _v === void 0 ? void 0 : _v.left) !== null && _w !== void 0 ? _w : 0,
861
+ y: (_z = (_y = (_x = elment.mark) === null || _x === void 0 ? void 0 : _x.relativePosition) === null || _y === void 0 ? void 0 : _y.top) !== null && _z !== void 0 ? _z : 0,
862
+ size: { width: params.viewBox.width(), height: 20 }
863
+ };
864
+ const attrs = vutils.isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
865
+ return attrs;
866
+ }
867
+ }
868
+ };
869
+ markSpec.layout = markLayout;
870
+ res.push(markSpec);
871
+ }
872
+ }
873
+ return res;
874
+ }
875
+ parseDataSpec() {
876
+ var _a;
877
+ const { data, player } = this.spec;
878
+ const res = [];
879
+ if (player === null || player === void 0 ? void 0 : player.data) {
880
+ res.push({
881
+ id: this.getDataIdOfPlayer(),
882
+ values: player.data
883
+ });
884
+ res.push({
885
+ id: this.getDataIdOfMain(),
886
+ values: (_a = player.data) === null || _a === void 0 ? void 0 : _a[0]
887
+ });
888
+ res.push({
889
+ id: this.getDataIdOfFiltered(),
890
+ source: this.getDataIdOfMain()
891
+ });
892
+ }
893
+ else if (data) {
894
+ const dataId = this.getDataIdOfMain();
895
+ const userTransforms = data.transform;
896
+ const transform = this.convertMarkTransform(userTransforms, this.setDefaultDataTransform());
897
+ res.push({
898
+ id: dataId,
899
+ values: data.values,
900
+ transform
901
+ });
902
+ res.push({
903
+ id: this.getDataIdOfFiltered(),
904
+ source: dataId
905
+ });
906
+ }
907
+ const multiDatas = this.setMultipleData();
908
+ if (multiDatas) {
909
+ multiDatas.forEach(entry => {
910
+ if (entry.id) {
911
+ if (entry.id === this.getDataIdOfFiltered() && res.length) {
912
+ res[res.length - 1].transform = entry.transform;
913
+ }
914
+ else {
915
+ res.push(entry);
916
+ }
917
+ }
918
+ });
919
+ }
920
+ return res;
921
+ }
922
+ parseScaleSpec() {
923
+ const { encode, scale, datazoom } = this.spec;
924
+ const scales = {};
925
+ if (encode) {
926
+ Object.keys(encode).forEach(k => {
927
+ var _a;
928
+ const encodeOption = encode[k];
929
+ const scaleId = this.getScaleId(k);
930
+ scales[scaleId] = Object.assign({ id: scaleId }, this.parseScaleByEncode(k, encodeOption), (_a = this.spec.scale) === null || _a === void 0 ? void 0 : _a[k]);
931
+ });
932
+ }
933
+ if (scale) {
934
+ Object.keys(scale).forEach(k => {
935
+ const scaleId = this.getScaleId(k);
936
+ if (!scales[scaleId]) {
937
+ scales[scaleId] = scale[k];
938
+ }
939
+ });
940
+ }
941
+ if (datazoom) {
942
+ Object.keys(datazoom).forEach(k => {
943
+ var _a, _b, _c, _d;
944
+ const scaleId = this.getScaleId(k);
945
+ const { x: xScaleId, y: yScaleId } = this.getDataZoomScaleId(k);
946
+ if (k === 'x' && encode[k]) {
947
+ scales[xScaleId] = {
948
+ type: scales[scaleId].type,
949
+ id: xScaleId,
950
+ domain: {
951
+ data: this.getDataIdOfMain(),
952
+ field: encode[k]
953
+ },
954
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
955
+ range: (scale, params) => {
956
+ return [0, params.viewBox.width()];
957
+ }
958
+ };
959
+ if (encode.y) {
960
+ scales[yScaleId] = {
961
+ type: (_b = (_a = scales[this.getScaleId('y')]) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'linear',
962
+ id: yScaleId,
963
+ domain: {
964
+ data: this.getDataIdOfMain(),
965
+ field: encode === null || encode === void 0 ? void 0 : encode.y
966
+ },
967
+ range: (scale, params) => {
968
+ var _a, _b;
969
+ const option = this.parseOption(datazoom[k]).option;
970
+ return [
971
+ 0,
972
+ vutils.isPlainObject(option)
973
+ ? (_b = (_a = option.size) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : defaultTheme.datazoom.size.height
974
+ : defaultTheme.datazoom.size.height
975
+ ];
976
+ }
977
+ };
978
+ }
979
+ }
980
+ else {
981
+ scales[xScaleId] = {
982
+ type: (_c = scales[scaleId].type) !== null && _c !== void 0 ? _c : 'band',
983
+ id: xScaleId,
984
+ domain: {
985
+ data: this.getDataIdOfMain(),
986
+ field: (_d = encode === null || encode === void 0 ? void 0 : encode[k]) !== null && _d !== void 0 ? _d : k
987
+ }
988
+ };
989
+ }
990
+ });
991
+ }
992
+ return Array.from(Object.values(scales));
993
+ }
994
+ parseCoordinateSpec() {
995
+ var _a;
996
+ if (!this._coordinate) {
997
+ return [];
998
+ }
999
+ const coordinate = {
1000
+ type: (_a = this._coordinate.type) !== null && _a !== void 0 ? _a : 'cartesian',
1001
+ transpose: this._coordinate.transpose,
1002
+ id: this._coordinate.id,
1003
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
1004
+ start: [0, 0],
1005
+ end: (coord, params) => {
1006
+ return [params.viewBox.width(), params.viewBox.height()];
1007
+ }
1008
+ };
1009
+ if (this._coordinate.type === 'polar' && this._coordinate.origin) {
1010
+ coordinate.origin = (coord, params) => {
1011
+ return [
1012
+ vgrammarUtil.toPercent(this._coordinate.origin[0], params.viewBox.width()),
1013
+ vgrammarUtil.toPercent(this._coordinate.origin[1], params.viewBox.height())
1014
+ ];
1015
+ };
1016
+ }
1017
+ return [coordinate];
1018
+ }
1019
+ setMainMarkEnterEncode() {
1020
+ return this.spec.style;
1021
+ }
1022
+ setMainMarkSpec() {
1023
+ return {};
1024
+ }
1025
+ setMultiMarksSpec() {
1026
+ return null;
1027
+ }
1028
+ toViewSpec() {
1029
+ var _a, _b;
1030
+ this.viewSpec = {};
1031
+ const filteredDataId = this.getDataIdOfFiltered();
1032
+ this.viewSpec.data = this.parseDataSpec();
1033
+ this.viewSpec.scales = this.parseScaleSpec();
1034
+ this.viewSpec.coordinates = this.parseCoordinateSpec();
1035
+ let marks = [];
1036
+ marks = marks.concat(this.parseLegendSpec());
1037
+ marks = marks.concat(this.parseAxisSpec());
1038
+ marks = marks.concat(this.parseCrosshairSpec());
1039
+ marks = marks.concat(this.parseSliderSpec());
1040
+ marks = marks.concat(this.parseDataZoomSpec());
1041
+ marks = marks.concat(this.parsePlayerSpec());
1042
+ marks.push(Object.assign({
1043
+ id: this.getMarkId(),
1044
+ type: this.setMarkType(),
1045
+ coordinate: (_a = this._coordinate) === null || _a === void 0 ? void 0 : _a.id,
1046
+ from: {
1047
+ data: filteredDataId
1048
+ },
1049
+ groupBy: (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b.group,
1050
+ layout: {
1051
+ position: 'content',
1052
+ skipBeforeLayouted: true
1053
+ },
1054
+ dependency: this.viewSpec.scales.map(scale => scale.id).concat(vgrammar.SIGNAL_VIEW_BOX),
1055
+ transform: this.convertMarkTransform(this.spec.transform, this.setDefaultMarkTransform()),
1056
+ animation: this.convertMarkAnimation(),
1057
+ encode: Object.assign({}, this.spec.state, {
1058
+ enter: this.setMainMarkEnterEncode(),
1059
+ update: this.convertMarkEncode(this.spec.encode)
1060
+ })
1061
+ }, this.setMainMarkSpec()));
1062
+ const otherMarks = this.setMultiMarksSpec();
1063
+ if (otherMarks) {
1064
+ marks = marks.concat(otherMarks);
1065
+ }
1066
+ marks = marks.concat(this.parseLabelSpec());
1067
+ marks = marks.concat(this.parseTooltipSpec());
1068
+ this.viewSpec.marks = marks;
1069
+ return this.viewSpec;
1070
+ }
1071
+ clear() {
1072
+ this.spec = { id: this.spec.id };
1073
+ }
1074
+ }
1075
+
1076
+ var PlotMakType;
1077
+ (function (PlotMakType) {
1078
+ PlotMakType["area"] = "area";
1079
+ PlotMakType["cell"] = "cell";
1080
+ PlotMakType["image"] = "image";
1081
+ PlotMakType["interval"] = "interval";
1082
+ PlotMakType["line"] = "line";
1083
+ PlotMakType["path"] = "path";
1084
+ PlotMakType["polygon"] = "polygon";
1085
+ PlotMakType["rectX"] = "rectX";
1086
+ PlotMakType["rectY"] = "rectY";
1087
+ PlotMakType["rect"] = "rect";
1088
+ PlotMakType["ruleX"] = "ruleX";
1089
+ PlotMakType["ruleY"] = "ruleY";
1090
+ PlotMakType["rule"] = "rule";
1091
+ PlotMakType["symbol"] = "symbol";
1092
+ PlotMakType["text"] = "text";
1093
+ PlotMakType["tree"] = "tree";
1094
+ PlotMakType["circlePacking"] = "circlePacking";
1095
+ PlotMakType["sunburst"] = "sunburst";
1096
+ PlotMakType["treemap"] = "treemap";
1097
+ PlotMakType["sankey"] = "sankey";
1098
+ PlotMakType["wordcloud"] = "wordcloud";
1099
+ PlotMakType["wordcloudShape"] = "wordcloudShape";
1100
+ })(PlotMakType || (PlotMakType = {}));
1101
+
1102
+ class Interval extends SemanticMark {
1103
+ constructor(id) {
1104
+ super(PlotMakType.interval, id);
1105
+ }
1106
+ setMarkType() {
1107
+ var _a;
1108
+ return ((_a = this._coordinate) === null || _a === void 0 ? void 0 : _a.type) === 'polar' ? vgrammar.GrammarMarkType.arc : vgrammar.GrammarMarkType.rect;
1109
+ }
1110
+ parseScaleByEncode(channel, option) {
1111
+ return this.parseScaleOfCommonEncode(channel, option);
1112
+ }
1113
+ setDefaultMarkTransform() {
1114
+ var _a, _b, _c, _d;
1115
+ return [
1116
+ {
1117
+ type: 'dodge',
1118
+ minWidth: (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.minWidth,
1119
+ maxWidth: (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.maxWidth,
1120
+ innerGap: (_c = this.spec.style) === null || _c === void 0 ? void 0 : _c.innerGap,
1121
+ categoryGap: (_d = this.spec.style) === null || _d === void 0 ? void 0 : _d.categoryGap
1122
+ }
1123
+ ];
1124
+ }
1125
+ setDefaultCrosshair() {
1126
+ return {
1127
+ x: { crosshairShape: 'rect' }
1128
+ };
1129
+ }
1130
+ setDefaultTooltip() {
1131
+ var _a;
1132
+ const encodeY = (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.y;
1133
+ return {
1134
+ content: vutils.isArray(encodeY)
1135
+ ? encodeY.map(entry => {
1136
+ return {
1137
+ value: entry
1138
+ };
1139
+ })
1140
+ : [
1141
+ {
1142
+ value: encodeY
1143
+ }
1144
+ ]
1145
+ };
1146
+ }
1147
+ setMainMarkSpec() {
1148
+ var _a;
1149
+ return ((_a = this._coordinate) === null || _a === void 0 ? void 0 : _a.type) === 'polar'
1150
+ ? {
1151
+ attributeTransforms: [
1152
+ {
1153
+ channels: ['x', 'y', 'x1', 'y1', 'cx', 'cy'],
1154
+ transform: (graphicAttributes, nextAttrs, storedAttrs) => {
1155
+ graphicAttributes.x = storedAttrs.cx;
1156
+ graphicAttributes.y = storedAttrs.cy;
1157
+ if (this._coordinate.transpose) {
1158
+ graphicAttributes.startAngle = storedAttrs.y;
1159
+ graphicAttributes.endAngle = storedAttrs.y1;
1160
+ graphicAttributes.innerRadius = storedAttrs.x;
1161
+ graphicAttributes.outerRadius = storedAttrs.x1;
1162
+ }
1163
+ else {
1164
+ graphicAttributes.startAngle = storedAttrs.x;
1165
+ graphicAttributes.endAngle = storedAttrs.x1;
1166
+ graphicAttributes.innerRadius = storedAttrs.y;
1167
+ graphicAttributes.outerRadius = storedAttrs.y1;
1168
+ }
1169
+ },
1170
+ storedAttrs: 'sizeAttrs'
1171
+ }
1172
+ ]
1173
+ }
1174
+ : {};
1175
+ }
1176
+ convertMarkEncode(encode) {
1177
+ var _a, _b, _c, _d, _e;
1178
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1179
+ const scaleXId = this.getScaleId('x');
1180
+ const scaleYId = this.getScaleId('y');
1181
+ const xAccessor = vgrammarUtil.field(markEncoder.x.field);
1182
+ const res = {
1183
+ x: (datum, el, params) => {
1184
+ const scale = params[scaleXId];
1185
+ const bandWidth = scale.bandwidth();
1186
+ return scale.scale(xAccessor(datum)) + bandWidth / 4;
1187
+ },
1188
+ x1: (datum, el, params) => {
1189
+ const scale = params[scaleXId];
1190
+ const bandWidth = scale.bandwidth();
1191
+ return scale.scale(xAccessor(datum)) + (3 * bandWidth) / 4;
1192
+ }
1193
+ };
1194
+ if (vutils.isArray((_a = markEncoder.y) === null || _a === void 0 ? void 0 : _a.field)) {
1195
+ res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };
1196
+ res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };
1197
+ }
1198
+ else {
1199
+ const yAccessor = vgrammarUtil.field(markEncoder.y.field);
1200
+ res.y = (datum, el, params) => {
1201
+ const yVals = yAccessor(datum);
1202
+ const scale = params[scaleYId];
1203
+ return vutils.isArray(yVals) ? scale.scale(yVals[0]) : scale.scale(yVals);
1204
+ };
1205
+ res.y1 = (datum, el, params) => {
1206
+ const scale = params[scaleYId];
1207
+ const yVals = yAccessor(datum);
1208
+ if (vutils.isArray(yVals) && yVals.length > 1) {
1209
+ return scale.scale(yVals[1]);
1210
+ }
1211
+ const domain = scale.domain();
1212
+ const min = Math.min.apply(null, domain);
1213
+ const max = Math.max.apply(null, domain);
1214
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
1215
+ return scale.scale(baseValue);
1216
+ };
1217
+ }
1218
+ if (markEncoder.color || markEncoder.group) {
1219
+ res.fill = (_b = markEncoder.color) !== null && _b !== void 0 ? _b : markEncoder.group;
1220
+ }
1221
+ else {
1222
+ res.fill = (_d = (_c = this.spec.style) === null || _c === void 0 ? void 0 : _c.fill) !== null && _d !== void 0 ? _d : vgrammar.getPalette()[0];
1223
+ }
1224
+ if (((_e = this._coordinate) === null || _e === void 0 ? void 0 : _e.type) === 'polar') {
1225
+ res.cx = (datum, el, params) => {
1226
+ const coord = params[this._coordinate.id];
1227
+ const origin = coord.origin();
1228
+ return origin.x;
1229
+ };
1230
+ res.cy = (datum, el, params) => {
1231
+ const coord = params[this._coordinate.id];
1232
+ const origin = coord.origin();
1233
+ return origin.y;
1234
+ };
1235
+ }
1236
+ return res;
1237
+ }
1238
+ }
1239
+ Interval.type = PlotMakType.interval;
1240
+
1241
+ class Line extends SemanticMark {
1242
+ constructor(id) {
1243
+ super(PlotMakType.line, id);
1244
+ }
1245
+ setMarkType() {
1246
+ return vgrammar.GrammarMarkType.line;
1247
+ }
1248
+ parseScaleOfEncodeX(option) {
1249
+ const res = super.parseScaleOfEncodeX(option);
1250
+ res.type = 'point';
1251
+ return res;
1252
+ }
1253
+ parseScaleByEncode(channel, option) {
1254
+ return this.parseScaleOfCommonEncode(channel, option);
1255
+ }
1256
+ setDefaultCrosshair() {
1257
+ return {
1258
+ x: { crosshairShape: 'line' }
1259
+ };
1260
+ }
1261
+ setDefaultTooltip() {
1262
+ var _a, _b;
1263
+ return {
1264
+ disableGraphicTooltip: true,
1265
+ title: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.x,
1266
+ content: [
1267
+ {
1268
+ value: (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b.y
1269
+ }
1270
+ ]
1271
+ };
1272
+ }
1273
+ convertMarkEncode(encode) {
1274
+ var _a, _b, _c;
1275
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1276
+ const res = {
1277
+ y: markEncoder.y,
1278
+ x: markEncoder.x
1279
+ };
1280
+ if (markEncoder.color || markEncoder.group) {
1281
+ res.stroke = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
1282
+ }
1283
+ else {
1284
+ res.stroke = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.stroke) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
1285
+ }
1286
+ return res;
1287
+ }
1288
+ }
1289
+ Line.type = PlotMakType.line;
1290
+
1291
+ class Cell extends SemanticMark {
1292
+ constructor(id) {
1293
+ super(PlotMakType.cell, id);
1294
+ }
1295
+ setMarkType() {
1296
+ return vgrammar.GrammarMarkType.cell;
1297
+ }
1298
+ parseScaleOfEncodeX(option) {
1299
+ const res = super.parseScaleOfEncodeX(option);
1300
+ res.type = 'point';
1301
+ return res;
1302
+ }
1303
+ parseScaleByEncode(channel, option) {
1304
+ return this.parseScaleOfCommonEncode(channel, option);
1305
+ }
1306
+ setDefaultCrosshair() {
1307
+ return {
1308
+ x: { crosshairShape: 'line' }
1309
+ };
1310
+ }
1311
+ setDefaultTooltip() {
1312
+ var _a, _b;
1313
+ return {
1314
+ title: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.x,
1315
+ content: [
1316
+ {
1317
+ value: (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b.y
1318
+ }
1319
+ ]
1320
+ };
1321
+ }
1322
+ convertMarkEncode(encode) {
1323
+ var _a, _b, _c;
1324
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1325
+ const res = {
1326
+ y: markEncoder.y,
1327
+ x: markEncoder.x
1328
+ };
1329
+ if (markEncoder.color || markEncoder.group) {
1330
+ res.stroke = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
1331
+ }
1332
+ else {
1333
+ res.stroke = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
1334
+ }
1335
+ return res;
1336
+ }
1337
+ }
1338
+ Cell.type = PlotMakType.cell;
1339
+
1340
+ class RuleX extends SemanticMark {
1341
+ constructor(id) {
1342
+ super(PlotMakType.ruleX, id);
1343
+ }
1344
+ setMarkType() {
1345
+ return vgrammar.GrammarMarkType.rule;
1346
+ }
1347
+ parseScaleOfEncodeX(option) {
1348
+ const res = super.parseScaleOfEncodeX(option);
1349
+ res.type = 'point';
1350
+ return res;
1351
+ }
1352
+ parseScaleByEncode(channel, option) {
1353
+ return this.parseScaleOfCommonEncode(channel, option);
1354
+ }
1355
+ convertMarkEncode(encode) {
1356
+ var _a, _b, _c;
1357
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1358
+ const res = {
1359
+ x: markEncoder.x,
1360
+ x1: markEncoder.x,
1361
+ y: (datum, el, params) => {
1362
+ return 0;
1363
+ },
1364
+ y1: (datum, el, params) => {
1365
+ return params.viewBox.height();
1366
+ }
1367
+ };
1368
+ if (markEncoder.color || markEncoder.group) {
1369
+ res.stroke = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
1370
+ }
1371
+ else {
1372
+ res.stroke = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.stroke) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
1373
+ }
1374
+ return res;
1375
+ }
1376
+ }
1377
+ RuleX.type = PlotMakType.ruleX;
1378
+
1379
+ class RuleY extends SemanticMark {
1380
+ constructor(id) {
1381
+ super(PlotMakType.ruleX, id);
1382
+ }
1383
+ setMarkType() {
1384
+ return vgrammar.GrammarMarkType.rule;
1385
+ }
1386
+ parseScaleOfEncodeX(option) {
1387
+ const res = super.parseScaleOfEncodeX(option);
1388
+ res.type = 'point';
1389
+ return res;
1390
+ }
1391
+ parseScaleByEncode(channel, option) {
1392
+ return this.parseScaleOfCommonEncode(channel, option);
1393
+ }
1394
+ convertMarkEncode(encode) {
1395
+ var _a, _b, _c;
1396
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1397
+ const res = {
1398
+ y: markEncoder.y,
1399
+ y1: markEncoder.y,
1400
+ x: (datum, el, params) => {
1401
+ return 0;
1402
+ },
1403
+ x1: (datum, el, params) => {
1404
+ return params.viewBox.width();
1405
+ }
1406
+ };
1407
+ if (markEncoder.color || markEncoder.group) {
1408
+ res.stroke = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
1409
+ }
1410
+ else {
1411
+ res.stroke = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.stroke) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
1412
+ }
1413
+ return res;
1414
+ }
1415
+ }
1416
+ RuleY.type = PlotMakType.ruleX;
1417
+
1418
+ class Area extends SemanticMark {
1419
+ constructor(id) {
1420
+ super(PlotMakType.area, id);
1421
+ }
1422
+ setMarkType() {
1423
+ return vgrammar.GrammarMarkType.area;
1424
+ }
1425
+ parseScaleOfEncodeX(option) {
1426
+ const res = super.parseScaleOfEncodeX(option);
1427
+ res.type = 'point';
1428
+ return res;
1429
+ }
1430
+ parseScaleByEncode(channel, option) {
1431
+ return this.parseScaleOfCommonEncode(channel, option);
1432
+ }
1433
+ setDefaultCrosshair() {
1434
+ return {
1435
+ x: { crosshairShape: 'line' }
1436
+ };
1437
+ }
1438
+ setDefaultTooltip() {
1439
+ var _a, _b;
1440
+ const encodeX = (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.x;
1441
+ const encodeY = (_b = this.spec.encode) === null || _b === void 0 ? void 0 : _b.y;
1442
+ return {
1443
+ disableGraphicTooltip: true,
1444
+ title: vutils.isArray(encodeX) ? encodeX[0] : encodeX,
1445
+ content: vutils.isArray(encodeY)
1446
+ ? encodeY.map(entry => {
1447
+ return {
1448
+ value: entry
1449
+ };
1450
+ })
1451
+ : [
1452
+ {
1453
+ value: encodeY
1454
+ }
1455
+ ]
1456
+ };
1457
+ }
1458
+ convertMarkEncode(encode) {
1459
+ var _a, _b, _c, _d, _e;
1460
+ const markEncoder = this.convertSimpleMarkEncode(encode);
1461
+ let res;
1462
+ if (vutils.isArray((_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field)) {
1463
+ res = {
1464
+ y: markEncoder.y,
1465
+ x: { field: markEncoder.x.field[0], scale: markEncoder.x.scale },
1466
+ x1: { field: markEncoder.x.field[1], scale: markEncoder.x.scale }
1467
+ };
1468
+ }
1469
+ else if (vutils.isArray((_b = markEncoder.y) === null || _b === void 0 ? void 0 : _b.field)) {
1470
+ res = {
1471
+ y: { field: markEncoder.y.field[0], scale: markEncoder.y.scale },
1472
+ y1: { field: markEncoder.y.field[1], scale: markEncoder.y.scale },
1473
+ x: markEncoder.x
1474
+ };
1475
+ }
1476
+ else {
1477
+ const scaleYId = this.getScaleId('y');
1478
+ res = {
1479
+ x: markEncoder.x,
1480
+ y: markEncoder.y,
1481
+ y1: (datum, el, params) => {
1482
+ const scale = params[scaleYId];
1483
+ const domain = scale.domain();
1484
+ const min = Math.min.apply(null, domain);
1485
+ const max = Math.max.apply(null, domain);
1486
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
1487
+ return scale.scale(baseValue);
1488
+ }
1489
+ };
1490
+ }
1491
+ if (markEncoder.color || markEncoder.group) {
1492
+ res.fill = (_c = markEncoder.color) !== null && _c !== void 0 ? _c : markEncoder.group;
1493
+ }
1494
+ else {
1495
+ res.fill = (_e = (_d = this.spec.style) === null || _d === void 0 ? void 0 : _d.fill) !== null && _e !== void 0 ? _e : vgrammar.getPalette()[0];
1496
+ }
1497
+ return res;
1498
+ }
1499
+ }
1500
+ Area.type = PlotMakType.area;
1501
+
1502
+ /******************************************************************************
1503
+ Copyright (c) Microsoft Corporation.
1504
+
1505
+ Permission to use, copy, modify, and/or distribute this software for any
1506
+ purpose with or without fee is hereby granted.
1507
+
1508
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1509
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1510
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1511
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1512
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1513
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1514
+ PERFORMANCE OF THIS SOFTWARE.
1515
+ ***************************************************************************** */
1516
+ function __awaiter(thisArg, _arguments, P, generator) {
1517
+ function adopt(value) {
1518
+ return value instanceof P ? value : new P(function (resolve) {
1519
+ resolve(value);
1520
+ });
1521
+ }
1522
+ return new (P || (P = Promise))(function (resolve, reject) {
1523
+ function fulfilled(value) {
1524
+ try {
1525
+ step(generator.next(value));
1526
+ } catch (e) {
1527
+ reject(e);
1528
+ }
1529
+ }
1530
+ function rejected(value) {
1531
+ try {
1532
+ step(generator["throw"](value));
1533
+ } catch (e) {
1534
+ reject(e);
1535
+ }
1536
+ }
1537
+ function step(result) {
1538
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1539
+ }
1540
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1541
+ });
1542
+ }
1543
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1544
+ var e = new Error(message);
1545
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1546
+ };
1547
+
1548
+ const mergeGrammarSpecs = (newSpecs, prevSpecs) => {
1549
+ return newSpecs.reduce((res, entry) => {
1550
+ if (entry.id && !res.some(prev => prev.id === entry.id)) {
1551
+ res.push(entry);
1552
+ }
1553
+ return res;
1554
+ }, prevSpecs);
1555
+ };
1556
+
1557
+ class Plot {
1558
+ static useMarks(marks) {
1559
+ marks.forEach(mark => {
1560
+ vgrammar.Factory.registerPlotMarks(mark.type, mark);
1561
+ });
1562
+ }
1563
+ constructor(option) {
1564
+ this._view = new vgrammar.View(option);
1565
+ this._semanticMarks = [];
1566
+ this._logger = vutils.Logger.getInstance();
1567
+ }
1568
+ _mergeScales(scales, prevScales) {
1569
+ return scales.reduce((res, scale) => {
1570
+ if (scale.id) {
1571
+ const prevScale = res.find(prev => prev.id === scale.id);
1572
+ if (prevScale) {
1573
+ if (scale.domain.data && scale.domain.field) {
1574
+ if (prevScale.domain.data && prevScale.domain.field) {
1575
+ if (scale.domain.data === prevScale.domain.data &&
1576
+ scale.domain.field !== prevScale.domain.field) {
1577
+ prevScale.domain.field = []
1578
+ .concat(prevScale.domain.field)
1579
+ .concat(scale.domain.field);
1580
+ }
1581
+ else if (scale.domain.data !== prevScale.domain.data) {
1582
+ prevScale.domain = {
1583
+ datas: [
1584
+ { data: prevScale.domain.data, field: prevScale.domain.field },
1585
+ { data: scale.domain.data, field: scale.domain.field }
1586
+ ],
1587
+ sort: prevScale.domain.sort
1588
+ };
1589
+ }
1590
+ if (!vutils.isNil(scale.domain.sort)) {
1591
+ prevScale.domain.sort = scale.domain.sort;
1592
+ }
1593
+ }
1594
+ else if (prevScale.domain.datas) {
1595
+ const prevData = prevScale.domain.datas.find(entry => entry.data !== scale.domain.data);
1596
+ if (prevData && scale.domain.field !== prevData.field) {
1597
+ prevData.field = [].concat(prevData.field).concat(scale.domain.field);
1598
+ }
1599
+ else if (!prevData) {
1600
+ prevScale.domain.datas.push({
1601
+ data: scale.domain.data,
1602
+ field: scale.domain.field
1603
+ });
1604
+ }
1605
+ if (!vutils.isNil(scale.domain.sort)) {
1606
+ prevScale.domain.sort = scale.domain.sort;
1607
+ }
1608
+ }
1609
+ }
1610
+ }
1611
+ else {
1612
+ res.push(scale);
1613
+ }
1614
+ }
1615
+ return res;
1616
+ }, prevScales);
1617
+ }
1618
+ parseViewSpec() {
1619
+ const spec = {
1620
+ data: [],
1621
+ marks: [],
1622
+ scales: [],
1623
+ coordinates: [],
1624
+ signals: [],
1625
+ projections: [],
1626
+ events: []
1627
+ };
1628
+ this._semanticMarks.forEach(mark => {
1629
+ if (this._coordinate) {
1630
+ mark.coordinate(this._coordinate);
1631
+ }
1632
+ const { data, marks, scales, coordinates, signals, projections, events } = mark.toViewSpec();
1633
+ if (data && data.length) {
1634
+ spec.data = mergeGrammarSpecs(data, spec.data);
1635
+ }
1636
+ if (marks && marks.length) {
1637
+ spec.marks = spec.marks.concat(marks);
1638
+ }
1639
+ if (scales && scales.length) {
1640
+ spec.scales = this._mergeScales(scales, spec.scales);
1641
+ }
1642
+ if (coordinates && coordinates.length) {
1643
+ spec.coordinates = mergeGrammarSpecs(coordinates, spec.coordinates);
1644
+ }
1645
+ if (signals && signals.length) {
1646
+ spec.signals = spec.signals.concat(signals);
1647
+ }
1648
+ if (projections && projections.length) {
1649
+ spec.projections = spec.projections.concat(projections);
1650
+ }
1651
+ if (events && events.length) {
1652
+ spec.events = spec.events.concat(events);
1653
+ }
1654
+ });
1655
+ spec.marks = [
1656
+ {
1657
+ type: 'group',
1658
+ layout: {
1659
+ display: 'relative',
1660
+ updateViewSignals: true
1661
+ },
1662
+ dependency: [vgrammar.SIGNAL_VIEW_BOX],
1663
+ encode: {
1664
+ update: (datum, elment, params) => {
1665
+ return {
1666
+ x: params.viewBox.x1,
1667
+ y: params.viewBox.y1,
1668
+ width: params.viewBox.width(),
1669
+ height: params.viewBox.height()
1670
+ };
1671
+ }
1672
+ },
1673
+ marks: spec.marks
1674
+ }
1675
+ ];
1676
+ return spec;
1677
+ }
1678
+ run(morphConfig) {
1679
+ if (this._view) {
1680
+ if (!this._hasInited) {
1681
+ this._view.parseSpec(this.parseViewSpec());
1682
+ }
1683
+ this._hasInited = true;
1684
+ this._view.runSync(morphConfig);
1685
+ }
1686
+ return this;
1687
+ }
1688
+ runAsync(morphConfig) {
1689
+ return __awaiter(this, void 0, void 0, function* () {
1690
+ if (this._view) {
1691
+ if (!this._hasInited) {
1692
+ this._view.parseSpec(this.parseViewSpec());
1693
+ }
1694
+ this._hasInited = true;
1695
+ yield this._view.runAsync(morphConfig);
1696
+ }
1697
+ return this;
1698
+ });
1699
+ }
1700
+ release() {
1701
+ if (this._view) {
1702
+ this._view.release();
1703
+ }
1704
+ return this;
1705
+ }
1706
+ updateSpec(spec) {
1707
+ this.parseSpec(spec, true);
1708
+ return this;
1709
+ }
1710
+ parseSpec(spec, isUpdate) {
1711
+ var _a;
1712
+ if (spec.coordinate) {
1713
+ this.coordinate(spec.coordinate.type, spec.coordinate);
1714
+ }
1715
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.marks) === null || _a === void 0 ? void 0 : _a.length) {
1716
+ spec.marks.forEach(mark => {
1717
+ const plotMark = vgrammar.Factory.createPlotMark(mark.type);
1718
+ plotMark.parseSpec(mark);
1719
+ this._semanticMarks.push(plotMark);
1720
+ });
1721
+ }
1722
+ const viewSpec = this.parseViewSpec();
1723
+ viewSpec.width = spec.width;
1724
+ viewSpec.height = spec.height;
1725
+ viewSpec.background = spec.background;
1726
+ viewSpec.padding = spec.padding;
1727
+ if (isUpdate) {
1728
+ this._view.updateSpec(viewSpec);
1729
+ }
1730
+ else {
1731
+ this._view.parseSpec(viewSpec);
1732
+ }
1733
+ this._hasInited = true;
1734
+ return this;
1735
+ }
1736
+ getImageBuffer() {
1737
+ var _a, _b;
1738
+ return (_b = (_a = this._view) === null || _a === void 0 ? void 0 : _a.getImageBuffer) === null || _b === void 0 ? void 0 : _b.call(_a);
1739
+ }
1740
+ on(type, handler) {
1741
+ if (this._view) {
1742
+ this._view.addEventListener(type, handler);
1743
+ }
1744
+ return this;
1745
+ }
1746
+ off(type, handler) {
1747
+ if (this._view) {
1748
+ this._view.removeEventListener(type, handler);
1749
+ }
1750
+ return this;
1751
+ }
1752
+ getCoordinateId(viewId = '0') {
1753
+ return `coordinate-${viewId}`;
1754
+ }
1755
+ coordinate(type, spec) {
1756
+ this._coordinate = Object.assign({ type, id: this.getCoordinateId() }, spec);
1757
+ return this;
1758
+ }
1759
+ interval() {
1760
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.interval);
1761
+ if (!mark) {
1762
+ this._logger.error(`Please register ${PlotMakType.interval} before use it`);
1763
+ }
1764
+ else {
1765
+ this._semanticMarks.push(mark);
1766
+ }
1767
+ return mark;
1768
+ }
1769
+ line() {
1770
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.line);
1771
+ if (!mark) {
1772
+ this._logger.error(`Please register ${PlotMakType.line} before use it`);
1773
+ }
1774
+ else {
1775
+ this._semanticMarks.push(mark);
1776
+ }
1777
+ return mark;
1778
+ }
1779
+ area() {
1780
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.area);
1781
+ if (!mark) {
1782
+ this._logger.error(`Please register ${PlotMakType.area} before use it`);
1783
+ }
1784
+ else {
1785
+ this._semanticMarks.push(mark);
1786
+ }
1787
+ return mark;
1788
+ }
1789
+ cell() {
1790
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.cell);
1791
+ if (!mark) {
1792
+ this._logger.error(`Please register ${PlotMakType.cell} before use it`);
1793
+ }
1794
+ else {
1795
+ this._semanticMarks.push(mark);
1796
+ }
1797
+ return mark;
1798
+ }
1799
+ ruleX() {
1800
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.ruleX);
1801
+ if (!mark) {
1802
+ this._logger.error(`Please register ${this.ruleX} before use it`);
1803
+ }
1804
+ else {
1805
+ this._semanticMarks.push(mark);
1806
+ }
1807
+ return mark;
1808
+ }
1809
+ ruleY() {
1810
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.ruleY);
1811
+ if (!mark) {
1812
+ this._logger.error(`Please register ${PlotMakType.ruleY} before use it`);
1813
+ }
1814
+ else {
1815
+ this._semanticMarks.push(mark);
1816
+ }
1817
+ return mark;
1818
+ }
1819
+ image() {
1820
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.image);
1821
+ if (!mark) {
1822
+ this._logger.error(`Please register ${PlotMakType.image} before use it`);
1823
+ }
1824
+ else {
1825
+ this._semanticMarks.push(mark);
1826
+ }
1827
+ return mark;
1828
+ }
1829
+ path() {
1830
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.path);
1831
+ if (!mark) {
1832
+ this._logger.error(`Please register ${PlotMakType.path} before use it`);
1833
+ }
1834
+ else {
1835
+ this._semanticMarks.push(mark);
1836
+ }
1837
+ return mark;
1838
+ }
1839
+ polygon() {
1840
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.polygon);
1841
+ if (!mark) {
1842
+ this._logger.error(`Please register ${PlotMakType.polygon} before use it`);
1843
+ }
1844
+ else {
1845
+ this._semanticMarks.push(mark);
1846
+ }
1847
+ return mark;
1848
+ }
1849
+ rectX() {
1850
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.rectX);
1851
+ if (!mark) {
1852
+ this._logger.error(`Please register ${PlotMakType.rectX} before use it`);
1853
+ }
1854
+ else {
1855
+ this._semanticMarks.push(mark);
1856
+ }
1857
+ return mark;
1858
+ }
1859
+ rectY() {
1860
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.rectY);
1861
+ if (!mark) {
1862
+ this._logger.error(`Please register ${PlotMakType.rectY} before use it`);
1863
+ }
1864
+ else {
1865
+ this._semanticMarks.push(mark);
1866
+ }
1867
+ return mark;
1868
+ }
1869
+ rect() {
1870
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.rect);
1871
+ if (!mark) {
1872
+ this._logger.error(`Please register ${PlotMakType.rect} before use it`);
1873
+ }
1874
+ else {
1875
+ this._semanticMarks.push(mark);
1876
+ }
1877
+ return mark;
1878
+ }
1879
+ rule() {
1880
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.rule);
1881
+ if (!mark) {
1882
+ this._logger.error(`Please register ${PlotMakType.rule} before use it`);
1883
+ }
1884
+ else {
1885
+ this._semanticMarks.push(mark);
1886
+ }
1887
+ return mark;
1888
+ }
1889
+ symbol() {
1890
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.symbol);
1891
+ if (!mark) {
1892
+ this._logger.error(`Please register ${PlotMakType.symbol} before use it`);
1893
+ }
1894
+ else {
1895
+ this._semanticMarks.push(mark);
1896
+ }
1897
+ return mark;
1898
+ }
1899
+ text() {
1900
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.text);
1901
+ if (!mark) {
1902
+ this._logger.error(`Please register ${PlotMakType.text} before use it`);
1903
+ }
1904
+ else {
1905
+ this._semanticMarks.push(mark);
1906
+ }
1907
+ return mark;
1908
+ }
1909
+ sankey() {
1910
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.sankey);
1911
+ if (!mark) {
1912
+ this._logger.error(`Please register ${PlotMakType.sankey} before use it`);
1913
+ }
1914
+ else {
1915
+ this._semanticMarks.push(mark);
1916
+ }
1917
+ return mark;
1918
+ }
1919
+ sunburst() {
1920
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.sunburst);
1921
+ if (!mark) {
1922
+ this._logger.error(`Please register ${PlotMakType.sunburst} before use it`);
1923
+ }
1924
+ else {
1925
+ this._semanticMarks.push(mark);
1926
+ }
1927
+ return mark;
1928
+ }
1929
+ tree() {
1930
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.tree);
1931
+ if (!mark) {
1932
+ this._logger.error(`Please register ${PlotMakType.tree} before use it`);
1933
+ }
1934
+ else {
1935
+ this._semanticMarks.push(mark);
1936
+ }
1937
+ return mark;
1938
+ }
1939
+ treemap() {
1940
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.treemap);
1941
+ if (!mark) {
1942
+ this._logger.error(`Please register ${PlotMakType.treemap} before use it`);
1943
+ }
1944
+ else {
1945
+ this._semanticMarks.push(mark);
1946
+ }
1947
+ return mark;
1948
+ }
1949
+ circlePacking() {
1950
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.circlePacking);
1951
+ if (!mark) {
1952
+ this._logger.error(`Please register ${PlotMakType.circlePacking} before use it`);
1953
+ }
1954
+ else {
1955
+ this._semanticMarks.push(mark);
1956
+ }
1957
+ return mark;
1958
+ }
1959
+ wordcloud() {
1960
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.wordcloud);
1961
+ if (!mark) {
1962
+ this._logger.error(`Please register ${PlotMakType.wordcloud} before use it`);
1963
+ }
1964
+ else {
1965
+ this._semanticMarks.push(mark);
1966
+ }
1967
+ return mark;
1968
+ }
1969
+ wordcloudShape() {
1970
+ const mark = vgrammar.Factory.createPlotMark(PlotMakType.wordcloudShape);
1971
+ if (!mark) {
1972
+ this._logger.error(`Please register ${PlotMakType.wordcloudShape} before use it`);
1973
+ }
1974
+ else {
1975
+ this._semanticMarks.push(mark);
1976
+ }
1977
+ return mark;
1978
+ }
1979
+ }
1980
+
1981
+ class ImageSemanticMark extends SemanticMark {
1982
+ constructor(id) {
1983
+ super(PlotMakType.image, id);
1984
+ }
1985
+ setMarkType() {
1986
+ return vgrammar.GrammarMarkType.image;
1987
+ }
1988
+ parseScaleOfEncodeX(option) {
1989
+ const res = super.parseScaleOfEncodeX(option);
1990
+ res.type = 'point';
1991
+ return res;
1992
+ }
1993
+ parseScaleByEncode(channel, option) {
1994
+ if (channel === 'src') {
1995
+ return {
1996
+ type: 'ordinal',
1997
+ id: this.getScaleId('src'),
1998
+ domain: {
1999
+ data: this.getDataIdOfMain(),
2000
+ field: option
2001
+ }
2002
+ };
2003
+ }
2004
+ return this.parseScaleOfCommonEncode(channel, option);
2005
+ }
2006
+ convertMarkEncode(encode) {
2007
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2008
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2009
+ const scaleXId = this.getScaleId('x');
2010
+ const scaleYId = this.getScaleId('y');
2011
+ const res = {
2012
+ image: markEncoder.src
2013
+ };
2014
+ if (markEncoder.src) {
2015
+ res.image = markEncoder.src;
2016
+ }
2017
+ if (vutils.isArray((_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field)) {
2018
+ const xAccessor = vgrammarUtil.field(markEncoder.x.field[0]);
2019
+ const x1Accessor = vgrammarUtil.field(markEncoder.x.field[1]);
2020
+ res.x = (datum, el, params) => {
2021
+ const scale = params[scaleXId];
2022
+ return Math.min(scale.scale(xAccessor(datum)), scale.scale(x1Accessor(datum)));
2023
+ };
2024
+ res.width = (datum, el, params) => {
2025
+ const scale = params[scaleXId];
2026
+ return Math.abs(scale.scale(xAccessor(datum)) - scale.scale(x1Accessor(datum)));
2027
+ };
2028
+ }
2029
+ else {
2030
+ const width = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : ImageSemanticMark.defaultSpec.width;
2031
+ const xAccessor = vgrammarUtil.field(markEncoder.x.field);
2032
+ res.x = (datum, el, params) => {
2033
+ const scale = params[scaleXId];
2034
+ return scale.scale(xAccessor(datum)) - width / 2;
2035
+ };
2036
+ res.width = width;
2037
+ }
2038
+ if (vutils.isArray((_d = markEncoder.y) === null || _d === void 0 ? void 0 : _d.field)) {
2039
+ const yAccessor = vgrammarUtil.field(markEncoder.y.field[0]);
2040
+ const y1Accessor = vgrammarUtil.field(markEncoder.y.field[1]);
2041
+ res.y = (datum, el, params) => {
2042
+ const scale = params[scaleYId];
2043
+ return Math.min(scale.scale(yAccessor(datum)), scale.scale(y1Accessor(datum)));
2044
+ };
2045
+ res.height = (datum, el, params) => {
2046
+ const scale = params[scaleYId];
2047
+ return Math.abs(scale.scale(yAccessor(datum)) - scale.scale(y1Accessor(datum)));
2048
+ };
2049
+ }
2050
+ else {
2051
+ const height = (_f = (_e = this.spec.style) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : ImageSemanticMark.defaultSpec.height;
2052
+ const yAccessor = vgrammarUtil.field(markEncoder.y.field);
2053
+ res.y = (datum, el, params) => {
2054
+ const scale = params[scaleXId];
2055
+ return scale.scale(yAccessor(datum)) - height / 2;
2056
+ };
2057
+ res.height = height;
2058
+ }
2059
+ if (markEncoder.color || markEncoder.group) {
2060
+ res.fill = (_g = markEncoder.color) !== null && _g !== void 0 ? _g : markEncoder.group;
2061
+ }
2062
+ else {
2063
+ res.fill = (_j = (_h = this.spec.style) === null || _h === void 0 ? void 0 : _h.fill) !== null && _j !== void 0 ? _j : vgrammar.getPalette()[0];
2064
+ }
2065
+ return res;
2066
+ }
2067
+ }
2068
+ ImageSemanticMark.type = PlotMakType.image;
2069
+ ImageSemanticMark.defaultSpec = { width: 10, height: 10 };
2070
+
2071
+ class PathSemanticMark extends SemanticMark {
2072
+ constructor(id) {
2073
+ super(PlotMakType.path, id);
2074
+ }
2075
+ setMarkType() {
2076
+ return vgrammar.GrammarMarkType.path;
2077
+ }
2078
+ parseScaleByEncode(channel, option) {
2079
+ return null;
2080
+ }
2081
+ convertMarkEncode(encode) {
2082
+ return null;
2083
+ }
2084
+ }
2085
+ PathSemanticMark.type = PlotMakType.path;
2086
+
2087
+ class PolygonSemanticMark extends SemanticMark {
2088
+ constructor(id) {
2089
+ super(PlotMakType.polygon, id);
2090
+ }
2091
+ setMarkType() {
2092
+ return vgrammar.GrammarMarkType.polygon;
2093
+ }
2094
+ parseScaleOfEncodeX(option) {
2095
+ const res = super.parseScaleOfEncodeX(option);
2096
+ res.type = 'point';
2097
+ return res;
2098
+ }
2099
+ parseScaleByEncode(channel, option) {
2100
+ return this.parseScaleOfCommonEncode(channel, option);
2101
+ }
2102
+ convertMarkEncode(encode) {
2103
+ var _a, _b, _c, _d, _e, _f, _g;
2104
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2105
+ const scaleXId = this.getScaleId('x');
2106
+ const scaleYId = this.getScaleId('y');
2107
+ const res = {};
2108
+ if (((_b = (_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field) === null || _b === void 0 ? void 0 : _b.length) && ((_d = (_c = markEncoder.y) === null || _c === void 0 ? void 0 : _c.field) === null || _d === void 0 ? void 0 : _d.length)) {
2109
+ const xAccessors = markEncoder.x.field.map((f) => vgrammarUtil.field(f));
2110
+ const yAccessors = markEncoder.y.field.map((f) => vgrammarUtil.field(f));
2111
+ res.points = (datum, el, params) => {
2112
+ const scaleX = params[scaleXId];
2113
+ const scaleY = params[scaleYId];
2114
+ const minLen = Math.min(xAccessors.length, yAccessors.length);
2115
+ const points = [];
2116
+ for (let i = 0; i < minLen; i++) {
2117
+ points.push({
2118
+ x: scaleX.scale(xAccessors[i](datum)),
2119
+ y: scaleY.scale(yAccessors[i](datum))
2120
+ });
2121
+ }
2122
+ return points;
2123
+ };
2124
+ }
2125
+ if (markEncoder.color || markEncoder.group) {
2126
+ res.fill = (_e = markEncoder.color) !== null && _e !== void 0 ? _e : markEncoder.group;
2127
+ }
2128
+ else {
2129
+ res.fill = (_g = (_f = this.spec.style) === null || _f === void 0 ? void 0 : _f.fill) !== null && _g !== void 0 ? _g : vgrammar.getPalette()[0];
2130
+ }
2131
+ return res;
2132
+ }
2133
+ }
2134
+ PolygonSemanticMark.type = PlotMakType.polygon;
2135
+
2136
+ class RectXSemanticMark extends SemanticMark {
2137
+ constructor(id) {
2138
+ super(PlotMakType.rectX, id);
2139
+ }
2140
+ setMarkType() {
2141
+ return vgrammar.GrammarMarkType.rect;
2142
+ }
2143
+ parseScaleByEncode(channel, option) {
2144
+ return this.parseScaleOfCommonEncode(channel, option);
2145
+ }
2146
+ setDefaultCrosshair() {
2147
+ return {
2148
+ x: { crosshairShape: 'rect' }
2149
+ };
2150
+ }
2151
+ setDefaultTooltip() {
2152
+ var _a;
2153
+ const encodeX = (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.x;
2154
+ return {
2155
+ content: vutils.isArray(encodeX)
2156
+ ? encodeX.map(entry => {
2157
+ return {
2158
+ value: entry
2159
+ };
2160
+ })
2161
+ : [
2162
+ {
2163
+ value: encodeX
2164
+ }
2165
+ ]
2166
+ };
2167
+ }
2168
+ convertMarkEncode(encode) {
2169
+ var _a, _b, _c, _d;
2170
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2171
+ const scaleXId = this.getScaleId('x');
2172
+ const res = {
2173
+ y: (datum, el, params) => {
2174
+ return 0;
2175
+ },
2176
+ y1: (datum, el, params) => {
2177
+ return params.viewBox.height();
2178
+ }
2179
+ };
2180
+ if (vutils.isArray((_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field)) {
2181
+ res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };
2182
+ res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };
2183
+ }
2184
+ else {
2185
+ const xAccessor = vgrammarUtil.field(markEncoder.x.field);
2186
+ res.x = (datum, el, params) => {
2187
+ const xVals = xAccessor(datum);
2188
+ const scale = params[scaleXId];
2189
+ return vutils.isArray(xVals) ? scale.scale(xVals[0]) : scale.scale(xVals);
2190
+ };
2191
+ res.x1 = (datum, el, params) => {
2192
+ const scale = params[scaleXId];
2193
+ const xVals = xAccessor(datum);
2194
+ if (vutils.isArray(xVals) && xVals.length > 1) {
2195
+ return scale.scale(xVals[1]);
2196
+ }
2197
+ const domain = scale.domain();
2198
+ const min = Math.min.apply(null, domain);
2199
+ const max = Math.max.apply(null, domain);
2200
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
2201
+ return scale.scale(baseValue);
2202
+ };
2203
+ }
2204
+ if (markEncoder.color || markEncoder.group) {
2205
+ res.fill = (_b = markEncoder.color) !== null && _b !== void 0 ? _b : markEncoder.group;
2206
+ }
2207
+ else {
2208
+ res.fill = (_d = (_c = this.spec.style) === null || _c === void 0 ? void 0 : _c.fill) !== null && _d !== void 0 ? _d : vgrammar.getPalette()[0];
2209
+ }
2210
+ return res;
2211
+ }
2212
+ }
2213
+ RectXSemanticMark.type = PlotMakType.rectX;
2214
+
2215
+ class RectYSemanticMark extends SemanticMark {
2216
+ constructor(id) {
2217
+ super(PlotMakType.rectY, id);
2218
+ }
2219
+ setMarkType() {
2220
+ return vgrammar.GrammarMarkType.rect;
2221
+ }
2222
+ parseScaleByEncode(channel, option) {
2223
+ return this.parseScaleOfCommonEncode(channel, option);
2224
+ }
2225
+ setDefaultCrosshair() {
2226
+ return {
2227
+ x: { crosshairShape: 'rect' }
2228
+ };
2229
+ }
2230
+ setDefaultTooltip() {
2231
+ var _a;
2232
+ const encodeY = (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.y;
2233
+ return {
2234
+ content: vutils.isArray(encodeY)
2235
+ ? encodeY.map(entry => {
2236
+ return {
2237
+ value: entry
2238
+ };
2239
+ })
2240
+ : [
2241
+ {
2242
+ value: encodeY
2243
+ }
2244
+ ]
2245
+ };
2246
+ }
2247
+ convertMarkEncode(encode) {
2248
+ var _a, _b, _c, _d;
2249
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2250
+ const scaleYId = this.getScaleId('y');
2251
+ const res = {
2252
+ x: (datum, el, params) => {
2253
+ return 0;
2254
+ },
2255
+ x1: (datum, el, params) => {
2256
+ return params.viewBox.width();
2257
+ }
2258
+ };
2259
+ if (vutils.isArray((_a = markEncoder.y) === null || _a === void 0 ? void 0 : _a.field)) {
2260
+ res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };
2261
+ res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };
2262
+ }
2263
+ else {
2264
+ const yAccessor = vgrammarUtil.field(markEncoder.y.field);
2265
+ res.y = (datum, el, params) => {
2266
+ const yVals = yAccessor(datum);
2267
+ const scale = params[scaleYId];
2268
+ return vutils.isArray(yVals) ? scale.scale(yVals[0]) : scale.scale(yVals);
2269
+ };
2270
+ res.y1 = (datum, el, params) => {
2271
+ const scale = params[scaleYId];
2272
+ const yVals = yAccessor(datum);
2273
+ if (vutils.isArray(yVals) && yVals.length > 1) {
2274
+ return scale.scale(yVals[1]);
2275
+ }
2276
+ const domain = scale.domain();
2277
+ const min = Math.min.apply(null, domain);
2278
+ const max = Math.max.apply(null, domain);
2279
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
2280
+ return scale.scale(baseValue);
2281
+ };
2282
+ }
2283
+ if (markEncoder.color || markEncoder.group) {
2284
+ res.fill = (_b = markEncoder.color) !== null && _b !== void 0 ? _b : markEncoder.group;
2285
+ }
2286
+ else {
2287
+ res.fill = (_d = (_c = this.spec.style) === null || _c === void 0 ? void 0 : _c.fill) !== null && _d !== void 0 ? _d : vgrammar.getPalette()[0];
2288
+ }
2289
+ return res;
2290
+ }
2291
+ }
2292
+ RectYSemanticMark.type = PlotMakType.rectY;
2293
+
2294
+ class RectSemanticMark extends SemanticMark {
2295
+ constructor(id) {
2296
+ super(PlotMakType.rect, id);
2297
+ }
2298
+ setMarkType() {
2299
+ return vgrammar.GrammarMarkType.rect;
2300
+ }
2301
+ parseScaleByEncode(channel, option) {
2302
+ return this.parseScaleOfCommonEncode(channel, option);
2303
+ }
2304
+ setDefaultCrosshair() {
2305
+ return {
2306
+ x: { crosshairShape: 'rect' }
2307
+ };
2308
+ }
2309
+ setDefaultTooltip() {
2310
+ var _a;
2311
+ const encodeY = (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.y;
2312
+ return {
2313
+ content: vutils.isArray(encodeY)
2314
+ ? encodeY.map(entry => {
2315
+ return {
2316
+ value: entry
2317
+ };
2318
+ })
2319
+ : [
2320
+ {
2321
+ value: encodeY
2322
+ }
2323
+ ]
2324
+ };
2325
+ }
2326
+ convertMarkEncode(encode) {
2327
+ var _a, _b, _c, _d, _e;
2328
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2329
+ const scaleXId = this.getScaleId('x');
2330
+ const scaleYId = this.getScaleId('y');
2331
+ const res = {};
2332
+ if (vutils.isArray((_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field)) {
2333
+ res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };
2334
+ res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };
2335
+ }
2336
+ else {
2337
+ const xAccessor = vgrammarUtil.field(markEncoder.x.field);
2338
+ res.x = (datum, el, params) => {
2339
+ const xVals = xAccessor(datum);
2340
+ const scale = params[scaleXId];
2341
+ return vutils.isArray(xVals) ? scale.scale(xVals[0]) : scale.scale(xVals);
2342
+ };
2343
+ res.x1 = (datum, el, params) => {
2344
+ const scale = params[scaleXId];
2345
+ const xVals = xAccessor(datum);
2346
+ if (vutils.isArray(xVals) && xVals.length > 1) {
2347
+ return scale.scale(xVals[1]);
2348
+ }
2349
+ const domain = scale.domain();
2350
+ const min = Math.min.apply(null, domain);
2351
+ const max = Math.max.apply(null, domain);
2352
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
2353
+ return scale.scale(baseValue);
2354
+ };
2355
+ }
2356
+ if (vutils.isArray((_b = markEncoder.y) === null || _b === void 0 ? void 0 : _b.field)) {
2357
+ res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };
2358
+ res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };
2359
+ }
2360
+ else {
2361
+ const yAccessor = vgrammarUtil.field(markEncoder.y.field);
2362
+ res.y = (datum, el, params) => {
2363
+ const yVals = yAccessor(datum);
2364
+ const scale = params[scaleYId];
2365
+ return vutils.isArray(yVals) ? scale.scale(yVals[0]) : scale.scale(yVals);
2366
+ };
2367
+ res.y1 = (datum, el, params) => {
2368
+ const scale = params[scaleYId];
2369
+ const yVals = yAccessor(datum);
2370
+ if (vutils.isArray(yVals) && yVals.length > 1) {
2371
+ return scale.scale(yVals[1]);
2372
+ }
2373
+ const domain = scale.domain();
2374
+ const min = Math.min.apply(null, domain);
2375
+ const max = Math.max.apply(null, domain);
2376
+ const baseValue = min > 0 ? min : max < 0 ? max : 0;
2377
+ return scale.scale(baseValue);
2378
+ };
2379
+ }
2380
+ if (markEncoder.color || markEncoder.group) {
2381
+ res.fill = (_c = markEncoder.color) !== null && _c !== void 0 ? _c : markEncoder.group;
2382
+ }
2383
+ else {
2384
+ res.fill = (_e = (_d = this.spec.style) === null || _d === void 0 ? void 0 : _d.fill) !== null && _e !== void 0 ? _e : vgrammar.getPalette()[0];
2385
+ }
2386
+ return res;
2387
+ }
2388
+ }
2389
+ RectSemanticMark.type = PlotMakType.rect;
2390
+
2391
+ class Rule extends SemanticMark {
2392
+ constructor(id) {
2393
+ super(PlotMakType.rule, id);
2394
+ }
2395
+ setMarkType() {
2396
+ return vgrammar.GrammarMarkType.rule;
2397
+ }
2398
+ parseScaleOfEncodeX(option) {
2399
+ const res = super.parseScaleOfEncodeX(option);
2400
+ res.type = 'point';
2401
+ return res;
2402
+ }
2403
+ parseScaleByEncode(channel, option) {
2404
+ return this.parseScaleOfCommonEncode(channel, option);
2405
+ }
2406
+ convertMarkEncode(encode) {
2407
+ var _a, _b, _c, _d, _e;
2408
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2409
+ let res;
2410
+ if (vutils.isArray((_a = markEncoder.x) === null || _a === void 0 ? void 0 : _a.field)) {
2411
+ res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };
2412
+ res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };
2413
+ }
2414
+ else {
2415
+ res.x = res.x1 = markEncoder.x;
2416
+ }
2417
+ if (vutils.isArray((_b = markEncoder.y) === null || _b === void 0 ? void 0 : _b.field)) {
2418
+ res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };
2419
+ res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };
2420
+ }
2421
+ else {
2422
+ res.y = res.y1 = markEncoder.y;
2423
+ }
2424
+ if (markEncoder.color || markEncoder.group) {
2425
+ res.stroke = (_c = markEncoder.color) !== null && _c !== void 0 ? _c : markEncoder.group;
2426
+ }
2427
+ else {
2428
+ res.stroke = (_e = (_d = this.spec.style) === null || _d === void 0 ? void 0 : _d.stroke) !== null && _e !== void 0 ? _e : vgrammar.getPalette()[0];
2429
+ }
2430
+ return res;
2431
+ }
2432
+ }
2433
+ Rule.type = PlotMakType.rule;
2434
+
2435
+ class SymbolSemanticMark extends SemanticMark {
2436
+ constructor(id) {
2437
+ super(PlotMakType.symbol, id);
2438
+ }
2439
+ setMarkType() {
2440
+ return vgrammar.GrammarMarkType.symbol;
2441
+ }
2442
+ parseScaleOfEncodeX(option) {
2443
+ const res = super.parseScaleOfEncodeX(option);
2444
+ res.type = 'point';
2445
+ return res;
2446
+ }
2447
+ parseScaleByEncode(channel, option) {
2448
+ if (channel === 'size') {
2449
+ return {
2450
+ type: 'linear',
2451
+ id: this.getScaleId('size'),
2452
+ domain: {
2453
+ data: this.getDataIdOfFiltered(),
2454
+ field: option
2455
+ },
2456
+ range: [SymbolSemanticMark.defaultSpec.size, SymbolSemanticMark.defaultSpec.size]
2457
+ };
2458
+ }
2459
+ if (channel === 'shape') {
2460
+ return {
2461
+ type: 'ordinal',
2462
+ id: this.getScaleId('shape'),
2463
+ domain: {
2464
+ data: this.getDataIdOfMain(),
2465
+ field: option
2466
+ }
2467
+ };
2468
+ }
2469
+ return this.parseScaleOfCommonEncode(channel, option);
2470
+ }
2471
+ convertMarkEncode(encode) {
2472
+ var _a, _b, _c;
2473
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2474
+ const res = {
2475
+ x: markEncoder.x,
2476
+ y: markEncoder.y
2477
+ };
2478
+ if (markEncoder.shape) {
2479
+ res.symbolType = markEncoder.shape;
2480
+ }
2481
+ if (markEncoder.size) {
2482
+ res.size = markEncoder.size;
2483
+ }
2484
+ if (markEncoder.color || markEncoder.group) {
2485
+ res.fill = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
2486
+ }
2487
+ else {
2488
+ res.fill = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
2489
+ }
2490
+ return res;
2491
+ }
2492
+ }
2493
+ SymbolSemanticMark.defaultSpec = {
2494
+ size: 10
2495
+ };
2496
+ SymbolSemanticMark.type = PlotMakType.symbol;
2497
+
2498
+ class TextSemanticMark extends SemanticMark {
2499
+ constructor(id) {
2500
+ super(PlotMakType.text, id);
2501
+ }
2502
+ setMarkType() {
2503
+ return vgrammar.GrammarMarkType.text;
2504
+ }
2505
+ parseScaleOfEncodeX(option) {
2506
+ const res = super.parseScaleOfEncodeX(option);
2507
+ res.type = 'point';
2508
+ return res;
2509
+ }
2510
+ parseScaleByEncode(channel, option) {
2511
+ return this.parseScaleOfCommonEncode(channel, option);
2512
+ }
2513
+ convertMarkEncode(encode) {
2514
+ var _a, _b, _c;
2515
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2516
+ const res = markEncoder;
2517
+ if (markEncoder.color || markEncoder.group) {
2518
+ res.fill = (_a = markEncoder.color) !== null && _a !== void 0 ? _a : markEncoder.group;
2519
+ }
2520
+ else {
2521
+ res.fill = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
2522
+ }
2523
+ return res;
2524
+ }
2525
+ }
2526
+ TextSemanticMark.type = PlotMakType.text;
2527
+
2528
+ class SankeySemanticMark extends SemanticMark {
2529
+ constructor(id) {
2530
+ super(PlotMakType.sankey, id);
2531
+ if (!vgrammar.getTransform(PlotMakType.sankey)) {
2532
+ this._logger.error(`Please add this line of code: import { registerSankeyTransforms } from '@visactor/vgrammar-sankey';
2533
+ and run registerSankeyTransforms() before use sankey`);
2534
+ }
2535
+ if (!vgrammar.getGlyph('linkPath')) {
2536
+ this._logger.error(`
2537
+ Please add this line of code: import { registerLinkPathGlyph } from '@visactor/vgrammar';
2538
+ add run registerLinkPathGlyph() before use sankey
2539
+ `);
2540
+ }
2541
+ }
2542
+ setMarkType() {
2543
+ return vgrammar.GrammarMarkType.rect;
2544
+ }
2545
+ setDefaultDataTransform() {
2546
+ var _a;
2547
+ return [
2548
+ {
2549
+ type: 'sankey',
2550
+ width: { signal: 'viewWidth' },
2551
+ height: { signal: 'viewHeight' },
2552
+ nodeKey: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.node
2553
+ }
2554
+ ];
2555
+ }
2556
+ getDataIdOfLink() {
2557
+ var _a, _b;
2558
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-data-link`;
2559
+ }
2560
+ setMultipleData() {
2561
+ return [
2562
+ {
2563
+ id: this.getDataIdOfFiltered(),
2564
+ transform: [
2565
+ {
2566
+ type: 'map',
2567
+ all: true,
2568
+ callback: (datum) => {
2569
+ return datum[0].nodes;
2570
+ }
2571
+ }
2572
+ ]
2573
+ },
2574
+ {
2575
+ source: this.getDataIdOfMain(),
2576
+ id: this.getDataIdOfLink(),
2577
+ transform: [
2578
+ {
2579
+ type: 'map',
2580
+ all: true,
2581
+ callback: (datum) => {
2582
+ return datum[0].links;
2583
+ }
2584
+ }
2585
+ ]
2586
+ }
2587
+ ];
2588
+ }
2589
+ parseScaleByEncode(channel, option) {
2590
+ if (channel === 'color') {
2591
+ return {
2592
+ type: 'ordinal',
2593
+ id: this.getScaleId('color'),
2594
+ domain: {
2595
+ data: this.getDataIdOfFiltered(),
2596
+ field: option
2597
+ },
2598
+ range: vgrammar.getPalette()
2599
+ };
2600
+ }
2601
+ return null;
2602
+ }
2603
+ convertMarkEncode(encode) {
2604
+ var _a, _b, _c;
2605
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2606
+ const res = {
2607
+ x: { field: 'x0' },
2608
+ x1: { field: 'x1' },
2609
+ y: { field: 'y0' },
2610
+ y1: { field: 'y1' }
2611
+ };
2612
+ if (markEncoder.color) {
2613
+ const scaleColorId = this.getScaleId('color');
2614
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
2615
+ res.fill = (datum, el, params) => {
2616
+ const scale = params[scaleColorId];
2617
+ return scale.scale(colorAccessor(datum === null || datum === void 0 ? void 0 : datum.datum));
2618
+ };
2619
+ }
2620
+ else {
2621
+ res.fill = (_c = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.nodeStyle) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
2622
+ }
2623
+ return res;
2624
+ }
2625
+ setMainMarkSpec() {
2626
+ return { key: 'key' };
2627
+ }
2628
+ setLabelTextGetter(channel, option) {
2629
+ const textGetter = vgrammarUtil.field(channel);
2630
+ return (datum, el, params) => {
2631
+ return textGetter(datum.datum);
2632
+ };
2633
+ }
2634
+ setMultiMarksSpec() {
2635
+ var _a;
2636
+ return [
2637
+ {
2638
+ id: `${this.getMarkId()}-link`,
2639
+ type: 'glyph',
2640
+ glyphType: 'linkPath',
2641
+ from: {
2642
+ data: this.getDataIdOfLink()
2643
+ },
2644
+ layout: {
2645
+ position: 'content',
2646
+ skipBeforeLayouted: true
2647
+ },
2648
+ key: 'index',
2649
+ dependency: this.viewSpec.scales.map(scale => scale.id).concat(vgrammar.SIGNAL_VIEW_BOX),
2650
+ animation: this.convertMarkAnimation(),
2651
+ encode: Object.assign({}, this.spec.state, {
2652
+ enter: Object.assign({
2653
+ backgroundStyle: { fillColor: '#ccc', fillOpacity: 0.2 },
2654
+ fillOpacity: 0.8,
2655
+ round: true
2656
+ }, (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.linkStyle),
2657
+ update: (datum, el, params) => {
2658
+ var _a, _b, _c;
2659
+ return {
2660
+ direction: datum.vertical ? 'vertical' : 'horizontal',
2661
+ x0: datum.x0,
2662
+ x1: datum.x1,
2663
+ y0: datum.y0,
2664
+ y1: datum.y1,
2665
+ thickness: datum.thickness,
2666
+ fill: (_c = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.linkStyle) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0]
2667
+ };
2668
+ }
2669
+ })
2670
+ }
2671
+ ];
2672
+ }
2673
+ }
2674
+ SankeySemanticMark.type = PlotMakType.sankey;
2675
+
2676
+ class SunburstSemanticMark extends SemanticMark {
2677
+ constructor(id) {
2678
+ super(PlotMakType.sunburst, id);
2679
+ if (!vgrammar.getTransform('sunburst')) {
2680
+ this._logger.error(`Please add this line of code: import { registerSunburstTransforms } from 'vgrammar-hierarchy':
2681
+ and run registerSunburstTransforms() before use sunburst chart`);
2682
+ }
2683
+ }
2684
+ setMarkType() {
2685
+ return vgrammar.GrammarMarkType.arc;
2686
+ }
2687
+ setDefaultDataTransform() {
2688
+ var _a;
2689
+ return [
2690
+ {
2691
+ type: 'sunburst',
2692
+ width: { signal: 'viewWidth' },
2693
+ height: { signal: 'viewHeight' },
2694
+ nodeKey: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.node,
2695
+ flatten: true
2696
+ }
2697
+ ];
2698
+ }
2699
+ getDataIdOfLabel() {
2700
+ var _a, _b;
2701
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-data-link`;
2702
+ }
2703
+ setMultipleData() {
2704
+ if (this.spec.label) {
2705
+ return [
2706
+ {
2707
+ source: this.getDataIdOfFiltered(),
2708
+ id: this.getDataIdOfLabel(),
2709
+ transform: [
2710
+ {
2711
+ type: 'filter',
2712
+ callback: (datum) => {
2713
+ return !!datum.label;
2714
+ }
2715
+ }
2716
+ ]
2717
+ }
2718
+ ];
2719
+ }
2720
+ return null;
2721
+ }
2722
+ parseScaleByEncode(channel, option) {
2723
+ if (channel === 'color') {
2724
+ return {
2725
+ type: 'ordinal',
2726
+ id: this.getScaleId('color'),
2727
+ domain: {
2728
+ data: this.getDataIdOfFiltered(),
2729
+ field: option
2730
+ },
2731
+ range: vgrammar.getPalette()
2732
+ };
2733
+ }
2734
+ return null;
2735
+ }
2736
+ convertMarkEncode(encode) {
2737
+ var _a, _b;
2738
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2739
+ const res = {
2740
+ x: { field: 'x' },
2741
+ y: { field: 'y' },
2742
+ innerRadius: { field: 'innerRadius' },
2743
+ outerRadius: { field: 'outerRadius' },
2744
+ startAngle: { field: 'startAngle' },
2745
+ endAngle: { field: 'endAngle' }
2746
+ };
2747
+ if (markEncoder.color) {
2748
+ const scaleColorId = this.getScaleId('color');
2749
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
2750
+ res.fill = (datum, el, params) => {
2751
+ const scale = params[scaleColorId];
2752
+ return (datum === null || datum === void 0 ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;
2753
+ };
2754
+ }
2755
+ else {
2756
+ res.fill = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.fill) !== null && _b !== void 0 ? _b : vgrammar.getPalette()[0];
2757
+ }
2758
+ return res;
2759
+ }
2760
+ setMainMarkEnterEncode() {
2761
+ var _a;
2762
+ return (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.nodeStyle;
2763
+ }
2764
+ setMainMarkSpec() {
2765
+ return { key: 'key' };
2766
+ }
2767
+ parseLabelSpec() {
2768
+ return [];
2769
+ }
2770
+ setMultiMarksSpec() {
2771
+ const label = this.spec.label;
2772
+ if (!label) {
2773
+ return null;
2774
+ }
2775
+ return Object.keys(label).map(key => {
2776
+ const textGetter = vgrammarUtil.field(key);
2777
+ return {
2778
+ id: `${this.getMarkId()}-text-${key}`,
2779
+ type: 'text',
2780
+ from: {
2781
+ data: this.getDataIdOfLabel()
2782
+ },
2783
+ layout: {
2784
+ position: 'content',
2785
+ skipBeforeLayouted: true
2786
+ },
2787
+ key: 'flattenIndex',
2788
+ dependency: this.viewSpec.scales.map(scale => scale.id).concat(vgrammar.SIGNAL_VIEW_BOX),
2789
+ animation: this.convertMarkAnimation(),
2790
+ encode: {
2791
+ enter: label[key].textStyle,
2792
+ update: (datum, el, params) => {
2793
+ return {
2794
+ x: datum.label.x,
2795
+ y: datum.label.y,
2796
+ textAlign: datum.label.textAlign,
2797
+ textBaseline: datum.label.textBaseline,
2798
+ text: textGetter(datum.datum[datum.datum.length - 1]),
2799
+ angle: datum.label.angle,
2800
+ maxLineWidth: datum.label.maxLineWidth
2801
+ };
2802
+ }
2803
+ }
2804
+ };
2805
+ });
2806
+ }
2807
+ }
2808
+ SunburstSemanticMark.type = PlotMakType.sunburst;
2809
+
2810
+ class TreemapSemanticMark extends SemanticMark {
2811
+ constructor(id) {
2812
+ super(PlotMakType.treemap, id);
2813
+ if (!vgrammar.getTransform('treemap')) {
2814
+ this._logger.error(`Please add this line of code: import { registerTreemapTransforms } from 'vgrammar-hierarchy';
2815
+ and run registerTreemapTransforms() before use treemap`);
2816
+ }
2817
+ }
2818
+ setMarkType() {
2819
+ return vgrammar.GrammarMarkType.rect;
2820
+ }
2821
+ setDefaultDataTransform() {
2822
+ var _a;
2823
+ return [
2824
+ {
2825
+ type: 'treemap',
2826
+ width: { signal: 'viewWidth' },
2827
+ height: { signal: 'viewHeight' },
2828
+ nodeKey: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.node,
2829
+ flatten: true
2830
+ }
2831
+ ];
2832
+ }
2833
+ parseScaleByEncode(channel, option) {
2834
+ if (channel === 'color') {
2835
+ return {
2836
+ type: 'ordinal',
2837
+ id: this.getScaleId('color'),
2838
+ domain: {
2839
+ data: this.getDataIdOfFiltered(),
2840
+ field: option
2841
+ },
2842
+ range: vgrammar.getPalette()
2843
+ };
2844
+ }
2845
+ return null;
2846
+ }
2847
+ convertMarkEncode(encode) {
2848
+ var _a, _b;
2849
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2850
+ const res = {
2851
+ x: { field: 'x0' },
2852
+ x1: { field: 'x1' },
2853
+ y: { field: 'y0' },
2854
+ y1: { field: 'y1' }
2855
+ };
2856
+ if (markEncoder.color) {
2857
+ const scaleColorId = this.getScaleId('color');
2858
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
2859
+ res.fill = (datum, el, params) => {
2860
+ const scale = params[scaleColorId];
2861
+ return (datum === null || datum === void 0 ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;
2862
+ };
2863
+ }
2864
+ else {
2865
+ res.fill = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.fill) !== null && _b !== void 0 ? _b : vgrammar.getPalette()[0];
2866
+ }
2867
+ return res;
2868
+ }
2869
+ setMainMarkSpec() {
2870
+ return { key: 'key' };
2871
+ }
2872
+ parseLabelSpec() {
2873
+ return [];
2874
+ }
2875
+ setMultiMarksSpec() {
2876
+ const label = this.spec.label;
2877
+ if (!label) {
2878
+ return null;
2879
+ }
2880
+ return Object.keys(label).map(key => {
2881
+ const textGetter = vgrammarUtil.field(key);
2882
+ return {
2883
+ id: `${this.getMarkId()}-text-${key}`,
2884
+ type: 'text',
2885
+ from: {
2886
+ data: this.getDataIdOfFiltered()
2887
+ },
2888
+ layout: {
2889
+ position: 'content',
2890
+ skipBeforeLayouted: true
2891
+ },
2892
+ key: 'flattenIndex',
2893
+ dependency: this.viewSpec.scales.map(scale => scale.id).concat(vgrammar.SIGNAL_VIEW_BOX),
2894
+ animation: this.convertMarkAnimation(),
2895
+ encode: {
2896
+ enter: Object.assign({
2897
+ textAlign: 'center',
2898
+ textBaseline: 'middle'
2899
+ }, label[key].textStyle),
2900
+ update: (datum, el, params) => {
2901
+ return {
2902
+ x: datum.labelRect ? (datum.labelRect.x0 + datum.labelRect.x1) / 2 : (datum.x0 + datum.x1) / 2,
2903
+ y: datum.labelRect ? (datum.labelRect.y0 + datum.labelRect.y1) / 2 : (datum.y0 + datum.y1) / 2,
2904
+ text: textGetter(datum.datum[datum.datum.length - 1])
2905
+ };
2906
+ }
2907
+ }
2908
+ };
2909
+ });
2910
+ }
2911
+ }
2912
+ TreemapSemanticMark.type = PlotMakType.treemap;
2913
+
2914
+ class CirclePackingSemanticMark extends SemanticMark {
2915
+ constructor(id) {
2916
+ super(PlotMakType.circlePacking, id);
2917
+ if (!vgrammar.getTransform(PlotMakType.circlePacking)) {
2918
+ this._logger.error(`Please add this line of code: import { registerCirclePackingTransforms } from '@visactor/vgrammar-hierarchy';
2919
+ and run registerCirclePackingTransforms() before use treemap chart`);
2920
+ }
2921
+ }
2922
+ setMarkType() {
2923
+ return vgrammar.GrammarMarkType.circle;
2924
+ }
2925
+ setDefaultDataTransform() {
2926
+ var _a;
2927
+ return [
2928
+ {
2929
+ type: PlotMakType.circlePacking,
2930
+ width: { signal: 'viewWidth' },
2931
+ height: { signal: 'viewHeight' },
2932
+ nodeKey: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.node,
2933
+ flatten: true
2934
+ }
2935
+ ];
2936
+ }
2937
+ parseScaleByEncode(channel, option) {
2938
+ if (channel === 'color') {
2939
+ return {
2940
+ type: 'ordinal',
2941
+ id: this.getScaleId('color'),
2942
+ domain: {
2943
+ data: this.getDataIdOfFiltered(),
2944
+ field: option
2945
+ },
2946
+ range: vgrammar.getPalette()
2947
+ };
2948
+ }
2949
+ return null;
2950
+ }
2951
+ convertMarkEncode(encode) {
2952
+ var _a, _b;
2953
+ const markEncoder = this.convertSimpleMarkEncode(encode);
2954
+ const res = {
2955
+ x: { field: 'x' },
2956
+ y: { field: 'y' },
2957
+ radius: { field: 'radius' }
2958
+ };
2959
+ if (markEncoder.color) {
2960
+ const scaleColorId = this.getScaleId('color');
2961
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
2962
+ res.fill = (datum, el, params) => {
2963
+ const scale = params[scaleColorId];
2964
+ return (datum === null || datum === void 0 ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;
2965
+ };
2966
+ }
2967
+ else {
2968
+ res.fill = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.fill) !== null && _b !== void 0 ? _b : vgrammar.getPalette()[0];
2969
+ }
2970
+ return res;
2971
+ }
2972
+ setMainMarkSpec() {
2973
+ return { key: 'key' };
2974
+ }
2975
+ setLabelTextGetter(channel, option) {
2976
+ const textGetter = vgrammarUtil.field(channel);
2977
+ return (datum, el, params) => {
2978
+ return textGetter(datum.datum[datum.datum.length - 1]);
2979
+ };
2980
+ }
2981
+ }
2982
+ CirclePackingSemanticMark.type = PlotMakType.circlePacking;
2983
+
2984
+ class TreeSemanticMark extends SemanticMark {
2985
+ constructor(id) {
2986
+ super(PlotMakType.tree, id);
2987
+ if (!vgrammar.getTransform(PlotMakType.tree)) {
2988
+ this._logger.error(`Please add this line of code: import { registerTreeTransforms } from 'vgrammar-hierarchy',
2989
+ and run registerTreeTransforms() before use tree`);
2990
+ }
2991
+ if (!vgrammar.getGlyph('treePath')) {
2992
+ this._logger.error(`Please add this line of code: import { registerTreePathGlyph } from '@visactor/vgrammar';
2993
+ and run registerTreePathGlyph() before use tree`);
2994
+ }
2995
+ }
2996
+ setMarkType() {
2997
+ return vgrammar.GrammarMarkType.symbol;
2998
+ }
2999
+ setDefaultDataTransform() {
3000
+ var _a;
3001
+ return [
3002
+ {
3003
+ type: 'tree',
3004
+ width: { signal: 'viewWidth' },
3005
+ height: { signal: 'viewHeight' },
3006
+ nodeKey: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.node,
3007
+ flatten: true
3008
+ }
3009
+ ];
3010
+ }
3011
+ getDataIdOfLink() {
3012
+ var _a, _b;
3013
+ return `${(_b = (_a = this.spec.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.spec.id}-data-link`;
3014
+ }
3015
+ setMultipleData() {
3016
+ return [
3017
+ {
3018
+ id: this.getDataIdOfFiltered(),
3019
+ transform: [
3020
+ {
3021
+ type: 'map',
3022
+ all: true,
3023
+ callback: (datum) => {
3024
+ return datum[0].nodes;
3025
+ }
3026
+ }
3027
+ ]
3028
+ },
3029
+ {
3030
+ source: this.getDataIdOfMain(),
3031
+ id: this.getDataIdOfLink(),
3032
+ transform: [
3033
+ {
3034
+ type: 'map',
3035
+ all: true,
3036
+ callback: (datum) => {
3037
+ return datum[0].links;
3038
+ }
3039
+ }
3040
+ ]
3041
+ }
3042
+ ];
3043
+ }
3044
+ parseScaleByEncode(channel, option) {
3045
+ if (channel === 'color') {
3046
+ return {
3047
+ type: 'ordinal',
3048
+ id: this.getScaleId('color'),
3049
+ domain: {
3050
+ data: this.getDataIdOfFiltered(),
3051
+ field: option
3052
+ },
3053
+ range: vgrammar.getPalette()
3054
+ };
3055
+ }
3056
+ return null;
3057
+ }
3058
+ convertMarkEncode(encode) {
3059
+ var _a, _b;
3060
+ const markEncoder = this.convertSimpleMarkEncode(encode);
3061
+ const res = {
3062
+ x: { field: 'x' },
3063
+ y: { field: 'y' }
3064
+ };
3065
+ if (markEncoder.color) {
3066
+ const scaleColorId = this.getScaleId('color');
3067
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
3068
+ res.fill = (datum, el, params) => {
3069
+ const scale = params[scaleColorId];
3070
+ return (datum === null || datum === void 0 ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;
3071
+ };
3072
+ }
3073
+ else {
3074
+ res.fill = (_b = (_a = this.spec.style) === null || _a === void 0 ? void 0 : _a.fill) !== null && _b !== void 0 ? _b : vgrammar.getPalette()[0];
3075
+ }
3076
+ return res;
3077
+ }
3078
+ setLabelTextGetter(channel, option) {
3079
+ const textGetter = vgrammarUtil.field(channel);
3080
+ return (datum, el, params) => {
3081
+ return textGetter(datum.datum[datum.datum.length - 1]);
3082
+ };
3083
+ }
3084
+ setMainMarkSpec() {
3085
+ return { key: 'key' };
3086
+ }
3087
+ setMultiMarksSpec() {
3088
+ const label = this.spec.label;
3089
+ if (!label) {
3090
+ return null;
3091
+ }
3092
+ const marks = [];
3093
+ marks.push({
3094
+ type: 'glyph',
3095
+ glyphType: 'treePath',
3096
+ from: { data: this.getDataIdOfLink() },
3097
+ key: 'key',
3098
+ zIndex: -1,
3099
+ encode: {
3100
+ update: {
3101
+ x0: { field: 'x0' },
3102
+ x1: { field: 'x1' },
3103
+ y0: { field: 'y0' },
3104
+ y1: { field: 'y1' },
3105
+ thickness: 1,
3106
+ round: true,
3107
+ stroke: '#333'
3108
+ }
3109
+ }
3110
+ });
3111
+ return marks;
3112
+ }
3113
+ }
3114
+ TreeSemanticMark.type = PlotMakType.tree;
3115
+
3116
+ class WordcloudSemanticMark extends SemanticMark {
3117
+ constructor(id) {
3118
+ super(PlotMakType.wordcloud, id);
3119
+ if (!vgrammar.getTransform(PlotMakType.wordcloud)) {
3120
+ this._logger.error(`Please add this line of code:
3121
+ 'import { registerWordCloudTransforms } from '@visactor/vgrammar-wordcloud';
3122
+ and run registerWordCloudTransforms() before use wordcloud`);
3123
+ }
3124
+ }
3125
+ setMarkType() {
3126
+ return vgrammar.GrammarMarkType.text;
3127
+ }
3128
+ setDefaultMarkTransform() {
3129
+ var _a;
3130
+ return [
3131
+ {
3132
+ type: 'wordcloud',
3133
+ size: {
3134
+ callback: (params) => {
3135
+ return [params.viewBox.width(), params.viewBox.height()];
3136
+ },
3137
+ dependency: ['viewBox']
3138
+ },
3139
+ text: { field: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.text }
3140
+ }
3141
+ ];
3142
+ }
3143
+ parseScaleByEncode(channel, option) {
3144
+ if (channel === 'color') {
3145
+ return {
3146
+ type: 'ordinal',
3147
+ id: this.getScaleId('color'),
3148
+ domain: {
3149
+ data: this.getDataIdOfFiltered(),
3150
+ field: option
3151
+ },
3152
+ range: vgrammar.getPalette()
3153
+ };
3154
+ }
3155
+ return null;
3156
+ }
3157
+ convertMarkEncode(encode) {
3158
+ var _a, _b, _c;
3159
+ const markEncoder = this.convertSimpleMarkEncode(encode);
3160
+ const res = {
3161
+ x: { field: 'x' },
3162
+ y: { field: 'y' },
3163
+ angle: { field: 'angle' },
3164
+ fontSize: { field: 'fontSize' },
3165
+ fontStyle: { field: 'fontStyle' },
3166
+ fontFamily: { field: 'fontFamily' },
3167
+ fontWeight: { field: 'fontWeight' },
3168
+ text: { field: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.text }
3169
+ };
3170
+ if (markEncoder.color) {
3171
+ const scaleColorId = this.getScaleId('color');
3172
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
3173
+ res.fill = (datum, el, params) => {
3174
+ const scale = params[scaleColorId];
3175
+ return scale.scale(colorAccessor(datum));
3176
+ };
3177
+ }
3178
+ else {
3179
+ res.fill = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
3180
+ }
3181
+ return res;
3182
+ }
3183
+ parseLabelSpec() {
3184
+ return [];
3185
+ }
3186
+ }
3187
+ WordcloudSemanticMark.type = PlotMakType.wordcloud;
3188
+
3189
+ class WordcloudShapeSemanticMark extends SemanticMark {
3190
+ constructor(id) {
3191
+ super(PlotMakType.wordcloudShape, id);
3192
+ if (!vgrammar.getTransform(PlotMakType.wordcloudShape)) {
3193
+ this._logger.error(`Please add this line of code:
3194
+ import { registerWordCloudShapeTransforms } from '@visactor/vgrammar-wordcloud-shape';
3195
+ and run registerWordCloudShapeTransforms() before use wordcloud-shape`);
3196
+ }
3197
+ }
3198
+ setMarkType() {
3199
+ return vgrammar.GrammarMarkType.text;
3200
+ }
3201
+ setDefaultDataTransform() {
3202
+ var _a;
3203
+ return [
3204
+ {
3205
+ type: 'wordcloudShape',
3206
+ size: {
3207
+ callback: (params) => {
3208
+ return [params.viewBox.width(), params.viewBox.height()];
3209
+ },
3210
+ dependency: ['viewBox']
3211
+ },
3212
+ colorList: vgrammar.getPalette(),
3213
+ text: { field: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.text }
3214
+ }
3215
+ ];
3216
+ }
3217
+ parseScaleByEncode(channel, option) {
3218
+ if (channel === 'color') {
3219
+ return {
3220
+ type: 'ordinal',
3221
+ id: this.getScaleId('color'),
3222
+ domain: {
3223
+ data: this.getDataIdOfFiltered(),
3224
+ field: option
3225
+ },
3226
+ range: vgrammar.getPalette()
3227
+ };
3228
+ }
3229
+ return null;
3230
+ }
3231
+ convertMarkEncode(encode) {
3232
+ var _a, _b, _c;
3233
+ const markEncoder = this.convertSimpleMarkEncode(encode);
3234
+ const res = {
3235
+ x: { field: 'x' },
3236
+ y: { field: 'y' },
3237
+ angle: { field: 'angle' },
3238
+ fontSize: { field: 'fontSize' },
3239
+ fontStyle: { field: 'fontStyle' },
3240
+ fontFamily: { field: 'fontFamily' },
3241
+ fontWeight: { field: 'fontWeight' },
3242
+ fillOpacity: { field: 'opacity' },
3243
+ text: { field: (_a = this.spec.encode) === null || _a === void 0 ? void 0 : _a.text }
3244
+ };
3245
+ if (markEncoder.color) {
3246
+ const scaleColorId = this.getScaleId('color');
3247
+ const colorAccessor = vgrammarUtil.field(markEncoder.color.field);
3248
+ res.fill = (datum, el, params) => {
3249
+ const scale = params[scaleColorId];
3250
+ return scale.scale(colorAccessor(datum));
3251
+ };
3252
+ }
3253
+ else {
3254
+ res.fill = (_c = (_b = this.spec.style) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : vgrammar.getPalette()[0];
3255
+ }
3256
+ return res;
3257
+ }
3258
+ parseLabelSpec() {
3259
+ return [];
3260
+ }
3261
+ }
3262
+ WordcloudShapeSemanticMark.type = PlotMakType.wordcloudShape;
3263
+
3264
+ Plot.useMarks([
3265
+ Interval,
3266
+ Line,
3267
+ Cell,
3268
+ RuleX,
3269
+ RuleY,
3270
+ Area,
3271
+ ImageSemanticMark,
3272
+ PathSemanticMark,
3273
+ PolygonSemanticMark,
3274
+ RectSemanticMark,
3275
+ RectXSemanticMark,
3276
+ RectYSemanticMark,
3277
+ Rule,
3278
+ SymbolSemanticMark,
3279
+ TextSemanticMark,
3280
+ SankeySemanticMark,
3281
+ SunburstSemanticMark,
3282
+ TreemapSemanticMark,
3283
+ CirclePackingSemanticMark,
3284
+ TreeSemanticMark,
3285
+ WordcloudSemanticMark,
3286
+ WordcloudShapeSemanticMark
3287
+ ]);
3288
+
3289
+ exports.Plot = Plot;
3290
+
3291
+ }));