forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxAnalysisGraph.java
More file actions
218 lines (194 loc) · 6.4 KB
/
mxAnalysisGraph.java
File metadata and controls
218 lines (194 loc) · 6.4 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
/**
* $Id: mxAnalysisGraph.java,v 1.10 2012/11/21 13:59:52 mate Exp $
* Copyright (c) 2012, JGraph Ltd
*/
package com.mxgraph.analysis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.mxgraph.costfunction.mxDoubleValCostFunction;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.view.mxGraph;
/**
* Implements a collection of utility methods abstracting the graph structure
* taking into account graph properties such as visible/non-visible traversal
*/
public class mxAnalysisGraph
{
// contains various filters, like visibility and direction
protected Map<String, Object> properties = new HashMap<String, Object>();
// contains various data that is used for graph generation and analysis
protected mxGraphGenerator generator;
protected mxGraph graph;
/**
* Returns the incoming and/or outgoing edges for the given cell.
* If the optional parent argument is specified, then only edges are returned
* where the opposite is in the given parent cell.
*
* @param cell Cell whose edges should be returned.
* @param parent Optional parent. If specified the opposite end of any edge
* must be a child of that parent in order for the edge to be returned. The
* recurse parameter specifies whether or not it must be the direct child
* or the parent just be an ancestral parent.
* @param incoming Specifies if incoming edges should be included in the
* result.
* @param outgoing Specifies if outgoing edges should be included in the
* result.
* @param includeLoops Specifies if loops should be included in the result.
* @param recurse Specifies if the parent specified only need be an ancestral
* parent, <code>true</code>, or the direct parent, <code>false</code>
* @return Returns the edges connected to the given cell.
*/
public Object[] getEdges(Object cell, Object parent, boolean incoming, boolean outgoing, boolean includeLoops, boolean recurse)
{
if (!mxGraphProperties.isTraverseVisible(properties, mxGraphProperties.DEFAULT_TRAVERSE_VISIBLE))
{
return graph.getEdges(cell, parent, incoming, outgoing, includeLoops, recurse);
}
else
{
Object[] edges = graph.getEdges(cell, parent, incoming, outgoing, includeLoops, recurse);
List<Object> result = new ArrayList<Object>(edges.length);
mxIGraphModel model = graph.getModel();
for (int i = 0; i < edges.length; i++)
{
Object source = model.getTerminal(edges[i], true);
Object target = model.getTerminal(edges[i], false);
if (((includeLoops && source == target) || ((source != target) && ((incoming && target == cell) || (outgoing && source == cell))))
&& model.isVisible(edges[i]))
{
result.add(edges[i]);
}
}
return result.toArray();
}
};
/**
* Returns the incoming and/or outgoing edges for the given cell.
* If the optional parent argument is specified, then only edges are returned
* where the opposite is in the given parent cell.
*
* @param cell Cell whose edges should be returned.
* @param parent Optional parent. If specified the opposite end of any edge
* must be a child of that parent in order for the edge to be returned. The
* recurse parameter specifies whether or not it must be the direct child
* or the parent just be an ancestral parent.
* @param includeLoops Specifies if loops should be included in the result.
* @param recurse Specifies if the parent specified only need be an ancestral
* parent, <code>true</code>, or the direct parent, <code>false</code>
* @return Returns the edges connected to the given cell.
*/
public Object[] getEdges(Object cell, Object parent, boolean includeLoops, boolean recurse)
{
if (mxGraphProperties.isDirected(properties, mxGraphProperties.DEFAULT_DIRECTED))
{
return getEdges(cell, parent, false, true, includeLoops, recurse);
}
else
{
return getEdges(cell, parent, true, true, includeLoops, recurse);
}
};
/**
*
* @param parent
* @return all vertices of the given <b>parent</b>
*/
public Object[] getChildVertices(Object parent)
{
return graph.getChildVertices(parent);
};
/**
*
* @param parent
* @return all edges of the given <b>parent</b>
*/
public Object[] getChildEdges(Object parent)
{
return graph.getChildEdges(parent);
};
/**
*
* @param edge
* @param isSource
* @return
*/
public Object getTerminal(Object edge, boolean isSource)
{
return graph.getModel().getTerminal(edge, isSource);
};
public Object[] getChildCells(Object parent, boolean vertices, boolean edges)
{
return graph.getChildCells(parent, vertices, edges);
}
/**
* Returns all distinct opposite cells for the specified terminal
* on the given edges.
*
* @param edges Edges whose opposite terminals should be returned.
* @param terminal Terminal that specifies the end whose opposite should be
* returned.
* @param sources Specifies if source terminals should be included in the
* result.
* @param targets Specifies if target terminals should be included in the
* result.
* @return Returns the cells at the opposite ends of the given edges.
*/
public Object[] getOpposites(Object[] edges, Object terminal, boolean sources, boolean targets)
{
// TODO needs non-visible graph version
return graph.getOpposites(edges, terminal, sources, targets);
};
/**
* Returns all distinct opposite cells for the specified terminal
* on the given edges.
*
* @param edges Edges whose opposite terminals should be returned.
* @param terminal Terminal that specifies the end whose opposite should be
* returned.
* @return Returns the cells at the opposite ends of the given edges.
*/
public Object[] getOpposites(Object[] edges, Object terminal)
{
if (mxGraphProperties.isDirected(properties, mxGraphProperties.DEFAULT_DIRECTED))
{
return getOpposites(edges, terminal, false, true);
}
else
{
return getOpposites(edges, terminal, true, true);
}
};
public Map<String, Object> getProperties()
{
return properties;
};
public void setProperties(Map<String, Object> properties)
{
this.properties = properties;
};
public mxGraph getGraph()
{
return graph;
};
public void setGraph(mxGraph graph)
{
this.graph = graph;
}
public mxGraphGenerator getGenerator()
{
if (generator != null)
{
return generator;
}
else
{
return new mxGraphGenerator(null, new mxDoubleValCostFunction());
}
}
public void setGenerator(mxGraphGenerator generator)
{
this.generator = generator;
};
};