1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var constant_1 = require("../constant");
|
6 | var engine_1 = require("../engine");
|
7 | var dom_1 = require("../util/dom");
|
8 | var view_1 = tslib_1.__importDefault(require("./view"));
|
9 |
|
10 |
|
11 |
|
12 | var Chart = (function (_super) {
|
13 | tslib_1.__extends(Chart, _super);
|
14 |
|
15 | function Chart(props) {
|
16 | var _this = this;
|
17 | var container = props.container, width = props.width, height = props.height, _a = props.autoFit, autoFit = _a === void 0 ? false : _a, padding = props.padding, appendPadding = props.appendPadding, _b = props.renderer, renderer = _b === void 0 ? 'canvas' : _b, pixelRatio = props.pixelRatio, _c = props.localRefresh, localRefresh = _c === void 0 ? true : _c, _d = props.visible, visible = _d === void 0 ? true : _d, _e = props.supportCSSTransform, supportCSSTransform = _e === void 0 ? false : _e, _f = props.defaultInteractions, defaultInteractions = _f === void 0 ? ['tooltip', 'legend-filter', 'legend-active', 'continuous-filter', 'ellipsis-text'] : _f, options = props.options, limitInPlot = props.limitInPlot, theme = props.theme, syncViewPadding = props.syncViewPadding;
|
18 | var ele = util_1.isString(container) ? document.getElementById(container) : container;
|
19 |
|
20 | var wrapperElement = dom_1.createDom('<div style="position:relative;"></div>');
|
21 | ele.appendChild(wrapperElement);
|
22 |
|
23 | var size = dom_1.getChartSize(ele, autoFit, width, height);
|
24 | var G = engine_1.getEngine(renderer);
|
25 | var canvas = new G.Canvas(tslib_1.__assign({ container: wrapperElement, pixelRatio: pixelRatio,
|
26 | localRefresh: localRefresh,
|
27 | supportCSSTransform: supportCSSTransform }, size));
|
28 |
|
29 | _this = _super.call(this, {
|
30 | parent: null,
|
31 | canvas: canvas,
|
32 |
|
33 | backgroundGroup: canvas.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.BG }),
|
34 | middleGroup: canvas.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.MID }),
|
35 | foregroundGroup: canvas.addGroup({ zIndex: constant_1.GROUP_Z_INDEX.FORE }),
|
36 | padding: padding,
|
37 | appendPadding: appendPadding,
|
38 | visible: visible,
|
39 | options: options,
|
40 | limitInPlot: limitInPlot,
|
41 | theme: theme,
|
42 | syncViewPadding: syncViewPadding,
|
43 | }) || this;
|
44 | |
45 |
|
46 |
|
47 | _this.onResize = util_1.debounce(function () {
|
48 | _this.forceFit();
|
49 | }, 300);
|
50 | _this.ele = ele;
|
51 | _this.canvas = canvas;
|
52 | _this.width = size.width;
|
53 | _this.height = size.height;
|
54 | _this.autoFit = autoFit;
|
55 | _this.localRefresh = localRefresh;
|
56 | _this.renderer = renderer;
|
57 | _this.wrapperElement = wrapperElement;
|
58 |
|
59 | _this.updateCanvasStyle();
|
60 | _this.bindAutoFit();
|
61 | _this.initDefaultInteractions(defaultInteractions);
|
62 | return _this;
|
63 | }
|
64 | Chart.prototype.initDefaultInteractions = function (interactions) {
|
65 | var _this = this;
|
66 | util_1.each(interactions, function (interaction) {
|
67 | _this.interaction(interaction);
|
68 | });
|
69 | };
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | Chart.prototype.changeSize = function (width, height) {
|
77 |
|
78 | if (this.width === width && this.height === height) {
|
79 | return this;
|
80 | }
|
81 | this.emit(constant_1.VIEW_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
|
82 | this.width = width;
|
83 | this.height = height;
|
84 | this.canvas.changeSize(width, height);
|
85 |
|
86 | this.render(true);
|
87 | this.emit(constant_1.VIEW_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
|
88 | return this;
|
89 | };
|
90 | |
91 |
|
92 |
|
93 |
|
94 | Chart.prototype.destroy = function () {
|
95 | _super.prototype.destroy.call(this);
|
96 | this.unbindAutoFit();
|
97 | this.canvas.destroy();
|
98 | dom_1.removeDom(this.wrapperElement);
|
99 | this.wrapperElement = null;
|
100 | };
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | Chart.prototype.changeVisible = function (visible) {
|
107 | _super.prototype.changeVisible.call(this, visible);
|
108 | this.wrapperElement.style.display = visible ? '' : 'none';
|
109 | return this;
|
110 | };
|
111 | |
112 |
|
113 |
|
114 | Chart.prototype.forceFit = function () {
|
115 |
|
116 | if (!this.destroyed) {
|
117 |
|
118 | var _a = dom_1.getChartSize(this.ele, true, this.width, this.height), width = _a.width, height = _a.height;
|
119 | this.changeSize(width, height);
|
120 | }
|
121 | };
|
122 | Chart.prototype.updateCanvasStyle = function () {
|
123 | dom_1.modifyCSS(this.canvas.get('el'), {
|
124 | display: 'inline-block',
|
125 | verticalAlign: 'middle',
|
126 | });
|
127 | };
|
128 | Chart.prototype.bindAutoFit = function () {
|
129 | if (this.autoFit) {
|
130 | window.addEventListener('resize', this.onResize);
|
131 | }
|
132 | };
|
133 | Chart.prototype.unbindAutoFit = function () {
|
134 | if (this.autoFit) {
|
135 | window.removeEventListener('resize', this.onResize);
|
136 | }
|
137 | };
|
138 | return Chart;
|
139 | }(view_1.default));
|
140 | exports.default = Chart;
|
141 |
|
\ | No newline at end of file |