"use strict";

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;
};

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.BaseMarkPoint = void 0;

const utils_1 = require("../utils"), vrender_components_1 = require("@visactor/vrender-components"), vutils_1 = require("@visactor/vutils"), style_1 = require("../../../util/style"), base_marker_1 = require("../base-marker"), layout_1 = require("../../../constant/layout");

class BaseMarkPoint extends base_marker_1.BaseMarker {
    constructor() {
        super(...arguments), this.specKey = "markPoint", this.layoutZIndex = layout_1.LayoutZIndex.MarkPoint;
    }
    static _getMarkerCoordinateType(markerSpec) {
        const {doPolarProcess: doPolarProcess, doGeoProcess: doGeoProcess} = (0, utils_1.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;
        const {itemContent: itemContent = {}, itemLine: itemLine = {}, targetSymbol: targetSymbol = {}} = this._spec, _9 = 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 = {}} = _9, restItemContent = __rest(_9, [ "type", "text", "symbol", "image", "richText", "customMark", "textStyle", "symbolStyle", "imageStyle", "richTextStyle", "customMarkStyle", "style", "state" ]);
        let itemContentState = null, itemContentStyle = null, defaultStyle = {};
        "text" === type ? (itemContentState = null !== (_a = null == label ? void 0 : label.state) && void 0 !== _a ? _a : state, 
        defaultStyle = {
            dx: 0,
            dy: 0
        }, itemContentStyle = (0, utils_1.transformLabelAttributes)(Object.assign(Object.assign({}, label), {
            style: (0, vutils_1.merge)(defaultStyle, null !== (_c = null !== (_b = null == label ? void 0 : label.textStyle) && void 0 !== _b ? _b : textStyle) && void 0 !== _c ? _c : style)
        }), this._markerData, this._markAttributeContext)) : "richText" === type ? (itemContentState = null !== (_d = null == richText ? void 0 : richText.state) && void 0 !== _d ? _d : state, 
        defaultStyle = {
            width: 100,
            height: 100
        }, itemContentStyle = (0, utils_1.transformStyle)((0, vutils_1.merge)(defaultStyle, null !== (_f = null !== (_e = null == richText ? void 0 : richText.style) && void 0 !== _e ? _e : richTextStyle) && void 0 !== _f ? _f : style), this._markerData, this._markAttributeContext)) : "symbol" === type ? (itemContentState = null !== (_g = null == symbol ? void 0 : symbol.state) && void 0 !== _g ? _g : state, 
        defaultStyle = {
            symbolType: "star",
            fill: "rgb(48, 115, 242)",
            fillOpacity: .8,
            size: 20
        }, itemContentStyle = (0, style_1.transformToGraphic)((0, utils_1.transformStyle)((0, 
        vutils_1.merge)(defaultStyle, null !== (_j = null !== (_h = null == symbol ? void 0 : symbol.style) && void 0 !== _h ? _h : symbolStyle) && void 0 !== _j ? _j : style), this._markerData, this._markAttributeContext))) : "image" === type ? (itemContentState = null !== (_k = null == image ? void 0 : image.state) && void 0 !== _k ? _k : state, 
        defaultStyle = {
            width: 80,
            height: 80
        }, itemContentStyle = (0, utils_1.transformStyle)((0, vutils_1.merge)(defaultStyle, null !== (_m = null !== (_l = null == image ? void 0 : image.style) && void 0 !== _l ? _l : imageStyle) && void 0 !== _m ? _m : style), this._markerData, this._markAttributeContext)) : "custom" === type && (itemContentState = null !== (_o = null == customMark ? void 0 : customMark.state) && void 0 !== _o ? _o : state, 
        itemContentStyle = (0, utils_1.transformStyle)(null !== (_q = null !== (_p = null == customMark ? void 0 : customMark.style) && void 0 !== _p ? _p : customMarkStyle) && void 0 !== _q ? _q : style, this._markerData, this._markAttributeContext));
        const markPointAttrs = {
            zIndex: this.layoutZIndex,
            interactive: null === (_r = this._spec.interactive) || void 0 === _r || _r,
            hover: null === (_s = this._spec.interactive) || void 0 === _s || _s,
            select: null === (_t = this._spec.interactive) || void 0 === _t || _t,
            position: {
                x: 0,
                y: 0
            },
            clipInRange: null !== (_u = this._spec.clip) && void 0 !== _u && _u,
            itemContent: Object.assign(Object.assign({
                type: type,
                offsetX: (0, utils_1.transformOffset)(itemContent.offsetX, this._relativeSeries.getRegion()),
                offsetY: (0, utils_1.transformOffset)(itemContent.offsetX, this._relativeSeries.getRegion())
            }, restItemContent), {
                style: (0, utils_1.transformStyle)(itemContentStyle, this._markerData, this._markAttributeContext)
            }),
            targetSymbol: {
                offset: null !== (_v = targetSymbol.offset) && void 0 !== _v ? _v : 0,
                visible: null !== (_w = targetSymbol.visible) && void 0 !== _w && _w,
                size: null !== (_x = targetSymbol.size) && void 0 !== _x ? _x : 20,
                style: (0, utils_1.transformStyle)(targetSymbol.style, this._markerData, this._markAttributeContext)
            },
            state: {
                line: (0, utils_1.transformState)(null !== (_z = null === (_y = this._spec.itemLine.line) || void 0 === _y ? void 0 : _y.state) && void 0 !== _z ? _z : {}, this._markerData, this._markAttributeContext),
                lineStartSymbol: (0, utils_1.transformState)(null !== (_1 = null === (_0 = this._spec.itemLine.startSymbol) || void 0 === _0 ? void 0 : _0.state) && void 0 !== _1 ? _1 : {}, this._markerData, this._markAttributeContext),
                lineEndSymbol: (0, utils_1.transformState)(null !== (_3 = null === (_2 = this._spec.itemLine.endSymbol) || void 0 === _2 ? void 0 : _2.state) && void 0 !== _3 ? _3 : {}, this._markerData, this._markAttributeContext),
                itemContent: (0, utils_1.transformState)(itemContentState, this._markerData, this._markAttributeContext),
                textBackground: (0, utils_1.transformState)(null === (_5 = null === (_4 = this._spec.itemContent.text) || void 0 === _4 ? void 0 : _4.labelBackground) || void 0 === _5 ? void 0 : _5.state, this._markerData, this._markAttributeContext),
                targetItem: (0, utils_1.transformState)(null !== (_7 = null === (_6 = this._spec.targetSymbol) || void 0 === _6 ? void 0 : _6.state) && void 0 !== _7 ? _7 : {}, this._markerData, this._markAttributeContext)
            },
            animation: null !== (_8 = this._spec.animation) && void 0 !== _8 && _8,
            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: (0, style_1.transformToGraphic)(line.style)
        }) : {
            visible: !1
        };
        return new vrender_components_1.MarkPoint(markPointAttrs);
    }
    _markerLayout() {
        var _a, _b, _c, _d, _e;
        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;
        let limitRect;
        if (spec.clip || (null === (_a = spec.itemContent) || void 0 === _a ? void 0 : _a.confine)) {
            const {minX: minX, maxX: maxX, minY: minY, maxY: maxY} = (0, utils_1.computeClipRange)([ relativeSeries.getRegion() ]);
            limitRect = {
                x: minX,
                y: minY,
                width: maxX - minX,
                height: maxY - minY
            };
        }
        if (this._markerComponent) {
            const attribute = null !== (_b = this._markerComponent.attribute) && void 0 !== _b ? _b : {}, textStyle = null !== (_d = null === (_c = attribute.itemContent) || void 0 === _c ? void 0 : _c.textStyle) && void 0 !== _d ? _d : {};
            this._markerComponent.setAttributes({
                position: void 0 === point ? {
                    x: null,
                    y: null
                } : point,
                itemContent: Object.assign(Object.assign({}, attribute.itemContent), {
                    textStyle: Object.assign(Object.assign({}, textStyle), {
                        text: (null === (_e = this._spec.itemContent.text) || void 0 === _e ? void 0 : _e.formatMethod) ? this._spec.itemContent.text.formatMethod(dataPoints, seriesData) : textStyle.text
                    }),
                    offsetX: (0, utils_1.computeOffsetFromRegion)(point, attribute.itemContent.offsetX, this._relativeSeries.getRegion()),
                    offsetY: (0, utils_1.computeOffsetFromRegion)(point, attribute.itemContent.offsetY, this._relativeSeries.getRegion())
                }),
                limitRect: limitRect,
                dx: this._layoutOffsetX,
                dy: this._layoutOffsetY
            });
        }
    }
    _initDataView() {
        const spec = this._spec, {doXYProcess: doXYProcess, doPolarProcess: doPolarProcess, doGeoProcess: doGeoProcess} = (0, 
        utils_1.getMarkPointProcessInfo)(spec);
        ((0, vutils_1.isValid)(spec.coordinate) || doXYProcess || doPolarProcess || doGeoProcess) && this._initCommonDataView();
    }
}

exports.BaseMarkPoint = BaseMarkPoint, BaseMarkPoint.specKey = "markPoint";
//# sourceMappingURL=base-mark-point.js.map
