Skip to content

Commit

Permalink
Fix: Pass additional color specifications to charts (streamlit#7061)
Browse files Browse the repository at this point in the history
Handles column specification in altair charts by passing header defaults for fonts/colors to both default and streamlit chart themes in CustomTheme.tsx
  • Loading branch information
mayagbarnes authored and Your Name committed Mar 22, 2024
1 parent d43eca0 commit 13eb453
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 6 deletions.
23 changes: 17 additions & 6 deletions e2e/scripts/st_arrow_altair_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@

chart = alt.Chart(data).mark_bar().encode(x="a", y="b")

st.write("Bar chart with default theme:")
st._arrow_altair_chart(chart)

st.write("Bar chart with streamlit theme:")
st._arrow_altair_chart(chart, theme="streamlit")

st.write("Bar chart with overwritten theme props:")
st._arrow_altair_chart(chart.configure_mark(color="black"), theme="streamlit")

Expand All @@ -77,3 +71,20 @@

st.write("Pie Chart with more than 4 Legend items")
st._arrow_altair_chart(chart, theme="streamlit")

# taken from vega_datasets barley example
barley = alt.UrlData(
"https://cdn.jsdelivr.net/npm/vega-datasets@v2.7.0/data/barley.json"
)

barley_chart = (
alt.Chart(barley)
.mark_bar()
.encode(x="year:O", y="sum(yield):Q", color="year:N", column="site:N")
)

st.write("Grouped Bar Chart with default theme:")
st.altair_chart(barley_chart, theme=None)

st.write("Grouped Bar Chart with streamlit theme:")
st.altair_chart(barley_chart, theme="streamlit")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export function applyStreamlitTheme(config: any, theme: EmotionTheme): any {
orient: "top",
offset: 26,
},
header: {
titleFontWeight: theme.fontWeights.normal,
titleFontSize: theme.fontSizes.mdPx,
titleColor: getGray70(theme),
titleFontStyle: "normal",
labelFontSize: theme.fontSizes.twoSmPx,
labelFontWeight: theme.fontWeights.normal,
labelColor: getGray70(theme),
labelFontStyle: "normal",
},
axis: {
labelFontSize: theme.fontSizes.twoSmPx,
labelFontWeight: theme.fontWeights.normal,
Expand Down Expand Up @@ -165,8 +175,11 @@ export function applyThemeDefaults(config: any, theme: EmotionTheme): any {
},
header: {
labelColor: colors.bodyText,
titleColor: colors.bodyText,
...themeFonts,
},
view: {
stroke: getGray30(theme),
continuousHeight: 350,
continuousWidth: 400,
},
Expand Down

0 comments on commit 13eb453

Please sign in to comment.