Skip to content

Commit

Permalink
Fixes for updating Graph colors (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 24, 2017
1 parent 0d2d2f1 commit 1bdec91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
8 changes: 6 additions & 2 deletions holoviews/plotting/bokeh/graphs.py
Expand Up @@ -124,20 +124,24 @@ def get_data(self, element, ranges, style):
for k, (x, y) in zip(index, node_positions)}
point_data = {'index': index}
cycle = self.lookup_options(element, 'style').kwargs.get('node_color')
colors = cycle if isinstance(cycle, Cycle) else None
if isinstance(cycle, Cycle):
style.pop('node_color', None)
colors = cycle
else:
colors = None
cdata, cmapping = self._get_color_data(
element.nodes, ranges, style, name='node_fill_color',
colors=colors, int_categories=True
)
point_data.update(cdata)
point_mapping = cmapping
edge_mapping = {}
if 'node_fill_color' in point_mapping:
style = {k: v for k, v in style.items() if k not in
['node_fill_color', 'node_nonselection_fill_color']}
point_mapping['node_nonselection_fill_color'] = point_mapping['node_fill_color']

# Get edge data
edge_mapping = {}
nan_node = index.max()+1
start, end = (element.dimension_values(i) for i in range(2))
if nodes.dtype.kind == 'f':
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/util.py
Expand Up @@ -90,7 +90,7 @@ def mpl_to_bokeh(properties):
new_properties['size'] = v
elif k == 'marker':
new_properties.update(markers.get(v, {'marker': v}))
elif k == 'color' or k.endswith('_color'):
elif k == 'color' or k.endswith('_color') and not isinstance(v, dict):
with abbreviated_exception():
v = colors.ColorConverter.colors.get(v, v)
if isinstance(v, tuple):
Expand Down
27 changes: 19 additions & 8 deletions holoviews/plotting/mpl/graphs.py
Expand Up @@ -124,26 +124,37 @@ def init_artists(self, ax, plot_args, plot_kwargs):

return {'nodes': nodes, 'edges': edges}

def update_handles(self, key, axis, element, ranges, style):

def _update_nodes(self, element, data, style):
nodes = self.handles['nodes']
data, style, axis_kwargs = self.get_data(element, ranges, style)
xs, ys = data['nodes']
nodes.set_offsets(np.column_stack([xs, ys]))
cdim = element.nodes.get_dimension(self.color_index)
if cdim:
if cdim and 'c' in style:
nodes.set_clim((style['vmin'], style['vmax']))
nodes.set_array(style['c'])
if 'norm' in style:
nodes.norm = style['norm']


def _update_edges(self, element, data, style):
edges = self.handles['edges']
paths = data['edges']
edges.set_paths(paths)
edges.set_visible(style.get('visible', True))
cdim = element.get_dimension(self.edge_color_index)
if cdim and 'edge_c' in edges:
edges.set_clim((style['edge_vmin'], style['edge_vmax']))
edges.set_array(style['edge_c'])
if 'norm' in style:
edges.norm = style['edge_norm']
if cdim:
if 'edge_array' in style:
edges.set_clim(style['edge_clim'])
edges.set_array(style['edge_array'])
if 'norm' in style:
edges.norm = style['edge_norm']
elif 'edge_colors' in style:
edges.set_edgecolors(style['edge_colors'])


def update_handles(self, key, axis, element, ranges, style):
data, style, axis_kwargs = self.get_data(element, ranges, style)
self._update_nodes(element, data, style)
self._update_edges(element, data, style)
return axis_kwargs

0 comments on commit 1bdec91

Please sign in to comment.