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

Community
  • 1
  • 1
Sergey Lapin
  • 1,008
  • 3
  • 12
  • 21
  • 1
    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. – Federico Berasategui Mar 22 '13 at 21:06
  • 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? – Sergey Lapin Mar 22 '13 at 21:11

1 Answers1

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

Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
  • 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. – Sergey Lapin Mar 23 '13 at 07:15
  • @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`. – Federico Berasategui Mar 23 '13 at 07:19
  • I mean library which implements "Layout methods" (you can Ctrl+F it here http://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. – Sergey Lapin Mar 23 '13 at 08:44
  • https://www.google.ru/search?q=graph+layout&hl=ru&newwindow=1&tbm=isch&tbo=u&source=univ&sa=X&ei=K2lNUYL3OeGs4ATQmoCQBg&ved=0CDQQsAQ&biw=1366&bih=643 – Sergey Lapin Mar 23 '13 at 08:46
  • 5
    @HighCore +1 Nice project. – Viv May 27 '13 at 16:18
  • @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. – Gerard Feb 18 '14 at 14:51
  • @Gerard 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. – Federico Berasategui Feb 18 '14 at 14:54
  • @Gerard 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 ;) – Federico Berasategui Feb 18 '14 at 15:03
  • @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? – Gerard Feb 21 '14 at 12:34
  • @Gerard 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 =) – Federico Berasategui Feb 21 '14 at 14:54
  • @HighCore: see http://stackoverflow.com/q/21920910/138078 – Gerard Feb 21 '14 at 14:57
  • I couldn't download the source file. Can you provide the correct link again – RobinAtTech Mar 30 '14 at 22:36
  • @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. – Federico Berasategui Mar 31 '14 at 16:48
  • 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. – Kazu May 21 '14 at 08:45
  • @Kazu 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. – Federico Berasategui May 21 '14 at 12:21
  • @HighCore Thought so already, a simple search and replace does the trick, fortunately. Very nice code, by the way, really useful. – Kazu May 21 '14 at 15:05
  • 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: `` to Canvas.Bottom, but then is problem with connectors. – esispaned Sep 22 '15 at 12:34