Skip to content

Commit

Permalink
Fix regression in Sankey computation (#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 30, 2020
1 parent ecca467 commit 2d25c77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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)

0 comments on commit 2d25c77

Please sign in to comment.