@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
@@ -0,0 +1,833 @@
1
+ import { Logger, array, isArray, isBoolean, isNil, isPlainObject } from "@visactor/vutils";
2
+
3
+ import { isContinuous, isDiscrete } from "@visactor/vscale";
4
+
5
+ import { getPalette, ComponentEnum, getTheme, SIGNAL_VIEW_BOX, BuiltInEncodeNames } from "@visactor/vgrammar";
6
+
7
+ import { field as getFieldAccessor, toPercent } from "@visactor/vgrammar-util";
8
+
9
+ const defaultTheme = getTheme("default");
10
+
11
+ let semanticMarkId = -1;
12
+
13
+ export class SemanticMark {
14
+ constructor(type, id) {
15
+ this.type = type, this.uid = ++semanticMarkId, this._logger = Logger.getInstance(),
16
+ this.spec = {
17
+ id: null != id ? id : `${this.type}-${this.uid}`
18
+ };
19
+ }
20
+ parseSpec(spec) {
21
+ return isNil(spec.id) && (spec.id = this.spec.id), this.spec = spec, this;
22
+ }
23
+ coordinate(option) {
24
+ return this._coordinate = option, this;
25
+ }
26
+ data(values, transform, id) {
27
+ return isNil(values) || (this.spec.data = {
28
+ values: values,
29
+ transform: transform,
30
+ id: id
31
+ }), this;
32
+ }
33
+ encode(channel, option) {
34
+ return this.spec.encode || (this.spec.encode = {}), this.spec.encode[channel] = option,
35
+ this;
36
+ }
37
+ scale(channel, option) {
38
+ return this.spec.scale || (this.spec.scale = {}), this.spec.scale[channel] = option,
39
+ this;
40
+ }
41
+ style(style) {
42
+ return this.spec.style = style, this;
43
+ }
44
+ transform(option) {
45
+ return this.spec.transform = array(option), this;
46
+ }
47
+ state(state, option) {
48
+ if (![ BuiltInEncodeNames.enter, BuiltInEncodeNames.update, BuiltInEncodeNames.exit, BuiltInEncodeNames.group ].includes(state)) return this.spec.state || (this.spec.state = {}),
49
+ this.spec.state[state] = option, this;
50
+ this._logger.warn(`[VGrammar]: ${state} is a reserved keyword to specify the encode of different data state, \n don't use this keyword`);
51
+ }
52
+ animate(state, option) {
53
+ return "state" === state ? (this._logger.warn(`[VGrammar]: ${state} is a keyword use to specify state animation config, don't use this keyword`),
54
+ this) : (this.spec.animation || (this.spec.animation = {}), this.spec.animation[state] = option,
55
+ this);
56
+ }
57
+ axis(channel, option = !0, layout) {
58
+ return this.spec.axis || (this.spec.axis = {}), this.spec.axis[channel] = {
59
+ option: option,
60
+ layout: layout
61
+ }, this;
62
+ }
63
+ legend(channel, option = !0, layout) {
64
+ return this.spec.legend || (this.spec.legend = {}), this.spec.legend[channel] = {
65
+ option: option,
66
+ layout: layout
67
+ }, this;
68
+ }
69
+ crosshair(channel, option) {
70
+ return this.spec.crosshair || (this.spec.crosshair = {}), this.spec.crosshair[channel] = option,
71
+ this;
72
+ }
73
+ tooltip(option) {
74
+ return this.spec.tooltip = option, this;
75
+ }
76
+ slider(channel, option, layout) {
77
+ return this.spec.slider || (this.spec.slider = {}), this.spec.slider[channel] = {
78
+ option: option,
79
+ layout: layout
80
+ }, this;
81
+ }
82
+ datazoom(channel, option, layout) {
83
+ return this.spec.datazoom || (this.spec.datazoom = {}), this.spec.datazoom[channel] = {
84
+ option: option,
85
+ layout: layout
86
+ }, this;
87
+ }
88
+ label(channel, option) {
89
+ return this.spec.label || (this.spec.label = {}), this.spec.label[channel] = option,
90
+ this;
91
+ }
92
+ player(data, option, layout) {
93
+ return this.spec.player = {
94
+ data: data,
95
+ option: option,
96
+ layout: layout
97
+ }, this;
98
+ }
99
+ setDefaultDataTransform() {
100
+ return [];
101
+ }
102
+ setMultipleData() {
103
+ return null;
104
+ }
105
+ setDefaultMarkTransform() {
106
+ return [];
107
+ }
108
+ convertMarkTransform(userTransform, defaultTransform = []) {
109
+ if (defaultTransform && defaultTransform.length) {
110
+ if (userTransform && userTransform.length) {
111
+ let transforms = [];
112
+ const excludeIndex = [];
113
+ for (let i = 0, len = userTransform.length; i < len; i++) {
114
+ const customizedSpec = userTransform[i], index = defaultTransform.findIndex((entry => entry.type === customizedSpec.type));
115
+ index >= 0 ? (transforms.push(Object.assign({}, defaultTransform[index], customizedSpec)),
116
+ excludeIndex.push(index)) : transforms.push(customizedSpec);
117
+ }
118
+ for (let j = 0, dlen = defaultTransform.length; j < dlen; j++) excludeIndex.includes(j) || (transforms = [ defaultTransform[j] ].concat(transforms));
119
+ return transforms;
120
+ }
121
+ return defaultTransform;
122
+ }
123
+ return userTransform;
124
+ }
125
+ convertMarkAnimation() {
126
+ return this.spec.animation ? this.spec.animation : null;
127
+ }
128
+ convertSimpleMarkEncode(encode) {
129
+ if (!encode) return {};
130
+ const markEncoder = {};
131
+ return Object.keys(encode).map((channel => {
132
+ markEncoder[channel] = {
133
+ field: encode[channel],
134
+ scale: this.getScaleId(channel)
135
+ };
136
+ })), markEncoder;
137
+ }
138
+ getDataIdOfFiltered() {
139
+ var _a, _b;
140
+ return `${null !== (_b = null === (_a = this.spec.data) || void 0 === _a ? void 0 : _a.id) && void 0 !== _b ? _b : this.spec.id}-data-filtered`;
141
+ }
142
+ getDataIdOfMain() {
143
+ var _a, _b;
144
+ return `${null !== (_b = null === (_a = this.spec.data) || void 0 === _a ? void 0 : _a.id) && void 0 !== _b ? _b : this.spec.id}-data`;
145
+ }
146
+ getDataIdOfPlayer() {
147
+ var _a, _b;
148
+ return `${null !== (_b = null === (_a = this.spec.data) || void 0 === _a ? void 0 : _a.id) && void 0 !== _b ? _b : this.spec.id}-player`;
149
+ }
150
+ getDataZoomScaleId(channel) {
151
+ return {
152
+ x: `datazoom-scale-${channel}-x`,
153
+ y: `datazoom-scale-${channel}-y`
154
+ };
155
+ }
156
+ getScaleId(channel) {
157
+ var _a, _b, _c;
158
+ return null !== (_c = null === (_b = null === (_a = this.spec.scale) || void 0 === _a ? void 0 : _a[channel]) || void 0 === _b ? void 0 : _b.id) && void 0 !== _c ? _c : `scale-${channel}`;
159
+ }
160
+ getMarkId() {
161
+ return `${this.spec.id}-mark`;
162
+ }
163
+ getScaleSpec(scaleId) {
164
+ var _a, _b, _c;
165
+ return null === (_c = null === (_b = null === (_a = this.viewSpec) || void 0 === _a ? void 0 : _a.scales) || void 0 === _b ? void 0 : _b.find) || void 0 === _c ? void 0 : _c.call(_b, (scale => scale.id === scaleId));
166
+ }
167
+ parseScaleOfEncodeX(option) {
168
+ return {
169
+ type: "band",
170
+ id: this.getScaleId("x"),
171
+ dependency: [ SIGNAL_VIEW_BOX ],
172
+ domain: {
173
+ data: this.getDataIdOfFiltered(),
174
+ field: option
175
+ },
176
+ range: this._coordinate ? {
177
+ coordinate: this._coordinate.id,
178
+ dimension: "x"
179
+ } : (scale, params) => [ 0, params.viewBox.width() ]
180
+ };
181
+ }
182
+ parseScaleOfEncodeY(option) {
183
+ return {
184
+ type: "linear",
185
+ dependency: [ SIGNAL_VIEW_BOX ],
186
+ id: this.getScaleId("y"),
187
+ domain: {
188
+ data: this.getDataIdOfFiltered(),
189
+ field: option
190
+ },
191
+ range: this._coordinate ? {
192
+ coordinate: this._coordinate.id,
193
+ dimension: "y"
194
+ } : (scale, params) => [ params.viewBox.height(), 0 ]
195
+ };
196
+ }
197
+ parseScaleOfEncodeColor(option) {
198
+ return {
199
+ type: "ordinal",
200
+ id: this.getScaleId("color"),
201
+ domain: {
202
+ data: this.getDataIdOfMain(),
203
+ field: option
204
+ },
205
+ range: getPalette()
206
+ };
207
+ }
208
+ parseScaleOfEncodeGroup(option) {
209
+ return {
210
+ type: "ordinal",
211
+ id: this.getScaleId("group"),
212
+ domain: {
213
+ data: this.getDataIdOfMain(),
214
+ field: option
215
+ },
216
+ range: getPalette()
217
+ };
218
+ }
219
+ parseScaleOfCommonEncode(channel, option) {
220
+ return "x" === channel ? this.parseScaleOfEncodeX(option) : "y" === channel ? this.parseScaleOfEncodeY(option) : "color" === channel ? this.parseScaleOfEncodeColor(option) : "group" === channel ? this.parseScaleOfEncodeGroup(option) : null;
221
+ }
222
+ setDefaultAxis() {
223
+ return {};
224
+ }
225
+ parseAxisSpec() {
226
+ const axis = this.spec.axis, res = [];
227
+ return axis && Object.keys(axis).forEach((channel => {
228
+ const {option: option, layout: layout} = this.parseOption(axis[channel]);
229
+ if (option) {
230
+ const axisMarkSpec = {
231
+ type: "component",
232
+ componentType: ComponentEnum.axis,
233
+ scale: this.getScaleId(channel),
234
+ dependency: [ SIGNAL_VIEW_BOX ],
235
+ tickCount: option.tickCount,
236
+ encode: {
237
+ update: (datum, elment, params) => {
238
+ const positionAttrs = this._coordinate ? {} : "x" === channel ? {
239
+ x: 0,
240
+ y: params.viewBox.height(),
241
+ start: {
242
+ x: 0,
243
+ y: 0
244
+ },
245
+ end: {
246
+ x: params.viewBox.width(),
247
+ y: 0
248
+ }
249
+ } : {
250
+ x: 0,
251
+ y: params.viewBox.height(),
252
+ start: {
253
+ x: 0,
254
+ y: 0
255
+ },
256
+ verticalFactor: -1,
257
+ end: {
258
+ x: 0,
259
+ y: -params.viewBox.height()
260
+ }
261
+ };
262
+ return isPlainObject(option) ? Object.assign(positionAttrs, option) : positionAttrs;
263
+ }
264
+ }
265
+ };
266
+ axisMarkSpec.layout = null != layout ? layout : {
267
+ position: this._coordinate ? "auto" : isPlainObject(layout) && !isNil(layout.orient) ? layout.orient : "x" === channel ? "bottom" : "left"
268
+ }, res.push(axisMarkSpec);
269
+ }
270
+ })), res;
271
+ }
272
+ parseOption(spec) {
273
+ let option, layout;
274
+ return isPlainObject(spec) ? isNil(spec.option) ? option = spec : (option = spec.option,
275
+ layout = spec.layout) : option = spec, {
276
+ option: option,
277
+ layout: layout
278
+ };
279
+ }
280
+ setDefaultLegend() {
281
+ return {};
282
+ }
283
+ parseLegendSpec() {
284
+ const legend = this.spec.legend, res = [];
285
+ return legend && Object.keys(legend).forEach((channel => {
286
+ var _a;
287
+ const {option: option, layout: layout} = this.parseOption(legend[channel]);
288
+ if (option) {
289
+ const markLayout = null != layout ? layout : isPlainObject(option) && !isNil(option.layout) ? "horizontal" === option.layout ? {
290
+ position: "top",
291
+ align: "center"
292
+ } : "vertical" === option.layout ? {
293
+ position: "right",
294
+ align: "middle"
295
+ } : {
296
+ position: "top",
297
+ align: "center"
298
+ } : {
299
+ position: "top",
300
+ align: "center"
301
+ }, markSpec = {
302
+ type: "component",
303
+ componentType: ComponentEnum.legend,
304
+ scale: this.getScaleId(channel),
305
+ dependency: [ SIGNAL_VIEW_BOX ],
306
+ target: {
307
+ data: this.getDataIdOfFiltered(),
308
+ filter: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a[channel]
309
+ },
310
+ encode: {
311
+ update: (datum, element, params) => {
312
+ 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;
313
+ const calculatedAttrs = "left" === markLayout.position ? {
314
+ layout: "vertical",
315
+ x: null !== (_c = null === (_b = null === (_a = element.mark) || void 0 === _a ? void 0 : _a.relativePosition) || void 0 === _b ? void 0 : _b.left) && void 0 !== _c ? _c : 0,
316
+ y: null !== (_f = null === (_e = null === (_d = element.mark) || void 0 === _d ? void 0 : _d.relativePosition) || void 0 === _e ? void 0 : _e.top) && void 0 !== _f ? _f : 0
317
+ } : "right" === markLayout.position ? {
318
+ layout: "vertical",
319
+ x: null !== (_j = null === (_h = null === (_g = element.mark) || void 0 === _g ? void 0 : _g.relativePosition) || void 0 === _h ? void 0 : _h.left) && void 0 !== _j ? _j : params.viewBox.width(),
320
+ y: null !== (_m = null === (_l = null === (_k = element.mark) || void 0 === _k ? void 0 : _k.relativePosition) || void 0 === _l ? void 0 : _l.top) && void 0 !== _m ? _m : 0
321
+ } : "bottom" === markLayout.position ? {
322
+ layout: "horizontal",
323
+ x: null !== (_q = null === (_p = null === (_o = element.mark) || void 0 === _o ? void 0 : _o.relativePosition) || void 0 === _p ? void 0 : _p.left) && void 0 !== _q ? _q : 0,
324
+ y: null !== (_t = null === (_s = null === (_r = element.mark) || void 0 === _r ? void 0 : _r.relativePosition) || void 0 === _s ? void 0 : _s.top) && void 0 !== _t ? _t : params.viewBox.height()
325
+ } : {
326
+ layout: "horizontal",
327
+ x: null !== (_w = null === (_v = null === (_u = element.mark) || void 0 === _u ? void 0 : _u.relativePosition) || void 0 === _v ? void 0 : _v.left) && void 0 !== _w ? _w : 0,
328
+ y: null !== (_z = null === (_y = null === (_x = element.mark) || void 0 === _x ? void 0 : _x.relativePosition) || void 0 === _y ? void 0 : _y.top) && void 0 !== _z ? _z : 0
329
+ };
330
+ return isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
331
+ }
332
+ }
333
+ };
334
+ markSpec.layout = markLayout, res.push(markSpec);
335
+ }
336
+ })), res;
337
+ }
338
+ setDefaultCrosshair() {
339
+ return {};
340
+ }
341
+ getVisualChannel(channel) {
342
+ var _a, _b;
343
+ return "polar" === (null === (_a = this._coordinate) || void 0 === _a ? void 0 : _a.type) ? this._coordinate.transpose ? "x" === channel ? "radius" : "angle" : "x" === channel ? "angle" : "radius" : (null === (_b = this._coordinate) || void 0 === _b ? void 0 : _b.transpose) ? "x" === channel ? "y" : "x" : channel;
344
+ }
345
+ parseCrosshairSpec() {
346
+ const defaultCrosshair = this.setDefaultCrosshair(), defaultKeys = Object.keys(defaultCrosshair), crosshairKeys = this.spec.crosshair ? Object.keys(this.spec.crosshair).reduce(((res, key) => (res.includes(key) || res.push(key),
347
+ res)), defaultKeys) : defaultKeys, res = [];
348
+ return crosshairKeys.length && crosshairKeys.forEach((channel => {
349
+ var _a, _b;
350
+ const userOption = null === (_a = this.spec.crosshair) || void 0 === _a ? void 0 : _a[channel], option = null != userOption ? userOption : defaultCrosshair[channel];
351
+ if (option) {
352
+ const scaleId = this.getScaleId(channel), scaleSpec = this.getScaleSpec(scaleId), markSpec = {
353
+ type: "component",
354
+ componentType: ComponentEnum.crosshair,
355
+ scale: this.getScaleId(channel),
356
+ dependency: [ SIGNAL_VIEW_BOX ],
357
+ crosshairShape: isBoolean(option) ? "band" === (null == scaleSpec ? void 0 : scaleSpec.type) ? "rect" : "line" : null !== (_b = option.crosshairShape) && void 0 !== _b ? _b : "band" === (null == scaleSpec ? void 0 : scaleSpec.type) ? "rect" : "line",
358
+ crosshairType: this.getVisualChannel(channel)
359
+ };
360
+ if (isPlainObject(userOption) && (markSpec.encode = {
361
+ update: userOption
362
+ }, "polygon" === userOption.type)) {
363
+ markSpec.crosshairType = "radius-polygon";
364
+ const anotherDimScaleId = this.getScaleId("x" === channel ? "y" : "x");
365
+ markSpec.dependency.push(anotherDimScaleId), markSpec.encode.update.sides = (datum, el, params) => {
366
+ const scale = params[anotherDimScaleId];
367
+ return scale && isDiscrete(scale.type) ? scale.domain().length : void 0;
368
+ }, markSpec.encode.update.startAngle = (datum, el, params) => {
369
+ var _a, _b;
370
+ const scale = params[anotherDimScaleId];
371
+ return scale && isDiscrete(scale.type) ? scale.range()[0] + (null !== (_b = null === (_a = null == scale ? void 0 : scale.bandwidth) || void 0 === _a ? void 0 : _a.call(scale)) && void 0 !== _b ? _b : 0) / 2 : void 0;
372
+ }, markSpec.encode.update.endAngle = (datum, el, params) => {
373
+ var _a, _b;
374
+ const scale = params[anotherDimScaleId];
375
+ return scale && isDiscrete(scale.type) ? scale.range()[1] + (null !== (_b = null === (_a = null == scale ? void 0 : scale.bandwidth) || void 0 === _a ? void 0 : _a.call(scale)) && void 0 !== _b ? _b : 0) / 2 : void 0;
376
+ };
377
+ }
378
+ res.push(markSpec);
379
+ }
380
+ })), res;
381
+ }
382
+ setDefaultTooltip() {
383
+ return null;
384
+ }
385
+ parseTooltipSpec() {
386
+ var _a;
387
+ const defaultTooltipSpec = this.setDefaultTooltip(), userTooltipSpec = this.spec.tooltip;
388
+ if (!1 !== userTooltipSpec && null !== userTooltipSpec && null !== defaultTooltipSpec) {
389
+ const res = [], tooltipSpec = Object.assign({}, defaultTooltipSpec, !0 === userTooltipSpec ? {} : userTooltipSpec), colorChannel = isNil(this.spec.encode.color) ? "group" : "color", colorEncode = this.spec.encode[colorChannel], dependency = colorEncode ? [ this.getScaleId(colorChannel) ] : [], colorAccessor = colorEncode ? getFieldAccessor(colorEncode) : null, title = {
390
+ visible: !!tooltipSpec.title || !!tooltipSpec.staticTitle,
391
+ key: "title",
392
+ value: isNil(tooltipSpec.staticTitle) ? {
393
+ field: (datum, el, params) => tooltipSpec.title && (null == datum ? void 0 : datum.length) ? getFieldAccessor(tooltipSpec.title)(datum[0]) : void 0
394
+ } : tooltipSpec.staticTitle
395
+ }, content = isArray(tooltipSpec.content) && tooltipSpec.content.length ? tooltipSpec.content.map(((entry, index) => ({
396
+ key: entry.key ? {
397
+ field: entry.key
398
+ } : isNil(tooltipSpec.staticContentKey) ? (datum, el, params) => colorAccessor ? colorAccessor(datum) : void 0 : isArray(tooltipSpec.staticContentKey) ? tooltipSpec.staticContentKey[index] : tooltipSpec.staticContentKey,
399
+ value: {
400
+ field: entry.value
401
+ },
402
+ symbol: (datum, el, params) => {
403
+ var _a;
404
+ const scale = params[this.getScaleId(colorChannel)];
405
+ return {
406
+ symbolType: entry.symbol && null !== (_a = getFieldAccessor(entry.symbol)(datum)) && void 0 !== _a ? _a : "circle",
407
+ fill: scale && colorAccessor ? scale.scale(colorAccessor(datum)) : getPalette()[0]
408
+ };
409
+ }
410
+ }))) : null;
411
+ return !0 !== tooltipSpec.disableGraphicTooltip && res.push({
412
+ type: "component",
413
+ componentType: ComponentEnum.tooltip,
414
+ target: this.getMarkId(),
415
+ dependency: dependency,
416
+ title: title,
417
+ content: content,
418
+ zIndex: 1e3
419
+ }), !0 !== tooltipSpec.disableDimensionTooltip && res.push({
420
+ type: "component",
421
+ componentType: ComponentEnum.dimensionTooltip,
422
+ tooltipType: this.getVisualChannel("x"),
423
+ scale: this.getScaleId("x"),
424
+ dependency: dependency,
425
+ target: {
426
+ data: this.getDataIdOfFiltered(),
427
+ filter: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.x
428
+ },
429
+ title: title,
430
+ content: content,
431
+ avoidMark: tooltipSpec.disableGraphicTooltip ? [] : [ this.getMarkId() ],
432
+ zIndex: 1e3
433
+ }), res;
434
+ }
435
+ return [];
436
+ }
437
+ setDefaultSlider() {
438
+ return {};
439
+ }
440
+ parseSliderSpec() {
441
+ const slider = this.spec.slider, res = [];
442
+ return slider && Object.keys(slider).forEach((channel => {
443
+ var _a, _b;
444
+ const {option: option, layout: layout} = this.parseOption(slider[channel]);
445
+ if (option) {
446
+ const scaleId = this.getScaleId(channel), scaleSpec = this.getScaleSpec(scaleId), dataId = this.getDataIdOfMain();
447
+ if (!scaleSpec || !isContinuous(scaleSpec.type)) return void this._logger.warn(`[VGrammar]: Don't use slider in a channel which has scale type = ${null == scaleSpec ? void 0 : scaleSpec.type}`);
448
+ const getter = getFieldAccessor(null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a[channel]), markLayout = null != layout ? layout : isPlainObject(option) && !isNil(option.layout) ? "horizontal" === option.layout ? {
449
+ position: "top",
450
+ align: "center"
451
+ } : "vertical" === option.layout ? {
452
+ position: "right",
453
+ align: "middle"
454
+ } : {
455
+ position: "top",
456
+ align: "center"
457
+ } : {
458
+ position: "top",
459
+ align: "center"
460
+ }, markSpec = {
461
+ type: "component",
462
+ componentType: ComponentEnum.slider,
463
+ dependency: [ SIGNAL_VIEW_BOX, dataId ],
464
+ min: (datum, elment, params) => {
465
+ const data = params[dataId];
466
+ return Math.min.apply(null, data.map(getter));
467
+ },
468
+ max: (datum, elment, params) => {
469
+ const data = params[dataId];
470
+ return Math.max.apply(null, data.map(getter));
471
+ },
472
+ target: {
473
+ data: this.getDataIdOfFiltered(),
474
+ filter: null === (_b = this.spec.encode) || void 0 === _b ? void 0 : _b[channel]
475
+ },
476
+ encode: {
477
+ update: (datum, elment, params) => {
478
+ 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;
479
+ const calculatedAttrs = "left" === markLayout.position ? {
480
+ layout: "vertical",
481
+ x: null !== (_c = null === (_b = null === (_a = elment.mark) || void 0 === _a ? void 0 : _a.relativePosition) || void 0 === _b ? void 0 : _b.left) && void 0 !== _c ? _c : 0,
482
+ y: null !== (_f = null === (_e = null === (_d = elment.mark) || void 0 === _d ? void 0 : _d.relativePosition) || void 0 === _e ? void 0 : _e.top) && void 0 !== _f ? _f : 0,
483
+ railWidth: defaultTheme.slider.railHeight,
484
+ railHeight: params.viewBox.height()
485
+ } : "right" === markLayout.position ? {
486
+ layout: "vertical",
487
+ x: null !== (_j = null === (_h = null === (_g = elment.mark) || void 0 === _g ? void 0 : _g.relativePosition) || void 0 === _h ? void 0 : _h.left) && void 0 !== _j ? _j : params.viewBox.width(),
488
+ y: null !== (_m = null === (_l = null === (_k = elment.mark) || void 0 === _k ? void 0 : _k.relativePosition) || void 0 === _l ? void 0 : _l.top) && void 0 !== _m ? _m : 0,
489
+ railWidth: defaultTheme.slider.railHeight,
490
+ railHeight: params.viewBox.height()
491
+ } : "bottom" === markLayout.position ? {
492
+ layout: "horizontal",
493
+ x: null !== (_q = null === (_p = null === (_o = elment.mark) || void 0 === _o ? void 0 : _o.relativePosition) || void 0 === _p ? void 0 : _p.left) && void 0 !== _q ? _q : 0,
494
+ y: null !== (_t = null === (_s = null === (_r = elment.mark) || void 0 === _r ? void 0 : _r.relativePosition) || void 0 === _s ? void 0 : _s.top) && void 0 !== _t ? _t : params.viewBox.height(),
495
+ railHeight: defaultTheme.slider.railHeight,
496
+ railWidth: params.viewBox.width()
497
+ } : {
498
+ layout: "horizontal",
499
+ x: null !== (_w = null === (_v = null === (_u = elment.mark) || void 0 === _u ? void 0 : _u.relativePosition) || void 0 === _v ? void 0 : _v.left) && void 0 !== _w ? _w : 0,
500
+ y: null !== (_z = null === (_y = null === (_x = elment.mark) || void 0 === _x ? void 0 : _x.relativePosition) || void 0 === _y ? void 0 : _y.top) && void 0 !== _z ? _z : 0,
501
+ railHeight: defaultTheme.slider.railHeight,
502
+ railWidth: params.viewBox.width()
503
+ };
504
+ return isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
505
+ }
506
+ }
507
+ };
508
+ markSpec.layout = markLayout, res.push(markSpec);
509
+ }
510
+ })), res;
511
+ }
512
+ setDefaultDataZoom() {
513
+ return {};
514
+ }
515
+ getVisiualPositionByDimension(channel) {
516
+ return "y" === channel ? "left" : "bottom";
517
+ }
518
+ parseDataZoomSpec() {
519
+ const datazoom = this.spec.datazoom, res = [];
520
+ return datazoom && Object.keys(datazoom).forEach((channel => {
521
+ var _a, _b, _c, _d, _e;
522
+ const {option: option, layout: layout} = this.parseOption(datazoom[channel]);
523
+ if (option) {
524
+ const dataId = this.getDataIdOfMain(), markLayout = null != layout ? layout : isPlainObject(option) && !isNil(option.orient) ? {
525
+ position: option.orient
526
+ } : {
527
+ position: this.getVisiualPositionByDimension(channel)
528
+ }, preview = {
529
+ data: dataId
530
+ }, {x: x, y: y} = this.getDataZoomScaleId(channel);
531
+ "x" === channel ? (preview.x = {
532
+ scale: x,
533
+ field: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a[channel]
534
+ }, preview.y = {
535
+ scale: y,
536
+ field: null === (_b = this.spec.encode) || void 0 === _b ? void 0 : _b.y
537
+ }) : preview["top" === markLayout.position || "bottom" === markLayout.position ? "x" : "y"] = {
538
+ scale: x,
539
+ field: null !== (_d = null === (_c = this.spec.encode) || void 0 === _c ? void 0 : _c[channel]) && void 0 !== _d ? _d : channel
540
+ };
541
+ const markSpec = {
542
+ type: "component",
543
+ componentType: ComponentEnum.datazoom,
544
+ dependency: [ SIGNAL_VIEW_BOX, dataId ],
545
+ target: {
546
+ data: this.getDataIdOfFiltered(),
547
+ filter: null === (_e = this.spec.encode) || void 0 === _e ? void 0 : _e[channel]
548
+ },
549
+ preview: preview,
550
+ encode: {
551
+ update: (datum, elment, params) => {
552
+ 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;
553
+ const calculatedAttrs = "left" === markLayout.position ? {
554
+ orient: markLayout.position,
555
+ x: null !== (_c = null === (_b = null === (_a = elment.mark) || void 0 === _a ? void 0 : _a.relativePosition) || void 0 === _b ? void 0 : _b.left) && void 0 !== _c ? _c : 0,
556
+ y: null !== (_f = null === (_e = null === (_d = elment.mark) || void 0 === _d ? void 0 : _d.relativePosition) || void 0 === _e ? void 0 : _e.top) && void 0 !== _f ? _f : 0,
557
+ size: {
558
+ height: params.viewBox.height(),
559
+ width: defaultTheme.datazoom.size.height
560
+ }
561
+ } : "right" === markLayout.position ? {
562
+ orient: markLayout.position,
563
+ x: null !== (_j = null === (_h = null === (_g = elment.mark) || void 0 === _g ? void 0 : _g.relativePosition) || void 0 === _h ? void 0 : _h.left) && void 0 !== _j ? _j : params.viewBox.width(),
564
+ y: null !== (_m = null === (_l = null === (_k = elment.mark) || void 0 === _k ? void 0 : _k.relativePosition) || void 0 === _l ? void 0 : _l.top) && void 0 !== _m ? _m : 0,
565
+ size: {
566
+ height: params.viewBox.height(),
567
+ width: defaultTheme.datazoom.size.height
568
+ }
569
+ } : "bottom" === markLayout.position ? {
570
+ orient: markLayout.position,
571
+ x: null !== (_q = null === (_p = null === (_o = elment.mark) || void 0 === _o ? void 0 : _o.relativePosition) || void 0 === _p ? void 0 : _p.left) && void 0 !== _q ? _q : 0,
572
+ y: null !== (_t = null === (_s = null === (_r = elment.mark) || void 0 === _r ? void 0 : _r.relativePosition) || void 0 === _s ? void 0 : _s.top) && void 0 !== _t ? _t : params.viewBox.height(),
573
+ size: {
574
+ width: params.viewBox.width(),
575
+ height: defaultTheme.datazoom.size.height
576
+ }
577
+ } : {
578
+ orient: markLayout.position,
579
+ x: null !== (_w = null === (_v = null === (_u = elment.mark) || void 0 === _u ? void 0 : _u.relativePosition) || void 0 === _v ? void 0 : _v.left) && void 0 !== _w ? _w : 0,
580
+ y: null !== (_z = null === (_y = null === (_x = elment.mark) || void 0 === _x ? void 0 : _x.relativePosition) || void 0 === _y ? void 0 : _y.top) && void 0 !== _z ? _z : 0,
581
+ size: {
582
+ width: params.viewBox.width(),
583
+ height: defaultTheme.datazoom.size.height
584
+ }
585
+ };
586
+ return isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
587
+ }
588
+ }
589
+ };
590
+ markSpec.layout = markLayout, res.push(markSpec);
591
+ }
592
+ })), res;
593
+ }
594
+ setDefaultLabel() {
595
+ return {};
596
+ }
597
+ getLabelPosition() {
598
+ var _a, _b;
599
+ return "polar" === (null === (_a = this._coordinate) || void 0 === _a ? void 0 : _a.type) ? this._coordinate.transpose ? "endAngle" : "outer" : (null === (_b = this._coordinate) || void 0 === _b ? void 0 : _b.transpose) ? "right" : "top";
600
+ }
601
+ setLabelTextGetter(channel, option) {
602
+ return null;
603
+ }
604
+ parseLabelSpec() {
605
+ const label = this.spec.label, res = [];
606
+ return label && Object.keys(label).forEach((channel => {
607
+ const option = label[channel];
608
+ if (option) {
609
+ const markSpec = {
610
+ type: "component",
611
+ componentType: ComponentEnum.label,
612
+ target: this.getMarkId(),
613
+ layout: {
614
+ position: "content",
615
+ skipBeforeLayouted: !0
616
+ },
617
+ labelStyle: isPlainObject(option) ? Object.assign({
618
+ position: this.getLabelPosition()
619
+ }, option) : {
620
+ position: this.getLabelPosition()
621
+ },
622
+ encode: {
623
+ update: {
624
+ text: this.spec.encode[channel] ? {
625
+ field: this.spec.encode[channel]
626
+ } : this.setLabelTextGetter(channel, option)
627
+ }
628
+ }
629
+ };
630
+ res.push(markSpec);
631
+ }
632
+ })), res;
633
+ }
634
+ setDefaultPlayer() {
635
+ return {};
636
+ }
637
+ parsePlayerSpec() {
638
+ var _a;
639
+ const player = this.spec.player, res = [];
640
+ if (player) {
641
+ const option = null == player ? void 0 : player.option, layout = null == player ? void 0 : player.layout;
642
+ if (option) {
643
+ const markLayout = null != layout ? layout : isPlainObject(option) && !isNil(option.orient) ? {
644
+ position: option.orient
645
+ } : {
646
+ position: "bottom"
647
+ }, markSpec = {
648
+ type: "component",
649
+ componentType: ComponentEnum.player,
650
+ dependency: [ SIGNAL_VIEW_BOX ],
651
+ target: {
652
+ data: this.getDataIdOfMain(),
653
+ source: this.getDataIdOfPlayer()
654
+ },
655
+ playerType: isPlainObject(option) && null !== (_a = option.type) && void 0 !== _a ? _a : "auto",
656
+ encode: {
657
+ update: (datum, elment, params) => {
658
+ 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;
659
+ const calculatedAttrs = "left" === markLayout.position ? {
660
+ x: null !== (_c = null === (_b = null === (_a = elment.mark) || void 0 === _a ? void 0 : _a.relativePosition) || void 0 === _b ? void 0 : _b.left) && void 0 !== _c ? _c : 0,
661
+ y: null !== (_f = null === (_e = null === (_d = elment.mark) || void 0 === _d ? void 0 : _d.relativePosition) || void 0 === _e ? void 0 : _e.top) && void 0 !== _f ? _f : 0,
662
+ size: {
663
+ height: params.viewBox.height(),
664
+ width: 20
665
+ }
666
+ } : "right" === markLayout.position ? {
667
+ x: null !== (_j = null === (_h = null === (_g = elment.mark) || void 0 === _g ? void 0 : _g.relativePosition) || void 0 === _h ? void 0 : _h.left) && void 0 !== _j ? _j : params.viewBox.width(),
668
+ y: null !== (_m = null === (_l = null === (_k = elment.mark) || void 0 === _k ? void 0 : _k.relativePosition) || void 0 === _l ? void 0 : _l.top) && void 0 !== _m ? _m : 0,
669
+ size: {
670
+ height: params.viewBox.height(),
671
+ width: 20
672
+ }
673
+ } : "bottom" === markLayout.position ? {
674
+ x: null !== (_q = null === (_p = null === (_o = elment.mark) || void 0 === _o ? void 0 : _o.relativePosition) || void 0 === _p ? void 0 : _p.left) && void 0 !== _q ? _q : 0,
675
+ y: null !== (_t = null === (_s = null === (_r = elment.mark) || void 0 === _r ? void 0 : _r.relativePosition) || void 0 === _s ? void 0 : _s.top) && void 0 !== _t ? _t : params.viewBox.height(),
676
+ size: {
677
+ width: params.viewBox.width(),
678
+ height: 20
679
+ }
680
+ } : {
681
+ x: null !== (_w = null === (_v = null === (_u = elment.mark) || void 0 === _u ? void 0 : _u.relativePosition) || void 0 === _v ? void 0 : _v.left) && void 0 !== _w ? _w : 0,
682
+ y: null !== (_z = null === (_y = null === (_x = elment.mark) || void 0 === _x ? void 0 : _x.relativePosition) || void 0 === _y ? void 0 : _y.top) && void 0 !== _z ? _z : 0,
683
+ size: {
684
+ width: params.viewBox.width(),
685
+ height: 20
686
+ }
687
+ };
688
+ return isPlainObject(option) ? Object.assign({}, calculatedAttrs, option) : calculatedAttrs;
689
+ }
690
+ }
691
+ };
692
+ markSpec.layout = markLayout, res.push(markSpec);
693
+ }
694
+ }
695
+ return res;
696
+ }
697
+ parseDataSpec() {
698
+ var _a;
699
+ const {data: data, player: player} = this.spec, res = [];
700
+ if (null == player ? void 0 : player.data) res.push({
701
+ id: this.getDataIdOfPlayer(),
702
+ values: player.data
703
+ }), res.push({
704
+ id: this.getDataIdOfMain(),
705
+ values: null === (_a = player.data) || void 0 === _a ? void 0 : _a[0]
706
+ }), res.push({
707
+ id: this.getDataIdOfFiltered(),
708
+ source: this.getDataIdOfMain()
709
+ }); else if (data) {
710
+ const dataId = this.getDataIdOfMain(), userTransforms = data.transform, transform = this.convertMarkTransform(userTransforms, this.setDefaultDataTransform());
711
+ res.push({
712
+ id: dataId,
713
+ values: data.values,
714
+ transform: transform
715
+ }), res.push({
716
+ id: this.getDataIdOfFiltered(),
717
+ source: dataId
718
+ });
719
+ }
720
+ const multiDatas = this.setMultipleData();
721
+ return multiDatas && multiDatas.forEach((entry => {
722
+ entry.id && (entry.id === this.getDataIdOfFiltered() && res.length ? res[res.length - 1].transform = entry.transform : res.push(entry));
723
+ })), res;
724
+ }
725
+ parseScaleSpec() {
726
+ const {encode: encode, scale: scale, datazoom: datazoom} = this.spec, scales = {};
727
+ return encode && Object.keys(encode).forEach((k => {
728
+ var _a;
729
+ const encodeOption = encode[k], scaleId = this.getScaleId(k);
730
+ scales[scaleId] = Object.assign({
731
+ id: scaleId
732
+ }, this.parseScaleByEncode(k, encodeOption), null === (_a = this.spec.scale) || void 0 === _a ? void 0 : _a[k]);
733
+ })), scale && Object.keys(scale).forEach((k => {
734
+ const scaleId = this.getScaleId(k);
735
+ scales[scaleId] || (scales[scaleId] = scale[k]);
736
+ })), datazoom && Object.keys(datazoom).forEach((k => {
737
+ var _a, _b, _c, _d;
738
+ const scaleId = this.getScaleId(k), {x: xScaleId, y: yScaleId} = this.getDataZoomScaleId(k);
739
+ "x" === k && encode[k] ? (scales[xScaleId] = {
740
+ type: scales[scaleId].type,
741
+ id: xScaleId,
742
+ domain: {
743
+ data: this.getDataIdOfMain(),
744
+ field: encode[k]
745
+ },
746
+ dependency: [ SIGNAL_VIEW_BOX ],
747
+ range: (scale, params) => [ 0, params.viewBox.width() ]
748
+ }, encode.y && (scales[yScaleId] = {
749
+ type: null !== (_b = null === (_a = scales[this.getScaleId("y")]) || void 0 === _a ? void 0 : _a.type) && void 0 !== _b ? _b : "linear",
750
+ id: yScaleId,
751
+ domain: {
752
+ data: this.getDataIdOfMain(),
753
+ field: null == encode ? void 0 : encode.y
754
+ },
755
+ range: (scale, params) => {
756
+ var _a, _b;
757
+ const option = this.parseOption(datazoom[k]).option;
758
+ return [ 0, isPlainObject(option) && null !== (_b = null === (_a = option.size) || void 0 === _a ? void 0 : _a.height) && void 0 !== _b ? _b : defaultTheme.datazoom.size.height ];
759
+ }
760
+ })) : scales[xScaleId] = {
761
+ type: null !== (_c = scales[scaleId].type) && void 0 !== _c ? _c : "band",
762
+ id: xScaleId,
763
+ domain: {
764
+ data: this.getDataIdOfMain(),
765
+ field: null !== (_d = null == encode ? void 0 : encode[k]) && void 0 !== _d ? _d : k
766
+ }
767
+ };
768
+ })), Array.from(Object.values(scales));
769
+ }
770
+ parseCoordinateSpec() {
771
+ var _a;
772
+ if (!this._coordinate) return [];
773
+ const coordinate = {
774
+ type: null !== (_a = this._coordinate.type) && void 0 !== _a ? _a : "cartesian",
775
+ transpose: this._coordinate.transpose,
776
+ id: this._coordinate.id,
777
+ dependency: [ SIGNAL_VIEW_BOX ],
778
+ start: [ 0, 0 ],
779
+ end: (coord, params) => [ params.viewBox.width(), params.viewBox.height() ]
780
+ };
781
+ return "polar" === this._coordinate.type && this._coordinate.origin && (coordinate.origin = (coord, params) => [ toPercent(this._coordinate.origin[0], params.viewBox.width()), toPercent(this._coordinate.origin[1], params.viewBox.height()) ]),
782
+ [ coordinate ];
783
+ }
784
+ setMainMarkEnterEncode() {
785
+ return this.spec.style;
786
+ }
787
+ setMainMarkSpec() {
788
+ return {};
789
+ }
790
+ setMultiMarksSpec() {
791
+ return null;
792
+ }
793
+ toViewSpec() {
794
+ var _a, _b;
795
+ this.viewSpec = {};
796
+ const filteredDataId = this.getDataIdOfFiltered();
797
+ this.viewSpec.data = this.parseDataSpec(), this.viewSpec.scales = this.parseScaleSpec(),
798
+ this.viewSpec.coordinates = this.parseCoordinateSpec();
799
+ let marks = [];
800
+ marks = marks.concat(this.parseLegendSpec()), marks = marks.concat(this.parseAxisSpec()),
801
+ marks = marks.concat(this.parseCrosshairSpec()), marks = marks.concat(this.parseSliderSpec()),
802
+ marks = marks.concat(this.parseDataZoomSpec()), marks = marks.concat(this.parsePlayerSpec()),
803
+ marks.push(Object.assign({
804
+ id: this.getMarkId(),
805
+ type: this.setMarkType(),
806
+ coordinate: null === (_a = this._coordinate) || void 0 === _a ? void 0 : _a.id,
807
+ from: {
808
+ data: filteredDataId
809
+ },
810
+ groupBy: null === (_b = this.spec.encode) || void 0 === _b ? void 0 : _b.group,
811
+ layout: {
812
+ position: "content",
813
+ skipBeforeLayouted: !0
814
+ },
815
+ dependency: this.viewSpec.scales.map((scale => scale.id)).concat(SIGNAL_VIEW_BOX),
816
+ transform: this.convertMarkTransform(this.spec.transform, this.setDefaultMarkTransform()),
817
+ animation: this.convertMarkAnimation(),
818
+ encode: Object.assign({}, this.spec.state, {
819
+ enter: this.setMainMarkEnterEncode(),
820
+ update: this.convertMarkEncode(this.spec.encode)
821
+ })
822
+ }, this.setMainMarkSpec()));
823
+ const otherMarks = this.setMultiMarksSpec();
824
+ return otherMarks && (marks = marks.concat(otherMarks)), marks = marks.concat(this.parseLabelSpec()),
825
+ marks = marks.concat(this.parseTooltipSpec()), this.viewSpec.marks = marks, this.viewSpec;
826
+ }
827
+ clear() {
828
+ this.spec = {
829
+ id: this.spec.id
830
+ };
831
+ }
832
+ }
833
+ //# sourceMappingURL=semantic-mark.js.map