Skip to content

Commit

Permalink
Add selectedpoints style property for plotly Scatter / Points elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Aug 8, 2019
1 parent a92408d commit 514383e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions holoviews/plotting/plotly/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class ScatterPlot(ChartPlot, ColorbarPlot):
allow_None=True, doc="""
Index of the dimension from which the color will the drawn""")

style_opts = ['marker', 'color', 'cmap', 'alpha', 'size', 'sizemin']
style_opts = [
'marker', 'color', 'cmap', 'alpha', 'size', 'sizemin', 'selectedpoints'
]

_nonvectorized_styles = ['cmap', 'alpha', 'sizemin']
_nonvectorized_styles = ['cmap', 'alpha', 'sizemin', 'selectedpoints']

trace_kwargs = {'type': 'scatter', 'mode': 'markers'}

Expand Down
4 changes: 4 additions & 0 deletions holoviews/plotting/plotly/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def graph_options(self, element, ranges, style):

opts[self._style_key] = {STYLE_ALIASES.get(k, k): v
for k, v in styles.items()}

# Move selectedpoints from style key back to root
if 'selectedpoints' in opts.get(self._style_key, {}):
opts['selectedpoints'] = opts[self._style_key].pop('selectedpoints')
else:
opts.update({STYLE_ALIASES.get(k, k): v
for k, v in style.items() if k != 'cmap'})
Expand Down
7 changes: 7 additions & 0 deletions holoviews/tests/plotting/plotly/testscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def test_scatter_markers(self):
state = self._get_plot_state(scatter)
self.assertEqual(state['data'][0]['marker']['symbol'],
np.array(['square', 'circle', 'triangle-up']))

def test_scatter_selectedpoints(self):
scatter = Scatter([
(0, 1,), (1, 2), (2, 3)
]).options(selectedpoints=[1, 2])
state = self._get_plot_state(scatter)
self.assertEqual(state['data'][0]['selectedpoints'], [1, 2])

0 comments on commit 514383e

Please sign in to comment.