Skip to content

Commit

Permalink
Correction to only show the visible graph
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Jun 12, 2024
1 parent dafa574 commit e70e3a9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @author Eduardo Ramos
*/
public interface GraphIndex {
Graph getGraph();

Graph getVisibleGraph();

int getNodeCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@ public GraphIndexImpl(VizEngine engine) {

//Graph
private GraphModel graphModel;
private Graph graph;
private float edgesMinWeight = 1;
private float edgesMaxWeight = 1;

private void init() {
graphModel = engine.getGraphModel();
graph = graphModel.getGraphVisible();
}

private void ensureInitialized() {
if (graph == null) {
if (graphModel == null) {
init();
}
}

@Override
public Graph getGraph() {
public Graph getVisibleGraph() {
ensureInitialized();
return graph;
return graphModel.getGraphVisible();
}

public void indexNodes() {
Expand All @@ -54,28 +51,29 @@ public void indexNodes() {
public void indexEdges() {
ensureInitialized();

if (graph.getEdgeCount() > 0) {
final Column weightColumn = graph.getModel().getEdgeTable().getColumn(GraphStoreConfiguration.EDGE_WEIGHT_INDEX);
final Graph visibleGraph = getVisibleGraph();
if (visibleGraph.getEdgeCount() > 0) {
final Column weightColumn = visibleGraph.getModel().getEdgeTable().getColumn(GraphStoreConfiguration.EDGE_WEIGHT_INDEX);

if (weightColumn.isIndexed() && AttributeUtils.isSimpleType(weightColumn.getTypeClass())) {
graph.readLock();
visibleGraph.readLock();
try {
edgesMinWeight = graph.getModel().getEdgeIndex().getMinValue(weightColumn).floatValue();
edgesMaxWeight = graph.getModel().getEdgeIndex().getMaxValue(weightColumn).floatValue();
edgesMinWeight = visibleGraph.getModel().getEdgeIndex().getMinValue(weightColumn).floatValue();
edgesMaxWeight = visibleGraph.getModel().getEdgeIndex().getMaxValue(weightColumn).floatValue();
} finally {
graph.readUnlockAll();
visibleGraph.readUnlockAll();
}
} else {
graph.readLock();
visibleGraph.readLock();
try {
final GraphView graphView = graph.getView();
final GraphView graphView = visibleGraph.getView();
final boolean isView = !graphView.isMainView();

if (!isView) {
float minWeight = Float.MAX_VALUE;
float maxWeight = Float.MIN_VALUE;

for (Edge edge : graph.getEdges()) {
for (Edge edge : visibleGraph.getEdges()) {
float weight = (float) edge.getWeight(graphView);
minWeight = weight <= minWeight ? weight : minWeight;
maxWeight = weight >= maxWeight ? weight : maxWeight;
Expand All @@ -85,7 +83,7 @@ public void indexEdges() {
edgesMaxWeight = maxWeight;
}
} finally {
graph.readUnlockAll();
visibleGraph.readUnlockAll();
}
}
} else {
Expand All @@ -97,14 +95,14 @@ public void indexEdges() {
public int getNodeCount() {
ensureInitialized();

return graph.getNodeCount();
return getVisibleGraph().getNodeCount();
}

@Override
public int getEdgeCount() {
ensureInitialized();

return graph.getEdgeCount();
return getVisibleGraph().getEdgeCount();
}

@Override
Expand All @@ -121,16 +119,17 @@ public float getEdgesMaxWeight() {
public NodeIterable getVisibleNodes() {
ensureInitialized();

return graphModel.getSpatialIndex().getNodesInArea(engine.getViewBoundaries());
return getVisibleGraph().getSpatialIndex().getNodesInArea(engine.getViewBoundaries());
}

@Override
public void getVisibleNodes(ElementsCallback<Node> callback) {
ensureInitialized();

callback.start(graph);
final Graph visibleGraph = getVisibleGraph();
callback.start(visibleGraph);

final NodeIterable nodeIterable = graphModel.getSpatialIndex().getNodesInArea(engine.getViewBoundaries());
final NodeIterable nodeIterable = visibleGraph.getSpatialIndex().getNodesInArea(engine.getViewBoundaries());
try {
for (Node node : nodeIterable) {
callback.accept(node);
Expand All @@ -139,22 +138,23 @@ public void getVisibleNodes(ElementsCallback<Node> callback) {
nodeIterable.doBreak();
}

callback.end(graph);
callback.end(visibleGraph);
}

@Override
public EdgeIterable getVisibleEdges() {
ensureInitialized();

return graphModel.getSpatialIndex().getEdgesInArea(engine.getViewBoundaries());
return getVisibleGraph().getSpatialIndex().getEdgesInArea(engine.getViewBoundaries());
}

@Override
public void getVisibleEdges(ElementsCallback<Edge> callback) {
ensureInitialized();

callback.start(graph);
final EdgeIterable edgeIterable = graphModel.getSpatialIndex().getEdgesInArea(engine.getViewBoundaries());
final Graph visibleGraph = getVisibleGraph();
callback.start(visibleGraph);
final EdgeIterable edgeIterable = visibleGraph.getSpatialIndex().getEdgesInArea(engine.getViewBoundaries());
try {
for (Edge edge : edgeIterable) {
callback.accept(edge);
Expand All @@ -163,14 +163,14 @@ public void getVisibleEdges(ElementsCallback<Edge> callback) {
edgeIterable.doBreak();
}

callback.end(graph);
callback.end(visibleGraph);
}

@Override
public NodeIterable getNodesUnderPosition(float x, float y) {
ensureInitialized();

return filterNodeIterable(graphModel.getSpatialIndex().getNodesInArea(getCircleRect2D(x, y, 0)), node -> {
return filterNodeIterable(getVisibleGraph().getSpatialIndex().getNodesInArea(getCircleRect2D(x, y, 0)), node -> {
final float size = node.size();

return Intersectionf.testPointCircle(x, y, node.x(), node.y(), size * size);
Expand All @@ -181,7 +181,7 @@ public NodeIterable getNodesUnderPosition(float x, float y) {
public NodeIterable getNodesInsideCircle(float centerX, float centerY, float radius) {
ensureInitialized();

return filterNodeIterable(graphModel.getSpatialIndex().getNodesInArea(getCircleRect2D(centerX, centerY, radius)), node -> {
return filterNodeIterable(getVisibleGraph().getSpatialIndex().getNodesInArea(getCircleRect2D(centerX, centerY, radius)), node -> {
return Intersectionf.testCircleCircle(centerX, centerY, radius, node.x(), node.y(), node.size());
});
}
Expand All @@ -190,7 +190,7 @@ public NodeIterable getNodesInsideCircle(float centerX, float centerY, float rad
public NodeIterable getNodesInsideRectangle(Rect2D rect) {
ensureInitialized();

return filterNodeIterable(graphModel.getSpatialIndex().getNodesInArea(rect), node -> {
return filterNodeIterable(getVisibleGraph().getSpatialIndex().getNodesInArea(rect), node -> {
final float size = node.size();

return Intersectionf.testAarCircle(rect.minX, rect.minY, rect.maxX, rect.maxY, node.x(), node.y(), size * size);
Expand All @@ -201,7 +201,7 @@ public NodeIterable getNodesInsideRectangle(Rect2D rect) {
public EdgeIterable getEdgesInsideRectangle(Rect2D rect) {
ensureInitialized();

return filterEdgeIterable(graphModel.getSpatialIndex().getEdgesInArea(rect), edge -> {
return filterEdgeIterable(getVisibleGraph().getSpatialIndex().getEdgesInArea(rect), edge -> {
final Node source = edge.getSource();
final Node target = edge.getTarget();

Expand All @@ -214,7 +214,7 @@ public EdgeIterable getEdgesInsideRectangle(Rect2D rect) {
public EdgeIterable getEdgesInsideCircle(float centerX, float centerY, float radius) {
ensureInitialized();

return filterEdgeIterable(graphModel.getSpatialIndex().getEdgesInArea(getCircleRect2D(centerX, centerY, radius)), edge -> {
return filterEdgeIterable(getVisibleGraph().getSpatialIndex().getEdgesInArea(getCircleRect2D(centerX, centerY, radius)), edge -> {
final Node source = edge.getSource();
final Node target = edge.getTarget();

Expand All @@ -232,13 +232,14 @@ public EdgeIterable getEdgesInsideCircle(float centerX, float centerY, float rad
public Rect2D getGraphBoundaries() {
ensureInitialized();

if (graph.getNodeCount() > 0) {
final Graph visibleGraph = getVisibleGraph();
if (visibleGraph.getNodeCount() > 0) {
float minX = Float.MAX_VALUE;
float maxX = Float.MIN_VALUE;
float minY = Float.MAX_VALUE;
float maxY = Float.MIN_VALUE;

for (Node node : graph.getNodes()) {
for (Node node : visibleGraph.getNodes()) {
final float x = node.x();
final float y = node.y();
final float size = node.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt
final Edge[] visibleEdgesArray = edgesCallback.getEdgesArray();
final int visibleEdgesCount = edgesCallback.getCount();

final Graph graph = graphIndex.getGraph();
final Graph graph = graphIndex.getVisibleGraph();

int attribsIndex = 0;
attribsIndex = updateUndirectedData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt
final Edge[] visibleEdgesArray = edgesCallback.getEdgesArray();
final int visibleEdgesCount = edgesCallback.getCount();

final Graph graph = graphIndex.getGraph();
final Graph graph = graphIndex.getVisibleGraph();

updateUndirectedData(
graph,
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<jcp-maven-plugin.version>7.1.2</jcp-maven-plugin.version>

<gephi.graphstore.version>0.7.1</gephi.graphstore.version>
<gephi.graphstore.version>0.7.2-SNAPSHOT</gephi.graphstore.version>
<gephi.version>0.11.0-SNAPSHOT</gephi.version>
<jogl.version>2.5.0</jogl.version>

Expand Down

0 comments on commit e70e3a9

Please sign in to comment.