wangyanshen
2023-01-09 695c5a332e4bf10b6b93c9973e1634730b4a60df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import FlowGraph from "../../../graph";
 
import { getImg } from '@/utils/util'
 
const tryToJSON = (val) => {
    try {
        return JSON.parse(val)
    } catch (error) {
        return val
    }
}
 
export default class GridOption {
    // 绘制网格
    static gridOpt(globalGridAttr) {
        let options
        if (globalGridAttr.type === 'doubleMesh') {
            options = {
                type: globalGridAttr.type,
                args: [
                    {
                        color: globalGridAttr.color,
                        thickness: globalGridAttr.thickness,
                    },
                    {
                        color: globalGridAttr.colorSecond,
                        thickness: globalGridAttr.thicknessSecond,
                        factor: globalGridAttr.factor,
                    },
                ],
            }
        } else {
            options = {
                type: globalGridAttr.type,
                args: [
                    {
                        color: globalGridAttr.color,
                        thickness: globalGridAttr.thickness,
                    },
                ],
            }
        }
        const { graph } = FlowGraph
        graph.drawGrid(options)
    }
 
    // 设置网格大小
    static setGridSize(globalGridAttr) {
        const { graph } = FlowGraph
        graph.setGridSize(globalGridAttr.size)
    }
 
    // 获取网格大小
    static getGridSize() {
        const { graph } = FlowGraph
        graph.getGridSize()
    }
 
    // 重绘背景
    static backGroundOpt(globalGridAttr) {
        const options = {
            color: globalGridAttr.bgColor,
            // image: globalGridAttr.showImage ? 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*o-MuTpQaj7EAAAAAAAAAAABkARQnAQ' : undefined,
            image: globalGridAttr.showImage ?getImg('logo.png')  : undefined,
            // image: undefined,
            repeat: globalGridAttr.repeat,
            angle: globalGridAttr.angle,
            size: tryToJSON(globalGridAttr.bgSize),
            position: tryToJSON(globalGridAttr.position),
            opacity: globalGridAttr.opacity,
        }
        const { graph } = FlowGraph
        graph.drawBackground(options)
    }
 
    // 是否显示网格
    static isShowGrid({ showGrid }) {
        const { graph } = FlowGraph
        if(showGrid) {
            graph.showGrid()
        } else {
            graph.hideGrid()
        }
    }
}