-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add four simple layouts #310
Conversation
Pull Request Test Coverage Report for Build 893561305
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
My only comment is that you should consider updating all layout functions to handle graphs with holes in node indices.
Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
Thanks, this is a good point, I forgot that indices can be non-consecutive. Will update soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
n = 5
graph = rx.generators.mesh_graph(n)
graph.remove_node(2)
rx.shell_layout(graph, nlist=[graph.node_indexes()])
will raise a panick exception.
I suggested some changes to fix this but feel free to proceed in your own way.
Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! One comment left and then it should be ready to go
src/layout.rs
Outdated
|
||
if let Some(scale) = scale { | ||
rescale(&mut pos, scale, (0..node_num).collect()); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(scale) = scale { | |
rescale(&mut pos, scale, (0..node_num).collect()); | |
} | |
} | |
} | |
if let Some(scale) = scale { | |
rescale(&mut pos, scale, (0..node_num).collect()); | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I forgot there's an else if
-- but the problem of moving it out is that if the graph only has 1 node, lim
in rescale
will be 0.0
and the point will become [NaN, NaN]
. I guess I can modify rescale
so it only does something when lim > 0.0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this LGTM, great work! I have 2 nits inline but not really worth blocking over. I might just update the test one myself real quickly so we can merge this (because getting good error messages from the tests are useful).
#[pyfunction] | ||
#[text_signature = "(graph, /, scale=1, center=None, resolution=0.35, | ||
equidistant=False)"] | ||
pub fn digraph_spiral_layout( | ||
graph: &digraph::PyDiGraph, | ||
scale: Option<f64>, | ||
center: Option<layout::Point>, | ||
resolution: Option<f64>, | ||
equidistant: Option<bool>, | ||
) -> Pos2DMapping { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would do something like:
#[pyfunction] | |
#[text_signature = "(graph, /, scale=1, center=None, resolution=0.35, | |
equidistant=False)"] | |
pub fn digraph_spiral_layout( | |
graph: &digraph::PyDiGraph, | |
scale: Option<f64>, | |
center: Option<layout::Point>, | |
resolution: Option<f64>, | |
equidistant: Option<bool>, | |
) -> Pos2DMapping { | |
#[pyfunction(scale="1.0", resolution="0.35", equidistant="false")] | |
#[text_signature = "(graph, /, scale=1, center=None, resolution=0.35, | |
equidistant=False)"] | |
pub fn digraph_spiral_layout( | |
graph: &digraph::PyDiGraph, | |
scale: f64, | |
center: Option<layout::Point>, | |
resolution: f64, | |
equidistant: bool, | |
) -> Pos2DMapping { |
so we set the default in the macro generated python c api ffi function. But this also works fine
This commit adds a new custom assertion method for comparing layouts with a tolerance (fixed at 1e-6) ensuring that no layout differs from the expected in any coordinate by more than this. If there is a failure it will print a detailed message about which node differs from the expected. With this change locally 2 bipartite layout tests failed so this commit updates the expected values so it passes (the layouts still look like valid bipartite layouts just the center point was different).
Related to #280. Four simplest layouts were added: bipartite, circular, shell, and spiral. A few things to note: