Skip to content

Commit 18dbe69

Browse files
authored
Merge pull request #1 from eduramiba/circlePack
Fixes and improvements
2 parents af38426 + 081bee1 commit 18dbe69

File tree

8 files changed

+112
-304
lines changed

8 files changed

+112
-304
lines changed

gephi-plugins.iml

Lines changed: 0 additions & 188 deletions
This file was deleted.

modules/CirclePack/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<groupId>org.netbeans.api</groupId>
2424
<artifactId>org-openide-util-lookup</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.netbeans.api</groupId>
28+
<artifactId>org-openide-util</artifactId>
29+
</dependency>
2630
<dependency>
2731
<groupId>org.gephi</groupId>
2832
<artifactId>graph-api</artifactId>

modules/CirclePack/src/main/java/org/gephi/plugin/CirclePack/AbstractComboBoxEditor.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,30 @@
3333
*
3434
* @author Matt
3535
*/
36-
public abstract class AbstractComboBoxEditor extends PropertyEditorSupport
37-
{
38-
public Map ComboValues;
36+
public abstract class AbstractComboBoxEditor extends PropertyEditorSupport {
37+
38+
public Map<String, String> comboValues;
3939

4040
@Override
41-
public String[] getTags()
42-
{
43-
return (String[])ComboValues.values().toArray(new String[0]);
41+
public String[] getTags() {
42+
return comboValues.values().toArray(new String[0]);
4443
}
4544

4645
@Override
47-
public String getAsText()
48-
{
49-
if(getValue() == null){
46+
public String getAsText() {
47+
if (getValue() == null) {
5048
return "No Selection";
5149
}
52-
return (String)ComboValues.get(getValue());
50+
return comboValues.get(getValue().toString());
5351
}
5452

5553
@Override
56-
public void setAsText(String s)
57-
{
58-
Set<Map.Entry<String, String> > Entries = ComboValues.entrySet();
59-
for (Map.Entry<String, String> Entry: Entries)
60-
{
61-
if ((Entry.getValue() == null) ? (s == null) : Entry.getValue().equals(s))
62-
{
54+
public void setAsText(String s) {
55+
Set<Map.Entry<String, String>> Entries = comboValues.entrySet();
56+
for (Map.Entry<String, String> Entry : Entries) {
57+
if ((Entry.getValue() == null) ? (s == null) : Entry.getValue().equals(s)) {
6358
setValue(Entry.getKey());
6459
}
6560
}
6661
}
67-
};
62+
};

modules/CirclePack/src/main/java/org/gephi/plugin/CirclePack/CirclePackAlgo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ private ArrayList<CircleWrap> extendBasis(ArrayList<CircleWrap> B, CircleWrap p)
4343

4444
StringBuilder extendBasisStr = new StringBuilder("ArrayList<CircleWrap> B = new ArrayList<>();\n");
4545
for (i = 0; i < B.size(); ++i) {
46-
extendBasisStr.append("B.add(" + B.get(i).toConStr() + ");\n");
46+
extendBasisStr.append("B.add(").append(B.get(i).toConStr()).append(");\n");
4747
}
48-
extendBasisStr.append("extendBasis(B, " + p.toConStr() + ");\n");
48+
extendBasisStr.append("extendBasis(B, ").append(p.toConStr()).append(");\n");
4949

5050
if (enclosesWeakAll(p, B)) {
5151
return new ArrayList<>(Arrays.asList(p));

modules/CirclePack/src/main/java/org/gephi/plugin/CirclePack/CirclePackLayout.java

Lines changed: 80 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
/**
22
* Created by pmurray on 6/13/2017.
33
*/
4-
54
package org.gephi.plugin.CirclePack;
65

76
import java.util.*;
87

9-
import javafx.scene.shape.Circle;
108
import org.gephi.graph.api.*;
119
import org.gephi.layout.spi.Layout;
1210
import org.gephi.layout.spi.LayoutBuilder;
1311
import org.gephi.layout.spi.LayoutProperty;
14-
12+
import org.openide.util.Exceptions;
1513

1614
public class CirclePackLayout implements Layout {
1715

18-
private static Object Bundle;
1916
//Architecture
2017
private final LayoutBuilder builder;
2118
private GraphModel graphModel;
2219
//Flags
2320
private boolean executing = false;
2421
//Properties
2522
private int radiusSize;
26-
private String hierarchy1;
27-
private String hierarchy2;
28-
private String hierarchy3;
29-
private String hierarchy4;
30-
private String hierarchy5;
23+
private String hierarchy1;
24+
private String hierarchy2;
25+
private String hierarchy3;
26+
private String hierarchy4;
27+
private String hierarchy5;
3128

3229
public CirclePackLayout(CirclePackLayoutBuilder builder) {
3330
this.builder = builder;
@@ -43,58 +40,79 @@ public void initAlgo() {
4340
executing = true;
4441
}
4542

46-
4743
@Override
4844
public void goAlgo() {
49-
Graph graph = graphModel.getGraphVisible();
50-
graph.readLock();
51-
int nodeCount = graph.getNodeCount();
52-
Node[] nodes = graph.getNodes().toArray();
53-
54-
CircleWrap container = new CircleWrap();
45+
ArrayList<String> attributesToUse = new ArrayList<>();
5546

56-
for(int i = 0; i < nodeCount; i++){
57-
Node node = nodes[i];
58-
59-
ArrayList attributes = new ArrayList<String>();
60-
if (this.hierarchy1 != null && this.hierarchy1 != "No Selection"){
61-
attributes.add(String.valueOf(node.getAttribute(this.hierarchy1)));
62-
}
63-
if (this.hierarchy2 != null && this.hierarchy2 != "No Selection"){
64-
attributes.add(String.valueOf(node.getAttribute(this.hierarchy2)));
65-
}
66-
if (this.hierarchy3 != null && this.hierarchy3 != "No Selection"){
67-
attributes.add(String.valueOf(node.getAttribute(this.hierarchy3)));
68-
}
69-
if (this.hierarchy4 != null && this.hierarchy4 != "No Selection"){
70-
attributes.add(String.valueOf(node.getAttribute(this.hierarchy4)));
71-
}
72-
if (this.hierarchy5 != null && this.hierarchy5 != "No Selection"){
73-
attributes.add(String.valueOf(node.getAttribute(this.hierarchy5)));
47+
for (String att : Arrays.asList(hierarchy1, hierarchy2, hierarchy3, hierarchy4, hierarchy5)) {
48+
if (att != null && !att.equals("No Selection")) {
49+
attributesToUse.add(att);
7450
}
51+
}
7552

76-
CircleWrap newCircleWrap = new CircleWrap((String) node.getId());
77-
newCircleWrap.r = node.size();
53+
final Graph graph;
54+
if (graphModel.isDirected() || graphModel.isMixed()) {
55+
graph = graphModel.getDirectedGraphVisible();
56+
} else {
57+
graph = graphModel.getGraphVisible();
58+
}
7859

79-
CircleWrap parentContainer = container;
80-
for (Object attribute : attributes) {
81-
parentContainer = parentContainer.getChild((String) attribute);
60+
graph.readLock();
61+
try {
62+
int nodeCount = graph.getNodeCount();
63+
Node[] nodes = graph.getNodes().toArray();
64+
65+
CircleWrap container = new CircleWrap();
66+
67+
for (int i = 0; i < nodeCount; i++) {
68+
Node node = nodes[i];
69+
70+
ArrayList<String> nodeAttributes = new ArrayList<>();
71+
72+
for (String att : attributesToUse) {
73+
switch (att) {
74+
case "NodeID":
75+
nodeAttributes.add(node.getId().toString());
76+
break;
77+
case "Degree":
78+
nodeAttributes.add(String.valueOf(graph.getDegree(node)));
79+
break;
80+
case "InDegree":
81+
nodeAttributes.add(String.valueOf(((DirectedGraph) graph).getInDegree(node)));
82+
break;
83+
case "OutDegree":
84+
nodeAttributes.add(String.valueOf(((DirectedGraph) graph).getOutDegree(node)));
85+
break;
86+
default:
87+
nodeAttributes.add(String.valueOf(node.getAttribute(att)));
88+
break;
89+
}
90+
}
91+
92+
CircleWrap newCircleWrap = new CircleWrap(node.getId().toString());
93+
newCircleWrap.r = node.size();
94+
95+
CircleWrap parentContainer = container;
96+
for (String attribute : nodeAttributes) {
97+
parentContainer = parentContainer.getChild(attribute);
98+
}
99+
parentContainer.addChild(node.getId().toString(), newCircleWrap);
82100
}
83-
parentContainer.addChild((String) node.getId(), newCircleWrap);
84-
}
85101

86-
CirclePackAlgo PackAlgo = new CirclePackAlgo();
102+
CirclePackAlgo PackAlgo = new CirclePackAlgo();
87103

88-
PackAlgo.packHierarchyAndShift(container);
89-
setNode(graph, container);
104+
PackAlgo.packHierarchyAndShift(container);
105+
setNode(graph, container);
90106

91-
graph.readUnlock();
107+
} finally {
108+
graph.readUnlockAll();
109+
}
92110
endAlgo();
93111
}
94112

95-
public void setNode(Graph graph, CircleWrap parentCircle){
113+
public void setNode(Graph graph, CircleWrap parentCircle) {
96114
for (CircleWrap circle : parentCircle.children.values()) {
97-
if (circle.hasChildren()){
115+
if (circle.hasChildren()) {
98116
setNode(graph, circle);
99117
} else {
100118
Node node = graph.getNode(circle.getId());
@@ -116,21 +134,20 @@ public boolean canAlgo() {
116134

117135
@Override
118136
public LayoutProperty[] getProperties() {
119-
List<LayoutProperty> properties = new ArrayList<LayoutProperty>();
120-
final String CIRCLELAYOUT = "Circle Pack Layout";
137+
List<LayoutProperty> properties = new ArrayList<>();
121138

122139
try {
123140
properties.add(LayoutProperty.createProperty(
124141
this, String.class,
125142
"Hierarchy1",
126143
"Hierarchy",
127-
"Hierarchy1",
144+
"Hierarchy1",
128145
"getHierarchy1", "setHierarchy1", LayoutComboBoxEditor.class));
129146
properties.add(LayoutProperty.createProperty(
130147
this, String.class,
131148
"Hierarchy2",
132149
"Hierarchy",
133-
"Hierarchy2",
150+
"Hierarchy2",
134151
"getHierarchy2", "setHierarchy2", LayoutComboBoxEditor.class));
135152
properties.add(LayoutProperty.createProperty(
136153
this, String.class,
@@ -150,8 +167,8 @@ public LayoutProperty[] getProperties() {
150167
"Hierarchy",
151168
"Hierarchy5",
152169
"getHierarchy5", "setHierarchy5", LayoutComboBoxEditor.class));
153-
} catch (Exception e) {
154-
e.printStackTrace();
170+
} catch (NoSuchMethodException e) {
171+
Exceptions.printStackTrace(e);
155172
}
156173

157174
return properties.toArray(new LayoutProperty[0]);
@@ -167,53 +184,43 @@ public LayoutBuilder getBuilder() {
167184
return builder;
168185
}
169186

170-
public String getHierarchy1()
171-
{
187+
public String getHierarchy1() {
172188
return this.hierarchy1;
173189
}
174190

175-
public void setHierarchy1(String attribute)
176-
{
191+
public void setHierarchy1(String attribute) {
177192
this.hierarchy1 = attribute;
178193
}
179194

180-
public String getHierarchy2()
181-
{
195+
public String getHierarchy2() {
182196
return this.hierarchy2;
183197
}
184198

185-
public void setHierarchy2(String attribute)
186-
{
199+
public void setHierarchy2(String attribute) {
187200
this.hierarchy2 = attribute;
188201
}
189202

190-
public void setHierarchy3(String attribute)
191-
{
203+
public void setHierarchy3(String attribute) {
192204
this.hierarchy3 = attribute;
193205
}
194206

195-
public String getHierarchy3()
196-
{
207+
public String getHierarchy3() {
197208
return this.hierarchy3;
198209
}
199210

200-
public void setHierarchy4(String attribute)
201-
{
211+
public void setHierarchy4(String attribute) {
202212
this.hierarchy4 = attribute;
203213
}
204214

205-
public String getHierarchy4()
206-
{
215+
public String getHierarchy4() {
207216
return this.hierarchy4;
208217
}
209218

210-
public void setHierarchy5(String attribute)
211-
{
219+
public void setHierarchy5(String attribute) {
212220
this.hierarchy5 = attribute;
213221
}
214222

215-
public String getHierarchy5()
216-
{
223+
public String getHierarchy5() {
217224
return this.hierarchy5;
218225
}
219226

modules/CirclePack/src/main/java/org/gephi/plugin/CirclePack/CirclePackLayoutBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public LayoutUI getUI() {
2929

3030
@Override
3131
public String getDescription() {
32-
return "";
32+
return "Packs circles using Mike Bostock's circle packing algorithm";
3333
}
3434

3535
@Override

modules/CirclePack/src/main/java/org/gephi/plugin/CirclePack/CircleWrap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.gephi.plugin.CirclePack;
22

3-
import java.util.ArrayList;
43
import java.util.HashMap;
54

65
public class CircleWrap {

0 commit comments

Comments
 (0)