forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxGeometry.php
More file actions
233 lines (205 loc) · 5.26 KB
/
mxGeometry.php
File metadata and controls
233 lines (205 loc) · 5.26 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
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
<?php
/**
* Copyright (c) 2006-2013, Gaudenz Alder
*/
class mxGeometry extends mxRectangle
{
/**
* Class: mxGeometry
*
* Represents the geometry of a cell. For vertices, the geometry consists
* of the x- and y-location, as well as the width and height. For edges,
* the edge either defines the source- and target-terminal, or the geometry
* defines the respective terminal points.
*
* Variable: TRANSLATE_CONTROL_POINTS
*
* Global switch to translate the points in translate. Default is true.
*/
public static $TRANSLATE_CONTROL_POINTS = true;
/**
* Variable: alternateBounds
*
* Stores alternate values for x, y, width and height in a rectangle.
* Default is null.
*/
var $alternateBounds;
/**
* Variable: sourcePoint
*
* Defines the source point of the edge. This is used if the corresponding
* edge does not have a source vertex. Otherwise it is ignored. Default is
* null.
*/
var $sourcePoint;
/**
* Variable: targetPoint
*
* Defines the target point of the edge. This is used if the corresponding
* edge does not have a target vertex. Otherwise it is ignored. Default is
* null.
*/
var $targetPoint;
/**
* Variable: points
*
* Array of <mxPoints> which specifies the control points along the edge.
* These points are the intermediate points on the edge, for the endpoints
* use <targetPoint> and <sourcePoint> or set the terminals of the edge to
* a non-null value. Default is null.
*/
var $points;
/**
* Variable: offset
*
* Holds the offset of the label for edges. This is the absolute vector
* between the center of the edge and the top, left point of the label.
* Default is null.
*/
var $offset;
/**
* Variable: relative
*
* Specifies if the coordinates in the geometry are to be interpreted as
* relative coordinates. Default is false. This is used to mark a geometry
* with an x- and y-coordinate that is used to describe an edge label
* position.
*/
var $relative = false;
/**
* Constructor: mxGeometry
*
* Constructs a new object to describe the size and location
* of a vertex or the control points of an edge.
*/
function mxGeometry($x=0, $y=0, $width=0, $height=0)
{
parent::mxRectangle($x, $y, $width, $height);
}
/**
* Function: getTerminalPoint
*
* Returns the <mxPoint> representing the source or target point of this
* edge. This is only used if the edge has no source or target vertex.
*
* Parameters:
*
* isSource - Boolean that specifies if the source or target point
* should be returned.
*/
function getTerminalPoint($isSource)
{
return ($isSource) ? $this->sourcePoint : $this->targetPoint;
}
/**
* Function: setTerminalPoint
*
* Sets the <sourcePoint> or <targetPoint> to the given <mxPoint> and
* returns the new point.
*
* Parameters:
*
* point - Point to be used as the new source or target point.
* isSource - Boolean that specifies if the source or target point
* should be set.
*/
function setTerminalPoint($point, $isSource)
{
if ($isSource)
{
$this->sourcePoint = $point;
}
else
{
$this->targetPoint = $point;
}
return $point;
}
/**
* Function: translate
*
* Translates the geometry by the specified amount. That is, <x> and <y>
* of the geometry, the <sourcePoint>, <targetPoint> and all elements of
* <points> are translated by the given amount. <x> and <y> are only
* translated if <relative> is false. If <TRANSLATE_CONTROL_POINTS> is
* false, then <points> are not modified by this function.
*
* Parameters:
*
* dx - Integer that specifies the x-coordinate of the translation.
* dy - Integer that specifies the y-coordinate of the translation.
*/
function translate($dx, $dy)
{
// Translates the geometry
if (!$this->relative)
{
$this->x += $dx;
$this->y += $dy;
}
// Translates the source point
if ($this->sourcePoint != null)
{
$this->sourcePoint->x += $dx;
$this->sourcePoint->y += $dy;
}
// Translates the target point
if ($this->targetPoint != null)
{
$this->targetPoint->x += $dx;
$this->targetPoint->y += $dy;
}
// Translate the control points
if (mxGeometry::$TRANSLATE_CONTROL_POINTS &&
$this->points != null)
{
$count = sizeof($this->points);
for ($i = 0; $i < $count; $i++)
{
$pt = $this->points[i];
$pt->x += $dx;
$pt->y += $dy;
}
}
}
/**
* Function: copy
*
* Returns a copy of this <mxGeometry>.
*/
function copy()
{
$clone = new mxGeometry($this->x, $this->y, $this->width, $this->height);
// Clones the points
if ($this->points != null)
{
$clone->points = array();
for ($i = 0; $i < sizeof($this->points); $i++)
{
array_push($clone->points, $this->points[$i]->copy());
}
}
// Clones the alternatebounds
if ($this->alternateBounds != null)
{
$clone->alternateBounds = $this->alternateBounds->copy();
}
// Clones the offset
if ($this->offset != null)
{
$clone->offset = $this->offset->copy();
}
// Clones the source and targetpoint
if ($this->sourcePoint != null)
{
$clone->sourcePoint = $this->sourcePoint->copy();
}
if ($this->targetPoint != null)
{
$clone->targetPoint = $this->targetPoint->copy();
}
$clone->relative = $this->relative;
return $clone;
}
}
?>