|
|
Hi,
I'm trying to get X and Y coordinates of the Vertex Control inside the graph canvas. I tried vertexControl.GetValue(GraphCanvas.XProperty) - vertexControl.GetValue(GraphCanvas.YProperty) but I get Nan values. Any ideas how to resolve this ?
Thanks
|
|
|
|
|
I believe you use GraphCanvas.GetX(vertexControl) and GraphCanvas.GetY(vertexControl).
|
|
|
|
|
Yes, I tried that one as well but did not work, I get Nan values.
|
|
|
|
|
Hello
Same problem here, reading out the Values with GetX() just returns that there are no values assigned.
As a consequence, SetX() ist without any effect because obviously, Graph# does not care about it.
|
|
|
|
|
Hi,
I have the same problem regarding getting AND setting the X and Y values of a vertex.
Do I need some dependencyproperty or something in my vertex class to do this?
Thanks
|
|
|
|
|
Just a beginner, but this thankfully works fine for me after a layout:
GraphCanvas.GetX(vc)
where vc is the VertexControl instance of the vertex I am after.
The property is also set when I move the vertex on the canvas. I have not tried the setter, nor "drag-and-drop to add", yet - that's next.
|
|
|
Mar 30, 2010 at 12:00 PM
Edited Mar 30, 2010 at 1:49 PM
|
Hey, I still have this problem. I have the following:
Size size = new Size(graphLayout.ActualWidth, graphLayout.ActualHeight);
graphLayout.Measure(size); graphLayout.Arrange(new Rect(size));
foreach (MyVertexBase vertex in graphLayout.Graph.Vertices) { double vertexX = GraphCanvas.GetX(vertex); double vertexY = GraphCanvas.GetY(vertex); //Do stuff here }
but vertexX and vertexY is NaN.
Can anyone please debunk the GraphCanvas.GetX&Y and GraphCanvas.SetX&Y myth for me please. I am trying to draw a rectangle on screen(working) and then moving all the vertices in that area as a collective, instead of moving the vertices one by one.
Any help is appreciated.
Thanks
|
|
|
|
|
I've done a bit of playing in that area, and I think the GetX, GetY calls are what you want. However, before layout is done, I think you will get NaNs back. Try doing a Relayout first just to see if you then get good values for the X and
Y.
-Jacob
|
|
|
Mar 31, 2010 at 6:56 AM
Edited Mar 31, 2010 at 8:26 AM
|
Hi Jacob.
After the Relayout() I still get NaN's.
Can anyone please help me?
Here is my Vertex if it helps:
public class MyVertexBase : DependencyObject
{
#region IMAGE
public static readonly DependencyProperty IMAGE_PROPERTY =
DependencyProperty.Register("IMAGE", typeof(Image), typeof(MyVertexBase));
public Image Image
{
get { return (Image)GetValue(IMAGE_PROPERTY); }
set { SetValue(IMAGE_PROPERTY, value); }
}
#endregion
#region LABEL
public static DependencyProperty LABEL_PROPERTY =
DependencyProperty.Register("LABEL", typeof(string), typeof(MyVertexBase));
public string LABEL
{
get { return (string)GetValue(LABEL_PROPERTY); }
set { SetValue(LABEL_PROPERTY, value); }
}
#endregion
#region SELECTED
public static DependencyProperty SELECTED_PROPERTY =
DependencyProperty.Register("SELECTED", typeof(bool), typeof(MyVertexBase));
public bool SELECTED
{
get { return (bool)GetValue(SELECTED_PROPERTY); }
set { SetValue(SELECTED_PROPERTY, value); }
}
#endregion
#region UID
public static DependencyProperty UID_PROPERTY =
DependencyProperty.Register("UID", typeof(string), typeof(MyVertexBase));
public string UID
{
get { return (string)GetValue(UID_PROPERTY); }
set { SetValue(UID_PROPERTY, value); }
}
#endregion
#region LEVEL
public static DependencyProperty LEVEL_PROPERTY =
DependencyProperty.Register("LEVEL", typeof(int), typeof(MyVertexBase));
public int LEVEL
{
get { return (int)GetValue(LEVEL_PROPERTY); }
set { SetValue(LEVEL_PROPERTY, value); }
}
#endregion
}
Should it inherit from VertexControl or something? Because everyone said: GraphCanvas.GetY(vertexControl)???
rootme
|
|
|
|
|
rootme,
When I've been doing it I have inherited from VertexControl (actually a few different times so different types of vertices all have their own control templates). I'm not sure it that will help you, but perhaps
it will. I'd have to dig in to try and figure out where I was doing something similar.
-Jacob
|
|
|
|
|
Hi,
I'm having similar problem. I need to put vertices in proper places on the screen so that they will create sort of network (for example streets in the city). I'm beginner in G# and I don't know were to find this settings of positions of vertices.
|
|
|
|
|
Hey guys',
I'm still stuck here. :( Please someone, just a short sample showing a working solution.
I think a lot of people are having this problem.
|
|
|
|
|
I'll look into this *issue* tonight. I'll let you know!
|
|
|
|
|
Ok thank you very much!
Eagerly awaiting your reply!
|
|
|
|
|
Try GraphLayout.GetX(graphLayout.GetVertexControl(vertex))
where:
- vertex = the vertex object
- graphLayout = the GraphLayout control
|
|
|
Apr 28, 2010 at 7:12 AM
Edited Apr 28, 2010 at 7:15 AM
|
promontis you GENIUS! Thank you! It works! Just a small correction from your sample. The first "GraphLayout" should be "GraphCanvas". Here is a working sample using promontis' sample: double x = GraphCanvas.GetX(graphLayout.GetVertexControl(vertex));
double y = GraphCanvas.GetY(graphLayout.GetVertexControl(vertex)); GraphCanvas.SetX(graphLayout.GetVertexControl(vertex), 100);//The 100 can be whatever. GraphCanvas.SetY(graphLayout.GetVertexControl(vertex), 100); //The 100 can be whatever. Hope this helps
anyone having the same problem in the future. *Edit: The post thing is broken. Sorry for the formatting.*
|
|
|
|
|
I and my friend have a very big problem with this solutions. In ours computer there is no such thing as GraphCanvas. Simple "The name 'GraphCanvas' does not exist in the current context ". We have very similar problem with GraphLayout.GetX(graphLayout.GetVertexControl(vertex)).
graphLayout exist but there is no such thing in graphLayout as GetX. Should we install some special librares ?This is the list of our librares
"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuickGraph;
"
If you can please help us :)
Press
ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
<input id="QuickWikiInput" class="QuickWiki" type="text" />
|
|
|
|
|
From your list, I can see that you're not using GraphSharp.
|
|
|
|
|
ok I add GraphSharp and my list looks like
"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuickGraph;
using GraphSharp;"
but there is still the same error "The name 'GraphCanvas' does not exist in the current context ". Moreover compilator doesn't give any error connecting with library so probably GraphSharp was founded on my computer ;/
|
|
|
|
|
Please try the tutorial and look for differences between that project and yours.
|
|
|
|
|
1. I solve part of the problem because using GraphSharp is not enought. I must use "using GraphSharp.Controls;".
2. In tutorial
http://www.youtube.com/watch?v=VTbuvkaPGxE
there is no "using GraphSharp;" at all . Only "using QuickGraph;" so this tutorial from my point of view is no so usefull
3. I include all librares
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuickGraph;
using QuickGraph.Algorithms;
using QuickGraph.Collections;
using QuickGraph.Contracts;
using QuickGraph.Petri;
using QuickGraph.Predicates;
using QuickGraph.Serialization;
using GraphSharp;
using GraphSharp.Controls;
using GraphSharp.Algorithms;
using GraphSharp.Contracts;
using GraphSharp.Converters;
using GraphSharp.Helpers;
but still have a problem
"\ 'GraphSharp.Controls.GraphLayout' does not contain a definition for 'GetVertexControl' and no extension method 'GetVertexControl' accepting a first argument of type 'GraphSharp.Controls.GraphLayout' could be found (are you missing a using directive
or an assembly reference?) "
so program finds GraphCanvas.GetX but in graphLayout cannot find GetVertexControl.
I made my graph in XAML exaclty like in tutorial so it is looks like
"<graphsharp:GraphLayout x:Name="graphLayout" Graph="{Binding ElementName=root ,Path=GraphToVisualize}"
LayoutAlgorithmType="FR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple">"
|
|
|
|
|
Have you added the references to the GraphSharp, GraphSharp.Controls?
|
|
|
|
|
Yes I have references to the GraphSharp, GraphSharp.Controls. Here is all my project. Maybe you find what is wrong ?
http://www.vjdw.michalin.pl/MaximalFlowNetwork.rar
Press
ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
<input id="QuickWikiInput" class="QuickWiki" type="text" />
|
|
|
|
|
Please guys help me. Option with set constant value of X and Y vertex position is
necessary in my work. If you don't help me with this little thing I will be forced to write everything on my own. I have deadline in thursday and in this case propably I don't make
whole project on time.
http://www.vjdw.michalin.pl/MaximalFlowNetwork.rar
Here is my project. If you cannot find why it isn't working maybe you give me a little working project containing only set X and set Y vertex positions.
regards
|
|
|
|
|
If you download the source code, you'll find a GraphSharpTutorial01 folder with a working sample. That's your starting point. Next, look at this post on how to set positions.
|
|
|
|
|
are you talking about this
http://graphsharp.codeplex.com/SourceControl/changeset/changes/24813
because there is a floder GraphSharp Tutorial01 and there is tutorial which I find long time ago but of course it is not working. I add "using GraphSharp" and "GraphSharp.controls"and there is still the same problem. "GraphSharp.Controls.GraphLayout'
does not contain a definition for 'GetVertexControl' and no extension method 'GetVertexControl' accepting a first argument of type 'GraphSharp.Controls.GraphLayout' could be found (are you missing a using directive or an assembly reference?) ".
|
|
|
Coordinator
May 2, 2010 at 7:11 AM
|
GraphLayout is a partial class. Look at the code in the GraphLayout.GraphElements.cs
file, there is a GetVertexControl method ( http://graphsharp.codeplex.com/SourceControl/changeset/view/31744#529203 )
public VertexControl GetVertexControl(TVertex vertex)
{
VertexControl vc = null;
_vertexControls.TryGetValue(vertex, out vc);
return vc;
}
Using this method you can get the VertexControl for a vertex, after that with the
GraphCanvas.SetX , SetY methods you can set the positions. Sorry, but it's not in the latest release, you need compile the lib from the latest source code.
palesz
|
|
|
|
|
Thank you very much . Problem is solved. The solution is to download 31744 file build libriaries and change them with libriaries from tutorial.
By the way I have some other question.There is a posibility to make that vertex will have the same position after every adding or reamoving ? Of course i can create a loop and using getX and setX do this on my own
but i guess that there is a simple possibility to turn off function which change position during adding..
Press
ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
<input id="QuickWikiInput" class="QuickWiki" type="text" />
|
|
|
|
|
Hi, it's me once again.
I have very strange situation with adding vertex and changing position. I have code in button_Click this:
BidirectionalGraph<object>> g = (BidirectionalGraph<object>>)_graphToVisualize.ToBidirectionalGraph<object>>();
VertexControl vs;
int k;
g.AddVertex(textBox3.Text);
for (int i = 0; i < g.Vertices.Count(); i++)
{
int.TryParse(g.Vertices.ElementAt(i).ToString(), out k);
vs = graphLayout.GetVertexControl(g.Vertices.ElementAt(i));
if (vs != null)
{
GraphCanvas.SetX(vs, position[k, 0]);
GraphCanvas.SetY(vs, position[k, 0]);
}
}</object></object></object>
The problem is that,, when I click "add vertex" all vertices totally change theirs positions. Moreover if I click once again (and
g.AddVertex is not working because textBox3.Text has value existing vertex) everything works perfectly and come back to proper positions. It looks like that when g.AddVertex(textBox3.Text) works program ignore GraphCanvas.SetX(vs, position[k, 0]) and when g.AddVertex(textBox3.Text) doesn't work
program set GraphCanvas.SetX(vs, position[k, 0]) properly. Do you have any idea why I have some strange problem ?
|
|
|
May 10, 2010 at 11:14 PM
Edited May 10, 2010 at 11:14 PM
|
Ok I change in xaml to "LayoutAlgorithmType="KK" " and now is better . When I add vertex the vertices doesn't dance so much. But they are still moving. Where I can find some information about LayoutAlgorithmType ?
How and what I should set that after adding vertex the rest of verticies will not move at all.
|
|
|
|
|
So I change "KK "to "FreeFR" and everything working perfectly ! So cannot understand why nobody said it to me ! This is so facking easy to write if you know that and so fucking timeconsuming if you have to make it up on your own.This
is only
5 letters !!!
Press
ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
<input id="QuickWikiInput" class="QuickWiki" type="text" />
|
|
|
|
|
I want to restore my vertex positions (not run the algorithm). When I call graphLayout.GetVertexControl(xxx), it returns empty :( But I did call AddVertex. My guess the controls aren't created yet.
Do you when I set the vertex positions without running the algorithm?
Any ideas? Thanks.
|
|
|
|
|
@poprostuJanek Would you post your code so that others can benefit from what you learned?
|
|
|
Oct 7, 2011 at 10:39 AM
Edited Oct 7, 2011 at 10:56 AM
|
I will thank that code
|
|
|
|
|
Hi, I'm having some strange trouble with this thing. When i add a vertex, the vertex count in data object(GraphToVisualize) increase but it doesn`t in Xaml object(graphsharplayout) and because of that i can´t set the position of vertex. I can see the
vertex, but graphsharplayout.Children.Count is not updated. All i want to do is when i add a new vertex to the graph that it appears in a different position than previous vertex, so i can see all vertex in the graph and draw the connections between them
as i wish.
This is what i am trying to do:
when i add a new vertex, i try to change its position, but i receive the error NullReferenceException, v Vertex is not in the graph.
C# code
GraphToVisualize.AddVertex(v);
if (GraphToVisualize.VertexCount > 1)
{
double x = GraphCanvas.GetX(graphsharplayout.GetVertexControl(v));
double y = GraphCanvas.GetY(graphsharplayout.GetVertexControl(v));
GraphCanvas.SetX(graphsharplayout.GetVertexControl(v), 100);
GraphCanvas.SetY(graphsharplayout.GetVertexControl(v), 100);
}
This is de xaml part:
<graphsharp:GraphLayout x:Name="graphsharplayout"
Graph="{Binding ElementName=root,Path=GraphToVisualize, NotifyOnSourceUpdated=True}"
LayoutAlgorithmType="FreeFR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple" />
Thanks for any help.
|
|
|
|
|
Sorry to further extend this thread (I hope it's still alive) but I have a related question.
I am trying to get the graph coordinates of each node as soon as possible after the graph loads. I can do this using the approach outlined above (eventually - the current release package DLLs don't seem to support the GetVertexControl method so a build is
required) but only in response to a mouse event.
If I handle the 'loaded' event on my GraphLayout object all vertex ordinates come back NaN. If I let the graph load, then mouseover and handle the 'MouseEnter' event I get useful numbers.
I thought maybe this was related to the startup animation, but that seems kind of weird.
Does anyone know at what point I can reliably retrieve coordinates?
Any help much appreciated.
|
|
|
|
|
I figured out my issue by handling both the Loaded and LayoutUpdated events from the GraphLayout.
LayoutUpdated is fired several times before Loaded, but within the Loaded event I call graphLayout.UpdateLayout() and the next time LayoutUpdated is fired the coordinates are available (not NaN) as expected.
I really like Graph# but the lack of documentation beyond a single video on Youtube and the tumbleweeds rolling through this forum are so frustrating - it seems crazy to put so much effort into writing the code but then discourage people from using it.
|
|