Skip to content

Commit 7617945

Browse files
committed
Force initial plot width to be chosen based on notebook width.
This is a bit of a hack to work around the problem that plotly.js doesn't seem to be able to detect the width of the div itself until after the first `newPlot` command completes.
1 parent f5805b5 commit 7617945

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

js/src/Figure.js

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -762,34 +762,59 @@ var FigureView = widgets.DOMWidgetView.extend({
762762
var initialTraces = _.cloneDeep(this.model.get("_data"));
763763
var initialLayout = _.cloneDeep(this.model.get("_layout"));
764764

765-
Plotly.newPlot(this.el, initialTraces, initialLayout).then(
766-
function () {
767-
// ### Send trace deltas ###
768-
// We create an array of deltas corresponding to the new
769-
// traces.
770-
that._sendTraceDeltas(trace_edit_id);
771-
772-
// ### Send layout delta ###
773-
that._sendLayoutDelta(layout_edit_id);
774-
775-
// Wire up plotly event callbacks
776-
that.el.on("plotly_restyle",
777-
function(update) {that.handle_plotly_restyle(update)});
778-
that.el.on("plotly_relayout",
779-
function(update) {that.handle_plotly_relayout(update)});
780-
that.el.on("plotly_update",
781-
function(update) {that.handle_plotly_update(update)});
782-
that.el.on("plotly_click",
783-
function(update) {that.handle_plotly_click(update)});
784-
that.el.on("plotly_hover",
785-
function(update) {that.handle_plotly_hover(update)});
786-
that.el.on("plotly_unhover",
787-
function(update) {that.handle_plotly_unhover(update)});
788-
that.el.on("plotly_selected",
789-
function(update) {that.handle_plotly_selected(update)});
790-
that.el.on("plotly_doubleclick",
791-
function(update) {that.handle_plotly_doubleclick(update)});
765+
Plotly.newPlot(that.el, [], {
766+
'xaxis': {'showgrid': false, 'showticklabels': false, 'zeroline': false},
767+
'yaxis': {'showgrid': false, 'showticklabels': false, 'zeroline': false}
768+
}).then(function () {
769+
Plotly.Plots.resize(that.el).then(function () {
770+
Plotly.newPlot(that.el, initialTraces, initialLayout).then(
771+
function () {
772+
// Plotly.Plots.resize(that.el);
773+
774+
// ### Send trace deltas ###
775+
// We create an array of deltas corresponding to the new
776+
// traces.
777+
that._sendTraceDeltas(trace_edit_id);
778+
779+
// ### Send layout delta ###
780+
that._sendLayoutDelta(layout_edit_id);
781+
782+
// Wire up plotly event callbacks
783+
that.el.on("plotly_restyle",
784+
function (update) {
785+
that.handle_plotly_restyle(update)
786+
});
787+
that.el.on("plotly_relayout",
788+
function (update) {
789+
that.handle_plotly_relayout(update)
790+
});
791+
that.el.on("plotly_update",
792+
function (update) {
793+
that.handle_plotly_update(update)
794+
});
795+
that.el.on("plotly_click",
796+
function (update) {
797+
that.handle_plotly_click(update)
798+
});
799+
that.el.on("plotly_hover",
800+
function (update) {
801+
that.handle_plotly_hover(update)
802+
});
803+
that.el.on("plotly_unhover",
804+
function (update) {
805+
that.handle_plotly_unhover(update)
806+
});
807+
that.el.on("plotly_selected",
808+
function (update) {
809+
that.handle_plotly_selected(update)
810+
});
811+
that.el.on("plotly_doubleclick",
812+
function (update) {
813+
that.handle_plotly_doubleclick(update)
814+
});
815+
});
792816
});
817+
});
793818
},
794819
/**
795820
* Purge Plotly.js data structures from the notebook output display

0 commit comments

Comments
 (0)