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
315
316
317
318
319
|
/**
* $Id: mxCylinder.js,v 1.38 2012-07-31 11:46:53 gaudenz Exp $
* Copyright (c) 2006-2010, JGraph Ltd
*/
/**
* Class: mxCylinder
*
* Extends <mxShape> to implement an cylinder shape. If a
* custom shape with one filled area and an overlay path is
* needed, then this shape's <redrawPath> should be overridden.
* This shape is registered under <mxConstants.SHAPE_CYLINDER>
* in <mxCellRenderer>.
*
* Constructor: mxCylinder
*
* Constructs a new cylinder shape.
*
* Parameters:
*
* bounds - <mxRectangle> that defines the bounds. This is stored in
* <mxShape.bounds>.
* fill - String that defines the fill color. This is stored in <fill>.
* stroke - String that defines the stroke color. This is stored in <stroke>.
* strokewidth - Optional integer that defines the stroke width. Default is
* 1. This is stored in <strokewidth>.
*/
function mxCylinder(bounds, fill, stroke, strokewidth)
{
this.bounds = bounds;
this.fill = fill;
this.stroke = stroke;
this.strokewidth = (strokewidth != null) ? strokewidth : 1;
};
/**
* Extends mxShape.
*/
mxCylinder.prototype = new mxShape();
mxCylinder.prototype.constructor = mxCylinder;
/**
* Variable: vmlNodes
*
* Adds local references to <mxShape.vmlNodes>.
*/
mxCylinder.prototype.vmlNodes = mxCylinder.prototype.vmlNodes.concat(['background', 'foreground']);
/**
* Variable: mixedModeHtml
*
* Overrides the parent value with false, meaning it will
* draw in VML in mixed Html mode.
*/
mxCylinder.prototype.mixedModeHtml = false;
/**
* Variable: preferModeHtml
*
* Overrides the parent value with false, meaning it will
* draw as VML in prefer Html mode.
*/
mxCylinder.prototype.preferModeHtml = false;
/**
* Variable: addPipe
*
* Specifies if a SVG path should be created around the background for better
* hit detection. Default is false.
*/
mxCylinder.prototype.addPipe = false;
/**
* Variable: strokedBackground
*
* Specifies if the background should be stroked. Default is true.
*/
mxCylinder.prototype.strokedBackground = true;
/**
* Variable: maxHeight
*
* Defines the maximum height of the top and bottom part
* of the cylinder shape.
*/
mxCylinder.prototype.maxHeight = 40;
/**
* Variable: vmlScale
*
* Renders VML with a scale of 2.
*/
mxCylinder.prototype.vmlScale = 2;
/**
* Function: create
*
* Overrides the method to make sure the <stroke> is never
* null. If it is null is will be assigned the <fill> color.
*/
mxCylinder.prototype.create = function(container)
{
if (this.stroke == null)
{
this.stroke = this.fill;
}
// Calls superclass implementation of create
return mxShape.prototype.create.apply(this, arguments);
};
/**
* Function: reconfigure
*
* Overrides the method to make sure the <stroke> is applied to the foreground.
*/
mxCylinder.prototype.reconfigure = function()
{
if (this.dialect == mxConstants.DIALECT_SVG)
{
this.configureSvgShape(this.foreground);
this.foreground.setAttribute('fill', 'none');
}
else if (mxUtils.isVml(this.node))
{
this.configureVmlShape(this.background);
this.configureVmlShape(this.foreground);
}
mxShape.prototype.reconfigure.apply(this);
};
/**
* Function: createVml
*
* Creates and returns the VML node to represent this shape.
*/
mxCylinder.prototype.createVml = function()
{
var node = document.createElement('v:group');
// Draws the background
this.background = document.createElement('v:shape');
this.label = this.background;
this.configureVmlShape(this.background);
node.appendChild(this.background);
// Ignores values that only apply to the background
this.fill = null;
this.isShadow = false;
this.configureVmlShape(node);
// Draws the foreground
this.foreground = document.createElement('v:shape');
this.configureVmlShape(this.foreground);
// To match SVG defaults jointsyle miter, miterlimit 4
this.fgStrokeNode = document.createElement('v:stroke');
this.fgStrokeNode.joinstyle = 'miter';
this.fgStrokeNode.miterlimit = 4;
this.foreground.appendChild(this.fgStrokeNode);
node.appendChild(this.foreground);
return node;
};
/**
* Function: redrawVml
*
* Updates the VML node(s) to reflect the latest bounds and scale.
*/
mxCylinder.prototype.redrawVml = function()
{
this.updateVmlShape(this.node);
this.updateVmlShape(this.background);
this.updateVmlShape(this.foreground);
this.background.path = this.createPath(false);
this.foreground.path = this.createPath(true);
this.fgStrokeNode.dashstyle = this.strokeNode.dashstyle;
};
/**
* Function: createSvg
*
* Creates and returns the SVG node(s) to represent this shape.
*/
mxCylinder.prototype.createSvg = function()
{
var g = this.createSvgGroup('path');
this.foreground = document.createElementNS(mxConstants.NS_SVG, 'path');
if (this.stroke != null && this.stroke != mxConstants.NONE)
{
this.foreground.setAttribute('stroke', this.stroke);
}
else
{
this.foreground.setAttribute('stroke', 'none');
}
this.foreground.setAttribute('fill', 'none');
g.appendChild(this.foreground);
if (this.addPipe)
{
this.pipe = this.createSvgPipe();
g.appendChild(this.pipe);
}
return g;
};
/**
* Function: redrawSvg
*
* Updates the SVG node(s) to reflect the latest bounds and scale.
*/
mxCylinder.prototype.redrawSvg = function()
{
var strokeWidth = Math.round(Math.max(1, this.strokewidth * this.scale));
this.innerNode.setAttribute('stroke-width', strokeWidth);
if (this.crisp && (this.rotation == null || this.rotation == 0))
{
this.innerNode.setAttribute('shape-rendering', 'crispEdges');
this.foreground.setAttribute('shape-rendering', 'crispEdges');
}
else
{
this.innerNode.removeAttribute('shape-rendering');
this.foreground.removeAttribute('shape-rendering');
}
// Paints background
var d = this.createPath(false);
if (d.length > 0)
{
this.innerNode.setAttribute('d', d);
// Updates event handling element
if (this.pipe != null)
{
this.pipe.setAttribute('d', d);
this.pipe.setAttribute('stroke-width', strokeWidth + mxShape.prototype.SVG_STROKE_TOLERANCE);
this.pipe.setAttribute('transform', (this.innerNode.getAttribute('transform') || ''));
}
}
else
{
this.innerNode.removeAttribute('d');
// Updates event handling element
if (this.pipe != null)
{
this.pipe.removeAttribute('d');
}
}
// Stroked background
if (!this.strokedBackground)
{
this.innerNode.setAttribute('stroke', 'none');
}
// Paints shadow
if (this.shadowNode != null)
{
this.shadowNode.setAttribute('stroke-width', strokeWidth);
this.shadowNode.setAttribute('d', d);
this.shadowNode.setAttribute('transform', this.getSvgShadowTransform());
}
// Paints foreground
d = this.createPath(true);
if (d.length > 0)
{
this.foreground.setAttribute('stroke-width', strokeWidth);
this.foreground.setAttribute('d', d);
}
else
{
this.foreground.removeAttribute('d');
}
if (this.isDashed)
{
var phase = Math.max(1, Math.round(3 * this.scale * this.strokewidth));
this.innerNode.setAttribute('stroke-dasharray', phase + ' ' + phase);
this.foreground.setAttribute('stroke-dasharray', phase + ' ' + phase);
}
};
/**
* Function: redrawPath
*
* Draws the path for this shape. This method uses the <mxPath>
* abstraction to paint the shape for VML and SVG.
*/
mxCylinder.prototype.redrawPath = function(path, x, y, w, h, isForeground)
{
var dy = Math.min(this.maxHeight, Math.round(h / 5));
if (isForeground)
{
path.moveTo(0, dy);
path.curveTo(0, 2 * dy, w, 2 * dy, w, dy);
}
else
{
path.moveTo(0, dy);
path.curveTo(0, -dy / 3, w, -dy / 3, w, dy);
path.lineTo(w, h - dy);
path.curveTo(w, h + dy / 3, 0, h + dy / 3, 0, h - dy);
path.close();
}
};
|