summaryrefslogtreecommitdiff
path: root/src/js/shape/mxEllipse.js
blob: f3882cff98637f3aa26bf9ab91d90f60698f0cb3 (plain)
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
/**
 * $Id: mxEllipse.js,v 1.20 2012-04-04 07:34:50 gaudenz Exp $
 * Copyright (c) 2006-2010, JGraph Ltd
 */
/**
 * Class: mxEllipse
 *
 * Extends <mxShape> to implement an ellipse shape.
 * This shape is registered under <mxConstants.SHAPE_ELLIPSE>
 * in <mxCellRenderer>.
 * 
 * Constructor: mxEllipse
 *
 * Constructs a new ellipse 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 mxEllipse(bounds, fill, stroke, strokewidth)
{
	this.bounds = bounds;
	this.fill = fill;
	this.stroke = stroke;
	this.strokewidth = (strokewidth != null) ? strokewidth : 1;
};

/**
 * Extends mxShape.
 */
mxEllipse.prototype = new mxShape();
mxEllipse.prototype.constructor = mxEllipse;

/**
 * Variable: mixedModeHtml
 *
 * Overrides the parent value with false, meaning it will
 * draw in VML in mixed Html mode.
 */
mxEllipse.prototype.mixedModeHtml = false;

/**
 * Variable: preferModeHtml
 *
 * Overrides the parent value with false, meaning it will
 * draw as VML in prefer Html mode.
 */
mxEllipse.prototype.preferModeHtml = false;

/**
 * Function: createVml
 *
 * Creates and returns the VML node to represent this shape.
 */
mxEllipse.prototype.createVml = function()
{
	// Uses an arc not an oval to make sure the
	// textbox fills out the outer bounds of the
	// circle, not just the inner rectangle
	var node = document.createElement('v:arc');
	node.startangle = '0';
	node.endangle = '360';
	this.configureVmlShape(node);

	return node;
};

/**
 * Function: createSvg
 *
 * Creates and returns the SVG node(s) to represent this shape.
 */
mxEllipse.prototype.createSvg = function()
{
	return this.createSvgGroup('ellipse');
};

/**
 * Function: redrawSvg
 *
 * Updates the SVG node(s) to reflect the latest bounds and scale.
 */
mxEllipse.prototype.redrawSvg = function()
{
	if (this.crisp)
	{
		this.innerNode.setAttribute('shape-rendering', 'crispEdges');
	}
	else
	{
		this.innerNode.removeAttribute('shape-rendering');
	}
	
	this.updateSvgNode(this.innerNode);
	this.updateSvgNode(this.shadowNode);
};

/**
 * Function: updateSvgNode
 *
 * Updates the given node to reflect the new <bounds> and <scale>.
 */
mxEllipse.prototype.updateSvgNode = function(node)
{
	if (node != null)
	{
		var strokeWidth = Math.round(Math.max(1, this.strokewidth * this.scale));
		node.setAttribute('stroke-width', strokeWidth);
		
		node.setAttribute('cx', this.bounds.x + this.bounds.width / 2);
		node.setAttribute('cy', this.bounds.y + this.bounds.height / 2);
		node.setAttribute('rx', this.bounds.width / 2);
		node.setAttribute('ry', this.bounds.height / 2);
		
		// Updates the shadow offset
		if (this.shadowNode != null)
		{
			this.shadowNode.setAttribute('transform',  this.getSvgShadowTransform());
		}

		if (this.isDashed)
		{
			var phase = Math.max(1, Math.round(3 * this.scale * this.strokewidth));
			node.setAttribute('stroke-dasharray', phase + ' ' + phase);
		}
	}
};