-
Notifications
You must be signed in to change notification settings - Fork 1
update structure of viz folder and classes #13
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
Draft
szvsw
wants to merge
7
commits into
main
Choose a base branch
from
feature/improve-visualizations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db5bab4
update structure of viz folder and classes
daryaguettler cfb694e
add new views and ploting utils
daryaguettler 2bc9c4e
add tester data
daryaguettler 39e7f52
update test_lib
daryaguettler c10ae69
update mapping functionality
daryaguettler d848178
add ability save map to html
daryaguettler 2e48daa
align buttons
daryaguettler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """Export helpers for chart download (e.g. HTML to PNG).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| from playwright.sync_api import sync_playwright | ||
|
|
||
|
|
||
| def render_html_to_png(html: str, width: int = 800, height: int = 500) -> bytes | None: | ||
| """Render chart HTML to PNG bytes using playwright if available.""" | ||
| with tempfile.NamedTemporaryFile( | ||
| mode="w", suffix=".html", delete=False, encoding="utf-8" | ||
| ) as f: | ||
| f.write(html) | ||
| path = Path(f.name) | ||
|
|
||
| try: | ||
| with sync_playwright() as p: | ||
| browser = p.chromium.launch() | ||
| page = browser.new_page(viewport={"width": width, "height": height}) | ||
| page.goto(f"file://{path.resolve()}") | ||
| page.wait_for_timeout(500) | ||
| png_bytes = page.screenshot(type="png", full_page=True) | ||
| browser.close() | ||
| except Exception: | ||
| return None | ||
| else: | ||
| return png_bytes | ||
| finally: | ||
| path.unlink(missing_ok=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,50 @@ | ||
| """Entry point for the GLOBI visualization app.""" | ||
| """Entry point for the GLOBI visualization app. Uses st.navigation so the first page displays as "Overview".""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import streamlit as st | ||
|
|
||
| from globi.tools.visualization.data_sources import DataSource | ||
| from globi.tools.visualization.models import LocalDataSourceConfig, S3DataSourceConfig | ||
| from globi.tools.visualization.pages import render_raw_data_page, render_use_cases_page | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Entry point for the visualization app.""" | ||
| st.set_page_config(page_title="GLOBI Visualization", layout="wide") | ||
| st.title("GLOBI Visualization") | ||
|
|
||
| with st.sidebar: | ||
| source_type = st.radio("Data Source", options=["Local", "S3"], index=0) | ||
|
|
||
| if source_type == "Local": | ||
| base_dir = st.text_input("Output Directory", value="outputs") | ||
| config = LocalDataSourceConfig(base_dir=Path(base_dir)) | ||
| else: | ||
| run_name = st.text_input("S3 Run Name", value="") | ||
| version = st.text_input("Version (optional)", value="") | ||
| if not run_name: | ||
| st.warning("Enter a run name to load from S3.") | ||
| return | ||
| config = S3DataSourceConfig( | ||
| run_name=run_name, | ||
| version=version if version else None, | ||
| ) | ||
|
|
||
| data_source = DataSource.from_config(config) | ||
|
|
||
| page = st.sidebar.selectbox( | ||
| "Page", | ||
| options=["Raw Data Visualization", "Use Cases"], | ||
| index=0, | ||
| ) | ||
|
|
||
| if page == "Raw Data Visualization": | ||
| render_raw_data_page(data_source) | ||
| elif page == "Use Cases": | ||
| render_use_cases_page(data_source) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| from globi.tools.visualization.sidebar import render_data_source_sidebar | ||
| from globi.tools.visualization.views import ( | ||
| render_overview_page, | ||
| render_raw_data_page, | ||
| render_use_cases_page, | ||
| ) | ||
|
|
||
| st.set_page_config(page_title="GLOBI Visualization", layout="wide") | ||
| st.title("GLOBI Visualization") | ||
|
|
||
| data_source = render_data_source_sidebar() | ||
| st.session_state["data_source"] = data_source | ||
|
|
||
|
|
||
| def _overview() -> None: | ||
| render_overview_page() | ||
|
|
||
|
|
||
| def _raw_data() -> None: | ||
| ds = st.session_state.get("data_source") | ||
| if ds is not None: | ||
| render_raw_data_page(ds) | ||
| else: | ||
| st.info( | ||
| "Configure a data source in the sidebar (e.g. Local with an output directory) to view raw data." | ||
| ) | ||
|
|
||
|
|
||
| def _use_cases() -> None: | ||
| ds = st.session_state.get("data_source") | ||
| if ds is not None: | ||
| render_use_cases_page(ds) | ||
| else: | ||
| st.info( | ||
| "Configure a data source in the sidebar (e.g. Local with an output directory) to run use cases." | ||
| ) | ||
|
|
||
|
|
||
| pg = st.navigation([ | ||
| st.Page(_overview, title="Overview"), | ||
| st.Page(_raw_data, title="Raw Data Visualization"), | ||
| st.Page(_use_cases, title="Use Cases"), | ||
| ]) | ||
| pg.run() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is not using the equivalent code from Scythe?