def test_repeat(): # wrapped repeat chart1 = (alt.Chart("data.csv").mark_point().encode( x=alt.X(alt.repeat(), type="quantitative"), y="y:Q", ).repeat(["A", "B", "C", "D"], columns=2)) dct1 = chart1.to_dict() assert dct1["repeat"] == ["A", "B", "C", "D"] assert dct1["columns"] == 2 assert dct1["spec"]["encoding"]["x"]["field"] == {"repeat": "repeat"} # explicit row/col repeat chart2 = (alt.Chart("data.csv").mark_point().encode( x=alt.X(alt.repeat("row"), type="quantitative"), y=alt.Y(alt.repeat("column"), type="quantitative"), ).repeat(row=["A", "B", "C"], column=["C", "B", "A"])) dct2 = chart2.to_dict() assert dct2["repeat"] == { "row": ["A", "B", "C"], "column": ["C", "B", "A"] } assert "columns" not in dct2 assert dct2["spec"]["encoding"]["x"]["field"] == {"repeat": "row"} assert dct2["spec"]["encoding"]["y"]["field"] == {"repeat": "column"}
def test_repeat(): # wrapped repeat chart1 = alt.Chart('data.csv').mark_point().encode( x=alt.X(alt.repeat(), type='quantitative'), y='y:Q', ).repeat( ['A', 'B', 'C', 'D'], columns=2 ) dct1 = chart1.to_dict() assert dct1['repeat'] == ['A', 'B', 'C', 'D'] assert dct1['columns'] == 2 assert dct1['spec']['encoding']['x']['field'] == {'repeat': 'repeat'} # explicit row/col repeat chart2 = alt.Chart('data.csv').mark_point().encode( x=alt.X(alt.repeat('row'), type='quantitative'), y=alt.Y(alt.repeat('column'), type='quantitative') ).repeat( row=['A', 'B', 'C'], column=['C', 'B', 'A'] ) dct2 = chart2.to_dict() assert dct2['repeat'] == {'row': ['A', 'B', 'C'], 'column': ['C', 'B', 'A']} assert 'columns' not in dct2 assert dct2['spec']['encoding']['x']['field'] == {'repeat': 'row'} assert dct2['spec']['encoding']['y']['field'] == {'repeat': 'column'}
def _make_chart_type(chart_type): data = pd.DataFrame({ "x": [28, 55, 43, 91, 81, 53, 19, 87], "y": [43, 91, 81, 53, 19, 87, 52, 28], "color": list("AAAABBBB"), }) base = (alt.Chart(data).mark_point().encode( x="x", y="y", color="color", )) if chart_type in ["layer", "hconcat", "vconcat", "concat"]: func = getattr(alt, chart_type) return func(base.mark_square(), base.mark_circle()) elif chart_type == "facet": return base.facet("color") elif chart_type == "facet_encoding": return base.encode(facet="color") elif chart_type == "repeat": return base.encode(alt.X(alt.repeat(), type="quantitative")).repeat(["x", "y"]) elif chart_type == "chart": return base else: raise ValueError( "chart_type='{}' is not recognized".format(chart_type))
def _make_chart_type(chart_type): data = pd.DataFrame({ 'x': [28, 55, 43, 91, 81, 53, 19, 87], 'y': [43, 91, 81, 53, 19, 87, 52, 28], 'color': list('AAAABBBB'), }) base = alt.Chart(data).mark_point().encode( x='x', y='y', color='color', ) if chart_type in ['layer', 'hconcat', 'vconcat', 'concat']: func = getattr(alt, chart_type) return func(base.mark_square(), base.mark_circle()) elif chart_type == 'facet': return base.facet('color') elif chart_type == 'facet_encoding': return base.encode(facet='color') elif chart_type == 'repeat': return base.encode( alt.X(alt.repeat(), type='quantitative') ).repeat( ['x', 'y'] ) elif chart_type == 'chart': return base else: raise ValueError("chart_type='{}' is not recognized".format(chart_type))