design_wev8.js
6.5 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
function draw(context, workflowBase, p) {
/*
var canvas = $("#mainArea")[0];
var _callBack = function() {
draw();
};
if (canvas == null || canvas == undefined) {
setTimeout(_callBack, 500);
return;
}
var context = canvas.getContext("2d");
*/
for (var i = 0; i < workflowBase.nodeBases.length; i++) {
var crtNode = workflowBase.nodeBases[i];
drawNode(context, crtNode);
}
for (var i = 0; i < workflowBase.nodeLinks.length; i++) {
drawLine(context, workflowBase.nodeLinks[i]);
}
for (var i = 0; i < workflowBase.groups.length; i++) {
var g = workflowBase.groups[i];
//alert(g.direction);
//console.log(g);
if (g.direction == 0) {
//alert("x=" + g.x + ", y=" + g.y + ", width=" + g.width + ", height=" + g.height);
dashRect(g.x, g.y, g.width, g.height, g.groupName, context);
} else if (g.direction == 1) {
drawBlock(0, g.x, g.y, maxWidth, g.height, g.groupName, context);
} else if (g.direction == 2) {
drawBlock(1, g.x, g.y, g.width, maxHeight, g.groupName, context);
}
//var maxWidth = 800;
//var maxHeight = 600;
}
}
/**
* 初始化节点
*/
function drawNode(content, node) {
if (node == null || node == undefined) {
return;
}
if (node.nodetype == 0 || node.nodetype == 3) {
var imgSrc = node.bgImage();
loadImage(imgSrc, function() {
content.drawImage(this, node.x, node.y);
//console.log(content.isPointInPath(90, 90));
content.fillStyle = node.fontColor();
//console.log(content.isPointInPath(90, 90));
drawText(content, node.text, 'normal 12px Microsoft YaHei', parseInt(node.x) + (113 - 70) / 2 - 10, parseInt(node.y) + 113 / 2 - 12, 70);
//console.log(content.isPointInPath(90, 90));
drawText(content, node.nodeOperatorName, 'normal 13px Microsoft YaHei', parseInt(node.x) + (113 - 70) / 2 - 10, parseInt(node.y) + 113 / 2 + 5, 70);
//console.log(content.isPointInPath(90, 90));
content.stroke();
//console.log(content.isPointInPath(90, 90));
});
} else if (node.nodetype == 1) {
if (node.nodeOptType == 1) {
diamond(content, parseInt(node.x), parseInt(node.y), 110, 100, 5, "#BD9F82", "#F1AF0A", "#E59C07", "#A96F05", "/workflow/design/h5display/images/node_bg2_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
} else if (node.nodeOptType == 0) {
diamond(content, parseInt(node.x), parseInt(node.y), 110, 100, 5, "#16A0CE", "#72D8F9", "#26B2E0", "#3A8DAA", "/workflow/design/h5display/images/node_bg3_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
} else {
diamond(content, parseInt(node.x), parseInt(node.y), 110, 100, 5, "#367819", "#A2E087", "#7FBF64", "#367819", "/workflow/design/h5display/images/node_bg_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
}
} else {
if (node.nodeOptType == 1) {
roundRect(content, parseInt(node.x + 2), parseInt(node.y), 108, 70, 5, "#BD9F82", "#F1AF0A", "#E59C07", "#A96F05", "/workflow/design/h5display/images/node_bg2_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
} else if (node.nodeOptType == 0) {
roundRect(content, parseInt(node.x + 2), parseInt(node.y), 108, 70, 5, "#16A0CE", "#72D8F9", "#26B2E0", "#3A8DAA", "/workflow/design/h5display/images/node_bg3_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
} else {
roundRect(content, parseInt(node.x + 2), parseInt(node.y), 108, 70, 5, "#367819", "#A2E087", "#7FBF64", "#367819", "/workflow/design/h5display/images/node_bg_wev8.png", "/workflow/design/h5display/images/line_wev8.png", node.text, node.nodeOperatorName, node.fontColor());
}
}
this.fillStyle = "#ffffff";
this.strokeStyle = "#000000";
this.lineWidth = 1;
}
function drawLine(ctx, nl) {
//console.log(nl);
if (nl == null || nl == undefined || nl.points == null || nl.points == "") return;
ctx.beginPath();
ctx.lineWidth = 2;
if (nl.ispass == "true" || nl.ispass == true) {
ctx.strokeStyle = '#E90B0A';
} else {
ctx.strokeStyle = '#8c8c8c';
}
var pointAry = new Array();
//var tempArray = nl.points.split(",");
for (var i = 0; i < nl.points.length; i++) {
var point = new Point(nl.points[i].x, nl.points[i].y);
pointAry.push(point);
}
if (pointAry.length <= 0) return;
ctx.moveTo(pointAry[0].x, pointAry[0].y);
//记录划线的记录
nl.pushDrawPoint(pointAry[0]);
var sPoint = null;
var ePoint = null;
//console.log(nl.text + ":" + nl.points);
var interval = 8;
for (var i = 0; i < pointAry.length; i++) {
var p = pointAry[i];
if (i == 0) {
if (parseInt(nl.startDirection) == 90) {
//p.x += interval - 1;
p.x = nl.startNode.leftPoint().x;
} else if (parseInt(nl.startDirection) == 180) {
//p.y += interval;
p.y = nl.startNode.topPoint().y;
} else if (parseInt(nl.startDirection) == -90) {
//p.x -= interval;
p.x = nl.startNode.rightPoint().x;
} else if (parseInt(nl.startDirection) == 0) {
//p.y -= interval;
p.y = nl.startNode.bottomPoint().y;
}
}
if (i == pointAry.length - 1) {
if (parseInt(nl.endDirection) == 90) {
//x += interval;
p.x = nl.endNode.leftPoint().x;
} else if (parseInt(nl.endDirection) == 180) {
//p.y += interval;
p.y = nl.endNode.topPoint().y;
} else if (parseInt(nl.endDirection) == -90) {
//p.x -= interval - 3;
p.x = nl.endNode.rightPoint().x;
} else if (parseInt(nl.endDirection) == 0) {
//p.y -= interval;
p.y = nl.endNode.bottomPoint().y;
}
}
//记录划线的记录
nl.pushDrawPoint(p);
//如果不是最后一个点,即线的结尾节点 && 不是第一个节点
if (sPoint != null && (i + 1) < pointAry.length) {
ePoint = pointAry[i + 1];
//如果3点不在一个坐标轴内,则画曲线
if (!(sPoint.x == p.x && p.x == ePoint.x) && !(sPoint.y == p.y && p.y == ePoint.y)) {
//console.log(nl.text + ":" + sPoint.toString() + ", " + p.toString() + "," + ePoint.toString());
var aPoint = calCenterPoint(sPoint, p);
var bPoint = calCenterPoint(ePoint, p);
ctx.arcTo(p.x, p.y, bPoint.x, bPoint.y, 5);
//ctx.lineTo(p.x, p.y);
} else {
ctx.lineTo(p.x, p.y);
}
} else {
ctx.lineTo(p.x, p.y);
}
sPoint = p;
}
//nl.pushDrawPoint(ePoint);
//画箭头
drawArrow(ctx, pointAry[pointAry.length - 2], pointAry[pointAry.length - 1]);
ctx.closePath();
ctx.stroke();
}
function drawGroup(ctx, g) {
if (g == null || g == undefined) {
return;
}
}
function drawBlock(ctx, g) {
}