Skip to content
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

Improved Graph element #2145

Merged
merged 5 commits into from
Nov 23, 2017
Merged

Improved Graph element #2145

merged 5 commits into from
Nov 23, 2017

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Nov 23, 2017

Since I started writing the Chord (#2138) and TriMesh (#2143) elements, it's become clear that the Graph element is quite useful as a baseclass for other elements. However currently it isn't as solid, optimized and tested as I'd like it to be, so rather than mixing up a bunch of changes into the Chord and TriMesh PRs I've decided to first build on Graph, ensuring that it is well tested and solid at it's core.

This will improve Graphs in a number of ways:

Graph Element Improvements

  1. Add an optimized pandas based implementation that handles drawing direct edge paths between nodes. The naive implementation relying just on HoloViews functionality is way to slow and this provides a ~100x speedup as long as pandas is installed.
  2. Graphs allowed supplying node information without defining the explicit node positions. This code was brittle and relied on implicit assumptions on the ordering of nodes. I've hardened the exception handling here, being much stricter about how node information is merged and relying on pandas to handle actual merges between node indices.

Graph Plot improvements

  1. The Graph glyphs are now updated in a well defined order, which ensures that explicit paths are re-rendered correctly when updated.
  2. The GraphPlot implementations now support an edge_color_index allowing them to be colored both by categorical attributes (e.g. by their source node) or by a value (e.g. a weight value).
  • Added tests
  • Added documentation

N = len(nodes)
circ = np.pi/N*np.arange(N)*2
x = np.cos(circ)
y = np.sin(circ)
return (x, y, nodes)


def connect_edges_pd(graph):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move some of these functions to element.util?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds good.

@@ -411,6 +412,59 @@ def map_colors(arr, crange, cmap, hex=True):
return arr


def mplcmap_to_palette(cmap, ncolors=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the right place for these utilities!

g = self.graph4.opts(plot=dict(edge_color_index='Weight'),
style=dict(edge_cmap=['#FFFFFF', '#000000']))
plot = bokeh_renderer.get_plot(g)
print(plot.handles)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray print.

@jlstevens
Copy link
Contributor

Looks good! Other than some very minor comments I posted above, I am happy for you to go ahead and merge once you think it is ready.

@philippjfr
Copy link
Member Author

Yay, even got a gain in coverage. Thanks for the review, merging.

@philippjfr philippjfr merged commit 4c1b01d into master Nov 23, 2017
@philippjfr philippjfr added this to the v1.9.2 milestone Dec 8, 2017
@philippjfr philippjfr deleted the graph_enhancements branch December 18, 2017 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants