Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple labels on node #124

Open
JanStolze opened this issue Jun 26, 2014 · 4 comments
Open

Multiple labels on node #124

JanStolze opened this issue Jun 26, 2014 · 4 comments

Comments

@JanStolze
Copy link

We would like to visualize a node with text:
Label 1
Label 2
To me it seems to be a very simple feature, but GraphStream currently does not support this.
As a work around the usage of images is suggested, which requires the need of generating images storing them on a disk somewhere, then let GraphStream access these images by means of a file url. This introduces a lot of disk access and the need to execute maintenance on those images on disk, they can stay there forever but are only accessed when actually visualized. This makes it impossible to use temporary files. All in all very cumbersome :-(.
Is it too much to ask, for support of multiple labels on a node? In other words is it an easy thing for the development team to implement, but failed to get enough priority to do so yet?

@VEckardt
Copy link

VEckardt commented Oct 2, 2014

I also have a strong interest to display text in multiple rows. In my case the second row shall display an additional description, with a smaller character set. If this could be implemented, this would be really great and would improve the layout significantly.
Hope someone has an idea how to implement this ...

@jordilaforge
Copy link

jordilaforge commented Oct 19, 2016

Actually this is possible, I did this with a additional Sprite on the Node. Add a sprite to the node:
SpriteManager aSpriteManager = new SpriteManager(graph); Sprite aSprite = spriteManager.addSprite(theSpriteId); aSprite.attachToNode(theNodeId); //this sets where the Label will be (adjust to fit your purpose) aSprite.setPosition(StyleConstants.Units.PX, 8, 50, -90); aSprite.addAttribute("ui.label", theSpriteLabel);
Now you can design you sprite as CSS (fontsize, color ...):
sprite { fill-mode: none; text-size:12; }
The only problem left is that you can now move your second label because the sprite is movable. But this can be handled by overriding elementMoving method in the DefaultGraphManager:
@Override protected void elementMoving(GraphicElement theElement, MouseEvent theEvent){ if(!(theElement.getSelectorType().equals(Selector.Type.SPRITE))){ view.moveElementAtPx(theElement, theEvent.getX(), theEvent.getY()); } }
But I agree this should be implemented in graphstream as a Attribute on the Node, or at least it should be possible to use "\n" in a String.

@VersusF
Copy link

VersusF commented Feb 18, 2020

Hello everybody. Is there any new solution to this problem? I'm trying to display a control flow graph like IDA, the disassembler, and i need to print many lines inside a node, making it as big as the text.
Currently my problem is that the text is under the sprite box

Screenshot from 2020-02-18 18-16-17

The code is:

Node current = mGraph.getNode(nodeId);
Sprite nodeSprite = aSpriteManager.addSprite(nodeId + "-sprite");
node.attachToNode(nodeId);
nodeSprite.setAttribute("ui.label", bb.toString());
nodeSprite.setPosition(0);
nodeSprite.setAttribute("ui.class", "basicBlock");
current.setAttribute("ui.size", nodeSprite.getAttribute("ui.size"));
current.setAttribute("ui.class", "basicBlock");

A way to do this without sprites would be great. Thanks

the css is:

sprite.basicBlock {
    shape: rounded-box;
    stroke-mode: plain;
    stroke-color: #000000;
    fill-color: green;
    size-mode: fit;
    text-alignment: center;
}

@hichbra
Copy link
Contributor

hichbra commented Feb 19, 2020

If you really want to do that without sprite (which is still a good option), you can still calculate yourself the optimal size of your nodes, and change the css property of these nodes.

Here a simple example based on your sample with graphstream 2 :

public void run( String[] args ) throws InterruptedException {
	graph  = new MultiGraph( "g1" );		
	graph.addNode("A");
	graph.addNode("B");
	graph.addNode("C");
	graph.addEdge("AB","A","B");
	graph.addEdge("AC","A","C");
	graph.addEdge("BC","B","C");
	graph.getNode("B").setAttribute("ui.label", "B");
	graph.getNode("C").setAttribute("ui.label", "C");
		
	Node current = graph.getNode("A");
	String label = "This is a test";
	current.setAttribute("ui.label", label);
	current.setAttribute("ui.class", "basicBlock");

	graph.setAttribute( "ui.default.title", "Layout Test Fx" );
	graph.setAttribute( "ui.stylesheet", styleSheet );
	graph.display();
		
	for (int i = 0 ; i < 8 ; i++) {
		label += "\nThis is a test";
		current.setAttribute("ui.label", label);

		int size = lineToLength((String)current.getAttribute("ui.label"), "\n") ;
		if (size != 0) {
			String sizeCss = "size: 90px, "+size+"px;";
			current.setAttribute("ui.style", sizeCss);
		}
		Thread.sleep(1000);
	}
}
	
public static int lineToLength(String str, String target) {
	int nbLine = ((str.length() - str.replace(target, "").length()) / target.length())+1;
	return 10+(nbLine*11);
}
	
private String styleSheet ="node {"
	+ "shape: box;"
	+ "stroke-mode: plain;"
	+ "stroke-color: #000000;"
	+ "fill-color: green;"
	+ "text-alignment: above;"
	+ "padding: 0, -10px;"
	+ "size: 20px, 20px;"
+ "}";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants