forked from wavedrom/wavedrom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcs.new.js
155 lines (147 loc) · 4.83 KB
/
arcs.new.js
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
'use strict';
var to,
from,
// lx,
dx,
dy;
// def,
// Edge;
// lx = ((from.x + to.x) / 2);
// ly = ((from.y + to.y) / 2);
function from_x_y () {
return from.x + ',' + from.y;
}
function dx_dy () {
return dx + ', ' + dy;
}
// def = function () {
// return {
// style: 'fill:none;stroke:#F00;stroke-width:1'
// };
// };
var arcs = {
'-': function () {
return {
style: 'fill:none;stroke:#F00;stroke-width:1'
};
},
'~' : function () {
return {
d: 'M ' + from_x_y() + ' c ' + (0.7 * dx) + ', 0 ' + (0.3 * dx) + ', ' + dy + ' ' + dx_dy()
};
},
'-~': function () {
// if (Edge.label) { lx = (from.x + (to.x - from.x) * 0.75); }
return {
d: 'M ' + from_x_y() + ' c ' + (0.7 * dx) + ', 0 ' + dx_dy() + ' ' + dx_dy()
};
},
'~-': function () {
// if (Edge.label) { lx = (from.x + (to.x - from.x) * 0.25); }
return {
d: 'M ' + from_x_y() + ' c ' + 0 + ', 0 ' + (0.3 * dx) + ', ' + dy + ' ' + dx_dy()
};
},
'-|': function () {
// if (Edge.label) { lx = to.x; }
return {
d: 'm ' + from_x_y() + ' ' + dx + ',0 0,' + dy
};
},
'|-': function () {
// if (Edge.label) { lx = from.x; }
return {
d: 'm ' + from_x_y() + ' 0,' + dy + ' ' + dx + ',0'
};
},
'-|-': function () {
return {
d: 'm ' + from_x_y() + ' ' + (dx / 2) + ',0 0,' + dy + ' ' + (dx / 2) + ',0'
};
},
'->': function () {
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none'
};
},
'~>': function () {
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'M ' + from_x_y() + ' ' + 'c ' + (0.7 * dx) + ', 0 ' + 0.3 * dx_dy() + ' ' + dx_dy()
};
},
'-~>': function () {
// if (Edge.label) { lx = (from.x + (to.x - from.x) * 0.75); }
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'M ' + from_x_y() + ' ' + 'c ' + (0.7 * dx) + ', 0 ' + dx_dy() + ' ' + dx_dy()
};
},
'~->': function () {
// if (Edge.label) { lx = (from.x + (to.x - from.x) * 0.25); }
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'M ' + from_x_y() + ' ' + 'c ' + 0 + ', 0 ' + (0.3 * dx) + ', ' + dy + ' ' + dx_dy()
};
},
'-|>' : function () {
// if (Edge.label) { lx = to.x; }
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'm ' + from_x_y() + ' ' + dx + ',0 0,' + dy
};
},
'|->': function () {
// if (Edge.label) { lx = from.x; }
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'm ' + from_x_y() + ' 0,' + dy + ' ' + dx + ',0'
};
},
'-|->': function () {
return {
style: 'marker-end:url(#arrowhead);stroke:#0041c4;stroke-width:1;fill:none',
d: 'm ' + from_x_y() + ' ' + (dx / 2) + ',0 0,' + dy + ' ' + (dx / 2) + ',0'
};
},
'<->': function () {
return {
style: 'marker-end:url(#arrowhead);marker-start:url(#arrowtail);stroke:#0041c4;stroke-width:1;fill:none'
};
},
'<~>': function () {
return {
style: 'marker-end:url(#arrowhead);marker-start:url(#arrowtail);stroke:#0041c4;stroke-width:1;fill:none',
d: 'M ' + from_x_y() + ' ' + 'c ' + (0.7 * dx) + ', 0 ' + (0.3 * dx) + ', ' + dy + ' ' + dx_dy()
};
},
'<-~>': function () {
// if (Edge.label) { lx = (from.x + (to.x - from.x) * 0.75); }
return {
style: 'marker-end:url(#arrowhead);marker-start:url(#arrowtail);stroke:#0041c4;stroke-width:1;fill:none',
d: 'M ' + from_x_y() + ' ' + 'c ' + (0.7 * dx) + ', 0 ' + dx_dy() + ' ' + dx_dy()
};
},
'<-|>': function () {
// if (Edge.label) { lx = to.x; }
return {
style: 'marker-end:url(#arrowhead);marker-start:url(#arrowtail);stroke:#0041c4;stroke-width:1;fill:none',
d: 'm ' + from_x_y() + ' ' + dx + ',0 0,' + dy
};
},
'<-|->': function () {
return {
style: 'marker-end:url(#arrowhead);marker-start:url(#arrowtail);stroke:#0041c4;stroke-width:1;fill:none',
d: 'm ' + from_x_y() + ' ' + (dx / 2) + ',0 0,' + dy + ' ' + (dx / 2) + ',0'
};
}
};
function arc (str, ifrom, ito) {
from = ifrom;
to = ito;
dx = to.x - from.x;
dy = to.y - from.y;
var target = arcs[str] || arcs['->'];
return target();
}
module.exports = arc;