Skip to content

Allowing for custom node positions on graphs - #193

Merged
64json merged 1 commit into
algorithm-visualizer:masterfrom
nadr0:setting-graph-nodes
Jun 23, 2016
Merged

64json merged 1 commit into
algorithm-visualizer:masterfrom
nadr0:setting-graph-nodes

Conversation

@nadr0

@nadr0 nadr0 commented Jun 23, 2016 •

Copy link
Copy Markdown
Contributor

Can add custom (x,y) positions for all the nodes in a graph! This code
should not work or effect the graphs that are “trees”, i.e using _setTreeData.

I needed some way to force tracer._setData(G) to reset the graph even though the data in G didn't change so I added some helper functions that make the data "dirty" to force it to reset and set the data again and the node positions because they need to be redrawn on the screen. Maybe there is a better way to achieve this?

this.nodePositions (inside directed_graph.js) stores objects in the format
var myNodePositions = [{x:0,y:0},{x:1,y:1},{x:2,y:2}];
someTracer._setNodePositions(myNodePositions);
that means the 0th node will get its (x,y) = (0,0) when drawn on the screen. This allows someone to control the positions of the nodes.

If someone gives an array of length 4 and there are 6 nodes in the graph it will go back to the default positioning given. Thats what the ternary check is for.

Can add custom (x,y) positions for all the nodes in a graph!  This code
doesn’t not work or effect the graphs that are “trees” i.e using
setTreeData.
@64json
64json merged commit 6c05885 into algorithm-visualizer:master Jun 23, 2016
64json added a commit that referenced this pull request Jun 23, 2016
@nadr0
nadr0 deleted the setting-graph-nodes branch June 25, 2016 18:26
64json added a commit that referenced this pull request Jul 24, 2018
Allowing for custom node positions on graphs
64json added a commit that referenced this pull request Jul 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants