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

Fix issues with Perspective theme and persist config when switching plugins #6764

Merged
merged 3 commits into from
Apr 19, 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
2 changes: 1 addition & 1 deletion examples/reference/panes/Perspective.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"df_stream = pd.DataFrame(np.random.randn(400, 4), columns=list('ABCD')).cumsum()\n",
"\n",
"stream_perspective = pn.pane.Perspective(\n",
" df_stream, plugin='d3_y_line', columns=['A', 'B', 'C', 'D'], theme='material-dark',\n",
" df_stream, plugin='d3_y_line', columns=['A', 'B', 'C', 'D'], theme='pro-dark',\n",
" sizing_mode='stretch_width', height=500, margin=0\n",
")\n",
"\n",
Expand Down
18 changes: 17 additions & 1 deletion panel/models/perspective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class PerspectiveView extends HTMLBoxView {
_updating: boolean = false
_config_listener: any = null
_current_config: any = null
_current_plugin: string | null = null
_loaded: boolean = false
_plugin_configs: any = new Map()

override connect_signals(): void {
super.connect_signals()
Expand Down Expand Up @@ -126,7 +128,7 @@ export class PerspectiveView extends HTMLBoxView {
this.perspective_element.restore({sort: this.model.sort})
}))
this.on_change(plugin, not_updating(() => {
this.perspective_element.restore({plugin: PLUGINS[this.model.plugin]})
this.perspective_element.restore({plugin: PLUGINS[this.model.plugin], ...settings})
}))
this.on_change(selectable, not_updating(() => {
this.perspective_element.restore({plugin_config: {...this._current_config, selectable: this.model.selectable}})
Expand Down Expand Up @@ -165,6 +167,7 @@ export class PerspectiveView extends HTMLBoxView {
zIndex: 0,
},
})
this._current_plugin = this.model.plugin
container.innerHTML = "<perspective-viewer style='height:100%; width:100%;'></perspective-viewer>"
this.perspective_element = container.children[0]

Expand Down Expand Up @@ -220,7 +223,20 @@ export class PerspectiveView extends HTMLBoxView {
return true
}
this.perspective_element.save().then((config: any) => {
if (config.plugin !== this._current_plugin) {
this._plugin_configs.set(this._current_plugin, {
columns: this._current_config.columns,
columns_config: this._current_config.columns_config,
plugin_config: this._current_config.plugin_config,
})
if (this._plugin_configs.has(config.plugin)) {
const overrides = this._plugin_configs.get(config.plugin)
this.perspective_element.restore(overrides)
config = {...config, ...overrides}
}
}
this._current_config = config
this._current_plugin = config.plugin
const props: any = {}
for (let option in config) {
let value = config[option]
Expand Down
1 change: 1 addition & 0 deletions panel/pane/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def _get_properties(self, doc, source=None):

def _get_theme(self, theme, resources=None):
from ..models.perspective import THEME_URL
theme = theme.replace('material', 'pro')
theme_url = f'{THEME_URL}{theme}.css'
if self._bokeh_model is not None:
self._bokeh_model.__css_raw__ = self._bokeh_model.__css_raw__[:5] + [theme_url]
Expand Down
Loading