Graph nodes coordinates evaluation [closed]
Asked Answered
T

1

9

Which of these (https://stackoverflow.com/questions/492893/graph-drawing-c-library) libraries can be used to evaluate nodes coordinates? I mean I want to draw and manipulate graph by clicking on it to add some nodes or delete, and then evaluate coordinates using some lightweight library.

All I need is algorithm which could on dot file and speciefied layout (http://en.wikipedia.org/wiki/DOT_language) give me conformity of graph nodes and 2D points.

Prefferable languages: C++, C#, Java

Tavern answered 22/3, 2013 at 20:11 Comment(2)
Is WPF an option for you? I have a complete sample application that allows to draw nodes and connectors in a 2D surface (with defined X and Y coordinates), which also supports drag and drop and many interesting visual features.Schlegel
Of course WPF will be perfect, it's my favorite GUI approach! Is it open source project? I have just misunderstood about "defined X and Y coordinates". What do you mean?Tavern
S
34

I made a complete WPF MVVM sample of a "Nodes Editor" supporting drag and drop, and many interesting visual features. It looks like this:

enter image description here

Full Source Code on GitHub

Schlegel answered 22/3, 2013 at 21:40 Comment(17)
Thank you for your sample. Initially I was looking for "layout library", you haven't got layouts at all as I understood. I think it would be great to implement them in your sample, cause I liked it visually. Is it hard to remove discrete grid? I want to manipulate nodes freely.Tavern
@SergeyLapin 1 - What do you mean by "layout library"? 2 - The grid is not actually snapping the nodes, it's just a visual. The actual snapping occurs in the Node.X and Node.Y properties. Take a look at that. If you want to remove the grid, just remove the Background using the VisualBrush.Schlegel
I mean library which implements "Layout methods" (you can Ctrl+F it here en.wikipedia.org/wiki/Graph_drawing), but evaluation of finite coordinates should be encapsulate. There it would be possible to use it separately from specific graph viewier implementation.Tavern
google.ru/…Tavern
@HighCore +1 Nice project.Dasheen
@HighCore Are you of the opinion that your solution follow MVVM pattern? Because your Thumb_Drag and MouseMove need to cast the DataContext to ViewModel objects. Just asking.Twelfthtide
@Twelfthtide MVVM does not dictate that the View must not take a dependency on the ViewModel. It dictates that the ViewModel must not take a dependency on the View. this means that it's perfectly valid for the view to "know" it's ViewModel. and code behind is also OK if it does not introduce business logic.Schlegel
@Twelfthtide otherwise, that could be implemented using EventToCommand (with no code behind), but I guess that was too much for this, which was intended as an example and nothing else. You're free to improve / change it as you need ;)Schlegel
@HighCore I tried dragging the connectors by putting them in a Thumb and simply add: connector.Start.X += e.HorizontalChange etc. Dragging of the lines behaves quite weird, any idea why?Twelfthtide
@Twelfthtide would you like to post a separate question with the specific code you're having problems with? let me know so I can look at it =)Schlegel
@HighCore: see https://mcmap.net/q/341619/-why-is-a-line-shape-on-a-canvas-drifting-away-while-dragging/138078Twelfthtide
I couldn't download the source file. Can you provide the correct link againKarisakarissa
@Robin the link is working for me. I wish I could upload stuff into github or the like but for the life of me I can't find an upload button there.Schlegel
Just wanted to say that the current code on GitHub has inconsistent namespaces. In half of the files the namespace is NodesEditor, in the other half it is HousePlan.Mislead
@Mislead thanks for the comment. HousePlan is another sample of mine. I guess I must have mixed the files somehow. I'll fix that when I get the chance.Schlegel
@HighCore Thought so already, a simple search and replace does the trick, fortunately. Very nice code, by the way, really useful.Mislead
Is possible to change direction of Y value? Now when I pul mouse Down, Y values goes to + and other way around. Is possible to change that? When I pul mouse Down, also Y goes to -. I try to change: <Setter Property="Canvas.Top" Value="{Binding Y}"/> to Canvas.Bottom, but then is problem with connectors.Ogren

© 2022 - 2024 — McMap. All rights reserved.