Skip to content

Commit

Permalink
feat: size of chart remains the same as size of html
Browse files Browse the repository at this point in the history
  • Loading branch information
longxiaofei committed Oct 9, 2023
1 parent b9afa0b commit 15de776
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions pygwalker/api/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

from typing_extensions import Literal
import streamlit.components.v1 as components

from .pygwalker import PygWalker
from pygwalker.communications.streamlit_comm import hack_streamlit_server
Expand Down Expand Up @@ -116,14 +117,39 @@ def __init__(
)
self.walker.init_streamlit_comm()

def render_explore(self) -> str:
def render_explore(
self,
width: int = 1300,
height: int = 1000,
scrolling: bool = False,
):
"""Render explore UI(it can drag and drop fields)"""
return self.walker.get_html_on_streamlit_v2()
html = self.walker.get_html_on_streamlit_v2()
components.html(html, height=height, width=width, scrolling=scrolling)

def render_pure_chart(self, index: int) -> str:
def render_pure_chart(
self,
index: int,
width: Optional[int] = None,
height: Optional[int] = None,
scrolling: bool = False,
) -> str:
"""Render pure chart, index is the order of chart, starting from 0."""
spec_obj = json.loads(self.walker.vis_spec)
return self.walker.get_html_on_streamlit_v2(
cur_spec_obj = json.loads(self.walker.vis_spec)[index]
cur_spec_obj["config"]["size"]["mode"] = "fixed"

if width is None:
width = cur_spec_obj["config"]["size"]["width"]
else:
cur_spec_obj["config"]["size"]["width"] = width

if height is None:
height = cur_spec_obj["config"]["size"]["height"]
else:
cur_spec_obj["config"]["size"]["height"] = height

html = self.walker.get_html_on_streamlit_v2(
mode="renderer",
vis_spec=json.dumps([spec_obj[index]])
vis_spec=json.dumps([cur_spec_obj])
)
components.html(html, height=height, width=width, scrolling=scrolling)

0 comments on commit 15de776

Please sign in to comment.