Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bokeh colorbars #861

Merged
merged 21 commits into from Sep 14, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+10 −17
Diff settings

Always

Just for now

Added client side colormapping for PointPlot

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Sep 13, 2016
commit 14048bdbf1967eea1ee71dad1c4072266ef660d3
@@ -12,12 +12,12 @@
from ...core.util import max_range, basestring, dimension_sanitizer
from ...core.options import abbreviated_exception
from ..util import compute_sizes, get_sideplot_ranges, match_spec, map_colors
from .element import ElementPlot, line_properties, fill_properties
from .element import ElementPlot, ColorbarPlot, line_properties, fill_properties
from .path import PathPlot, PolygonPlot
from .util import get_cmap, mpl_to_bokeh, update_plot, rgb2hex, bokeh_version


class PointPlot(ElementPlot):
class PointPlot(ColorbarPlot):

color_index = param.ClassSelector(default=3, class_=(basestring, int),
allow_None=True, doc="""
@@ -55,21 +55,12 @@ def get_data(self, element, ranges=None, empty=False):
mapping = dict(x=dims[xidx], y=dims[yidx])
data = {}

cmap = style.get('palette', style.get('cmap', None))
cdim = element.get_dimension(self.color_index)
if cdim and cmap:
map_key = 'color_' + cdim.name
mapping['color'] = map_key
if empty:
data[map_key] = []
else:
cmap = get_cmap(cmap)
colors = element.dimension_values(self.color_index)
if colors.dtype.kind in 'if':
crange = ranges.get(cdim.name, element.range(cdim.name))
else:
crange = np.unique(colors)
data[map_key] = map_colors(colors, crange, cmap)
if cdim:
mapper = self._get_colormapper(cdim, element, ranges, style)
data[cdim.name] = [] if empty else element.dimension_values(cdim)
mapping['color'] = {'field': cdim.name,
'transform': mapper}

This comment has been minimized.

Copy link
@jlstevens

jlstevens Sep 14, 2016

Contributor

Looks much cleaner!

sdim = element.get_dimension(self.size_index)
if sdim:
@@ -98,7 +89,7 @@ def get_batched_data(self, element, ranges=None, empty=False):
eldata, elmapping = self.get_data(el, ranges, empty)
for k, eld in eldata.items():
data[k].append(eld)
if 'color' not in eldata:
if 'color' not in elmapping:
zorder = self.get_zorder(element, key, el)
val = style[zorder].get('color')
elmapping['color'] = 'color'
@@ -128,6 +119,8 @@ def _init_glyph(self, plot, mapping, properties):
else:
plot_method = self._plot_methods.get('batched' if self.batched else 'single')
renderer = getattr(plot, plot_method)(**dict(properties, **mapping))
if self.colorbar and 'color_mapper' in self.handles:
self._draw_colorbar(plot, self.handles['color_mapper'])
return renderer, renderer.glyph

This comment has been minimized.

Copy link
@jlstevens

jlstevens Sep 14, 2016

Contributor

When could you request a colorbar but not have a color_mapper available?

This comment has been minimized.

Copy link
@philippjfr

philippjfr Sep 14, 2016

Author Contributor

They might have enabled colorbar by default but not set a color_index.

This comment has been minimized.

Copy link
@jlstevens

jlstevens Sep 14, 2016

Contributor

Ok, makes sense, thanks.



ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.