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

Fix regression in Sankey computation #4337

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion holoviews/element/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def computeNodeBreadths(self, graph):
if py is None:
max_depth = max(depths.values()) - 1 if depths else 1
height = self.p.bounds[3] - self.p.bounds[1]
py = min((height * 0.1) / max_depth, 20)
py = min((height * 0.1) / max_depth, 20) if max_depth else 20

def initializeNodeBreadth():
kys = []
Expand Down
41 changes: 41 additions & 0 deletions holoviews/tests/element/testgraphelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from holoviews.element.graphs import (
Graph, Nodes, TriMesh, Chord, circular_layout, connect_edges,
connect_edges_pd)
from holoviews.element.sankey import Sankey
from holoviews.element.comparison import ComparisonTestCase

pd_skip = skipIf(util.pd is None, 'Pandas not available')
Expand Down Expand Up @@ -294,3 +295,43 @@ def test_trimesh_edgepaths(self):
def test_trimesh_select(self):
trimesh = TriMesh((self.simplices, self.nodes)).select(x=(0.1, None))
self.assertEqual(trimesh.array(), np.array(self.simplices[1:]))


class TestSankey(ComparisonTestCase):

def test_single_edge_sankey(self):
sankey = Sankey([('A', 'B', 1)])
links = list(sankey._sankey['links'])
self.assertEqual(len(links), 1)
del links[0]['source']['sourceLinks']
del links[0]['target']['targetLinks']
link = {
'index': 0,
'source': {
'index': 'A',
'values': (),
'targetLinks': [],
'value': 1,
'depth': 0,
'height': 1,
'x0': 0,
'x1': 15,
'y0': 0.0,
'y1': 500.0},
'target': {
'index': 'B',
'values': (),
'sourceLinks': [],
'value': 1,
'depth': 1,
'height': 0,
'x0': 985.0,
'x1': 1000.0,
'y0': 0.0,
'y1': 500.0},
'value': 1,
'width': 500.0,
'y0': 0.0,
'y1': 0.0
}
self.assertEqual(links[0], link)