Add interactive visualization examples using Vega-Altair
Resolves #7
Change-Id: Ib90189326b47e4a0541a65f91502d9225760d52c
diff --git a/examples/hello_world_interactive.py b/examples/hello_world_interactive.py
new file mode 100755
index 0000000..edc5662
--- /dev/null
+++ b/examples/hello_world_interactive.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+import altair as alt
+
+from KorAPClient import KorAPClient, KorAPConnection
+
+QUERY = "Hello World"
+YEARS = range(2010, 2019)
+COUNTRIES = ["DE", "CH"]
+
+kcon = KorAPConnection(verbose=True)
+
+vcs = [f"textType=/Zeit.*/ & pubPlaceKey={c} & pubDate in {y}" for c in COUNTRIES for y in YEARS]
+df = KorAPClient.ipm(kcon.frequencyQuery(QUERY, vcs))
+print(df)
+
+df['Year'] = [y for c in COUNTRIES for y in YEARS]
+df['Country'] = [c for c in COUNTRIES for y in YEARS]
+df['tooltip'] = "ctrl+click to open concordances in new tab"
+
+band = alt.Chart(df).mark_errorband().encode(
+ y=alt.Y("conf.low", title=""),
+ y2="conf.high",
+ x="Year",
+ color="Country",
+ tooltip=["Country", "Year", alt.Tooltip("ipm", format=".2f")]
+)
+
+line = alt.Chart(df).mark_line(point=True).encode(
+ y="ipm",
+ x="Year",
+ color="Country",
+ href="webUIRequestUrl",
+ tooltip="tooltip"
+)
+
+(band + line).show()
diff --git a/examples/variant_by_country_interactive_barchart.py b/examples/variant_by_country_interactive_barchart.py
new file mode 100644
index 0000000..01542ba
--- /dev/null
+++ b/examples/variant_by_country_interactive_barchart.py
@@ -0,0 +1,21 @@
+import altair as alt
+
+from KorAPClient import KorAPConnection, KorAPClient
+
+COUNTRIES = ["DE", "AT", "CH"]
+
+kcon = KorAPConnection(verbose=True)
+df = kcon.frequencyQuery(query=['"Wissenschaftler.*"', '"Wissenschafter.*"'],
+ vc=[f"pubPlaceKey = {c}" for c in COUNTRIES],
+ **{"as.alternatives": True})
+
+df["Land"] = KorAPClient.queryStringToLabel(df.vc)
+
+alt.Chart(df).mark_bar().encode(
+ y="Land",
+ x=alt.X("f", title="Anteil", axis=alt.Axis(format='%')),
+ color=alt.Color("query", title="Variante"),
+ href="webUIRequestUrl",
+ tooltip=[alt.Tooltip('f', format=".1%", title="Anteil")]
+).show()
+