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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
/**
* $Id: mxPath.js,v 1.24 2012-06-13 17:31:32 gaudenz Exp $
* Copyright (c) 2006-2010, JGraph Ltd
*/
/**
* Class: mxPath
*
* An abstraction for creating VML and SVG paths. See <mxActor> for using this
* object inside an <mxShape> for painting cells.
*
* Constructor: mxPath
*
* Constructs a path for the given format, which is one of svg or vml.
*
* Parameters:
*
* format - String specifying the <format>. May be one of vml or svg
* (default).
*/
function mxPath(format)
{
this.format = format;
this.path = [];
this.translate = new mxPoint(0, 0);
};
/**
* Variable: format
*
* Defines the format for the output of this path. Possible values are
* svg and vml.
*/
mxPath.prototype.format = null;
/**
* Variable: translate
*
* <mxPoint> that specifies the translation of the complete path.
*/
mxPath.prototype.translate = null;
/**
* Variable: scale
*
* Number that specifies the translation of the path.
*/
mxPath.prototype.scale = 1;
/**
* Variable: path
*
* Contains the textual representation of the path as an array.
*/
mxPath.prototype.path = null;
/**
* Function: isVml
*
* Returns true if <format> is vml.
*/
mxPath.prototype.isVml = function()
{
return this.format == 'vml';
};
/**
* Function: getPath
*
* Returns string that represents the path in <format>.
*/
mxPath.prototype.getPath = function()
{
return this.path.join('');
};
/**
* Function: setTranslate
*
* Set the global translation of this path, that is, the origin of the
* coordinate system.
*
* Parameters:
*
* x - X-coordinate of the new origin.
* y - Y-coordinate of the new origin.
*/
mxPath.prototype.setTranslate = function(x, y)
{
this.translate = new mxPoint(x, y);
};
/**
* Function: moveTo
*
* Moves the cursor to (x, y).
*
* Parameters:
*
* x - X-coordinate of the new cursor location.
* y - Y-coordinate of the new cursor location.
*/
mxPath.prototype.moveTo = function(x, y)
{
x += this.translate.x;
y += this.translate.y;
x *= this.scale;
y *= this.scale;
if (this.isVml())
{
this.path.push('m ', Math.round(x), ' ', Math.round(y), ' ');
}
else
{
this.path.push('M ', x, ' ', y, ' ');
}
};
/**
* Function: lineTo
*
* Draws a straight line from the current poin to (x, y).
*
* Parameters:
*
* x - X-coordinate of the endpoint.
* y - Y-coordinate of the endpoint.
*/
mxPath.prototype.lineTo = function(x, y)
{
x += this.translate.x;
y += this.translate.y;
x *= this.scale;
y *= this.scale;
if (this.isVml())
{
this.path.push('l ', Math.round(x), ' ', Math.round(y), ' ');
}
else
{
this.path.push('L ', x, ' ', y, ' ');
}
};
/**
* Function: quadTo
*
* Draws a quadratic Bézier curve from the current point to (x, y) using
* (x1, y1) as the control point.
*
* Parameters:
*
* x1 - X-coordinate of the control point.
* y1 - Y-coordinate of the control point.
* x - X-coordinate of the endpoint.
* y - Y-coordinate of the endpoint.
*/
mxPath.prototype.quadTo = function(x1, y1, x, y)
{
x1 += this.translate.x;
y1 += this.translate.y;
x1 *= this.scale;
y1 *= this.scale;
x += this.translate.x;
y += this.translate.y;
x *= this.scale;
y *= this.scale;
if (this.isVml())
{
this.path.push('c ', Math.round(x1), ' ', Math.round(y1), ' ', Math.round(x), ' ',
Math.round(y), ' ', Math.round(x), ' ', Math.round(y), ' ');
}
else
{
this.path.push('Q ', x1, ' ', y1, ' ', x, ' ', y, ' ');
}
};
/**
* Function: curveTo
*
* Draws a cubic Bézier curve from the current point to (x, y) using
* (x1, y1) as the control point at the beginning of the curve and (x2, y2)
* as the control point at the end of the curve.
*
* Parameters:
*
* x1 - X-coordinate of the first control point.
* y1 - Y-coordinate of the first control point.
* x2 - X-coordinate of the second control point.
* y2 - Y-coordinate of the second control point.
* x - X-coordinate of the endpoint.
* y - Y-coordinate of the endpoint.
*/
mxPath.prototype.curveTo = function(x1, y1, x2, y2, x, y)
{
x1 += this.translate.x;
y1 += this.translate.y;
x1 *= this.scale;
y1 *= this.scale;
x2 += this.translate.x;
y2 += this.translate.y;
x2 *= this.scale;
y2 *= this.scale;
x += this.translate.x;
y += this.translate.y;
x *= this.scale;
y *= this.scale;
if (this.isVml())
{
this.path.push('c ', Math.round(x1), ' ', Math.round(y1), ' ', Math.round(x2),
' ', Math.round(y2), ' ', Math.round(x), ' ', Math.round(y), ' ');
}
else
{
this.path.push('C ', x1, ' ', y1, ' ', x2,
' ', y2, ' ', x, ' ', y, ' ');
}
};
/**
* Function: ellipse
*
* Adds the given ellipse. Some implementations may require the path to be
* closed after this operation.
*/
mxPath.prototype.ellipse = function(x, y, w, h)
{
x += this.translate.x;
y += this.translate.y;
x *= this.scale;
y *= this.scale;
if (this.isVml())
{
this.path.push('at ', Math.round(x), ' ', Math.round(y), ' ', Math.round(x + w), ' ', Math.round(y + h), ' ',
Math.round(x), ' ', Math.round(y + h / 2), ' ', Math.round(x), ' ', Math.round(y + h / 2));
}
else
{
var startX = x;
var startY = y + h/2;
var endX = x + w;
var endY = y + h/2;
var r1 = w/2;
var r2 = h/2;
this.path.push('M ', startX, ' ', startY, ' ');
this.path.push('A ', r1, ' ', r2, ' 0 1 0 ', endX, ' ', endY, ' ');
this.path.push('A ', r1, ' ', r2, ' 0 1 0 ', startX, ' ', startY);
}
};
/**
* Function: addPath
*
* Adds the given path.
*/
mxPath.prototype.addPath = function(path)
{
this.path = this.path.concat(path.path);
};
/**
* Function: write
*
* Writes directly into the path. This bypasses all conversions.
*/
mxPath.prototype.write = function(string)
{
this.path.push(string, ' ');
};
/**
* Function: end
*
* Ends the path.
*/
mxPath.prototype.end = function()
{
if (this.format == 'vml')
{
this.path.push('e');
}
};
/**
* Function: close
*
* Closes the path.
*/
mxPath.prototype.close = function()
{
if (this.format == 'vml')
{
this.path.push('x e');
}
else
{
this.path.push('Z');
}
};
|