public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Length < 2) { return(null); } if (values[0] == null) { return(null); } ObservableDictionary <GraphNodeVM, Point> nodes = values[0] as ObservableDictionary <GraphNodeVM, Point>; if (nodes == null) { return(null); } if (values[1] == null) { return(null); } GraphNodeVM node = values[1] as GraphNodeVM; if (node == null) { return(null); } if (!nodes.ContainsKey(node)) { return(null); } return(nodes[node]); }
private double Distance(GraphNodeVM n1, GraphNodeVM n2) { return(GraphFactory.Distance( Nodes[n1].X, Nodes[n1].Y, Nodes[n2].X, Nodes[n2].Y)); }
public Point Position(GraphNodeVM node, double rx, double ry, double cx, double cy) { int index = graph.Nodes.IndexOf(node); double angle = ((double)graph.Nodes.IndexOf(node) / graph.Nodes.Count) * (Math.PI * 2); return(new Point( cx + Math.Cos(angle) * rx, cy + Math.Sin(angle) * ry)); }
private Point CalculatePosition(GraphNodeVM node, double margin, double actualWidth, double actualHeight) { double width = actualWidth - margin; double height = actualHeight - margin; double rx = width / 2; double ry = height / 2; double cx = width / 2; double cy = height / 2; if (rx < 10) { rx = 10; // I just want to see anything, uglynees is not important } if (ry < 10) { ry = 10; // I just want to see anything, uglynees is not important } var newPos = positioner.Position(node, rx, ry, cx, ry); newPos.X += margin / 2; newPos.Y += margin / 2; return(newPos); }