UNPKG

1.8 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import { getElements, getElementValue, getCurrentElement } from '../util';
3import Highlight, { STATUS_ACTIVE, STATUS_UNACTIVE } from './highlight';
4/**
5 * Highlight x
6 * @ignore
7 */
8var HighlightX = /** @class */ (function (_super) {
9 __extends(HighlightX, _super);
10 function HighlightX() {
11 return _super !== null && _super.apply(this, arguments) || this;
12 }
13 // 不允许多选
14 HighlightX.prototype.setElementHighlight = function (el, callback) {
15 if (callback(el)) {
16 if (el.hasState(STATUS_UNACTIVE)) {
17 el.setState(STATUS_UNACTIVE, false);
18 }
19 el.setState(STATUS_ACTIVE, true);
20 }
21 else {
22 el.setState(STATUS_UNACTIVE, true);
23 if (el.hasState(STATUS_ACTIVE)) {
24 el.setState(STATUS_ACTIVE, false);
25 }
26 }
27 };
28 HighlightX.prototype.setStateByElement = function (element, enable) {
29 var view = this.context.view;
30 var scale = view.getXScale();
31 var value = getElementValue(element, scale.field);
32 var elements = getElements(view);
33 var highlightElements = elements.filter(function (el) {
34 return getElementValue(el, scale.field) === value;
35 });
36 this.setHighlightBy(elements, function (el) { return highlightElements.includes(el); }, enable);
37 };
38 /**
39 * 切换状态
40 */
41 HighlightX.prototype.toggle = function () {
42 var element = getCurrentElement(this.context);
43 if (element) {
44 var hasState = element.hasState(this.stateName);
45 this.setStateByElement(element, !hasState);
46 }
47 };
48 return HighlightX;
49}(Highlight));
50export default HighlightX;
51//# sourceMappingURL=highlight-by-x.js.map
\No newline at end of file