Skip to content

Commit

Permalink
feat: add new param: default_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
longxiaofei committed Feb 2, 2024
1 parent e5c2c35 commit 3f5d3af
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import { observer } from "mobx-react-lite";
import { GraphicWalker, PureRenderer, GraphicRenderer } from '@kanaries/graphic-walker'
import type { VizSpecStore } from '@kanaries/graphic-walker/dist/store/visualSpecStore'
import { IRow, IGWHandler, IViewField } from '@kanaries/graphic-walker/dist/interfaces';
import { IRow, IGWHandler, IViewField, ISegmentKey } from '@kanaries/graphic-walker/dist/interfaces';
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

import Options from './components/options';
Expand Down Expand Up @@ -111,6 +111,12 @@ const App: React.FC<IAppProps> = observer((props) => {
}
}, []);

useEffect(() => {
setTimeout(() => {
storeRef.current?.setSegmentKey(props.defaultTab as ISegmentKey);
}, 0);
}, [mode]);

const exportTool = getExportTool(setExportOpen);

const tools = [exportTool];
Expand Down
1 change: 1 addition & 0 deletions app/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IAppProps {
extraConfig?: any;
fieldMetas: any;
isExportDataFrame: boolean;
defaultTab: "data" | "vis";
}

export interface IDataSourceProps {
Expand Down
2 changes: 1 addition & 1 deletion pygwalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pygwalker.services.global_var import GlobalVarManager
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle

__version__ = "0.4.5a4"
__version__ = "0.4.5a5"
__hash__ = __rand_str()

from pygwalker.api.walker import walk
Expand Down
3 changes: 3 additions & 0 deletions pygwalker/api/gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_html_on_gradio(
debug: bool = False,
use_kernel_calc: bool = True,
kanaries_api_key: str = "",
default_tab: Literal["data", "vis"] = "vis",
**kwargs
) -> str:
"""Get pygwalker html render to gradio
Expand All @@ -41,6 +42,7 @@ def get_html_on_gradio(
- debug (bool): Whether to use debug mode, Default to False.
- use_kernel_calc(bool): Whether to use kernel compute for datas, Default to True.
- kanaries_api_key (str): kanaries api key, Default to "".
- default_tab (Literal["data", "vis"]): default tab to show. Default to "vis"
"""
walker = PygWalker(
gid=gid,
Expand All @@ -58,6 +60,7 @@ def get_html_on_gradio(
use_save_tool=debug,
is_export_dataframe=False,
kanaries_api_key=kanaries_api_key,
default_tab=default_tab,
**kwargs
)

Expand Down
2 changes: 2 additions & 0 deletions pygwalker/api/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def to_html(
hideDataSourceConfig: bool = True,
themeKey: Literal['vega', 'g2'] = 'g2',
dark: Literal['media', 'light', 'dark'] = 'media',
default_tab: Literal["data", "vis"] = "vis",
**kwargs
):
"""
Expand Down Expand Up @@ -60,6 +61,7 @@ def to_html(
gw_mode="explore",
is_export_dataframe=False,
kanaries_api_key="",
default_tab=default_tab,
**kwargs
)

Expand Down
6 changes: 5 additions & 1 deletion pygwalker/api/pygwalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
use_save_tool: bool,
is_export_dataframe: bool,
kanaries_api_key: str,
default_tab: Literal["data", "vis"],
**kwargs
):
self.kanaries_api_key = kanaries_api_key or GlobalVarManager.kanaries_api_key
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(
self.is_export_dataframe = is_export_dataframe
self._last_exported_dataframe = None
self.cloud_service = CloudService(self.kanaries_api_key)
self.default_tab = default_tab
check_update()
# Temporarily adapt to pandas import module bug
if self.use_kernel_calc:
Expand Down Expand Up @@ -417,7 +419,8 @@ def _send_props_track(self, props: Dict[str, Any]):
needed_fields = {
"id", "version", "hashcode", "hideDataSourceConfig", "themeKey",
"dark", "env", "specType", "needLoadDatas", "showCloudTool",
"useKernelCalc", "useSaveTool", "parseDslType", "gwMode", "datasetType"
"useKernelCalc", "useSaveTool", "parseDslType", "gwMode", "datasetType",
"defaultTab"
}
event_info = {key: value for key, value in props.items() if key in needed_fields}
event_info["hasKanariesToken"] = bool(self.kanaries_api_key)
Expand Down Expand Up @@ -466,6 +469,7 @@ def _get_props(
"extraConfig": self.other_props,
"fieldMetas": self.data_parser.field_metas,
"isExportDataFrame": self.is_export_dataframe,
"defaultTab": self.default_tab
}

self._send_props_track(props)
Expand Down
9 changes: 8 additions & 1 deletion pygwalker/api/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
use_kernel_calc: bool = True,
show_cloud_tool: Optional[bool] = None,
kanaries_api_key: str = "",
default_tab: Literal["data", "vis"] = "vis",
**kwargs
):
"""Get pygwalker html render to streamlit
Expand All @@ -79,6 +80,7 @@ def __init__(
- debug (bool): Whether to use debug mode, Default to False.
- use_kernel_calc(bool): Whether to use kernel compute for datas, Default to True.
- kanaries_api_key (str): kanaries api key, Default to "".
- default_tab (Literal["data", "vis"]): default tab to show. Default to "vis"
"""
self.walker = PygWalker(
gid=gid,
Expand All @@ -96,6 +98,7 @@ def __init__(
use_save_tool=debug,
is_export_dataframe=False,
kanaries_api_key=kanaries_api_key,
default_tab=default_tab,
**kwargs
)
comm = StreamlitCommunication(str(self.walker.gid))
Expand Down Expand Up @@ -188,9 +191,10 @@ def render_explore(
width: int = 1300,
height: int = 1000,
scrolling: bool = False,
default_tab: Literal["data", "vis"] = "vis"
) -> "DeltaGenerator":
"""Render explore UI(it can drag and drop fields)"""
html = self._get_html()
html = self._get_html(**{"defaultTab": default_tab})
return components.html(html, height=height, width=width, scrolling=scrolling)

def render_pure_chart(
Expand Down Expand Up @@ -264,6 +268,7 @@ def get_streamlit_html(
debug: bool = False,
kanaries_api_key: str = "",
mode: Literal["explore", "filter_renderer"] = "explore",
default_tab: Literal["data", "vis"] = "vis",
**kwargs
) -> str:
"""Get pygwalker html render to streamlit
Expand All @@ -280,6 +285,7 @@ def get_streamlit_html(
- use_kernel_calc(bool): Whether to use kernel compute for datas, Default to False.
- debug (bool): Whether to use debug mode, Default to False.
- kanaries_api_key (str): kanaries api key, Default to "".
- default_tab (Literal["data", "vis"]): default tab to show. Default to "vis"
"""
if fieldSpecs is None:
fieldSpecs = {}
Expand All @@ -295,6 +301,7 @@ def get_streamlit_html(
use_kernel_calc=use_kernel_calc,
show_cloud_tool=show_cloud_tool,
kanaries_api_key=kanaries_api_key,
default_tab=default_tab,
**kwargs
)

Expand Down
3 changes: 3 additions & 0 deletions pygwalker/api/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def walk(
use_kernel_calc: bool = False,
show_cloud_tool: bool = True,
kanaries_api_key: str = "",
default_tab: Literal["data", "vis"] = "vis",
**kwargs
):
"""Walk through pandas.DataFrame df with Graphic Walker
Expand All @@ -48,6 +49,7 @@ def walk(
- store_chart_data(bool): Whether to save chart to disk, only work when spec is json file, Default to False.
- use_kernel_calc(bool): Whether to use kernel compute for datas, Default to False.
- kanaries_api_key (str): kanaries api key, Default to "".
- default_tab (Literal["data", "vis"]): default tab to show. Default to "vis"
"""
if fieldSpecs is None:
fieldSpecs = {}
Expand All @@ -73,6 +75,7 @@ def walk(
gw_mode="explore",
is_export_dataframe=True,
kanaries_api_key=kanaries_api_key,
default_tab=default_tab,
**kwargs
)

Expand Down

0 comments on commit 3f5d3af

Please sign in to comment.