def test_filter_transform_selection_predicates(): selector1 = alt.selection_interval(name='s1') selector2 = alt.selection_interval(name='s2') base = alt.Chart('data.txt').mark_point() chart = base.transform_filter(selector1) assert chart.to_dict()['transform'] == [{'filter': {'selection': 's1'}}] chart = base.transform_filter(~selector1) assert chart.to_dict()['transform'] == [{ 'filter': { 'selection': { 'not': 's1' } } }] chart = base.transform_filter(selector1 & selector2) assert chart.to_dict()['transform'] == [{ 'filter': { 'selection': { 'and': ['s1', 's2'] } } }] chart = base.transform_filter(selector1 | selector2) assert chart.to_dict()['transform'] == [{ 'filter': { 'selection': { 'or': ['s1', 's2'] } } }]
def test_SelectionMapping(): # test instantiation of selections interval = alt.selection_interval(name='selec_1') assert interval['selec_1'].type == 'interval' assert interval._get_name() == 'selec_1' single = alt.selection_single(name='selec_2') assert single['selec_2'].type == 'single' assert single._get_name() == 'selec_2' multi = alt.selection_multi(name='selec_3') assert multi['selec_3'].type == 'multi' assert multi._get_name() == 'selec_3' # test addition x = single + multi + interval assert set(x.to_dict().keys()) == {'selec_1', 'selec_2', 'selec_3'} y = single.copy() y += multi y += interval assert x.to_dict() == y.to_dict() # test logical operations x = single & multi assert isinstance(x, alt.SelectionAnd) y = single | multi assert isinstance(y, alt.SelectionOr)
def test_add_selection(): selections = [ alt.selection_interval(), alt.selection_single(), alt.selection_multi() ] chart = alt.Chart().mark_point().add_selection( selections[0]).add_selection(selections[1], selections[2]) expected = selections[0] + selections[1] + selections[2] assert chart.selection.to_dict() == expected.to_dict()