Skip to content

Commit

Permalink
Add support for datashader Graph layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 21, 2017
1 parent b6eb55a commit 75bf59a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion holoviews/element/graphs.py
Expand Up @@ -8,6 +8,12 @@
from .chart import Points
from .path import Path

try:
from datashader.layout import LayoutAlgorithm
except:
LayoutAlgorithm = None


class graph_redim(redim):
"""
Extension for the redim utility that allows re-dimensioning
Expand Down Expand Up @@ -43,14 +49,19 @@ class layout_nodes(Operation):
A NetworkX layout function""")

def _process(self, element, key=None):
if self.p.layout:
if self.p.layout and not (LayoutAlgorithm and issubclass(self.p.layout, LayoutAlgorithm)):
graph = nx.from_edgelist(element.array([0, 1]))
positions = self.p.layout(graph)
return Nodes([tuple(pos)+(idx,) for idx, pos in sorted(positions.items())])
else:
source = element.dimension_values(0, expanded=False)
target = element.dimension_values(1, expanded=False)
nodes = np.unique(np.concatenate([source, target]))
if self.p.layout:
import pandas as pd
df = pd.DataFrame({'index': nodes})
nodes = self.p.layout(df, element.dframe())
return Nodes(nodes[['x', 'y', 'index']])
return Nodes(circular_layout(nodes))


Expand Down

0 comments on commit 75bf59a

Please sign in to comment.