@visactor/vchart
Version:
charts lib based @visactor/VGrammar
200 lines (187 loc) • 15.1 kB
JavaScript
var __rest = this && this.__rest || function(s, e) {
var t = {};
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
var i = 0;
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
}
return t;
};
import { computeClipRange, computeOffsetFromRegion, getMarkPointProcessInfo, transformLabelAttributes, transformOffset, transformState, transformStyle } from "../utils";
import { MarkPoint as MarkPointComponent } from "@visactor/vrender-components";
import { array, isValid, merge } from "@visactor/vutils";
import { transformToGraphic } from "../../../util/style";
import { BaseMarker } from "../base-marker";
import { LayoutZIndex } from "../../../constant/layout";
import { STATE_VALUE_ENUM } from "../../../compile/mark/interface";
import { DimensionEventEnum } from "../../../event/events/dimension/interface";
const isRichTextStyle = style => "rich" === (null == style ? void 0 : style.type), normalizeRichTextStyle = style => {
if (!style) return style;
const {type: _type, text: text, textConfig: textConfig} = style, restStyle = __rest(style, [ "type", "text", "textConfig" ]), normalizedStyle = Object.assign({}, restStyle), richTextConfig = isValid(textConfig) ? textConfig : text;
return isValid(richTextConfig) && (normalizedStyle.textConfig = richTextConfig),
normalizedStyle;
};
export class BaseMarkPoint extends BaseMarker {
constructor() {
super(...arguments), this.specKey = "markPoint", this.layoutZIndex = LayoutZIndex.MarkPoint,
this._handleDimensionHover = params => {
var _a, _b;
const targetSymbol = this._getTargetSymbolGraphic();
if (targetSymbol) switch (params.action) {
case "enter":
targetSymbol.removeState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER), targetSymbol.removeState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER_REVERSE),
this._isDimensionHoverTarget(params) ? targetSymbol.addState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER, !0) : (null === (_b = null === (_a = this._spec.targetSymbol) || void 0 === _a ? void 0 : _a.state) || void 0 === _b ? void 0 : _b.dimension_hover_reverse) && targetSymbol.addState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER_REVERSE, !0);
break;
case "leave":
targetSymbol.removeState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER), targetSymbol.removeState(STATE_VALUE_ENUM.STATE_DIMENSION_HOVER_REVERSE);
}
};
}
initEvent() {
var _a;
super.initEvent();
const targetSymbolState = null === (_a = this._spec.targetSymbol) || void 0 === _a ? void 0 : _a.state;
"cartesian" === this.coordinateType && ((null == targetSymbolState ? void 0 : targetSymbolState.dimension_hover) || (null == targetSymbolState ? void 0 : targetSymbolState.dimension_hover_reverse)) && this.event.on(DimensionEventEnum.dimensionHover, this._handleDimensionHover);
}
_getTargetSymbolGraphic() {
var _a;
return null === (_a = this._markerComponent) || void 0 === _a ? void 0 : _a.find((node => "mark-point-targetItem" === node.name), !0);
}
_isDimensionHoverTarget(params) {
var _a, _b, _c, _d;
const latestData = null === (_a = this._markerData) || void 0 === _a ? void 0 : _a.latestData, markerData = null !== (_c = null === (_b = null == latestData ? void 0 : latestData[0]) || void 0 === _b ? void 0 : _b.latestData) && void 0 !== _c ? _c : latestData;
return array(null === (_d = null == markerData ? void 0 : markerData[0]) || void 0 === _d ? void 0 : _d.x).filter(isValid).some((value => params.dimensionInfo.some((dimension => dimension.value === value))));
}
static _getMarkerCoordinateType(markerSpec) {
const {doPolarProcess: doPolarProcess, doGeoProcess: doGeoProcess} = getMarkPointProcessInfo(markerSpec);
return "polar" === markerSpec.coordinateType || doPolarProcess ? "polar" : "geo" === markerSpec.coordinateType || doGeoProcess ? "geo" : "cartesian";
}
_createMarkerComponent() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
const {itemContent: itemContent = {}, itemLine: itemLine = {}, targetSymbol: targetSymbol = {}} = this._spec, region = this._relativeSeries.getRegion(), _10 = itemContent, {type: type = "text", text: label, symbol: symbol, image: image, richText: richText, customMark: customMark, textStyle: textStyle, symbolStyle: symbolStyle, imageStyle: imageStyle, richTextStyle: richTextStyle, customMarkStyle: customMarkStyle, style: style = {}, state: state = {}} = _10, restItemContent = __rest(_10, [ "type", "text", "symbol", "image", "richText", "customMark", "textStyle", "symbolStyle", "imageStyle", "richTextStyle", "customMarkStyle", "style", "state" ]);
let itemContentState = null, itemContentStyle = null, itemContentType = type, defaultStyle = {};
if ("text" === type) {
itemContentState = null !== (_a = null == label ? void 0 : label.state) && void 0 !== _a ? _a : state;
const labelStyle = null !== (_d = null !== (_c = null !== (_b = null == label ? void 0 : label.style) && void 0 !== _b ? _b : null == label ? void 0 : label.textStyle) && void 0 !== _c ? _c : textStyle) && void 0 !== _d ? _d : style;
isRichTextStyle(labelStyle) ? (itemContentType = "richText", defaultStyle = {
width: 100,
height: 100
}, itemContentStyle = transformStyle(merge(defaultStyle, normalizeRichTextStyle(labelStyle)), this._markerData, this._markAttributeContext)) : (defaultStyle = {
dx: 0,
dy: 0
}, itemContentStyle = transformLabelAttributes(Object.assign(Object.assign({}, label), {
style: merge(defaultStyle, labelStyle)
}), this._markerData, this._markAttributeContext));
} else "richText" === type ? (itemContentState = null !== (_e = null == richText ? void 0 : richText.state) && void 0 !== _e ? _e : state,
defaultStyle = {
width: 100,
height: 100
}, itemContentStyle = transformStyle(merge(defaultStyle, null !== (_g = null !== (_f = null == richText ? void 0 : richText.style) && void 0 !== _f ? _f : richTextStyle) && void 0 !== _g ? _g : style), this._markerData, this._markAttributeContext)) : "symbol" === type ? (itemContentState = null !== (_h = null == symbol ? void 0 : symbol.state) && void 0 !== _h ? _h : state,
defaultStyle = {
symbolType: "star",
fill: "rgb(48, 115, 242)",
fillOpacity: .8,
size: 20
}, itemContentStyle = transformToGraphic(transformStyle(merge(defaultStyle, null !== (_k = null !== (_j = null == symbol ? void 0 : symbol.style) && void 0 !== _j ? _j : symbolStyle) && void 0 !== _k ? _k : style), this._markerData, this._markAttributeContext))) : "image" === type ? (itemContentState = null !== (_l = null == image ? void 0 : image.state) && void 0 !== _l ? _l : state,
defaultStyle = {
width: 80,
height: 80
}, itemContentStyle = transformStyle(merge(defaultStyle, null !== (_o = null !== (_m = null == image ? void 0 : image.style) && void 0 !== _m ? _m : imageStyle) && void 0 !== _o ? _o : style), this._markerData, this._markAttributeContext)) : "custom" === type && (itemContentState = null !== (_p = null == customMark ? void 0 : customMark.state) && void 0 !== _p ? _p : state,
itemContentStyle = transformStyle(null !== (_r = null !== (_q = null == customMark ? void 0 : customMark.style) && void 0 !== _q ? _q : customMarkStyle) && void 0 !== _r ? _r : style, this._markerData, this._markAttributeContext));
const markPointAttrs = {
zIndex: this.layoutZIndex,
interactive: null === (_s = this._spec.interactive) || void 0 === _s || _s,
hover: null === (_t = this._spec.interactive) || void 0 === _t || _t,
select: null === (_u = this._spec.interactive) || void 0 === _u || _u,
position: {
x: 0,
y: 0
},
clipInRange: null !== (_v = this._spec.clip) && void 0 !== _v && _v,
itemContent: Object.assign(Object.assign({
type: itemContentType,
offsetX: transformOffset(itemContent.offsetX, region),
offsetY: transformOffset(itemContent.offsetY, region)
}, restItemContent), {
style: transformStyle(itemContentStyle, this._markerData, this._markAttributeContext)
}),
targetSymbol: {
offset: null !== (_w = targetSymbol.offset) && void 0 !== _w ? _w : 0,
visible: null !== (_x = targetSymbol.visible) && void 0 !== _x && _x,
size: null !== (_y = targetSymbol.size) && void 0 !== _y ? _y : 20,
style: transformStyle(targetSymbol.style, this._markerData, this._markAttributeContext)
},
state: {
line: transformState(null !== (_0 = null === (_z = this._spec.itemLine.line) || void 0 === _z ? void 0 : _z.state) && void 0 !== _0 ? _0 : {}, this._markerData, this._markAttributeContext),
lineStartSymbol: transformState(null !== (_2 = null === (_1 = this._spec.itemLine.startSymbol) || void 0 === _1 ? void 0 : _1.state) && void 0 !== _2 ? _2 : {}, this._markerData, this._markAttributeContext),
lineEndSymbol: transformState(null !== (_4 = null === (_3 = this._spec.itemLine.endSymbol) || void 0 === _3 ? void 0 : _3.state) && void 0 !== _4 ? _4 : {}, this._markerData, this._markAttributeContext),
itemContent: transformState(itemContentState, this._markerData, this._markAttributeContext),
textBackground: transformState(null === (_6 = null === (_5 = this._spec.itemContent.text) || void 0 === _5 ? void 0 : _5.labelBackground) || void 0 === _6 ? void 0 : _6.state, this._markerData, this._markAttributeContext),
targetItem: transformState(null !== (_8 = null === (_7 = this._spec.targetSymbol) || void 0 === _7 ? void 0 : _7.state) && void 0 !== _8 ? _8 : {}, this._markerData, this._markAttributeContext)
},
animation: null !== (_9 = this._spec.animation) && void 0 !== _9 && _9,
animationEnter: this._spec.animationEnter,
animationExit: this._spec.animationExit,
animationUpdate: this._spec.animationUpdate
}, {visible: visible, line: line = {}} = itemLine, restItemLine = __rest(itemLine, [ "visible", "line" ]);
markPointAttrs.itemLine = !1 !== visible ? Object.assign(Object.assign({}, restItemLine), {
visible: !0,
lineStyle: transformToGraphic(line.style)
}) : {
visible: !1
};
return new MarkPointComponent(markPointAttrs);
}
_markerLayout() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
const spec = this._spec, data = this._markerData, relativeSeries = this._relativeSeries, {point: point} = this._computePointsAttr(), seriesData = this._getRelativeDataView().latestData, dataPoints = data ? data.latestData[0] && data.latestData[0].latestData ? data.latestData[0].latestData : data.latestData : seriesData, {itemLine: itemLine = {}, itemContent: itemContent = {}} = this._spec, region = this._relativeSeries.getRegion(), {visible: itemLineVisible, line: line = {}} = itemLine, restItemLine = __rest(itemLine, [ "visible", "line" ]), itemLineAttrs = !1 !== itemLineVisible ? Object.assign(Object.assign({}, restItemLine), {
visible: !0,
lineStyle: transformToGraphic(line.style)
}) : {
visible: !1
}, labelAttrs = transformLabelAttributes(Object.assign(Object.assign({}, itemContent.text), {
style: merge({
dx: 0,
dy: 0
}, null !== (_b = null === (_a = itemContent.text) || void 0 === _a ? void 0 : _a.style) && void 0 !== _b ? _b : itemContent.style)
}), data, this._markAttributeContext);
let limitRect;
if (spec.clip || (null === (_c = spec.itemContent) || void 0 === _c ? void 0 : _c.confine)) {
const {minX: minX, maxX: maxX, minY: minY, maxY: maxY} = computeClipRange([ relativeSeries.getRegion() ]);
limitRect = {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
}
if (this._markerComponent) {
const attribute = null !== (_d = this._markerComponent.attribute) && void 0 !== _d ? _d : {}, textStyle = null !== (_f = null === (_e = attribute.itemContent) || void 0 === _e ? void 0 : _e.textStyle) && void 0 !== _f ? _f : {}, specText = null === (_g = this._spec.itemContent.text) || void 0 === _g ? void 0 : _g.text, offsetX = transformOffset(itemContent.offsetX, region), offsetY = transformOffset(itemContent.offsetY, region);
this._markerComponent.setAttributes({
position: void 0 === point ? {
x: null,
y: null
} : point,
itemContent: Object.assign(Object.assign({}, attribute.itemContent), {
panel: null !== (_h = labelAttrs.panel) && void 0 !== _h ? _h : null === (_j = attribute.itemContent) || void 0 === _j ? void 0 : _j.panel,
padding: null !== (_k = labelAttrs.padding) && void 0 !== _k ? _k : null === (_l = attribute.itemContent) || void 0 === _l ? void 0 : _l.padding,
textStyle: Object.assign(Object.assign(Object.assign({}, textStyle), null !== (_m = labelAttrs.textStyle) && void 0 !== _m ? _m : {}), {
text: (null === (_o = this._spec.itemContent.text) || void 0 === _o ? void 0 : _o.formatMethod) ? this._spec.itemContent.text.formatMethod(dataPoints, seriesData) : isValid(specText) ? specText : textStyle.text
}),
offsetX: computeOffsetFromRegion(point, offsetX, region),
offsetY: computeOffsetFromRegion(point, offsetY, region)
}),
itemLine: itemLineAttrs,
limitRect: limitRect,
dx: this._layoutOffsetX,
dy: this._layoutOffsetY
});
}
}
_initDataView() {
const spec = this._spec, {doXYProcess: doXYProcess, doPolarProcess: doPolarProcess, doGeoProcess: doGeoProcess} = getMarkPointProcessInfo(spec);
(isValid(spec.coordinate) || doXYProcess || doPolarProcess || doGeoProcess) && this._initCommonDataView();
}
}
BaseMarkPoint.specKey = "markPoint";
//# sourceMappingURL=base-mark-point.js.map