Skip to content

Commit

Permalink
feat: add docs and update demo (#14)
Browse files Browse the repository at this point in the history
* docs: use markdown to show code

* docs: add JS api document
  • Loading branch information
hustcc authored Jan 10, 2024
1 parent d18dfad commit 8388386
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 33 deletions.
3 changes: 1 addition & 2 deletions example/pages/10_ Funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/11_Boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/12_Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
9 changes: 3 additions & 6 deletions example/pages/1_Bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down Expand Up @@ -97,8 +96,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down Expand Up @@ -178,8 +176,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
9 changes: 3 additions & 6 deletions example/pages/2_Column.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down Expand Up @@ -112,8 +111,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down Expand Up @@ -203,8 +201,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/3_Line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/4_Area.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/5_Pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/6_Scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/7_DualAxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/8_Liquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
3 changes: 1 addition & 2 deletions example/pages/9_Ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@

g2(options=options)

source = st.expander("Source Code")
source.markdown("""
st.markdown("""
```py
import streamlit as st
from streamlit_g2 import g2
Expand Down
30 changes: 29 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ options = {
}
}

g2(options=options, style=None, key="streamlit_g2")
g2(options=options, style=None)
```

<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*XqCnTbkpAkQAAAAAAAAAAAAADmJ7AQ/fmt.webp" width="640" alt="example">
Expand All @@ -64,6 +64,34 @@ Now, There is only one API for `streamlit-g2`, named `g2`, see the `options` in
| options | the [options](https://g2.antv.antgroup.com/manual/core/api) for the visualization, say `chart.options(options)` | `G2options` \| `null` | - |
| style | the style of the container | `CSSProperties` | - |

## FAQ

- How to use Javascript callback function?

```py
import streamlit as st
from streamlit_g2 import g2, JS

options = {
"type": "interval",
"data": [
{ "genre": 'Sports', "sold": 275 },
{ "genre": 'Strategy', "sold": 115 },
{ "genre": 'Action', "sold": 120 },
{ "genre": 'Shooter', "sold": 350 },
{ "genre": 'Other', "sold": 150 },
],
"encode": {
"x": "genre",
"y": "sold",
# Use Javascript function.
"color": JS('''(d) => d.sold > 300 ? "red" : "green"'''),
}
}

g2(options=option)
```


## Development

Expand Down

0 comments on commit 8388386

Please sign in to comment.