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