Skip to content

Commit

Permalink
Only add legend options to trace types that support them
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Apr 22, 2019
1 parent 8ff0764 commit 4557972
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions holoviews/plotting/plotly/element.py
Expand Up @@ -10,7 +10,8 @@
from ..plot import GenericElementPlot, GenericOverlayPlot
from ..util import dim_range_key, dynamic_update
from .plot import PlotlyPlot
from .util import STYLE_ALIASES, get_colorscale, merge_figure
from .util import (
STYLE_ALIASES, get_colorscale, merge_figure, legend_trace_types)


class ElementPlot(PlotlyPlot, GenericElementPlot):
Expand Down Expand Up @@ -158,9 +159,12 @@ def graph_options(self, element, ranges, style):
legend = element.label

opts = dict(
showlegend=self.show_legend, legendgroup=element.group,
name=legend, **self.trace_kwargs)

if self.trace_kwargs.get('type', None) in legend_trace_types:
opts.update(
showlegend=self.show_legend, legendgroup=element.group)

if self._style_key is not None:
styles = self._apply_transforms(element, ranges, style)
opts[self._style_key] = {STYLE_ALIASES.get(k, k): v
Expand Down
28 changes: 28 additions & 0 deletions holoviews/plotting/plotly/util.py
Expand Up @@ -79,6 +79,34 @@
'scattermapbox': ['mapbox']
}

# trace types that support legends
legend_trace_types = {
'scatter',
'bar',
'box',
'histogram',
'histogram2dcontour',
'contour',
'scatterternary',
'violin',
'waterfall',
'pie',
'scatter3d',
'scattergeo',
'scattergl',
'splom',
'pointcloud',
'scattermapbox',
'scattercarpet',
'contourcarpet',
'ohlc',
'candlestick',
'scatterpolar',
'scatterpolargl',
'barpolar',
'area',
}

# Aliases - map common style options to more common names

STYLE_ALIASES = {'line_width': 'width', 'alpha': 'opacity',
Expand Down

0 comments on commit 4557972

Please sign in to comment.