forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxStylesheet.php
More file actions
226 lines (204 loc) · 5.27 KB
/
mxStylesheet.php
File metadata and controls
226 lines (204 loc) · 5.27 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
<?php
/**
* Copyright (c) 2006-2013, Gaudenz Alder
*/
class mxStylesheet
{
/**
* Class: mxStylesheet
*
* Defines the appearance of the cells in a graph. See
* <putCellStyle> for an example of creating a style.
*
* Default Styles:
*
* The stylesheet contains two built-om styles, which are
* used if no style is defined for a cell:
*
* defaultVertex - Default style for vertices
* defaultEdge - Default style for edges
*
* Function: styles
*
* Maps from names to styles.
*/
var $styles = array();
/**
* Constructor: mxStylesheet
*
* Constructs a new stylesheet and assigns default styles.
*/
function mxStylesheet()
{
$this->putDefaultVertexStyle($this->createDefaultVertexStyle());
$this->putDefaultEdgeStyle($this->createDefaultEdgeStyle());
}
/**
* Function: createDefaultVertexStyle
*
* Creates and returns the default vertex style.
*/
function createDefaultVertexStyle()
{
$style = array();
$style[mxConstants::$STYLE_SHAPE] = mxConstants::$SHAPE_RECTANGLE;
$style[mxConstants::$STYLE_PERIMETER] = mxPerimeter::$RectanglePerimeter;
$style[mxConstants::$STYLE_VERTICAL_ALIGN] = mxConstants::$ALIGN_MIDDLE;
$style[mxConstants::$STYLE_ALIGN] = mxConstants::$ALIGN_CENTER;
$style[mxConstants::$STYLE_FILLCOLOR] = "#C3D9FF";
$style[mxConstants::$STYLE_STROKECOLOR] = "#6482B9";
$style[mxConstants::$STYLE_FONTCOLOR] = "#774400";
return $style;
}
/**
* Function: createDefaultEdgeStyle
*
* Creates and returns the default edge style.
*/
function createDefaultEdgeStyle()
{
$style = array();
$style[mxConstants::$STYLE_SHAPE] = mxConstants::$SHAPE_CONNECTOR;
$style[mxConstants::$STYLE_ENDARROW] = mxConstants::$ARROW_CLASSIC;
$style[mxConstants::$STYLE_VERTICAL_ALIGN] = mxConstants::$ALIGN_MIDDLE;
$style[mxConstants::$STYLE_ALIGN] = mxConstants::$ALIGN_CENTER;
$style[mxConstants::$STYLE_STROKECOLOR] = "#6482B9";
$style[mxConstants::$STYLE_FONTCOLOR] = "#446299";
return $style;
}
/**
* Function: putDefaultVertexStyle
*
* Sets the default style for vertices.
*/
function putDefaultVertexStyle($style)
{
$this->putCellStyle("defaultVertex", $style);
}
/**
* Function: putDefaultEdgeStyle
*
* Sets the default style for edges.
*/
function putDefaultEdgeStyle($style)
{
$this->putCellStyle("defaultEdge", $style);
}
/**
* Function: getDefaultVertexStyle
*
* Returns the default style for vertices.
*/
function getDefaultVertexStyle()
{
return $this->styles["defaultVertex"];
}
/**
* Function: getDefaultEdgeStyle
*
* Sets the default style for edges.
*/
function getDefaultEdgeStyle()
{
return $this->styles["defaultEdge"];
}
/**
* Function: putCellStyle
*
* Stores the specified style under the given name.
*
* Example:
*
* The following example adds a new style (called 'rounded') into an
* existing stylesheet:
*
* (code)
* var style = new Array();
* style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RECTANGLE;
* style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RightAngleRectanglePerimeter;
* style[mxConstants.STYLE_ROUNDED] = 'true';
* graph.stylesheet.putCellStyle('rounded', style);
* (end)
*
* In the above example, the new style is an array. The possible keys of
* the array are all the constants in <mxConstants> that start with STYLE
* and the values are either JavaScript objects, such as
* <mxPerimeter.RightAngleRectanglePerimeter> (which is in fact a function)
* or expressions, such as 'true'. Note that not all keys will be
* interpreted by all shapes (eg. the line shape ignores the fill color).
* The final call to this method associates the style with a name in the
* stylesheet. The style is used in a cell with the following code:
*
* (code)
* model.setStyle(cell, 'rounded');
* (end)
*
* Parameters:
*
* name - Name for the style to be stored.
* style - Key, value pairs that define the style.
*/
function putCellStyle($name, $style)
{
$this->styles[$name] = $style;
}
/**
* Function: getCellStyle
*
* Returns the cell style for the specified cell or the given defaultStyle
* if no style can be found for the given stylename.
*
* Parameters:
*
* name - String of the form [(stylename|key=value);] that represents the
* style.
* defaultStyle - Default style to be returned if no style can be found.
*/
function getCellStyle($name, $defaultStyle = null)
{
$style = $defaultStyle;
if ($name != null && strlen($name) > 0)
{
$pairs = explode(";", $name);
if (isset($pairs))
{
if (isset($style) && $name{0} != ';')
{
$style = array_slice($style, 0);
}
else
{
$style = array();
}
for ($i = 0; $i < sizeof($pairs); $i++)
{
$tmp = $pairs[$i];
$pos = strpos($pairs[$i], "=");
if ($pos !== false)
{
$key = substr($tmp, 0, $pos);
$value = substr($tmp, $pos+1);
if ($value == mxConstants::$NONE)
{
unset($style[$key]);
}
else
{
$style[$key] = $value;
}
}
else if (isset($this->styles[$tmp]))
{
$tmpStyle = $this->styles[$tmp];
foreach ($tmpStyle as $key => $value)
{
$style[$key] = $value;
}
}
}
}
}
return $style;
}
}
?>