UNPKG

@visactor/vrender-components

Version:

components library for dp visualization

65 lines (58 loc) 2.81 kB
import { merge } from "@visactor/vutils"; import { Tag } from "../tag"; import { limitShapeInBounds } from "../util/limit-shape"; import { DEFAULT_STATES } from "../constant"; import { Marker } from "./base"; import { DefaultExitMarkerAnimation, DefaultUpdateMarkLineAnimation } from "./animate/animate"; export class MarkCommonLine extends Marker { constructor() { super(...arguments), this.name = "markCommonLine", this.defaultUpdateAnimation = DefaultUpdateMarkLineAnimation, this.defaultExitAnimation = DefaultExitMarkerAnimation; } getLine() { return this._line; } getLabel() { return this._label; } setLabelPos() { const {label: label = {}, limitRect: limitRect} = this.attribute, {position: position, confine: confine, autoRotate: autoRotate} = label, labelPoint = this.getPointAttrByPosition(position), labelAngle = position.toString().toLocaleLowerCase().includes("start") ? this._line.getStartAngle() || 0 : this._line.getEndAngle() || 0; if (this._label.setAttributes(Object.assign(Object.assign({}, labelPoint.position), { angle: autoRotate ? this.getRotateByAngle(labelPoint.angle) : 0, textStyle: Object.assign(Object.assign({}, this.getTextStyle(position, labelAngle, autoRotate)), label.textStyle) })), limitRect && confine) { const {x: x, y: y, width: width, height: height} = limitRect; limitShapeInBounds(this._label, { x1: x, y1: y, x2: x + width, y2: y + height }); } } initMarker(container) { const {label: label, state: state} = this.attribute, line = this.createSegment(); line.name = "mark-common-line-line", this._line = line, container.add(line); const markLabel = new Tag(Object.assign(Object.assign({}, label), { state: { panel: merge({}, DEFAULT_STATES, null == state ? void 0 : state.labelBackground), text: merge({}, DEFAULT_STATES, null == state ? void 0 : state.label) } })); markLabel.name = "mark-common-line-label", this._label = markLabel, container.add(markLabel), this.setLabelPos(); } updateMarker() { const {label: label, state: state} = this.attribute; this.setLineAttributes(), this._label && (this._label.setAttributes(Object.assign(Object.assign({ dx: 0, dy: 0 }, label), { state: { panel: merge({}, DEFAULT_STATES, null == state ? void 0 : state.labelBackground), text: merge({}, DEFAULT_STATES, null == state ? void 0 : state.label) } })), this.setLabelPos()); } } //# sourceMappingURL=common-line.js.map