From b6097e27210d77411fb5b4611c1ac0b4927289f2 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Thu, 19 Apr 2018 18:14:05 +0100
Subject: [PATCH 1/2] Add support for looping edges in Chords element
---
holoviews/element/graphs.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/holoviews/element/graphs.py b/holoviews/element/graphs.py
index 8b41343453..2f3465db67 100644
--- a/holoviews/element/graphs.py
+++ b/holoviews/element/graphs.py
@@ -581,7 +581,7 @@ def _process(self, element, key=None):
matrix[s, t] += v
# Compute weighted angular slice for each connection
- weights_of_areas = (matrix.sum(axis=0) + matrix.sum(axis=1)) - matrix.diagonal()
+ weights_of_areas = (matrix.sum(axis=0) + matrix.sum(axis=1))
areas_in_radians = (weights_of_areas / weights_of_areas.sum()) * (2 * np.pi)
# We add a zero in the begging for the cumulative sum
@@ -608,9 +608,11 @@ def _process(self, element, key=None):
empty = np.array([[np.NaN, np.NaN]])
paths = []
for i in range(len(element)):
- src_area, tgt_area = all_areas[src_idx[i]], all_areas[tgt_idx[i]]
+ sidx, tidx = src_idx[i], tgt_idx[i]
+ src_area, tgt_area = all_areas[sidx], all_areas[tidx]
+ n_conns = matrix[sidx, tidx]
subpaths = []
- for _ in range(int(values[i])):
+ for _ in range(int(n_conns)):
if not src_area or not tgt_area:
continue
x0, y0 = src_area.pop()
@@ -625,7 +627,7 @@ def _process(self, element, key=None):
if subpaths:
paths.append(np.concatenate(subpaths))
else:
- paths.append(np.array([]))
+ paths.append(np.empty((0, 2)))
# Construct Chord element from components
if nodes_el:
From d41373c66bc9582c1f7f4451b16a1b79fc99aef9 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Thu, 19 Apr 2018 18:22:15 +0100
Subject: [PATCH 2/2] Added unit test for Chord self-referential nodes
---
tests/element/testgraphelement.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tests/element/testgraphelement.py b/tests/element/testgraphelement.py
index 23b048a075..cda99dc928 100644
--- a/tests/element/testgraphelement.py
+++ b/tests/element/testgraphelement.py
@@ -155,6 +155,14 @@ def test_chord_constructor_with_vdims(self):
self.assertEqual(chord.nodes, Nodes(nodes))
self.assertEqual(chord.array(), np.array(self.simplices))
+ def test_chord_constructor_self_reference(self):
+ chord = Chord([('A', 'B', 2), ('B', 'A', 3), ('A', 'A', 2)])
+ nodes = np.array(
+ [[-0.5, 0.866025, 0],
+ [0.5, -0.866025, 1]]
+ )
+ self.assertEqual(chord.nodes, Nodes(nodes))
+
class TriMeshTests(ComparisonTestCase):