Skip to content

Commit

Permalink
Merge pull request #9 from vizzu-streamlit/container-width
Browse files Browse the repository at this point in the history
Add use_container_width argument
  • Loading branch information
blackary authored Aug 22, 2023
2 parents 6d4e1c1 + 628d786 commit db79713
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 135 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
with:
python-version: "3.8"
- uses: pre-commit/[email protected]
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repos:
args:
- --ignore-missing-imports
- --follow-imports=silent
- --python-version=3.8
additional_dependencies:
- types-all
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
21 changes: 8 additions & 13 deletions 1-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,29 @@
chart = VizzuChart()

# Generate some data and add it to the chart
df = pd.DataFrame({
"cat": ["x", "y", "z"],
"val": [1, 2, 3]})
df = pd.DataFrame({"cat": ["x", "y", "z"], "val": [1, 2, 3]})
data = Data()
data.add_data_frame(df)
chart.animate(data)

st.subheader('Visit [intro-to-vizzu-in.streamlit.app](https://intro-to-vizzu-in.streamlit.app/) to follow along')
st.subheader(
"Visit [intro-to-vizzu-in.streamlit.app](https://intro-to-vizzu-in.streamlit.app/) "
"to follow along"
)

# Add some configuration to tell Vizzu how to display the data
chart.animate(Config({
"x": "cat",
"y": "val",
"title": "Look at my plot!"}))
chart.animate(Config({"x": "cat", "y": "val", "title": "Look at my plot!"}))

if st.checkbox("Swap"):
chart.animate(Config({
"x": "val",
"y": "cat",
"title": "Swapped!"}))
chart.animate(Config({"x": "val", "y": "cat", "title": "Swapped!"}))

# Show the chart in the app!
output = chart.show()

if output is not None and "marker" in output:
st.write("value of clicked bar:", output["marker"]["values"]["val"])

st.caption('Data shown on the chart')
st.caption("Data shown on the chart")
st.dataframe(df)

st.write(
Expand Down
40 changes: 0 additions & 40 deletions 3-drilldown.py

This file was deleted.

2 changes: 2 additions & 0 deletions filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pandas as pd
import streamlit as st
from streamlit_vizzu import Config, Data, Style, VizzuChart
Expand Down
45 changes: 25 additions & 20 deletions football-transfers/football_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from streamlit_vizzu import VizzuChart

data_frame = pd.read_csv("football-transfers/football_transfers_cleaned.csv", dtype={"year": str})
data_frame = pd.read_csv(
"football-transfers/football_transfers_cleaned.csv", dtype={"year": str}
)

data = Data()
data.add_data_frame(data_frame)
Expand All @@ -16,35 +18,38 @@
year = st.slider("Pick a year", min_value=1992, max_value=2022, value=2010)
compare_by = st.radio("Compare by", ["Fees earned", "Fees spent", "Balance"], index=2)
if compare_by == "Fees earned":
compare_title = "Transfer fees earned in "
x = "fee[m€]"
filter = f"record.year == '{year}' && record.transfer_movement == 'out'"
compare_title = "Transfer fees earned in "
x = "fee[m€]"
filter = f"record.year == '{year}' && record.transfer_movement == 'out'"
elif compare_by == "Fees spent":
compare_title = "Transfer fees spent in "
x = "fee[m€]"
filter = f"record.year == '{year}' && record.transfer_movement == 'in' && record.club_name =='Arsenal FC'"
compare_title = "Transfer fees spent in "
x = "fee[m€]"
filter = (
f"record.year == '{year}' && record.transfer_movement == 'in' "
"&& record.club_name =='Arsenal FC'"
)
else:
compare_title = "Balance of transfer fees in "
x = "fee_real[m€]"
filter = f"record.year == '{year}'"
compare_title = "Balance of transfer fees in "
x = "fee_real[m€]"
filter = f"record.year == '{year}'"


chart.animate(
Data.filter(filter),
Data.filter(filter),
Config(
{"x": [x,"player_name"],
"y": "club_name",
"color": "club_name",
"lightness":"player_name",
#"sort": "byValue",
"title": f"{compare_title}{year}"}
{
"x": [x, "player_name"],
"y": "club_name",
"color": "club_name",
"lightness": "player_name",
# "sort": "byValue",
"title": f"{compare_title}{year}",
}
),
Style(
{
"plot": {
"xAxis": {
"label": {
"numberScale": "shortScaleSymbolUS"}},
"xAxis": {"label": {"numberScale": "shortScaleSymbolUS"}},
"marker": {
"colorPalette": (
"#b74c20FF #c47f58FF #1c9761FF #ea4549FF #875792FF #3562b6FF "
Expand Down
29 changes: 17 additions & 12 deletions football-transfers/pages/2-bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from streamlit_vizzu import VizzuChart

data_frame = pd.read_csv("football-transfers/football_transfers_cleaned.csv", dtype={"year": str})
data_frame = pd.read_csv(
"football-transfers/football_transfers_cleaned.csv", dtype={"year": str}
)

data = Data()
data.add_data_frame(data_frame)
Expand All @@ -17,25 +19,28 @@

compare_title = "Transfer fees spent in "
x = "fee[m€]"
filter = f"record.year == '{year}' && record.transfer_movement == 'in' && record.club_name =='Arsenal FC'"
filter = (
f"record.year == '{year}' && record.transfer_movement == 'in' "
"&& record.club_name =='Arsenal FC'"
)


chart.animate(
Data.filter(filter),
Data.filter(filter),
Config(
{"x": x,
"y": "player_name",
"color": "player_name",
"sort": "byValue",
"label": x,
"title": f"{compare_title}{year}"}
{
"x": x,
"y": "player_name",
"color": "player_name",
"sort": "byValue",
"label": x,
"title": f"{compare_title}{year}",
}
),
Style(
{
"plot": {
"xAxis": {
"label": {
"numberScale": "shortScaleSymbolUS"}},
"xAxis": {"label": {"numberScale": "shortScaleSymbolUS"}},
"marker": {
"colorPalette": (
"#b74c20FF #c47f58FF #1c9761FF #ea4549FF #875792FF #3562b6FF "
Expand Down
16 changes: 8 additions & 8 deletions pages/2-slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
chart.animate(
Data.filter(f"record.Year <= '{year}'"),
Config.groupedBar(
{"x": "Revenue[$]",
"y": "Format",
"groupedBy": "Format",
"sort": "byValue",
"title": f"Music Revenues up to {year}"}
{
"x": "Revenue[$]",
"y": "Format",
"groupedBy": "Format",
"sort": "byValue",
"title": f"Music Revenues up to {year}",
}
),
Style(
{
"plot": {
"xAxis": {
"label": {
"numberScale": "shortScaleSymbolUS"}},
"xAxis": {"label": {"numberScale": "shortScaleSymbolUS"}},
"marker": {
"colorPalette": (
"#b74c20FF #c47f58FF #1c9761FF #ea4549FF #875792FF #3562b6FF "
Expand Down
70 changes: 36 additions & 34 deletions pages/3-drilldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@
data = Data()
data.add_data_frame(data_frame)

style = Style({
"plot": {
"xAxis": {
"label": {
"angle": "-1.1"}},
"yAxis": {
"label": {
"numberScale": "shortScaleSymbolUS"}},
"marker": {
"colorPalette": (
"#b74c20FF #c47f58FF #1c9761FF #ea4549FF #875792FF #3562b6FF "
"#ee7c34FF #efae3aFF"
),
"label": {
"numberFormat": "prefixed",
"maxFractionDigits": "1",
"numberScale": "shortScaleSymbolUS",
},
},
"paddingLeft": "8em",
}
})
style = Style(
{
"plot": {
"xAxis": {"label": {"angle": "-1.1"}},
"yAxis": {"label": {"numberScale": "shortScaleSymbolUS"}},
"marker": {
"colorPalette": (
"#b74c20FF #c47f58FF #1c9761FF #ea4549FF #875792FF #3562b6FF "
"#ee7c34FF #efae3aFF"
),
"label": {
"numberFormat": "prefixed",
"maxFractionDigits": "1",
"numberScale": "shortScaleSymbolUS",
},
},
"paddingLeft": "8em",
}
}
)

chart.animate(data, style)

Expand All @@ -38,26 +36,30 @@

if bar_clicked is None:
chart.animate(
Data.filter(),
Data.filter(),
Config(
{"x": "Year",
"y": "Revenue[$]",
"sort" : "none",
"color": None,
"label": None,
"title": "Music Revenues"}
),style,
delay="0")
{
"x": "Year",
"y": "Revenue[$]",
"sort": "none",
"color": None,
"label": None,
"title": "Music Revenues",
}
),
style,
delay="0",
)
else:
chart.animate(Data.filter(f"record['Year'] == '{bar_clicked}'"))
chart.animate(
Config.groupedColumn(
{
"x": "Format",
"y": "Revenue[$]",
"groupedBy": "Format",
"sort":"byValue",
"title": f"Drilldown for Year {bar_clicked}"
"groupedBy": "Format",
"sort": "byValue",
"title": f"Drilldown for Year {bar_clicked}",
}
)
)
Expand Down
4 changes: 3 additions & 1 deletion pages/4-explorer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pandas as pd
import streamlit as st

Expand All @@ -20,7 +22,7 @@

col1, col2, col3, col4, col5 = st.columns(5)

measure: str = col1.radio("Measure", ["Sales", "Revenue [$]"])
measure: str = col1.radio("Measure", ["Sales", "Revenue [$]"])
compare_by = col2.radio("Compare by", ["Product", "Region", "Both"])
coords = col3.radio("Coordinate system", ["Cartesian (desktop)", "Polar (mobile)"])
order = col4.radio("Order items", ["Alphabetically", "By value"])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="streamlit-vizzu",
version="0.1.3",
version="0.1.4",
author="Zachary Blackwoood",
author_email="[email protected]",
description=(
Expand Down
Loading

0 comments on commit db79713

Please sign in to comment.