From 853438739b5afd67b8ec360a2110806f7ddfb1d5 Mon Sep 17 00:00:00 2001 From: longxiaofei Date: Fri, 2 Feb 2024 14:54:53 +0800 Subject: [PATCH] feat: streamlit add new component: filter renderer --- app/src/index.tsx | 124 ++++++++++++++++++++---------------- app/src/interfaces/index.ts | 13 +--- pygwalker/api/streamlit.py | 16 ++++- 3 files changed, 82 insertions(+), 71 deletions(-) diff --git a/app/src/index.tsx b/app/src/index.tsx index 5b7944d..ef0b57d 100644 --- a/app/src/index.tsx +++ b/app/src/index.tsx @@ -7,7 +7,7 @@ import { IRow, IGWHandler, IViewField } from '@kanaries/graphic-walker/dist/inte import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import Options from './components/options'; -import { IAppProps, IGraphicRendererProps } from './interfaces'; +import { IAppProps } from './interfaces'; import { loadDataSource, postDataService, finishDataService, getDatasFromKernelBySql, getDatasFromKernelByPayload } from './dataSource'; @@ -154,54 +154,46 @@ const App: React.FC = observer((props) => { return ( -
- - - - - - - { - mode === "walker" ? - : - - } - - -
+ + + + + + { + mode === "walker" ? + : + + } + +
); }) @@ -212,7 +204,6 @@ const PureRednererApp: React.FC = observer((props) => { return ( - { const initOnHttpCommunication = async(props: IAppProps) => { const comm = initHttpCommunication(props.id, props.communicationUrl); communicationStore.setComm(comm); - if (props.gwMode === "explore" && props.needLoadLastSpec) { + if ((props.gwMode === "explore" || props.gwMode === "filter_renderer") && props.needLoadLastSpec) { const visSpecResp = await comm.sendMsg("get_latest_vis_spec", {}); props.visSpec = visSpecResp["data"]["visSpec"]; } @@ -272,8 +263,27 @@ function GWalker(props: IAppProps, id: string) { } preRender(props).then(() => { + let component = ; + switch(props.gwMode) { + case "explore": + component = ; + break; + case "renderer": + component = ; + break; + case "filter_renderer": + component = ; + break; + default: + component = + } + const isDark = currentMediaTheme(props.dark) === "dark"; + ReactDOM.render( - props.gwMode === "explore" ? : , +
+ + {component} +
, document.getElementById(id) ); }) @@ -293,18 +303,20 @@ function ChartPreviewApp(props: IChartPreviewProps, id: string) { ); } -function GraphicRendererApp(props: IGraphicRendererProps) { +function GraphicRendererApp(props: IAppProps) { + const computationCallback = getComputationCallback(props); + return (
- {props.charts.map((chart, index) => { + {props.visSpec.map((chart, index) => { return {chart.name} })}
- {props.charts.map((chart, index) => { + {props.visSpec.map((chart, index) => { return { props.useKernelCalc ? @@ -313,7 +325,7 @@ function GraphicRendererApp(props: IGraphicRendererProps) { containerStyle={{ height: "600px", width: "60%" }} themeKey={props.themeKey} dark={props.dark} - computation={props.computation!} + computation={computationCallback!} chart={[chart]} /> : str: def _get_html( self, *, - mode: Literal["explore", "renderer"] = "explore", + mode: Literal["explore", "renderer", "filter_renderer"] = "explore", vis_spec: Optional[List[Dict[str, Any]]] = None, **kwargs: Dict[str, Any] ) -> str: @@ -174,6 +173,16 @@ def set_global_pre_filters(self, pre_filters: List[PreFilter]): """It will append new filters to exists charts.""" self.global_pre_filters = pre_filters + def render_filter_renderer( + self, + width: int = 1300, + height: int = 1000, + scrolling: bool = False, + ) -> "DeltaGenerator": + """Render filter renderer UI""" + html = self._get_html(mode="filter_renderer") + return components.html(html, height=height, width=width, scrolling=scrolling) + def render_explore( self, width: int = 1300, @@ -254,6 +263,7 @@ def get_streamlit_html( show_cloud_tool: Optional[bool] = None, debug: bool = False, kanaries_api_key: str = "", + mode: Literal["explore", "filter_renderer"] = "explore", **kwargs ) -> str: """Get pygwalker html render to streamlit @@ -288,4 +298,4 @@ def get_streamlit_html( **kwargs ) - return renderer._get_html() + return renderer._get_html(mode=mode)