import { SCanvasView, SColor } from "@saga-web/draw/lib";
export class GraphView extends SCanvasView {
    constructor(id) {
        super(id);
        // 0 :line 1:area 2:img
        this._type = 0;
        // 线条颜色
        this._strokecolor = "";
        // 背景颜色
        this._bgcolor = "";
        //线条类型
        this._lineType = "";
        //线条粗细
        this._lineWidth = 1;
        /** 图片地址 */
        this._url = "";
    }
    get type() {
        return this._type;
    }
    set type(v) {
        this._type = v;
        this.update();
    }
    get strokecolor() {
        return this._strokecolor;
    }
    set strokecolor(v) {
        this._strokecolor = v;
        this.update();
    }
    get bgcolor() {
        return this._bgcolor;
    }
    set bgcolor(v) {
        this._bgcolor = v;
        this.update();
    }
    get lineType() {
        return this._lineType;
    }
    set lineType(v) {
        this._lineType = v;
        this.update();
    }
    get lineWidth() {
        return this._lineWidth;
    }
    set lineWidth(v) {
        this._lineWidth = v;
        this.update();
    }
    get url() {
        return this._url;
    }
    set url(v) {
        this._url = v;
        this.img = new Image();
        this.img.src = v;
        this.img.onload = () => {
            this.update();
        };
        this.img.onerror = (e) => {
            this.update();
        };
    }
    onDraw(canvas) {
        canvas.clearRect(0, 0, this.width, this.height);
        canvas.pen.lineWidth = this.lineWidth;
        if (this.lineType == 'dashed') {
            canvas.pen.lineDash = [10, 2];
        }
        if (this.lineType == 'dotted') {
            canvas.pen.lineDash = [this.lineWidth, this.lineWidth];
        }
        canvas.pen.color = new SColor(this.strokecolor);
        canvas.brush.color = new SColor(this.bgcolor);
        if (this.type == 0) {
            canvas.drawLine(0, 14, 28, 14);
        }
        else if (this.type == 1) {
            canvas.drawRect(0, 0, 28, 28);
        }
        else if (this.type == 2) {
            if (this.img) {
                console.log(this.img);
                canvas.drawImage(this.img, 0, 0, 28, 28);
            }
        }
    }
}
