UNPKG

3.73 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import { each } from '@antv/util';
3import { getElements, getElementsByState } from '../util';
4import { clearHighlight } from './highlight-util';
5import StateAction from './state';
6import { ELEMENT_STATE } from '../../../constant';
7export var STATUS_UNACTIVE = ELEMENT_STATE.INACTIVE;
8export var STATUS_ACTIVE = ELEMENT_STATE.ACTIVE;
9/**
10 * @ignore
11 * highlight,指定图形高亮,其他图形变暗
12 */
13var ElementHighlight = /** @class */ (function (_super) {
14 __extends(ElementHighlight, _super);
15 function ElementHighlight() {
16 var _this = _super !== null && _super.apply(this, arguments) || this;
17 _this.stateName = STATUS_ACTIVE;
18 return _this;
19 }
20 // 多个元素设置、取消 highlight
21 ElementHighlight.prototype.setElementsStateByItem = function (elements, field, item, enable) {
22 var _this = this;
23 var callback = function (el) { return _this.isMathItem(el, field, item); };
24 this.setHighlightBy(elements, callback, enable);
25 };
26 // 设置元素的 highlight
27 ElementHighlight.prototype.setElementHighlight = function (el, callback) {
28 if (callback(el)) {
29 if (el.hasState(STATUS_UNACTIVE)) {
30 el.setState(STATUS_UNACTIVE, false);
31 }
32 el.setState(STATUS_ACTIVE, true);
33 }
34 else if (!el.hasState(STATUS_ACTIVE)) {
35 el.setState(STATUS_UNACTIVE, true);
36 }
37 };
38 ElementHighlight.prototype.setHighlightBy = function (elements, callback, enable) {
39 var _this = this;
40 if (enable) {
41 // 如果是设置 highlight ,则将匹配的 element 设置成 active,
42 // 其他如果不是 active,则设置成 unactive
43 each(elements, function (el) {
44 _this.setElementHighlight(el, callback);
45 });
46 }
47 else {
48 // 如果取消 highlight,则要检测是否全部取消 highlight
49 var activeElements = getElementsByState(this.context.view, STATUS_ACTIVE);
50 var allCancel_1 = true;
51 // 检测所有 activeElements 都要取消 highlight
52 each(activeElements, function (el) {
53 if (!callback(el)) {
54 allCancel_1 = false;
55 return false;
56 }
57 });
58 if (allCancel_1) {
59 // 都要取消,则取消所有的 active,unactive 状态
60 this.clear();
61 }
62 else {
63 // 如果不是都要取消 highlight, 则设置匹配的 element 的状态为 unactive
64 // 其他 element 状态不变
65 each(elements, function (el) {
66 if (callback(el)) {
67 if (el.hasState(STATUS_ACTIVE)) {
68 el.setState(STATUS_ACTIVE, false);
69 }
70 el.setState(STATUS_UNACTIVE, true);
71 }
72 });
73 }
74 }
75 };
76 // 单个元素设置和取消 highlight
77 ElementHighlight.prototype.setElementState = function (element, enable) {
78 var view = this.context.view;
79 var elements = getElements(view);
80 this.setHighlightBy(elements, function (el) { return element === el; }, enable);
81 };
82 ElementHighlight.prototype.highlight = function () {
83 this.setState();
84 };
85 // 清理掉所有的 active, unactive 状态
86 ElementHighlight.prototype.clear = function () {
87 var view = this.context.view;
88 clearHighlight(view);
89 };
90 return ElementHighlight;
91}(StateAction));
92export default ElementHighlight;
93//# sourceMappingURL=highlight.js.map
\No newline at end of file