1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.registerGeometry = exports.View = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var util_1 = require("@antv/util");
|
6 | var constant_1 = require("../constant");
|
7 | var base_1 = tslib_1.__importDefault(require("../base"));
|
8 | var facet_1 = require("../facet");
|
9 | var interaction_1 = require("../interaction");
|
10 | var theme_1 = require("../theme");
|
11 | var bbox_1 = require("../util/bbox");
|
12 | var coordinate_1 = require("../util/coordinate");
|
13 | var helper_1 = require("../util/helper");
|
14 | var tooltip_1 = require("../util/tooltip");
|
15 | var padding_1 = require("../util/padding");
|
16 | var scale_1 = require("../util/scale");
|
17 | var util_2 = require("../theme/util");
|
18 | var controller_1 = require("./controller");
|
19 | var coordinate_2 = tslib_1.__importDefault(require("./controller/coordinate"));
|
20 | var event_1 = tslib_1.__importDefault(require("./event"));
|
21 | var layout_1 = tslib_1.__importDefault(require("./layout"));
|
22 | var scale_pool_1 = require("./util/scale-pool");
|
23 | var padding_cal_1 = require("./layout/padding-cal");
|
24 | var auto_1 = require("./layout/auto");
|
25 | var sync_view_padding_1 = require("./util/sync-view-padding");
|
26 |
|
27 |
|
28 |
|
29 | var View = (function (_super) {
|
30 | tslib_1.__extends(View, _super);
|
31 | function View(props) {
|
32 | var _this = _super.call(this, { visible: props.visible }) || this;
|
33 |
|
34 | _this.views = [];
|
35 |
|
36 | _this.geometries = [];
|
37 |
|
38 | _this.controllers = [];
|
39 |
|
40 | _this.interactions = {};
|
41 |
|
42 | _this.limitInPlot = false;
|
43 |
|
44 | _this.options = {
|
45 | data: [],
|
46 | animate: true,
|
47 | };
|
48 |
|
49 | _this.usedControllers = controller_1.getComponentControllerNames();
|
50 |
|
51 | _this.scalePool = new scale_pool_1.ScalePool();
|
52 |
|
53 | _this.layoutFunc = layout_1.default;
|
54 |
|
55 | _this.isPreMouseInPlot = false;
|
56 |
|
57 | _this.isDataChanged = false;
|
58 |
|
59 | _this.isCoordinateChanged = false;
|
60 |
|
61 | _this.createdScaleKeys = new Map();
|
62 | _this.onCanvasEvent = function (evt) {
|
63 | var name = evt.name;
|
64 | if (!name.includes(':')) {
|
65 |
|
66 | var e = _this.createViewEvent(evt);
|
67 |
|
68 | _this.doPlotEvent(e);
|
69 | _this.emit(name, e);
|
70 | }
|
71 | };
|
72 | |
73 |
|
74 |
|
75 |
|
76 | _this.onDelegateEvents = function (evt) {
|
77 |
|
78 |
|
79 | var name = evt.name;
|
80 | if (!name.includes(':')) {
|
81 | return;
|
82 | }
|
83 |
|
84 | var e = _this.createViewEvent(evt);
|
85 |
|
86 | _this.emit(name, e);
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | };
|
99 | var _a = props.id, id = _a === void 0 ? util_1.uniqueId('view') : _a, parent = props.parent, canvas = props.canvas, backgroundGroup = props.backgroundGroup, middleGroup = props.middleGroup, foregroundGroup = props.foregroundGroup, _b = props.region, region = _b === void 0 ? { start: { x: 0, y: 0 }, end: { x: 1, y: 1 } } : _b, padding = props.padding, appendPadding = props.appendPadding, theme = props.theme, options = props.options, limitInPlot = props.limitInPlot, syncViewPadding = props.syncViewPadding;
|
100 | _this.parent = parent;
|
101 | _this.canvas = canvas;
|
102 | _this.backgroundGroup = backgroundGroup;
|
103 | _this.middleGroup = middleGroup;
|
104 | _this.foregroundGroup = foregroundGroup;
|
105 | _this.region = region;
|
106 | _this.padding = padding;
|
107 | _this.appendPadding = appendPadding;
|
108 |
|
109 | _this.options = tslib_1.__assign(tslib_1.__assign({}, _this.options), options);
|
110 | _this.limitInPlot = limitInPlot;
|
111 | _this.id = id;
|
112 | _this.syncViewPadding = syncViewPadding;
|
113 |
|
114 | _this.themeObject = util_1.isObject(theme) ? util_1.deepMix({}, theme_1.getTheme('default'), util_2.createTheme(theme)) : theme_1.getTheme(theme);
|
115 | _this.init();
|
116 | return _this;
|
117 | }
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 | View.prototype.setLayout = function (layout) {
|
124 | this.layoutFunc = layout;
|
125 | };
|
126 | |
127 |
|
128 |
|
129 |
|
130 | View.prototype.init = function () {
|
131 |
|
132 | this.calculateViewBBox();
|
133 |
|
134 | this.initEvents();
|
135 |
|
136 | this.initComponentController();
|
137 | this.initOptions();
|
138 | };
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | View.prototype.render = function (isUpdate, payload) {
|
146 | if (isUpdate === void 0) { isUpdate = false; }
|
147 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_RENDER, event_1.default.fromData(this, constant_1.VIEW_LIFE_CIRCLE.BEFORE_RENDER, payload));
|
148 |
|
149 | this.paint(isUpdate);
|
150 | this.emit(constant_1.VIEW_LIFE_CIRCLE.AFTER_RENDER, event_1.default.fromData(this, constant_1.VIEW_LIFE_CIRCLE.AFTER_RENDER, payload));
|
151 | if (this.visible === false) {
|
152 |
|
153 | this.changeVisible(false);
|
154 | }
|
155 | };
|
156 | |
157 |
|
158 |
|
159 |
|
160 | View.prototype.clear = function () {
|
161 | var _this = this;
|
162 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_CLEAR);
|
163 |
|
164 | this.filteredData = [];
|
165 | this.coordinateInstance = undefined;
|
166 | this.isDataChanged = false;
|
167 | this.isCoordinateChanged = false;
|
168 |
|
169 | var geometries = this.geometries;
|
170 | for (var i = 0; i < geometries.length; i++) {
|
171 | geometries[i].clear();
|
172 |
|
173 | geometries[i].container.remove(true);
|
174 | }
|
175 | this.geometries = [];
|
176 |
|
177 | var controllers = this.controllers;
|
178 | for (var i = 0; i < controllers.length; i++) {
|
179 | if (controllers[i].name === 'annotation') {
|
180 |
|
181 | controllers[i].clear(true);
|
182 | }
|
183 | else {
|
184 | controllers[i].clear();
|
185 | }
|
186 | }
|
187 |
|
188 | this.createdScaleKeys.forEach(function (v, k) {
|
189 | _this.getRootView().scalePool.deleteScale(k);
|
190 | });
|
191 | this.createdScaleKeys.clear();
|
192 |
|
193 | var views = this.views;
|
194 | for (var i = 0; i < views.length; i++) {
|
195 | views[i].clear();
|
196 | }
|
197 | this.emit(constant_1.VIEW_LIFE_CIRCLE.AFTER_CLEAR);
|
198 | };
|
199 | |
200 |
|
201 |
|
202 |
|
203 | View.prototype.destroy = function () {
|
204 |
|
205 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_DESTROY);
|
206 | var interactions = this.interactions;
|
207 |
|
208 | util_1.each(interactions, function (interaction) {
|
209 | if (interaction) {
|
210 |
|
211 | interaction.destroy();
|
212 | }
|
213 | });
|
214 | this.clear();
|
215 |
|
216 | var controllers = this.controllers;
|
217 | for (var i = 0, len = controllers.length; i < len; i++) {
|
218 | var controller = controllers[i];
|
219 | controller.destroy();
|
220 | }
|
221 | this.backgroundGroup.remove(true);
|
222 | this.middleGroup.remove(true);
|
223 | this.foregroundGroup.remove(true);
|
224 | _super.prototype.destroy.call(this);
|
225 | };
|
226 |
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 | View.prototype.changeVisible = function (visible) {
|
233 | _super.prototype.changeVisible.call(this, visible);
|
234 | var geometries = this.geometries;
|
235 | for (var i = 0, len = geometries.length; i < len; i++) {
|
236 | var geometry = geometries[i];
|
237 | geometry.changeVisible(visible);
|
238 | }
|
239 | var controllers = this.controllers;
|
240 | for (var i = 0, len = controllers.length; i < len; i++) {
|
241 | var controller = controllers[i];
|
242 | controller.changeVisible(visible);
|
243 | }
|
244 | this.foregroundGroup.set('visible', visible);
|
245 | this.middleGroup.set('visible', visible);
|
246 | this.backgroundGroup.set('visible', visible);
|
247 |
|
248 | this.getCanvas().draw();
|
249 | return this;
|
250 | };
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | View.prototype.data = function (data) {
|
262 | util_1.set(this.options, 'data', data);
|
263 | this.isDataChanged = true;
|
264 | return this;
|
265 | };
|
266 | |
267 |
|
268 |
|
269 |
|
270 | View.prototype.source = function (data) {
|
271 | console.warn('This method will be removed at G2 V4.1. Please use chart.data() instead.');
|
272 | return this.data(data);
|
273 | };
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | View.prototype.filter = function (field, condition) {
|
289 | if (util_1.isFunction(condition)) {
|
290 | util_1.set(this.options, ['filters', field], condition);
|
291 | return this;
|
292 | }
|
293 |
|
294 | if (!condition && util_1.get(this.options, ['filters', field])) {
|
295 | delete this.options.filters[field];
|
296 | }
|
297 | return this;
|
298 | };
|
299 | View.prototype.axis = function (field, axisOption) {
|
300 | if (util_1.isBoolean(field)) {
|
301 | util_1.set(this.options, ['axes'], field);
|
302 | }
|
303 | else {
|
304 | util_1.set(this.options, ['axes', field], axisOption);
|
305 | }
|
306 | return this;
|
307 | };
|
308 | View.prototype.legend = function (field, legendOption) {
|
309 | if (util_1.isBoolean(field)) {
|
310 | util_1.set(this.options, ['legends'], field);
|
311 | }
|
312 | else if (util_1.isString(field)) {
|
313 | util_1.set(this.options, ['legends', field], legendOption);
|
314 | if (util_1.isPlainObject(legendOption) && (legendOption === null || legendOption === void 0 ? void 0 : legendOption.selected)) {
|
315 | util_1.set(this.options, ['filters', field], function (name) {
|
316 | var _a;
|
317 | return (_a = legendOption === null || legendOption === void 0 ? void 0 : legendOption.selected[name]) !== null && _a !== void 0 ? _a : true;
|
318 | });
|
319 | }
|
320 | }
|
321 | else {
|
322 |
|
323 | util_1.set(this.options, ['legends'], field);
|
324 | }
|
325 | return this;
|
326 | };
|
327 | View.prototype.scale = function (field, scaleOption) {
|
328 | var _this = this;
|
329 | if (util_1.isString(field)) {
|
330 | util_1.set(this.options, ['scales', field], scaleOption);
|
331 | }
|
332 | else if (util_1.isObject(field)) {
|
333 | util_1.each(field, function (v, k) {
|
334 | util_1.set(_this.options, ['scales', k], v);
|
335 | });
|
336 | }
|
337 | return this;
|
338 | };
|
339 | |
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | View.prototype.tooltip = function (cfg) {
|
354 | util_1.set(this.options, 'tooltip', cfg);
|
355 | return this;
|
356 | };
|
357 | |
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 | View.prototype.annotation = function () {
|
375 | return this.getController('annotation');
|
376 | };
|
377 | |
378 |
|
379 |
|
380 |
|
381 | View.prototype.guide = function () {
|
382 | console.warn('This method will be removed at G2 V4.1. Please use chart.annotation() instead.');
|
383 | return this.annotation();
|
384 | };
|
385 | View.prototype.coordinate = function (type, coordinateCfg) {
|
386 |
|
387 | if (util_1.isString(type)) {
|
388 | util_1.set(this.options, 'coordinate', { type: type, cfg: coordinateCfg });
|
389 | }
|
390 | else {
|
391 | util_1.set(this.options, 'coordinate', type);
|
392 | }
|
393 |
|
394 | this.coordinateController.update(this.options.coordinate);
|
395 | return this.coordinateController;
|
396 | };
|
397 | |
398 |
|
399 |
|
400 |
|
401 | View.prototype.coord = function (type, coordinateCfg) {
|
402 | console.warn('This method will be removed at G2 V4.1. Please use chart.coordinate() instead.');
|
403 |
|
404 | return this.coordinate(type, coordinateCfg);
|
405 | };
|
406 | |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 | View.prototype.facet = function (type, cfg) {
|
424 |
|
425 | if (this.facetInstance) {
|
426 | this.facetInstance.destroy();
|
427 | }
|
428 |
|
429 | var Ctor = facet_1.getFacet(type);
|
430 | if (!Ctor) {
|
431 | throw new Error("facet '" + type + "' is not exist!");
|
432 | }
|
433 | this.facetInstance = new Ctor(this, tslib_1.__assign(tslib_1.__assign({}, cfg), { type: type }));
|
434 | return this;
|
435 | };
|
436 | |
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 | View.prototype.animate = function (status) {
|
447 | util_1.set(this.options, 'animate', status);
|
448 | return this;
|
449 | };
|
450 | |
451 |
|
452 |
|
453 |
|
454 | View.prototype.updateOptions = function (options) {
|
455 | this.clear();
|
456 | util_1.mix(this.options, options);
|
457 |
|
458 |
|
459 | this.views.forEach(function (view) { return view.destroy(); });
|
460 | this.views = [];
|
461 | this.initOptions();
|
462 |
|
463 | this.coordinateBBox = this.viewBBox;
|
464 | return this;
|
465 | };
|
466 | |
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 | View.prototype.option = function (name, opt) {
|
473 |
|
474 |
|
475 | if (View.prototype[name]) {
|
476 | throw new Error("Can't use built in variable name \"" + name + "\", please change another one.");
|
477 | }
|
478 |
|
479 | util_1.set(this.options, name, opt);
|
480 | return this;
|
481 | };
|
482 | |
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 | View.prototype.theme = function (theme) {
|
495 | this.themeObject = util_1.isObject(theme) ? util_1.deepMix({}, this.themeObject, util_2.createTheme(theme)) : theme_1.getTheme(theme);
|
496 | return this;
|
497 | };
|
498 |
|
499 | |
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 | View.prototype.interaction = function (name, cfg) {
|
511 | var existInteraction = this.interactions[name];
|
512 |
|
513 | if (existInteraction) {
|
514 | existInteraction.destroy();
|
515 | }
|
516 |
|
517 | var interaction = interaction_1.createInteraction(name, this, cfg);
|
518 | if (interaction) {
|
519 | interaction.init();
|
520 | this.interactions[name] = interaction;
|
521 | }
|
522 | return this;
|
523 | };
|
524 | |
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 | View.prototype.removeInteraction = function (name) {
|
532 | var existInteraction = this.interactions[name];
|
533 |
|
534 | if (existInteraction) {
|
535 | existInteraction.destroy();
|
536 | this.interactions[name] = undefined;
|
537 | }
|
538 | };
|
539 | |
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 | View.prototype.changeData = function (data) {
|
550 | this.isDataChanged = true;
|
551 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, event_1.default.fromData(this, constant_1.VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, null));
|
552 |
|
553 | this.data(data);
|
554 |
|
555 | this.paint(true);
|
556 |
|
557 | var views = this.views;
|
558 | for (var i = 0, len = views.length; i < len; i++) {
|
559 | var view = views[i];
|
560 |
|
561 | view.changeData(data);
|
562 | }
|
563 | this.emit(constant_1.VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, event_1.default.fromData(this, constant_1.VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, null));
|
564 | };
|
565 |
|
566 | |
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 | View.prototype.createView = function (cfg) {
|
581 |
|
582 |
|
583 | if (this.parent && this.parent.parent) {
|
584 |
|
585 | console.warn('The view nesting recursive feature will be removed at G2 V4.1. Please avoid to use it.');
|
586 | }
|
587 |
|
588 | var sharedOptions = {
|
589 | data: this.options.data,
|
590 | scales: util_1.clone(this.options.scales),
|
591 | axes: util_1.clone(this.options.axes),
|
592 | coordinate: util_1.clone(this.coordinateController.getOption()),
|
593 | tooltip: util_1.clone(this.options.tooltip),
|
594 | legends: util_1.clone(this.options.legends),
|
595 | animate: this.options.animate,
|
596 | visible: this.visible,
|
597 | };
|
598 | var v = new View(tslib_1.__assign(tslib_1.__assign({ parent: this, canvas: this.canvas,
|
599 |
|
600 | backgroundGroup: this.backgroundGroup.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.BG }), middleGroup: this.middleGroup.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.MID }), foregroundGroup: this.foregroundGroup.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.FORE }), theme: this.themeObject, padding: this.padding }, cfg), { options: tslib_1.__assign(tslib_1.__assign({}, sharedOptions), util_1.get(cfg, 'options', {})) }));
|
601 | this.views.push(v);
|
602 | return v;
|
603 | };
|
604 | |
605 |
|
606 |
|
607 |
|
608 | View.prototype.view = function (cfg) {
|
609 | console.warn('This method will be removed at G2 V4.1. Please use chart.createView() instead.');
|
610 | return this.createView(cfg);
|
611 | };
|
612 | |
613 |
|
614 |
|
615 |
|
616 |
|
617 | View.prototype.removeView = function (view) {
|
618 | var removedView = util_1.remove(this.views, function (v) { return v === view; })[0];
|
619 | if (removedView) {
|
620 | removedView.destroy();
|
621 | }
|
622 | return removedView;
|
623 | };
|
624 |
|
625 |
|
626 | |
627 |
|
628 |
|
629 |
|
630 | View.prototype.getCoordinate = function () {
|
631 | return this.coordinateInstance;
|
632 | };
|
633 | |
634 |
|
635 |
|
636 |
|
637 | View.prototype.getTheme = function () {
|
638 | return this.themeObject;
|
639 | };
|
640 | |
641 |
|
642 |
|
643 |
|
644 | View.prototype.getXScale = function () {
|
645 |
|
646 |
|
647 | var g = this.geometries[0];
|
648 | return g ? g.getXScale() : null;
|
649 | };
|
650 | |
651 |
|
652 |
|
653 |
|
654 | View.prototype.getYScales = function () {
|
655 |
|
656 | var tmpMap = {};
|
657 | return this.geometries.map(function (g) {
|
658 | var yScale = g.getYScale();
|
659 | var field = yScale.field;
|
660 | if (!tmpMap[field]) {
|
661 | tmpMap[field] = true;
|
662 | return yScale;
|
663 | }
|
664 | });
|
665 | };
|
666 | |
667 |
|
668 |
|
669 |
|
670 |
|
671 | View.prototype.getScalesByDim = function (dimType) {
|
672 | var geometries = this.geometries;
|
673 | var scales = {};
|
674 | for (var i = 0, len = geometries.length; i < len; i++) {
|
675 | var geometry = geometries[i];
|
676 | var scale = dimType === 'x' ? geometry.getXScale() : geometry.getYScale();
|
677 | if (scale && !scales[scale.field]) {
|
678 | scales[scale.field] = scale;
|
679 | }
|
680 | }
|
681 | return scales;
|
682 | };
|
683 | |
684 |
|
685 |
|
686 |
|
687 |
|
688 | View.prototype.getScaleByField = function (field, key) {
|
689 | var defaultKey = key ? key : this.getScaleKey(field);
|
690 |
|
691 | return this.getRootView().scalePool.getScale(defaultKey);
|
692 | };
|
693 | |
694 |
|
695 |
|
696 |
|
697 | View.prototype.getOptions = function () {
|
698 | return this.options;
|
699 | };
|
700 | |
701 |
|
702 |
|
703 |
|
704 | View.prototype.getData = function () {
|
705 | return this.filteredData;
|
706 | };
|
707 | |
708 |
|
709 |
|
710 |
|
711 |
|
712 | View.prototype.getLayer = function (layer) {
|
713 | return layer === constant_1.LAYER.BG
|
714 | ? this.backgroundGroup
|
715 | : layer === constant_1.LAYER.MID
|
716 | ? this.middleGroup
|
717 | : layer === constant_1.LAYER.FORE
|
718 | ? this.foregroundGroup
|
719 | : this.foregroundGroup;
|
720 | };
|
721 | |
722 |
|
723 |
|
724 |
|
725 | View.prototype.isPointInPlot = function (point) {
|
726 | return coordinate_1.isPointInCoordinate(this.getCoordinate(), point);
|
727 | };
|
728 | |
729 |
|
730 |
|
731 |
|
732 | View.prototype.getLegendAttributes = function () {
|
733 | return util_1.flatten(this.geometries.map(function (g) { return g.getGroupAttributes(); }));
|
734 | };
|
735 | |
736 |
|
737 |
|
738 |
|
739 | View.prototype.getGroupScales = function () {
|
740 |
|
741 | var scales = this.geometries.map(function (g) { return g.getGroupScales(); });
|
742 | return helper_1.uniq(util_1.flatten(scales));
|
743 | };
|
744 | |
745 |
|
746 |
|
747 |
|
748 | View.prototype.getCanvas = function () {
|
749 | return this.getRootView().canvas;
|
750 | };
|
751 | |
752 |
|
753 |
|
754 | View.prototype.getRootView = function () {
|
755 | var v = this;
|
756 | while (true) {
|
757 | if (v.parent) {
|
758 | v = v.parent;
|
759 | continue;
|
760 | }
|
761 | break;
|
762 | }
|
763 | return v;
|
764 | };
|
765 | |
766 |
|
767 |
|
768 |
|
769 |
|
770 | View.prototype.getXY = function (data) {
|
771 | var coordinate = this.getCoordinate();
|
772 | var xScales = this.getScalesByDim('x');
|
773 | var yScales = this.getScalesByDim('y');
|
774 | var x;
|
775 | var y;
|
776 | util_1.each(data, function (value, key) {
|
777 | if (xScales[key]) {
|
778 | x = xScales[key].scale(value);
|
779 | }
|
780 | if (yScales[key]) {
|
781 | y = yScales[key].scale(value);
|
782 | }
|
783 | });
|
784 | if (!util_1.isNil(x) && !util_1.isNil(y)) {
|
785 | return coordinate.convert({ x: x, y: y });
|
786 | }
|
787 | };
|
788 | |
789 |
|
790 |
|
791 |
|
792 | View.prototype.getController = function (name) {
|
793 | return util_1.find(this.controllers, function (c) { return c.name === name; });
|
794 | };
|
795 | |
796 |
|
797 |
|
798 |
|
799 |
|
800 | View.prototype.showTooltip = function (point) {
|
801 | var tooltip = this.getController('tooltip');
|
802 | if (tooltip) {
|
803 | tooltip.showTooltip(point);
|
804 | }
|
805 | return this;
|
806 | };
|
807 | |
808 |
|
809 |
|
810 |
|
811 | View.prototype.hideTooltip = function () {
|
812 | var tooltip = this.getController('tooltip');
|
813 | if (tooltip) {
|
814 | tooltip.hideTooltip();
|
815 | }
|
816 | return this;
|
817 | };
|
818 | |
819 |
|
820 |
|
821 |
|
822 | View.prototype.lockTooltip = function () {
|
823 | var tooltip = this.getController('tooltip');
|
824 | if (tooltip) {
|
825 | tooltip.lockTooltip();
|
826 | }
|
827 | return this;
|
828 | };
|
829 | |
830 |
|
831 |
|
832 |
|
833 | View.prototype.unlockTooltip = function () {
|
834 | var tooltip = this.getController('tooltip');
|
835 | if (tooltip) {
|
836 | tooltip.unlockTooltip();
|
837 | }
|
838 | return this;
|
839 | };
|
840 | |
841 |
|
842 |
|
843 |
|
844 | View.prototype.isTooltipLocked = function () {
|
845 | var tooltip = this.getController('tooltip');
|
846 | return tooltip && tooltip.isTooltipLocked();
|
847 | };
|
848 | |
849 |
|
850 |
|
851 |
|
852 |
|
853 | View.prototype.getTooltipItems = function (point) {
|
854 | var tooltip = this.getController('tooltip');
|
855 | return tooltip ? tooltip.getTooltipItems(point) : [];
|
856 | };
|
857 | |
858 |
|
859 |
|
860 |
|
861 |
|
862 | View.prototype.getSnapRecords = function (point) {
|
863 | var geometries = this.geometries;
|
864 | var rst = [];
|
865 | for (var i = 0, len = geometries.length; i < len; i++) {
|
866 | var geom = geometries[i];
|
867 | var dataArray = geom.dataArray;
|
868 | geom.sort(dataArray);
|
869 | var record = void 0;
|
870 | for (var j = 0, dataLen = dataArray.length; j < dataLen; j++) {
|
871 | var data = dataArray[j];
|
872 | record = tooltip_1.findDataByPoint(point, data, geom);
|
873 | if (record) {
|
874 | rst.push(record);
|
875 | }
|
876 | }
|
877 | }
|
878 |
|
879 | var views = this.views;
|
880 | for (var i = 0, len = views.length; i < len; i++) {
|
881 | var view = views[i];
|
882 | var snapRecords = view.getSnapRecords(point);
|
883 | rst = rst.concat(snapRecords);
|
884 | }
|
885 | return rst;
|
886 | };
|
887 | |
888 |
|
889 |
|
890 | View.prototype.getComponents = function () {
|
891 | var components = [];
|
892 | var controllers = this.controllers;
|
893 | for (var i = 0, len = controllers.length; i < len; i++) {
|
894 | var controller = controllers[i];
|
895 | components = components.concat(controller.getComponents());
|
896 | }
|
897 | return components;
|
898 | };
|
899 | |
900 |
|
901 |
|
902 |
|
903 |
|
904 | View.prototype.filterData = function (data) {
|
905 | var filters = this.options.filters;
|
906 |
|
907 | if (util_1.size(filters) === 0) {
|
908 | return data;
|
909 | }
|
910 |
|
911 | return util_1.filter(data, function (datum, idx) {
|
912 |
|
913 | var fields = Object.keys(filters);
|
914 |
|
915 | return fields.every(function (field) {
|
916 | var condition = filters[field];
|
917 |
|
918 | return condition(datum[field], datum, idx);
|
919 | });
|
920 | });
|
921 | };
|
922 | |
923 |
|
924 |
|
925 |
|
926 |
|
927 | View.prototype.filterFieldData = function (field, data) {
|
928 | var filters = this.options.filters;
|
929 | var condition = util_1.get(filters, field);
|
930 | if (util_1.isUndefined(condition)) {
|
931 | return data;
|
932 | }
|
933 | return data.filter(function (datum, idx) { return condition(datum[field], datum, idx); });
|
934 | };
|
935 | |
936 |
|
937 |
|
938 | View.prototype.adjustCoordinate = function () {
|
939 | var _a = this.getCoordinate(), curStart = _a.start, curEnd = _a.end;
|
940 | var start = this.coordinateBBox.bl;
|
941 | var end = this.coordinateBBox.tr;
|
942 |
|
943 | if (util_1.isEqual(curStart, start) && util_1.isEqual(curEnd, end)) {
|
944 | this.isCoordinateChanged = false;
|
945 |
|
946 | return;
|
947 | }
|
948 | this.isCoordinateChanged = true;
|
949 | this.coordinateInstance = this.coordinateController.adjust(start, end);
|
950 | };
|
951 | View.prototype.paint = function (isUpdate) {
|
952 | this.renderDataRecursive(isUpdate);
|
953 |
|
954 | this.syncScale();
|
955 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_PAINT);
|
956 |
|
957 | this.renderPaddingRecursive(isUpdate);
|
958 |
|
959 | this.renderLayoutRecursive(isUpdate);
|
960 |
|
961 | this.renderBackgroundStyleShape();
|
962 |
|
963 | this.renderPaintRecursive(isUpdate);
|
964 | this.emit(constant_1.VIEW_LIFE_CIRCLE.AFTER_PAINT);
|
965 | this.isDataChanged = false;
|
966 | };
|
967 | |
968 |
|
969 |
|
970 |
|
971 | View.prototype.renderBackgroundStyleShape = function () {
|
972 |
|
973 | if (this.parent) {
|
974 | return;
|
975 | }
|
976 | var background = util_1.get(this.themeObject, 'background');
|
977 |
|
978 | if (background) {
|
979 |
|
980 | if (!this.backgroundStyleRectShape) {
|
981 | this.backgroundStyleRectShape = this.backgroundGroup.addShape('rect', {
|
982 | attrs: {},
|
983 | zIndex: -1,
|
984 |
|
985 | capture: false,
|
986 | });
|
987 | this.backgroundStyleRectShape.toBack();
|
988 | }
|
989 |
|
990 | var _a = this.viewBBox, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
991 | this.backgroundStyleRectShape.attr({
|
992 | fill: background,
|
993 | x: x,
|
994 | y: y,
|
995 | width: width,
|
996 | height: height,
|
997 | });
|
998 | }
|
999 | else {
|
1000 |
|
1001 | if (this.backgroundStyleRectShape) {
|
1002 | this.backgroundStyleRectShape.remove(true);
|
1003 | this.backgroundStyleRectShape = undefined;
|
1004 | }
|
1005 | }
|
1006 | };
|
1007 | |
1008 |
|
1009 |
|
1010 |
|
1011 | View.prototype.renderPaddingRecursive = function (isUpdate) {
|
1012 |
|
1013 | this.calculateViewBBox();
|
1014 |
|
1015 | this.adjustCoordinate();
|
1016 |
|
1017 | this.initComponents(isUpdate);
|
1018 |
|
1019 |
|
1020 | this.autoPadding = auto_1.calculatePadding(this).shrink(padding_1.parsePadding(this.appendPadding));
|
1021 |
|
1022 |
|
1023 | this.coordinateBBox = this.viewBBox.shrink(this.autoPadding.getPadding());
|
1024 | this.adjustCoordinate();
|
1025 |
|
1026 | var views = this.views;
|
1027 | for (var i = 0, len = views.length; i < len; i++) {
|
1028 | var view = views[i];
|
1029 | view.renderPaddingRecursive(isUpdate);
|
1030 | }
|
1031 | };
|
1032 | |
1033 |
|
1034 |
|
1035 |
|
1036 | View.prototype.renderLayoutRecursive = function (isUpdate) {
|
1037 |
|
1038 |
|
1039 | var syncViewPaddingFn = this.syncViewPadding === true
|
1040 | ? sync_view_padding_1.defaultSyncViewPadding
|
1041 | : util_1.isFunction(this.syncViewPadding)
|
1042 | ? this.syncViewPadding
|
1043 | : undefined;
|
1044 | if (syncViewPaddingFn) {
|
1045 | syncViewPaddingFn(this, this.views, padding_cal_1.PaddingCal);
|
1046 |
|
1047 | this.views.forEach(function (v) {
|
1048 | v.coordinateBBox = v.viewBBox.shrink(v.autoPadding.getPadding());
|
1049 | v.adjustCoordinate();
|
1050 | });
|
1051 | }
|
1052 |
|
1053 | this.doLayout();
|
1054 |
|
1055 | var views = this.views;
|
1056 | for (var i = 0, len = views.length; i < len; i++) {
|
1057 | var view = views[i];
|
1058 | view.renderLayoutRecursive(isUpdate);
|
1059 | }
|
1060 | };
|
1061 | |
1062 |
|
1063 |
|
1064 |
|
1065 | View.prototype.renderPaintRecursive = function (isUpdate) {
|
1066 | var middleGroup = this.middleGroup;
|
1067 | if (this.limitInPlot) {
|
1068 | var _a = coordinate_1.getCoordinateClipCfg(this.coordinateInstance), type = _a.type, attrs = _a.attrs;
|
1069 | middleGroup.setClip({
|
1070 | type: type,
|
1071 | attrs: attrs,
|
1072 | });
|
1073 | }
|
1074 | else {
|
1075 |
|
1076 | middleGroup.setClip(undefined);
|
1077 | }
|
1078 |
|
1079 | this.paintGeometries(isUpdate);
|
1080 |
|
1081 | this.renderComponents(isUpdate);
|
1082 |
|
1083 | var views = this.views;
|
1084 | for (var i = 0, len = views.length; i < len; i++) {
|
1085 | var view = views[i];
|
1086 | view.renderPaintRecursive(isUpdate);
|
1087 | }
|
1088 | };
|
1089 |
|
1090 | |
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 | View.prototype.createScale = function (field, data, scaleDef, key) {
|
1098 |
|
1099 | var currentScaleDef = util_1.get(this.options.scales, [field]);
|
1100 | var mergedScaleDef = tslib_1.__assign(tslib_1.__assign({}, currentScaleDef), scaleDef);
|
1101 |
|
1102 | if (this.parent) {
|
1103 | return this.parent.createScale(field, data, mergedScaleDef, key);
|
1104 | }
|
1105 |
|
1106 | return this.scalePool.createScale(field, data, mergedScaleDef, key);
|
1107 | };
|
1108 | |
1109 |
|
1110 |
|
1111 |
|
1112 | View.prototype.renderDataRecursive = function (isUpdate) {
|
1113 |
|
1114 | this.doFilterData();
|
1115 |
|
1116 | this.createCoordinate();
|
1117 |
|
1118 | this.initGeometries(isUpdate);
|
1119 |
|
1120 | this.renderFacet(isUpdate);
|
1121 |
|
1122 | var views = this.views;
|
1123 | for (var i = 0, len = views.length; i < len; i++) {
|
1124 | var view = views[i];
|
1125 | view.renderDataRecursive(isUpdate);
|
1126 | }
|
1127 | };
|
1128 | |
1129 |
|
1130 |
|
1131 |
|
1132 | View.prototype.calculateViewBBox = function () {
|
1133 | var x;
|
1134 | var y;
|
1135 | var width;
|
1136 | var height;
|
1137 | if (this.parent) {
|
1138 | var bbox = this.parent.coordinateBBox;
|
1139 |
|
1140 | x = bbox.x;
|
1141 | y = bbox.y;
|
1142 | width = bbox.width;
|
1143 | height = bbox.height;
|
1144 | }
|
1145 | else {
|
1146 |
|
1147 | x = 0;
|
1148 | y = 0;
|
1149 | width = this.canvas.get('width');
|
1150 | height = this.canvas.get('height');
|
1151 | }
|
1152 | var _a = this.region, start = _a.start, end = _a.end;
|
1153 |
|
1154 | var viewBBox = new bbox_1.BBox(x + width * start.x, y + height * start.y, width * (end.x - start.x), height * (end.y - start.y));
|
1155 | if (!this.viewBBox || !this.viewBBox.isEqual(viewBBox)) {
|
1156 |
|
1157 | this.viewBBox = new bbox_1.BBox(x + width * start.x, y + height * start.y, width * (end.x - start.x), height * (end.y - start.y));
|
1158 | }
|
1159 |
|
1160 | this.coordinateBBox = this.viewBBox;
|
1161 | };
|
1162 | |
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 | View.prototype.initEvents = function () {
|
1170 |
|
1171 | this.foregroundGroup.on('*', this.onDelegateEvents);
|
1172 | this.middleGroup.on('*', this.onDelegateEvents);
|
1173 | this.backgroundGroup.on('*', this.onDelegateEvents);
|
1174 | this.canvas.on('*', this.onCanvasEvent);
|
1175 | };
|
1176 | |
1177 |
|
1178 |
|
1179 | View.prototype.initComponentController = function () {
|
1180 | var usedControllers = this.usedControllers;
|
1181 | for (var i = 0, len = usedControllers.length; i < len; i++) {
|
1182 | var controllerName = usedControllers[i];
|
1183 | var Ctor = controller_1.getComponentController(controllerName);
|
1184 | if (Ctor) {
|
1185 | this.controllers.push(new Ctor(this));
|
1186 | }
|
1187 | }
|
1188 | };
|
1189 | View.prototype.createViewEvent = function (evt) {
|
1190 | var shape = evt.shape, name = evt.name;
|
1191 | var data = shape ? shape.get('origin') : null;
|
1192 |
|
1193 | var e = new event_1.default(this, evt, data);
|
1194 | e.type = name;
|
1195 | return e;
|
1196 | };
|
1197 | |
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 | View.prototype.doPlotEvent = function (e) {
|
1204 | var type = e.type, x = e.x, y = e.y;
|
1205 | var point = { x: x, y: y };
|
1206 | var ALL_EVENTS = [
|
1207 | 'mousedown',
|
1208 | 'mouseup',
|
1209 | 'mousemove',
|
1210 | 'mouseleave',
|
1211 | 'mousewheel',
|
1212 | 'touchstart',
|
1213 | 'touchmove',
|
1214 | 'touchend',
|
1215 | 'touchcancel',
|
1216 | 'click',
|
1217 | 'dblclick',
|
1218 | 'contextmenu',
|
1219 | ];
|
1220 | if (ALL_EVENTS.includes(type)) {
|
1221 | var currentInPlot = this.isPointInPlot(point);
|
1222 | var newEvent = e.clone();
|
1223 | if (currentInPlot) {
|
1224 | var TYPE = "plot:" + type;
|
1225 | newEvent.type = TYPE;
|
1226 | this.emit(TYPE, newEvent);
|
1227 | if (type === 'mouseleave' || type === 'touchend') {
|
1228 |
|
1229 | this.isPreMouseInPlot = false;
|
1230 | }
|
1231 | }
|
1232 |
|
1233 | if (type === 'mousemove' || type === 'touchmove') {
|
1234 | if (this.isPreMouseInPlot && !currentInPlot) {
|
1235 | if (type === 'mousemove') {
|
1236 | newEvent.type = constant_1.PLOT_EVENTS.MOUSE_LEAVE;
|
1237 | this.emit(constant_1.PLOT_EVENTS.MOUSE_LEAVE, newEvent);
|
1238 | }
|
1239 | newEvent.type = constant_1.PLOT_EVENTS.LEAVE;
|
1240 | this.emit(constant_1.PLOT_EVENTS.LEAVE, newEvent);
|
1241 | }
|
1242 | else if (!this.isPreMouseInPlot && currentInPlot) {
|
1243 | if (type === 'mousemove') {
|
1244 | newEvent.type = constant_1.PLOT_EVENTS.MOUSE_ENTER;
|
1245 | this.emit(constant_1.PLOT_EVENTS.MOUSE_ENTER, newEvent);
|
1246 | }
|
1247 | newEvent.type = constant_1.PLOT_EVENTS.ENTER;
|
1248 | this.emit(constant_1.PLOT_EVENTS.ENTER, newEvent);
|
1249 | }
|
1250 |
|
1251 | this.isPreMouseInPlot = currentInPlot;
|
1252 | }
|
1253 | else if (type === 'mouseleave' || type === 'touchend') {
|
1254 |
|
1255 | if (this.isPreMouseInPlot) {
|
1256 | if (type === 'mouseleave') {
|
1257 | newEvent.type = constant_1.PLOT_EVENTS.MOUSE_LEAVE;
|
1258 | this.emit(constant_1.PLOT_EVENTS.MOUSE_LEAVE, newEvent);
|
1259 | }
|
1260 | newEvent.type = constant_1.PLOT_EVENTS.LEAVE;
|
1261 | this.emit(constant_1.PLOT_EVENTS.LEAVE, newEvent);
|
1262 | this.isPreMouseInPlot = false;
|
1263 | }
|
1264 | }
|
1265 | }
|
1266 | };
|
1267 |
|
1268 | |
1269 |
|
1270 |
|
1271 |
|
1272 | View.prototype.doFilterData = function () {
|
1273 | var data = this.options.data;
|
1274 | this.filteredData = this.filterData(data);
|
1275 | };
|
1276 | |
1277 |
|
1278 |
|
1279 |
|
1280 | View.prototype.initGeometries = function (isUpdate) {
|
1281 |
|
1282 | this.createOrUpdateScales();
|
1283 |
|
1284 | var coordinate = this.getCoordinate();
|
1285 | var scaleDefs = util_1.get(this.options, 'scales', {});
|
1286 | var geometries = this.geometries;
|
1287 | for (var i = 0, len = geometries.length; i < len; i++) {
|
1288 | var geometry = geometries[i];
|
1289 |
|
1290 | geometry.scales = this.getGeometryScales();
|
1291 | var cfg = {
|
1292 | coordinate: coordinate,
|
1293 | scaleDefs: scaleDefs,
|
1294 | data: this.filteredData,
|
1295 | theme: this.themeObject,
|
1296 | isDataChanged: this.isDataChanged,
|
1297 | isCoordinateChanged: this.isCoordinateChanged,
|
1298 | };
|
1299 | if (isUpdate) {
|
1300 |
|
1301 | geometry.update(cfg);
|
1302 | }
|
1303 | else {
|
1304 | geometry.init(cfg);
|
1305 | }
|
1306 | }
|
1307 |
|
1308 | this.adjustScales();
|
1309 | };
|
1310 | |
1311 |
|
1312 |
|
1313 |
|
1314 | View.prototype.createOrUpdateScales = function () {
|
1315 | var fields = this.getScaleFields();
|
1316 | var groupedFields = this.getGroupedFields();
|
1317 | var _a = this.getOptions(), data = _a.data, _b = _a.scales, scales = _b === void 0 ? {} : _b;
|
1318 | var filteredData = this.filteredData;
|
1319 | for (var i = 0, len = fields.length; i < len; i++) {
|
1320 | var field = fields[i];
|
1321 | var scaleDef = scales[field];
|
1322 |
|
1323 | var key = this.getScaleKey(field);
|
1324 | this.createScale(field,
|
1325 |
|
1326 | groupedFields.includes(field) ? data : filteredData, scaleDef, key);
|
1327 |
|
1328 | this.createdScaleKeys.set(key, true);
|
1329 | }
|
1330 | };
|
1331 | |
1332 |
|
1333 |
|
1334 | View.prototype.syncScale = function () {
|
1335 |
|
1336 | this.getRootView().scalePool.sync(this.getCoordinate(), this.theme);
|
1337 | };
|
1338 | |
1339 |
|
1340 |
|
1341 | View.prototype.getGeometryScales = function () {
|
1342 | var fields = this.getScaleFields();
|
1343 | var scales = {};
|
1344 | for (var i = 0; i < fields.length; i++) {
|
1345 | var field = fields[i];
|
1346 | scales[field] = this.getScaleByField(field);
|
1347 | }
|
1348 | return scales;
|
1349 | };
|
1350 | View.prototype.getScaleFields = function () {
|
1351 | var fields = [];
|
1352 | var tmpMap = {};
|
1353 | var geometries = this.geometries;
|
1354 | for (var i = 0; i < geometries.length; i++) {
|
1355 | var geometry = geometries[i];
|
1356 | var geometryScales = geometry.getScaleFields();
|
1357 | helper_1.uniq(geometryScales, fields, tmpMap);
|
1358 | }
|
1359 | return fields;
|
1360 | };
|
1361 | View.prototype.getGroupedFields = function () {
|
1362 | var fields = [];
|
1363 | var tmpMap = {};
|
1364 | var geometries = this.geometries;
|
1365 | for (var i = 0; i < geometries.length; i++) {
|
1366 | var geometry = geometries[i];
|
1367 | var groupFields = geometry.getGroupFields();
|
1368 | helper_1.uniq(groupFields, fields, tmpMap);
|
1369 | }
|
1370 | return fields;
|
1371 | };
|
1372 | |
1373 |
|
1374 |
|
1375 |
|
1376 | View.prototype.adjustScales = function () {
|
1377 |
|
1378 |
|
1379 | this.adjustCategoryScaleRange();
|
1380 | };
|
1381 | |
1382 |
|
1383 |
|
1384 |
|
1385 | View.prototype.adjustCategoryScaleRange = function () {
|
1386 | var _this = this;
|
1387 | var xyScales = tslib_1.__spreadArrays([this.getXScale()], this.getYScales()).filter(function (e) { return !!e; });
|
1388 | var coordinate = this.getCoordinate();
|
1389 | var scaleOptions = this.options.scales;
|
1390 | util_1.each(xyScales, function (scale) {
|
1391 | var field = scale.field, values = scale.values, isCategory = scale.isCategory, isIdentity = scale.isIdentity;
|
1392 |
|
1393 | if (isCategory || isIdentity) {
|
1394 |
|
1395 | if (values && !util_1.get(scaleOptions, [field, 'range'])) {
|
1396 |
|
1397 | scale.range = scale_1.getDefaultCategoryScaleRange(scale, coordinate, _this.theme);
|
1398 | }
|
1399 | }
|
1400 | });
|
1401 | };
|
1402 | |
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 | View.prototype.initComponents = function (isUpdate) {
|
1408 |
|
1409 | var controllers = this.controllers;
|
1410 | for (var i = 0; i < controllers.length; i++) {
|
1411 | var controller = controllers[i];
|
1412 |
|
1413 | if (isUpdate) {
|
1414 | controller.update();
|
1415 | }
|
1416 | else {
|
1417 | controller.clear();
|
1418 | controller.render();
|
1419 | }
|
1420 | }
|
1421 | };
|
1422 | View.prototype.doLayout = function () {
|
1423 | this.layoutFunc(this);
|
1424 | };
|
1425 | |
1426 |
|
1427 |
|
1428 |
|
1429 | View.prototype.createCoordinate = function () {
|
1430 | var start = this.coordinateBBox.bl;
|
1431 | var end = this.coordinateBBox.tr;
|
1432 | this.coordinateInstance = this.coordinateController.create(start, end);
|
1433 | };
|
1434 | |
1435 |
|
1436 |
|
1437 |
|
1438 | View.prototype.paintGeometries = function (isUpdate) {
|
1439 | var doAnimation = this.options.animate;
|
1440 |
|
1441 | var coordinate = this.getCoordinate();
|
1442 | var canvasRegion = {
|
1443 | x: this.viewBBox.x,
|
1444 | y: this.viewBBox.y,
|
1445 | minX: this.viewBBox.minX,
|
1446 | minY: this.viewBBox.minY,
|
1447 | maxX: this.viewBBox.maxX,
|
1448 | maxY: this.viewBBox.maxY,
|
1449 | width: this.viewBBox.width,
|
1450 | height: this.viewBBox.height,
|
1451 | };
|
1452 | var geometries = this.geometries;
|
1453 | for (var i = 0; i < geometries.length; i++) {
|
1454 | var geometry = geometries[i];
|
1455 | geometry.coordinate = coordinate;
|
1456 | geometry.canvasRegion = canvasRegion;
|
1457 | if (!doAnimation) {
|
1458 |
|
1459 | geometry.animate(false);
|
1460 | }
|
1461 | geometry.paint(isUpdate);
|
1462 | }
|
1463 | };
|
1464 | |
1465 |
|
1466 |
|
1467 |
|
1468 | View.prototype.renderComponents = function (isUpdate) {
|
1469 |
|
1470 | for (var i = 0; i < this.getComponents().length; i++) {
|
1471 | var co = this.getComponents()[i];
|
1472 | co.component.render();
|
1473 | }
|
1474 | };
|
1475 | |
1476 |
|
1477 |
|
1478 |
|
1479 | View.prototype.renderFacet = function (isUpdate) {
|
1480 | if (this.facetInstance) {
|
1481 | if (isUpdate) {
|
1482 | this.facetInstance.update();
|
1483 | }
|
1484 | else {
|
1485 | this.facetInstance.clear();
|
1486 |
|
1487 | this.facetInstance.init();
|
1488 |
|
1489 | this.facetInstance.render();
|
1490 | }
|
1491 | }
|
1492 | };
|
1493 | View.prototype.initOptions = function () {
|
1494 | var _this = this;
|
1495 | var _a = this.options, _b = _a.geometries, geometries = _b === void 0 ? [] : _b, _c = _a.interactions, interactions = _c === void 0 ? [] : _c, _d = _a.views, views = _d === void 0 ? [] : _d, _e = _a.annotations, annotations = _e === void 0 ? [] : _e, coordinate = _a.coordinate, events = _a.events, facets = _a.facets;
|
1496 |
|
1497 | if (this.coordinateController) {
|
1498 |
|
1499 | coordinate && this.coordinateController.update(coordinate);
|
1500 | }
|
1501 | else {
|
1502 |
|
1503 | this.coordinateController = new coordinate_2.default(coordinate);
|
1504 | }
|
1505 |
|
1506 | for (var i = 0; i < geometries.length; i++) {
|
1507 | var geometryOption = geometries[i];
|
1508 | this.createGeometry(geometryOption);
|
1509 | }
|
1510 |
|
1511 | for (var j = 0; j < interactions.length; j++) {
|
1512 | var interactionOption = interactions[j];
|
1513 | var type = interactionOption.type, cfg = interactionOption.cfg;
|
1514 | this.interaction(type, cfg);
|
1515 | }
|
1516 |
|
1517 | for (var k = 0; k < views.length; k++) {
|
1518 | var viewOption = views[k];
|
1519 | this.createView(viewOption);
|
1520 | }
|
1521 |
|
1522 | var annotationComponent = this.getController('annotation');
|
1523 | for (var l = 0; l < annotations.length; l++) {
|
1524 | var annotationOption = annotations[l];
|
1525 | annotationComponent.annotation(annotationOption);
|
1526 | }
|
1527 |
|
1528 | if (events) {
|
1529 | util_1.each(events, function (eventCallback, eventName) {
|
1530 | _this.on(eventName, eventCallback);
|
1531 | });
|
1532 | }
|
1533 | if (facets) {
|
1534 | util_1.each(facets, function (facet) {
|
1535 | var type = facet.type, rest = tslib_1.__rest(facet, ["type"]);
|
1536 | _this.facet(type, rest);
|
1537 | });
|
1538 | }
|
1539 | };
|
1540 | View.prototype.createGeometry = function (geometryOption) {
|
1541 | var type = geometryOption.type, _a = geometryOption.cfg, cfg = _a === void 0 ? {} : _a;
|
1542 | if (this[type]) {
|
1543 | var geometry_1 = this[type](cfg);
|
1544 | util_1.each(geometryOption, function (v, k) {
|
1545 | if (util_1.isFunction(geometry_1[k])) {
|
1546 | geometry_1[k](v);
|
1547 | }
|
1548 | });
|
1549 | }
|
1550 | };
|
1551 | |
1552 |
|
1553 |
|
1554 |
|
1555 | View.prototype.getScaleKey = function (field) {
|
1556 | return this.id + "-" + field;
|
1557 | };
|
1558 | return View;
|
1559 | }(base_1.default));
|
1560 | exports.View = View;
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 | function registerGeometry(name, Ctor) {
|
1568 |
|
1569 | View.prototype[name.toLowerCase()] = function (cfg) {
|
1570 | if (cfg === void 0) { cfg = {}; }
|
1571 | var props = tslib_1.__assign({
|
1572 |
|
1573 | container: this.middleGroup.addGroup(), labelsContainer: this.foregroundGroup.addGroup() }, cfg);
|
1574 | var geometry = new Ctor(props);
|
1575 | this.geometries.push(geometry);
|
1576 | return geometry;
|
1577 | };
|
1578 | }
|
1579 | exports.registerGeometry = registerGeometry;
|
1580 | exports.default = View;
|
1581 |
|
\ | No newline at end of file |