-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Preserve ui state across Plotly.react redraws #3236
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
Changes from 6 commits
3a70fee
a86ca58
4ca328a
082ac38
b134a52
c62cf25
a11ec44
10ddbb9
4af2bf8
03baca7
6a9d0d7
a443747
54304b4
86b90d4
502082f
5182f6a
89dde84
778ec15
21f5db5
8f0f075
eb728fe
c95ae07
7ab8630
756308f
874a72a
090231b
5a27c00
2034941
6cfe7c5
8d11985
d9b3aea
0621e43
bdef7d3
2b77911
067bd7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ var isNumeric = require('fast-isnumeric'); | |
var hasHover = require('has-hover'); | ||
|
||
var Lib = require('../lib'); | ||
var nestedProperty = Lib.nestedProperty; | ||
|
||
var Events = require('../lib/events'); | ||
var Queue = require('../lib/queue'); | ||
|
||
|
@@ -842,7 +844,7 @@ function getExtendProperties(gd, update, indices, maxPoints) { | |
* instance that references the key and value for this particular trace. | ||
*/ | ||
trace = gd.data[indices[j]]; | ||
prop = Lib.nestedProperty(trace, key); | ||
prop = nestedProperty(trace, key); | ||
|
||
/* | ||
* Target is the existing gd.data.trace.dataArray value like "x" or "marker.size" | ||
|
@@ -1420,6 +1422,16 @@ function _restyle(gd, aobj, traces) { | |
|
||
function rangeAttr(axName) { return 'LAYOUT' + axName + '.range'; } | ||
|
||
function getFullTrace(traceIndex) { | ||
// usually fullData maps 1:1 onto data, but with groupby transforms | ||
// the fullData index can be greater. Take the *first* matching trace. | ||
for(var j = traceIndex; j < fullData.length; j++) { | ||
if(fullData[j]._input === data[traceIndex]) return fullData[j]; | ||
} | ||
// should never get here - and if we *do* it should cause an error | ||
// later on undefined fullTrace is passed to nestedProperty. | ||
} | ||
|
||
// for attrs that interact (like scales & autoscales), save the | ||
// old vals before making the change | ||
// val=undefined will not set a value, just record what the value was. | ||
|
@@ -1507,7 +1519,7 @@ function _restyle(gd, aobj, traces) { | |
undoit[ai] = a0(); | ||
for(i = 0; i < traces.length; i++) { | ||
cont = data[traces[i]]; | ||
contFull = fullData[traces[i]]; | ||
contFull = getFullTrace(traces[i]); | ||
param = Lib.nestedProperty(cont, ai); | ||
oldVal = param.get(); | ||
newVal = Array.isArray(vi) ? vi[i % vi.length] : vi; | ||
|
@@ -1518,7 +1530,7 @@ function _restyle(gd, aobj, traces) { | |
var prefix = ai.substr(0, ai.length - finalPart.length - 1); | ||
var prefixDot = prefix ? prefix + '.' : ''; | ||
var innerContFull = prefix ? | ||
Lib.nestedProperty(contFull, prefix).get() : contFull; | ||
nestedProperty(contFull, prefix).get() : contFull; | ||
|
||
valObject = PlotSchema.getTraceValObject(contFull, param.parts); | ||
|
||
|
@@ -1565,14 +1577,14 @@ function _restyle(gd, aobj, traces) { | |
Lib.swapAttrs(cont, ['?', '?src'], 'values', valuesTo); | ||
|
||
if(oldVal === 'pie') { | ||
Lib.nestedProperty(cont, 'marker.color') | ||
.set(Lib.nestedProperty(cont, 'marker.colors').get()); | ||
nestedProperty(cont, 'marker.color') | ||
.set(nestedProperty(cont, 'marker.colors').get()); | ||
|
||
// super kludgy - but if all pies are gone we won't remove them otherwise | ||
fullLayout._pielayer.selectAll('g.trace').remove(); | ||
} else if(Registry.traceIs(cont, 'cartesian')) { | ||
Lib.nestedProperty(cont, 'marker.colors') | ||
.set(Lib.nestedProperty(cont, 'marker.color').get()); | ||
nestedProperty(cont, 'marker.colors') | ||
.set(nestedProperty(cont, 'marker.color').get()); | ||
} | ||
} | ||
|
||
|
@@ -1643,7 +1655,7 @@ function _restyle(gd, aobj, traces) { | |
|
||
// swap hovermode if set to "compare x/y data" | ||
if(ai === 'orientationaxes') { | ||
var hovermode = Lib.nestedProperty(gd.layout, 'hovermode'); | ||
var hovermode = nestedProperty(gd.layout, 'hovermode'); | ||
if(hovermode.get() === 'x') { | ||
hovermode.set('y'); | ||
} else if(hovermode.get() === 'y') { | ||
|
@@ -1898,8 +1910,8 @@ function _relayout(gd, aobj) { | |
var pleafPlus = p.parts[pend - 1] + '.' + pleaf; | ||
// trunk nodes (everything except the leaf) | ||
var ptrunk = p.parts.slice(0, pend).join('.'); | ||
var parentIn = Lib.nestedProperty(gd.layout, ptrunk).get(); | ||
var parentFull = Lib.nestedProperty(fullLayout, ptrunk).get(); | ||
var parentIn = nestedProperty(gd.layout, ptrunk).get(); | ||
var parentFull = nestedProperty(fullLayout, ptrunk).get(); | ||
var vOld = p.get(); | ||
|
||
if(vi === undefined) continue; | ||
|
@@ -1944,20 +1956,20 @@ function _relayout(gd, aobj) { | |
// check autorange vs range | ||
else if(pleafPlus.match(AX_RANGE_RE)) { | ||
recordAlteredAxis(pleafPlus); | ||
Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
} | ||
else if(pleafPlus.match(AX_AUTORANGE_RE)) { | ||
recordAlteredAxis(pleafPlus); | ||
Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
var axFull = Lib.nestedProperty(fullLayout, ptrunk).get(); | ||
nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
var axFull = nestedProperty(fullLayout, ptrunk).get(); | ||
if(axFull._inputDomain) { | ||
// if we're autoranging and this axis has a constrained domain, | ||
// reset it so we don't get locked into a shrunken size | ||
axFull._input.domain = axFull._inputDomain.slice(); | ||
} | ||
} | ||
else if(pleafPlus.match(AX_DOMAIN_RE)) { | ||
Lib.nestedProperty(fullLayout, ptrunk + '._inputDomain').set(null); | ||
nestedProperty(fullLayout, ptrunk + '._inputDomain').set(null); | ||
} | ||
|
||
// toggling axis type between log and linear: we need to convert | ||
|
@@ -2026,10 +2038,10 @@ function _relayout(gd, aobj) { | |
doextra(ptrunk + '.autorange', true); | ||
doextra(ptrunk + '.range', null); | ||
} | ||
Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); | ||
} | ||
else if(pleaf.match(AX_NAME_PATTERN)) { | ||
var fullProp = Lib.nestedProperty(fullLayout, ai).get(), | ||
var fullProp = nestedProperty(fullLayout, ai).get(), | ||
newType = (vi || {}).type; | ||
|
||
// This can potentially cause strange behavior if the autotype is not | ||
|
@@ -2051,8 +2063,6 @@ function _relayout(gd, aobj) { | |
arrayStr = containerArrayMatch.array; | ||
i = containerArrayMatch.index; | ||
var propStr = containerArrayMatch.property; | ||
var componentArray = Lib.nestedProperty(layout, arrayStr); | ||
var obji = (componentArray || [])[i] || {}; | ||
var updateValObject = valObject || {editType: 'calc'}; | ||
|
||
if(i !== '' && propStr === '') { | ||
|
@@ -2062,7 +2072,7 @@ function _relayout(gd, aobj) { | |
if(manageArrays.isAddVal(vi)) { | ||
undoit[ai] = null; | ||
} else if(manageArrays.isRemoveVal(vi)) { | ||
undoit[ai] = obji; | ||
undoit[ai] = (nestedProperty(layout, arrayStr).get() || [])[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might not have anyone who cares about undo/redo anymore, but we have it so here's a fix. We were missing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmt0 @nicolaskruchten for the future perhaps ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a tentative plan to 🔪 undo/redo in v2 #420 (comment), with the rationale:
so unless we reverse that conclusion let's not build anything else using it. |
||
} else { | ||
Lib.warn('unrecognized full object value', aobj); | ||
} | ||
|
@@ -2106,7 +2116,7 @@ function _relayout(gd, aobj) { | |
// now we've collected component edits - execute them all together | ||
for(arrayStr in arrayEdits) { | ||
var finished = manageArrays.applyContainerArrayChanges(gd, | ||
Lib.nestedProperty(layout, arrayStr), arrayEdits[arrayStr], flags); | ||
nestedProperty(layout, arrayStr), arrayEdits[arrayStr], flags); | ||
if(!finished) flags.plot = true; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.