From b188a9c8cb31aaff29c2582dd8953b2bc3b4a23f Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 30 Mar 2020 15:14:24 +0200 Subject: [PATCH] Fix regression in Sankey computation --- holoviews/element/sankey.py | 2 +- holoviews/tests/element/testgraphelement.py | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/holoviews/element/sankey.py b/holoviews/element/sankey.py index 2c1f6f8d95..653d622e15 100644 --- a/holoviews/element/sankey.py +++ b/holoviews/element/sankey.py @@ -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 = [] diff --git a/holoviews/tests/element/testgraphelement.py b/holoviews/tests/element/testgraphelement.py index a0b48ed896..90309cb40b 100644 --- a/holoviews/tests/element/testgraphelement.py +++ b/holoviews/tests/element/testgraphelement.py @@ -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') @@ -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)