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

Plotly: Fixes for continuous viewport updates #575

Merged
merged 3 commits into from
Aug 6, 2019
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
9 changes: 8 additions & 1 deletion panel/io/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@
if (!window.PyViz) {{
return;
}}
var events = [];
var receiver = window.PyViz.receivers['{plot_id}'];
var events = receiver ? receiver._partial.content.events : [];
if (receiver &&
receiver._partial &&
receiver._partial.content &&
receiver._partial.content.events) {{
events = receiver._partial.content.events;
}}

for (var event of events) {{
if ((event.kind === 'ModelChanged') && (event.attr === '{change}') &&
(cb_obj.id === event.model.id) &&
Expand Down
2 changes: 1 addition & 1 deletion panel/models/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlotlyPlot(LayoutDOM):
clickannotation_data = Dict(String, Any)
selected_data = Dict(String, Any)
viewport = Dict(String, Any)
viewport_update_policy = Enum("continuous", "mouseup", "throttle")
viewport_update_policy = Enum( "mouseup", "continuous", "throttle")
viewport_update_throttle = Int()
_render_count = Int()

Expand Down
24 changes: 23 additions & 1 deletion panel/models/plotly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export class PlotlyPlotView extends HTMLBoxView {
_settingViewport: boolean = false
_plotInitialized: boolean = false
_reacting: boolean = false
_relayouting: boolean = false

_end_relayouting = _.debounce(() => {
this._relayouting = false
}, 2000, {leading: false})

connect_signals(): void {
super.connect_signals();
Expand All @@ -124,8 +129,22 @@ export class PlotlyPlotView extends HTMLBoxView {
data.push(this._get_trace(i, false));
}

let newLayout = _.cloneDeep(this.model.layout);

if (this._relayouting) {
const layout = (this.el as any).layout;

// For each xaxis* and yaxis* property of layout, if the value has a 'range'
// property then use this in newLayout
_.forOwn(layout, (value: any, key: string) => {
if (key.slice(1, 5) === "axis" && _.has(value, 'range')) {
newLayout[key].range = value.range;
}
});
}

this._reacting = true;
Plotly.react(this.el, data, _.cloneDeep(this.model.layout), this.model.config).then(() => {
Plotly.react(this.el, data, newLayout, this.model.config).then(() => {
this._updateSetViewportFunction();
this._updateViewportProperty();

Expand All @@ -139,12 +158,15 @@ export class PlotlyPlotView extends HTMLBoxView {
this.el, eventData, 'relayout');

this._updateViewportProperty();

this._end_relayouting();
}
});

// - plotly_relayouting
(<PlotlyHTMLElement>(this.el)).on('plotly_relayouting', () => {
if (this.model.viewport_update_policy !== 'mouseup') {
this._relayouting = true;
this._updateViewportProperty();
}
});
Expand Down