How to turn off the edge labels in JGraphX? - java

I am trying to create a JGraphXAdapter which receives a directed graph as a constructor argument and applied a mxHierarchicalLayout to it. Then, I use mxCellRenderer to create a BufferedImage and write the visualization to a png file.
The problem is that I do not want the edge labels to be visible. I tried (incorrectly) using this command, but it turns off all the labels.
JGraphXAdapter<String, DefaultEdge> graphAdapter = new JGraphXAdapter<>(directedGraph);
graphAdapter.setLabelsVisible(false);
Is there any way to just turn off the edge labels, but not the vertex labels? Thanks

graphAdapter.getEdgeToCellMap().forEach((edge, cell) -> cell.setValue(null));
Edit: there is not much to comment there... "cells" in JGraphX terminology are objects representing visuals of both edges and vertices. So, if you want to change how one specific element is drawn, you should first find its cell through edge->cell or vertex->cell map.
Cell's "value" is its reference to a represented object. Strings that you see on vertices and edges after JGraphX renders everything are basically cell.value == null ? "" : cell.value.toString() (might look a bit different in the source code).

Related

Adding a label to a Point on map in ArcGIS

I have static points on a map.
I use this code to draw them:
point = GeometryEngine.project(longitude, latitude, mapSR);
pointGraphic = new Graphic(point, symbol);
graphicsLayer.addGraphic(pointGraphic);
The point is drawed on the map.
Now I want to add a label to it - show under the drawn point it's longitude and latitude.
I can do it using text adding, but then when I resize the map, the text placement changes.
I want to put it like a label - let's say on the bottom right from the point.
I want it to be sensitive for zooming, and binded to the Point.
I read about dinamic labels, but it seems very complex for such a simple request.
How can I do this?
Thanks.
Individual graphics don't have labels, but you can create two graphics with the same geometry. Use your current symbol for one of them. For the other graphic, use a TextSymbol, calling setOffsetX(float) and setOffsetY(float) to place it the way you want.

How to change color of selected connection in jgrapht or jgraphx?

I'm visualizing a graph in a java swing application using jgrapht/jgraphx.
By default the connections (the arrows that point from one node to an other) between 2 nodes are rendered in light blue. When I select a connection by clicking on it, the color changes from light blue to green.
How can I change this color? I didn't find a way to do this so far. I'm using jgrapht 0.9.1, jgraphx 2.0.0.1, jgraph 5.13.0.0.
And here is the proper way (I think)
mxCellTracker trackColor = new mxCellTracker(myGraphComponent, Color.CYAN);
(EDIT: tested this for JgraphX 3.4.1.3)
This selection color is defined in mxSwingConstants.java.
It can be overwritten by:
mxSwingConstants.EDGE_SELECTION_COLOR = new Color(255,0,0,255);
But this is not so pretty I would say, and you cannot set it differently for different edges like this. Probably you can change it after some event.
A pretty solution would be if one could add it to an edge style...

Draw line chart in Java using JAVAFX

What i want to do:
How my program looks like:
So currently i have a table which contains elements. I thought the right idea would be maybe work with lines and circles to draw graph? Or is there a better alternative? Also the main question here is how to set a layout, so if there's an element number one it has a circle under it and if the element is 15 it has an element under it. My thought is for every circle to has it's own row, if one has been placed the next one is 10px below etc. Although still the question remains about layout, any pointers?
E:/
I came up with a little idea to use Line Chart, but the Line Chart doesen't allow me to manipulate it with the way i want. It will just create lines in ascending order but i would like to move from point one to point five and then to point 2 (as shown in the chart above with different elements but the idea is same).

Java - Drawing a dynamic shape outline

I wish to create a dynamic outline to a Shape (AWT) by adding objects (with draw functions) to appropriate positions on screen along the shape's perimeter. I want a roughly even distance between each object. (An alternative approach to the same affect will be fine.)
How might I acquire the locations for these objects? I know shapes have a path iterator, but I have no idea how to use it.
You might look at a library such as the one described in A Shape Diagram Editor.
If you want to experiment, GraphPanel is a simple object drawing program that features moveable, resizable, colored nodes connected by edges. If the nodes were a little smaller, they'd be moveable points on a Shape that can be iterated as shown here for Polygon.
Addendum: I want a roughly even distance between each object.
The class Node exposes a number of static methods that operate on a List<Node> such as selected. Existing implementations serve, for example, to translate or resize multiple selections as a unit. Functions for Align and Distribute could be implemented similarly. I'd look at LayoutManger as an example for the latter.
Use FlatteningPathIterator to get points for Shape's path.
Also you can use BasicStroke's method
public Shape createStrokedShape(Shape s)
to get Shape's outline with desire width.

Overlapping vertex labels in JUNG

First of all, I am new to JUNG. I am trying to visualize trees in JUNG using the TreeLayout, but I am always faced with the issue of overlapping vertex labels. More so when the number of nodes and paths are many. Any ideas as to how to go about preventing such an overlap ?
I am aware of the vertex label renderer, but I did not get far with this either.
Here are a couple of options:
(1) Increase distx (the distance between adjacent tree leaves). This is an optional constructor argument.
(2) Use a Transformer for the rendered label that uses a substring of the label, or a shortened representation. Then separately set hover text to show the entire label.

Categories

Resources