Skip to content

Commit

Permalink
Add support for looping edges in Chords element (#2583)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Apr 19, 2018
1 parent 876ddf9 commit 97bc1dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions holoviews/element/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/element/testgraphelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 97bc1dd

Please sign in to comment.