UNPKG

1.6 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import { each } from '@antv/util';
3import Action from '../base';
4import { getElementsByState } from '../util';
5/**
6 * 状态量 Action 的基类
7 * @abstract
8 * @class
9 * @ignore
10 */
11var StateBase = /** @class */ (function (_super) {
12 __extends(StateBase, _super);
13 function StateBase() {
14 var _this = _super !== null && _super.apply(this, arguments) || this;
15 /**
16 * 状态名称
17 */
18 _this.stateName = '';
19 return _this;
20 }
21 /**
22 * 是否具有某个状态
23 * @param element 图表 Element 元素
24 */
25 StateBase.prototype.hasState = function (element) {
26 return element.hasState(this.stateName);
27 };
28 /**
29 * 设置状态激活
30 * @param enable 状态值
31 */
32 StateBase.prototype.setElementState = function (element, enable) {
33 // 防止闪烁
34 element.setState(this.stateName, enable);
35 };
36 /**
37 * 设置状态
38 */
39 StateBase.prototype.setState = function () {
40 this.setStateEnable(true);
41 };
42 /**
43 * 清除所有 Element 的状态
44 */
45 StateBase.prototype.clear = function () {
46 var view = this.context.view;
47 this.clearViewState(view);
48 };
49 StateBase.prototype.clearViewState = function (view) {
50 var _this = this;
51 var elements = getElementsByState(view, this.stateName);
52 each(elements, function (el) {
53 _this.setElementState(el, false);
54 });
55 };
56 return StateBase;
57}(Action));
58export default StateBase;
59//# sourceMappingURL=state-base.js.map
\No newline at end of file