# 矩形&圆角矩形
# item 实例
查看源代码:/persagy-web-graph/src/items/SGraphRectItem.ts
圆角半径 :
示例中展示了 一种渐变风格的 json 传参
"Default":{
"Stroke": "#cccccc",
"Fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 2,
"Effect": {}
},
"Selected": {
"Stroke": "#66ff66",
"Fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 3,
"Effect": {}
},
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
一种普通纯色风格的 json 传参
"Default":{
"Stroke": "#cccccc",
"Fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 2,
"Effect": {}
},
"Selected": {
"Stroke": "#66ff66",
"Fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 3,
"Effect": {}
},
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
查看代码使用
<template>
<div style="margin-top: 10px;">
<el-button size="small" @click="changeEnable">切换item1禁用状态</el-button>
圆角半径 : <el-input-number @change="changeY" v-model="R" size="mini" style="width: 100px"></el-input-number>
<canvas :id="id" width="740" height="400" />
</div>
</template>
<script lang="ts">
import {SGraphRectItem, SGraphScene, SGraphView} from "@persagy-web/graph/lib";
import { Component, Vue } from "vue-property-decorator";
@Component
export default class RectCanvas extends Vue {
id: string = 'rect' + Date.now();
view: SGraphView | undefined;
item: SGraphRectItem | undefined;
item2: SGraphRectItem | undefined;
R: number = 0;
rectData = {
X: 0,
Y: 0,
Width: 500,
Height: 500,
Radius: 0,
Style: {
"Default":{
"Stroke": "#cccccc",
"Fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 2,
"Effect": {}
},
"Selected": {
"Stroke": "#66ff66",
"Fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
"LineWidth": 3,
"Effect": {}
},
"Disabled": {
"Stroke": "#333333",
"Fill": "#afafaf",
"LineWidth": 1,
"Effect": {}
},
}
};
rectData2 = {
X: 1000,
Y: 0,
Width: 500,
Height: 500,
Radius: 0,
Style: {
"Default":{
"Stroke": "#cccccc",
"Fill": "#ffccee",
"LineWidth": 2,
"Effect": {}
},
"Selected": {
"Stroke": "#66ff66",
"Fill": "#ff33ee",
"LineWidth": 3,
"Effect": {}
},
"Disabled": {
"Stroke": "#333333",
"Fill": "#afafaf",
"LineWidth": 1,
"Effect": {}
},
}
};
private mounted (): void {
console.log(9999999999999)
this.init();
}
init(): void {
this.view = new SGraphView(this.id);
const scene = new SGraphScene();
this.item = new SGraphRectItem(null, this.rectData);
this.item.selectable = true;
scene.addItem(this.item);
this.item2 = new SGraphRectItem(null, this.rectData2);
this.item2.selectable = true;
scene.addItem(this.item2);
this.view.scene = scene;
this.view.fitSceneToView();
this.view.scalable = false;
}
changeEnable(): void{
if (this.item) {
this.item.enabled = !this.item.enabled;
}
}
// 修改圆角半径
changeY(val: number): void {
if (this.item){
this.item.radius = val;
}
if(this.item2) {
this.item2.radius = val;
}
}
}
</script>
<style scoped>
</style>
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# item 传参注意
item 传入的圆角的半径默认是 0,即不绘制圆角; 如果传入的值是数字类型且不为0则绘制圆角;
item 传入的数据 data 大写跟随数据字典;
保存item的时候,保存类型为 String ,调用渐变类的value()
方法即可返回当前渐变类的字符串;
item 状态切换及 Style 内容详情参考 建筑信息图-底图风格