public DiagramGenerator(List <DiagramNode> nodes, List <DiagramNodeConnection> connections, int imageWidth) { _nodes = nodes; _connections = connections; _simulator = new ForceSimulator(); _simulator.AddForce(new NBodyForce()); _simulator.AddForce(new SpringForce()); _simulator.AddForce(new DragForce()); _imageWidth = imageWidth; }
/// <summary> /// Loads the simulator with all relevant force items and springs. /// </summary> /// <param name="fsim"> the force simulator driving this layout.</param> protected void InitializeSimulator(ForceSimulator fsim) { //TODO: some checks here...? float startX = (referrer == null ? 0f : (float)referrer.X); float startY = (referrer == null ? 0f : (float)referrer.Y); startX = float.IsNaN(startX) ? 0f : startX; startY = float.IsNaN(startY) ? 0f : startY; if (Nodes != null && Nodes.Count > 0) { foreach (INode item in Nodes) { ForceItem fitem = Pars[item.Uid.ToString()]; fitem.Mass = getMassValue(item); double x = item.X; double y = item.Y; fitem.Location[0] = (Double.IsNaN(x) ? startX : (float)x); fitem.Location[1] = (Double.IsNaN(y) ? startY : (float)y); fsim.addItem(fitem); } } if (Edges != null && Edges.Count > 0) { foreach (IEdge e in Edges) { INode n1 = e.SourceNode; if (n1 == null) { continue; } ForceItem f1 = Pars[n1.Uid.ToString()]; INode n2 = e.TargetNode; if (n2 == null) { continue; } ForceItem f2 = Pars[n2.Uid.ToString()]; float coeff = getSpringCoefficient(e); float slen = getSpringLength(e); fsim.addSpring(f1, f2, (coeff >= 0 ? coeff : -1.0F), (slen >= 0 ? slen : -1.0F)); } } }
private bool Init() { mEnforceBounds = false; m_runonce = true; m_fsim = new ForceSimulator(); m_fsim.AddForce(new NBodyForce()); m_fsim.AddForce(new SpringForce()); m_fsim.AddForce(new DragForce()); this.Graph = this.Model as IGraph; if (Graph == null) { throw new InconsistencyException("The model has not been set and the Graph property is hence 'null'"); } //Graph.ClearSpanningTree(); //Graph.MakeSpanningTree(LayoutRoot as INode); if (Graph.Nodes.Count == 0) { return(false); } if (Graph.Edges.Count == 0) //this layout is base on embedded springs in the connections { return(false); } Pars = new Dictionary <string, ForceItem>(); foreach (INode node in Nodes) { Pars.Add(node.Uid.ToString(), new ForceItem()); } return(true); }
/// <summary> /// Loads the simulator with all relevant force items and springs. /// </summary> /// <param name="fsim"> the force simulator driving this layout.</param> protected void InitializeSimulator(ForceSimulator fsim) { //TODO: some checks here...? float startX = (referrer == null ? 0f : (float)referrer.X); float startY = (referrer == null ? 0f : (float)referrer.Y); startX = float.IsNaN(startX) ? 0f : startX; startY = float.IsNaN(startY) ? 0f : startY; foreach (node item in graph.nodes) { ForceItem fitem = Pars[item.name]; fitem.Mass = getMassValue(item); double x = item.X; double y = item.Y; fitem.Location[0] = (Double.IsNaN(x) ? startX : (float)x); fitem.Location[1] = (Double.IsNaN(y) ? startY : (float)y); fsim.addItem(fitem); } foreach (arc e in graph.arcs) { node n1 = e.From; if (n1 == null) { continue; } ForceItem f1 = Pars[n1.name]; node n2 = e.To; if (n2 == null) { continue; } ForceItem f2 = Pars[n2.name]; float coeff = getSpringCoefficient(e); float slen = getSpringLength(e); fsim.addSpring(f1, f2, (coeff >= 0 ? coeff : -1.0F), (slen >= 0 ? slen : -1.0F)); } }
public DiagramGenerator(List <DiagramNodeConnection> connections, int imageWidth) { //Build a node list from the connections _nodes = new List <DiagramNode>(); foreach (DiagramNodeConnection currConnection in connections) { if (!_nodes.Contains(currConnection.FirstNode)) { _nodes.Add(currConnection.FirstNode); } if (!_nodes.Contains(currConnection.SecondNode)) { _nodes.Add(currConnection.SecondNode); } } _connections = connections; _simulator = new ForceSimulator(); _simulator.AddForce(new NBodyForce()); _simulator.AddForce(new SpringForce()); _simulator.AddForce(new DragForce()); _imageWidth = imageWidth; }
protected override bool RunLayout() { m_fsim = new ForceSimulator(); m_fsim.AddForce(new NBodyForce()); m_fsim.AddForce(new SpringForce()); m_fsim.AddForce(new DragForce()); Pars = new Dictionary <string, ForceItem>(); foreach (node n in graph.nodes) { Pars.Add(n.name.ToString(), new ForceItem()); } progress = 20; backgroundWorker.ReportProgress(progress); if (backgroundWorker.CancellationPending) { return(false); } defaultSpan = 100 * graph.nodes.Count; bool success = Run(defaultSpan); return(success); }