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

Preserve ui state across Plotly.react redraws #3236

Merged
merged 35 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3a70fee
make hover label test independent of selection order
alexcjohnson Nov 3, 2018
a86ca58
fix and :lock: bug with impliedEdits and groupby transform
alexcjohnson Oct 31, 2018
4ca328a
remove impliedEdits that got forgotten in #3044
alexcjohnson Oct 31, 2018
082ac38
alias `Lib.nestedProperty` separately in plot_api
alexcjohnson Oct 31, 2018
b134a52
fix obscure undo/redo bug with container array relayout removal
alexcjohnson Oct 31, 2018
c62cf25
clean up handleHover3d
alexcjohnson Nov 2, 2018
a11ec44
add _gui(Restyle|Relayout|Update) and _storeDirectGUIEdit and track c…
alexcjohnson Nov 2, 2018
10ddbb9
fix and :lock: problem with dragging colorbars in sub-containers
alexcjohnson Nov 6, 2018
4af2bf8
add and coerce uirevision attributes
alexcjohnson Nov 8, 2018
03baca7
use uirevisions in Plotly.react to preserve ui state
alexcjohnson Nov 9, 2018
6a9d0d7
add selectedpoints to uirevision framework
alexcjohnson Nov 9, 2018
a443747
break Plotly.react tests out of plot_api_test into plot_api_react_test
alexcjohnson Nov 9, 2018
54304b4
test uirevision + react logic
alexcjohnson Nov 9, 2018
86b90d4
remove `apply` arg from _storeDirectGUIEdit
alexcjohnson Nov 10, 2018
502082f
:palm_tree: uirevision tests
alexcjohnson Nov 10, 2018
5182f6a
fix and :lock: polar uirevisions
alexcjohnson Nov 10, 2018
89dde84
:lock: ternary uirevisions
alexcjohnson Nov 10, 2018
778ec15
fix and :lock: mapbox uirevisions
alexcjohnson Nov 10, 2018
21f5db5
fix and :lock: editable shapes & annotations uirevision
alexcjohnson Nov 11, 2018
8f0f075
:palm_tree: uirevision tests
alexcjohnson Nov 11, 2018
eb728fe
fix and :lock: editable: true uirevisions
alexcjohnson Nov 11, 2018
c95ae07
revert form of rangeslider relayout call (but it's still _guiRelayout)
alexcjohnson Nov 12, 2018
7ab8630
comment on uirevision<->uid in trace.uirevision attribute description
alexcjohnson Nov 12, 2018
756308f
record real initial axis (auto)range so we can update to autorange
alexcjohnson Nov 13, 2018
874a72a
remove now-obsolete comment about autorange/autofill
alexcjohnson Nov 13, 2018
090231b
fix and :lock: selectionrevision with groupby
alexcjohnson Nov 13, 2018
5a27c00
update trace.uirevision description with what it does/doesn't control
alexcjohnson Nov 13, 2018
2034941
partial preGUI fix for 3D camera
alexcjohnson Nov 19, 2018
6cfe7c5
Merge branch 'master' into ui-key
alexcjohnson Nov 29, 2018
8d11985
write camera.up back to layout only when necessary
alexcjohnson Nov 29, 2018
d9b3aea
Merge branch 'master' into ui-key
alexcjohnson Nov 29, 2018
0621e43
update uirevisions for new title attribute structure #3276
alexcjohnson Nov 30, 2018
bdef7d3
more permissive tickson rotation test for AJ's machine
alexcjohnson Nov 30, 2018
2b77911
looser acceptance for title centering, to work on AJ's machine
alexcjohnson Nov 30, 2018
067bd7d
biger tickwidth difference in tickson rotation test
alexcjohnson Nov 30, 2018
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
6 changes: 3 additions & 3 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
});
},
doneFn: function() {
Registry.call('relayout', gd, getUpdateObj());
Registry.call('_guiRelayout', gd, getUpdateObj());
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand Down Expand Up @@ -667,7 +667,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
},
doneFn: function() {
setCursor(annTextGroupInner);
Registry.call('relayout', gd, getUpdateObj());
Registry.call('_guiRelayout', gd, getUpdateObj());
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand All @@ -691,7 +691,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
modifyBase(ya._name + '.autorange', true);
}

Registry.call('relayout', gd, getUpdateObj());
Registry.call('_guiRelayout', gd, getUpdateObj());
});
}
else annText.call(textLayout);
Expand Down
26 changes: 14 additions & 12 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,10 @@ module.exports = function draw(gd, id) {
}

function drawTitle(titleClass, titleOpts) {
var trace = getTrace();
var propName = 'colorbar.title';
var containerName = trace._module.colorbar.container;
if(containerName) propName = containerName + '.' + propName;

var dfltTitleOpts = {
propContainer: cbAxisOut,
propName: propName,
traceIndex: trace.index,
propName: getPropName('title'),
traceIndex: getTrace().index,
placeholder: fullLayout._dfltTitle.colorbar,
containerGroup: container.select('.cbtitle')
};
Expand Down Expand Up @@ -627,11 +622,10 @@ module.exports = function draw(gd, id) {
setCursor(container);

if(xf !== undefined && yf !== undefined) {
Registry.call('restyle',
gd,
{'colorbar.x': xf, 'colorbar.y': yf},
getTrace().index
);
var update = {};
update[getPropName('x')] = xf;
update[getPropName('y')] = yf;
Registry.call('_guiRestyle', gd, update, getTrace().index);
}
}
});
Expand All @@ -649,6 +643,14 @@ module.exports = function draw(gd, id) {
}
}

function getPropName(suffix) {
var trace = getTrace();
var propName = 'colorbar.';
var containerName = trace._module.colorbar.container;
if(containerName) propName = containerName + '.' + propName;
return propName + suffix;
}

// setter/getters for every item defined in opts
Object.keys(opts).forEach(function(name) {
component[name] = function(v) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ module.exports = function draw(gd) {
},
doneFn: function() {
if(xf !== undefined && yf !== undefined) {
Registry.call('relayout', gd, {'legend.x': xf, 'legend.y': yf});
Registry.call('_guiRelayout', gd, {'legend.x': xf, 'legend.y': yf});
}
},
clickFn: function(numClicks, e) {
Expand Down Expand Up @@ -446,7 +446,7 @@ function drawTexts(g, gd, maxLength) {
update.name = newName;
}

return Registry.call('restyle', gd, update, traceIndex);
return Registry.call('_guiRestyle', gd, update, traceIndex);
});
} else {
textLayout(textEl);
Expand Down
4 changes: 2 additions & 2 deletions src/components/legend/handle_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Registry.call('relayout', gd, 'hiddenlabels', hiddenSlices);
Registry.call('_guiRelayout', gd, 'hiddenlabels', hiddenSlices);
} else {
var hasLegendgroup = legendgroup && legendgroup.length;
var traceIndicesInGroup = [];
Expand Down Expand Up @@ -217,6 +217,6 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Registry.call('restyle', gd, attrUpdate, attrIndices);
Registry.call('_guiRestyle', gd, attrUpdate, attrIndices);
}
};
76 changes: 35 additions & 41 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function handleCartesian(gd, ev) {
aobj[astr] = val;
}

Registry.call('relayout', gd, aobj);
Registry.call('_guiRelayout', gd, aobj);
}

modeBarButtons.zoom3d = {
Expand Down Expand Up @@ -317,7 +317,7 @@ function handleDrag3d(gd, ev) {
var val2d = (val === 'pan') ? val : 'zoom';
layoutUpdate.dragmode = val2d;

Registry.call('relayout', gd, layoutUpdate);
Registry.call('_guiRelayout', gd, layoutUpdate);
}

modeBarButtons.resetCameraDefault3d = {
Expand Down Expand Up @@ -356,7 +356,7 @@ function handleCamera3d(gd, ev) {
}
}

Registry.call('relayout', gd, aobj);
Registry.call('_guiRelayout', gd, aobj);
}

modeBarButtons.hoverClosest3d = {
Expand All @@ -370,54 +370,48 @@ modeBarButtons.hoverClosest3d = {
click: handleHover3d
};

function handleHover3d(gd, ev) {
function getNextHover3d(gd, ev) {
var button = ev.currentTarget;
var val = button._previousVal || false;
var layout = gd.layout;
var val = button._previousVal;
var fullLayout = gd._fullLayout;
var sceneIds = fullLayout._subplots.gl3d;

var axes = ['xaxis', 'yaxis', 'zaxis'];
var spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];

// initialize 'current spike' object to be stored in the DOM
var currentSpikes = {};
var axisSpikes = {};
var layoutUpdate = {};

if(val) {
layoutUpdate = Lib.extendDeep(layout, val);
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
layoutUpdate = val;
button._previousVal = null;
}
else {
layoutUpdate = {
'allaxes.showspikes': false
};

for(var i = 0; i < sceneIds.length; i++) {
var sceneId = sceneIds[i],
sceneLayout = fullLayout[sceneId],
sceneSpikes = currentSpikes[sceneId] = {};
var sceneId = sceneIds[i];
var sceneLayout = fullLayout[sceneId];

sceneSpikes.hovermode = sceneLayout.hovermode;
layoutUpdate[sceneId + '.hovermode'] = false;
var hovermodeAStr = sceneId + '.hovermode';
currentSpikes[hovermodeAStr] = sceneLayout.hovermode;
layoutUpdate[hovermodeAStr] = false;

// copy all the current spike attrs
for(var j = 0; j < 3; j++) {
var axis = axes[j];
axisSpikes = sceneSpikes[axis] = {};

for(var k = 0; k < spikeAttrs.length; k++) {
var spikeAttr = spikeAttrs[k];
axisSpikes[spikeAttr] = sceneLayout[axis][spikeAttr];
}
var spikeAStr = sceneId + '.' + axis + '.showspikes';
layoutUpdate[spikeAStr] = false;
currentSpikes[spikeAStr] = sceneLayout[axis].showspikes;
}
}

button._previousVal = Lib.extendDeep({}, currentSpikes);
button._previousVal = currentSpikes;
}
return layoutUpdate;
}

Registry.call('relayout', gd, layoutUpdate);
function handleHover3d(gd, ev) {
var layoutUpdate = getNextHover3d(gd, ev);
Registry.call('_guiRelayout', gd, layoutUpdate);
}

modeBarButtons.zoomInGeo = {
Expand Down Expand Up @@ -473,7 +467,7 @@ function handleGeo(gd, ev) {
var scale = geoLayout.projection.scale;
var newScale = (val === 'in') ? 2 * scale : 0.5 * scale;

Registry.call('relayout', gd, id + '.projection.scale', newScale);
Registry.call('_guiRelayout', gd, id + '.projection.scale', newScale);
} else if(attr === 'reset') {
resetView(gd, 'geo');
}
Expand Down Expand Up @@ -501,18 +495,20 @@ modeBarButtons.hoverClosestPie = {
click: toggleHover
};

function toggleHover(gd) {
function getNextHover(gd) {
var fullLayout = gd._fullLayout;

var onHoverVal;
if(fullLayout.hovermode) return false;

if(fullLayout._has('cartesian')) {
onHoverVal = fullLayout._isHoriz ? 'y' : 'x';
return fullLayout._isHoriz ? 'y' : 'x';
}
else onHoverVal = 'closest';

var newHover = gd._fullLayout.hovermode ? false : onHoverVal;
return 'closest';
}

Registry.call('relayout', gd, 'hovermode', newHover);
function toggleHover(gd) {
var newHover = getNextHover(gd);
Registry.call('_guiRelayout', gd, 'hovermode', newHover);
}

// buttons when more then one plot types are present
Expand All @@ -526,12 +522,10 @@ modeBarButtons.toggleHover = {
icon: Icons.tooltip_basic,
gravity: 'ne',
click: function(gd, ev) {
toggleHover(gd);
var layoutUpdate = getNextHover3d(gd, ev);
layoutUpdate.hovermode = getNextHover(gd);

// the 3d hovermode update must come
// last so that layout.hovermode update does not
// override scene?.hovermode?.layout.
handleHover3d(gd, ev);
Registry.call('_guiRelayout', gd, layoutUpdate);
}
};

Expand Down Expand Up @@ -567,7 +561,7 @@ modeBarButtons.toggleSpikelines = {

var aobj = setSpikelineVisibility(gd);

Registry.call('relayout', gd, aobj);
Registry.call('_guiRelayout', gd, aobj);
}
};

Expand Down Expand Up @@ -614,5 +608,5 @@ function resetView(gd, subplotType) {
}
}

Registry.call('relayout', gd, aObj);
Registry.call('_guiRelayout', gd, aObj);
}
2 changes: 1 addition & 1 deletion src/components/rangeselector/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = function draw(gd) {
button.on('click', function() {
if(gd._dragged) return;

Registry.call('relayout', gd, update);
Registry.call('_guiRelayout', gd, update);
});

button.on('mouseover', function() {
Expand Down
5 changes: 4 additions & 1 deletion src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
dataMax = clamp(opts.p2d(opts._pixelMax));

window.requestAnimationFrame(function() {
Registry.call('relayout', gd, axisOpts._name + '.range', [dataMin, dataMax]);
var update = {};
update[axisOpts._name + '.range[0]'] = dataMin;
update[axisOpts._name + '.range[1]'] = dataMax;
Registry.call('_guiRelayout', gd, update);
etpinard marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/shapes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) {

// Don't rely on clipPath being activated during re-layout
setClipPath(shapePath, gd, shapeOptions);
Registry.call('relayout', gd, editHelpers.getUpdateObj());
Registry.call('_guiRelayout', gd, editHelpers.getUpdateObj());
}

function abortDrag() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/titles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ function draw(gd, titleClass, options) {
el.call(svgTextUtils.makeEditable, {gd: gd})
.on('edit', function(text) {
if(traceIndex !== undefined) {
Registry.call('restyle', gd, prop, text, traceIndex);
Registry.call('_guiRestyle', gd, prop, text, traceIndex);
} else {
Registry.call('relayout', gd, prop, text);
Registry.call('_guiRelayout', gd, prop, text);
}
})
.on('cancel', function() {
Expand Down
3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var plotApi = require('./plot_api');
var methodNames = Object.keys(plotApi);
for(var i = 0; i < methodNames.length; i++) {
var name = methodNames[i];
exports[name] = plotApi[name];
// _ -> private API methods, but still registered for internal use
if(name.charAt(0) !== '_') exports[name] = plotApi[name];
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
register({
moduleType: 'apiMethod',
name: name,
Expand Down
4 changes: 4 additions & 0 deletions src/plot_api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ exports.restyle = main.restyle;
exports.relayout = main.relayout;
exports.redraw = main.redraw;
exports.update = main.update;
exports._guiRestyle = main._guiRestyle;
exports._guiRelayout = main._guiRelayout;
exports._guiUpdate = main._guiUpdate;
exports._storeDirectGUIEdit = main._storeDirectGUIEdit;
exports.react = main.react;
exports.extendTraces = main.extendTraces;
exports.prependTraces = main.prependTraces;
Expand Down
Loading