Skip to content

Commit

Permalink
Merge pull request #1794 from jakevdp/layer-selection
Browse files Browse the repository at this point in the history
BUG: LayerChart.add_selection: apply selection only to first layer
  • Loading branch information
jakevdp authored Nov 18, 2019
2 parents 1d80b59 + 8f3538a commit 6ea2f81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions altair/vegalite/v3/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,8 +1882,7 @@ def add_selection(self, *selections):
if not selections or not self.layer:
return self
copy = self.copy()
copy.layer = [chart.add_selection(*selections)
for chart in copy.layer]
copy.layer[0] = copy.layer[0].add_selection(*selections)
return copy


Expand Down
10 changes: 9 additions & 1 deletion altair/vegalite/v3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,15 @@ def test_facet_add_selections():
assert chart1.to_dict() == chart2.to_dict()


@pytest.mark.parametrize('charttype', [alt.layer, alt.concat, alt.hconcat, alt.vconcat])
def test_layer_add_selection():
base = alt.Chart('data.csv').mark_point()
selection = alt.selection_single()
chart1 = alt.layer(base.add_selection(selection), base)
chart2 = alt.layer(base, base).add_selection(selection)
assert chart1.to_dict() == chart2.to_dict()


@pytest.mark.parametrize('charttype', [alt.concat, alt.hconcat, alt.vconcat])
def test_compound_add_selections(charttype):
base = alt.Chart('data.csv').mark_point()
selection = alt.selection_single()
Expand Down

0 comments on commit 6ea2f81

Please sign in to comment.