@visactor/vchart
Version:
charts lib based @visactor/VGrammar
51 lines (47 loc) • 2.38 kB
JavaScript
import { error } from "../../../util/debug";
import { isDiscrete } from "@visactor/vscale";
import { isXAxis } from "../../../component/axis/cartesian/util";
export class DimensionEvent {
constructor(eventDispatcher, mode) {
this._eventDispatcher = eventDispatcher, this._mode = mode;
}
get chart() {
var _a, _b;
return this._chart || (this._chart = null === (_b = (_a = this._eventDispatcher.globalInstance).getChart) || void 0 === _b ? void 0 : _b.call(_a)),
this._chart;
}
register(eType, handler) {
var _a, _b;
(null !== (_b = null === (_a = this.chart) || void 0 === _a ? void 0 : _a.getOption().onError) && void 0 !== _b ? _b : error)("Method not implemented.");
}
unregister() {
var _a, _b;
(null !== (_b = null === (_a = this.chart) || void 0 === _a ? void 0 : _a.getOption().onError) && void 0 !== _b ? _b : error)("Method not implemented.");
}
getTargetDimensionInfo(x, y) {
var _a, _b, _c;
const dimensionInfo = null !== (_c = null === (_b = (_a = this.chart.getModelOption()).getDimensionInfo) || void 0 === _b ? void 0 : _b.call(_a, this.chart, {
x: x,
y: y
})) && void 0 !== _c ? _c : [];
return 0 === dimensionInfo.length ? null : dimensionInfo;
}
dispatch(v, opt) {
var _a, _b;
const axes = null === (_a = this.chart) || void 0 === _a ? void 0 : _a.getAllComponents().filter((c => "axes" === c.specKey && (!(null == opt ? void 0 : opt.filter) || opt.filter(c)))), discreteAxes = axes.filter((axis => {
const scale = axis.getScale();
return isDiscrete(scale.type);
})), dimAxes = discreteAxes.length ? discreteAxes : axes.filter((axis => {
const orient = axis.getOrient();
return isXAxis(orient) || "angle" === orient;
})), dimensionInfo = [], getDimensionInfoByValue = null === (_b = this.chart) || void 0 === _b ? void 0 : _b.getModelOption().getDimensionInfoByValue;
return getDimensionInfoByValue && dimAxes.forEach((a => {
const info = getDimensionInfoByValue(a, v);
info && dimensionInfo.push(info);
})), this._callback.call(null, {
action: "enter",
dimensionInfo: dimensionInfo
}), dimensionInfo;
}
}
//# sourceMappingURL=base.js.map