Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples): add larger example for layouts #9

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/data/claims.json

Large diffs are not rendered by default.

File renamed without changes.
4 changes: 2 additions & 2 deletions examples/demos/edge_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import streamlit as st
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle

with open("./sample_data.json", "r") as f:
with open("./data/social.json", "r") as f:
elements = json.load(f)

PERSON_ATTRS = list(elements["edges"][0]["data"].keys()) + [None]
Expand Down Expand Up @@ -69,7 +69,7 @@

elements = {json.dumps(elements)}

st_link_analysis(elements, layout, node_styles, edge_styles)
st_link_analysis(elements, layout, node_styles, edge_styles, key="xyz")
""",
language="python",
)
43 changes: 23 additions & 20 deletions examples/demos/layout.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import json
import streamlit as st
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle
from st_link_analysis import st_link_analysis, NodeStyle
from st_link_analysis.component.layouts import LAYOUTS

LAYOUT_NAMES = list(LAYOUTS.keys())

with open("./sample_data.json", "r") as f:
with open("./data/claims.json", "r") as f:
elements = json.load(f)

sample = {
"nodes": [
{"data": {"id": "n1", "label": "PERSON"}},
{"data": {"id": "n2", "label": "CAR"}},
{"data": {"id": "n3", "label": "CLAIM"}},
],
"edges": [
{"data": {"id": "e1", "source": "n1", "target": "n2", "label": "DRIVES"}},
{"data": {"id": "e2", "source": "n2", "target": "n3", "label": "INVOVLED_IN"}},
],
}

st.markdown("# Layout Algorithms")
st.markdown(
"""
Expand All @@ -20,39 +32,30 @@
layout = st.selectbox("Layout Name", LAYOUT_NAMES, index=0)

node_styles = [
NodeStyle("PERSON", "#FF7F3E", None, "person"),
NodeStyle("POST", "#2A629A", None, "description"),
NodeStyle("CLAIM", "#a87c2a", None, "description"),
NodeStyle("CAR", "#028391", None, "directions_car"),
NodeStyle("PERSON", "#01204E", None, "person"),
]

edge_styles = [
EdgeStyle("FOLLOWS", labeled=True, directed=True),
EdgeStyle("POSTED", labeled=True, directed=True),
EdgeStyle("QUOTES", labeled=True, directed=True),
]
st_link_analysis(elements, layout, node_styles, key="xyz")

st_link_analysis(elements, layout, node_styles, edge_styles, key="xyz")

with st.expander("Snippet", expanded=False, icon="💻"):
st.code(
f"""
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle

edge_styles = [
EdgeStyle("FOLLOWS", labeled=True, directed=True),
EdgeStyle("POSTED", labeled=True, directed=True),
EdgeStyle("QUOTES", labeled=True, directed=True),
]

node_styles = [
NodeStyle("PERSON", "#FF7F3E", None, "person"),
NodeStyle("POST", "#2A629A", None, "description"),
NodeStyle("CLAIM", "#a87c2a", None, "description"),
NodeStyle("CAR", "#028391", None, "directions_car"),
NodeStyle("PERSON", "#01204E", None, "person"),
]

{layout=}

elements = {json.dumps(elements)}
elements = {json.dumps(sample)}

st_link_analysis(elements, layout, node_styles, edge_styles)
st_link_analysis(elements, layout, node_styles, key="xyz")
""",
language="python",
)
4 changes: 2 additions & 2 deletions examples/demos/node_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle
from st_link_analysis.component.icons import SUPPORTED_ICONS

with open("./sample_data.json", "r") as f:
with open("./data/social.json", "r") as f:
elements = json.load(f)

PERSON_ATTRS = list(elements["nodes"][0]["data"].keys()) + [None]
Expand Down Expand Up @@ -59,7 +59,7 @@

elements = {json.dumps(elements)}

st_link_analysis(elements, layout, node_styles, edge_styles)
st_link_analysis(elements, layout, node_styles, edge_styles, key="xyz")
""",
language="python",
)