Skip to content

Commit 4af2bf8

Browse files
committed
add and coerce uirevision attributes
1 parent 10ddbb9 commit 4af2bf8

15 files changed

+186
-6
lines changed

src/components/legend/attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,14 @@ module.exports = {
120120
'or *bottom* of the legend.'
121121
].join(' ')
122122
},
123+
uirevision: {
124+
valType: 'any',
125+
role: 'info',
126+
editType: 'none',
127+
description: [
128+
'Controls persistence of legend-driven changes in trace and pie label',
129+
'visibility. Defaults to `layout.uirevision`.'
130+
].join(' ')
131+
},
123132
editType: 'legend'
124133
};

src/components/legend/defaults.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
6666
basePlotLayoutAttributes, 'showlegend',
6767
legendReallyHasATrace && legendTraceCount > 1);
6868

69-
if(showLegend === false) return;
69+
if(showLegend === false && !containerIn.uirevision) return;
7070

7171
var containerOut = Template.newContainer(layoutOut, 'legend');
7272

7373
function coerce(attr, dflt) {
7474
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
7575
}
7676

77+
coerce('uirevision', layoutOut.uirevision);
78+
79+
if(showLegend === false) return;
80+
7781
coerce('bgcolor', layoutOut.paper_bgcolor);
7882
coerce('bordercolor');
7983
coerce('borderwidth');

src/plots/attributes.js

+12
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,17 @@ module.exports = {
164164
'An array of operations that manipulate the trace data,',
165165
'for example filtering or sorting the data arrays.'
166166
].join(' ')
167+
},
168+
uirevision: {
169+
valType: 'any',
170+
role: 'info',
171+
editType: 'none',
172+
description: [
173+
'Controls persistence of user-driven changes to the trace:',
174+
'interactions like `selectedpoints` and type-specific ones such as',
175+
'`constraintrange` in `parcoords` traces, as well as some',
176+
'`editable: true` modifications such as `name` and `colorbar.title`.',
177+
'Defaults to `layout.uirevision`.'
178+
].join(' ')
167179
}
168180
};

src/plots/cartesian/layout_attributes.js

+10
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ module.exports = {
766766
'Used with `categoryorder`.'
767767
].join(' ')
768768
},
769+
uirevision: {
770+
valType: 'any',
771+
role: 'info',
772+
editType: 'none',
773+
description: [
774+
'Controls persistence of user-driven changes in axis `range`,',
775+
'`autorange`, and `title` if in `editable: true` configuration.',
776+
'Defaults to `layout.uirevision`.'
777+
].join(' ')
778+
},
769779
editType: 'calc',
770780

771781
_deprecated: {

src/plots/cartesian/layout_defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
176176
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
177177
};
178178

179+
coerce('uirevision', layoutOut.uirevision);
180+
179181
handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
180182
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
181183

src/plots/geo/layout/layout_attributes.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var geoAxesAttrs = {
6565
}
6666
};
6767

68-
module.exports = overrideAll({
68+
var attrs = module.exports = overrideAll({
6969
domain: domainAttrs({name: 'geo'}, {
7070
description: [
7171
'Note that geo subplots are constrained by domain.',
@@ -311,3 +311,14 @@ module.exports = overrideAll({
311311
lonaxis: geoAxesAttrs,
312312
lataxis: geoAxesAttrs
313313
}, 'plot', 'from-root');
314+
315+
// set uirevision outside of overrideAll so it can be `editType: 'none'`
316+
attrs.uirevision = {
317+
valType: 'any',
318+
role: 'info',
319+
editType: 'none',
320+
description: [
321+
'Controls persistence of user-driven changes in the view',
322+
'(projection and center). Defaults to `layout.uirevision`.'
323+
].join(' ')
324+
};

src/plots/gl3d/layout/layout_attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ module.exports = {
156156
'Determines the mode of hover interactions for this scene.'
157157
].join(' ')
158158
},
159+
uirevision: {
160+
valType: 'any',
161+
role: 'info',
162+
editType: 'none',
163+
description: [
164+
'Controls persistence of user-driven changes in camera attributes.',
165+
'Defaults to `layout.uirevision`.'
166+
].join(' ')
167+
},
159168
editType: 'plot',
160169

161170
_deprecated: {

src/plots/layout_attributes.js

+42
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ module.exports = {
202202
'different identity from its predecessor contains new data.'
203203
].join(' ')
204204
},
205+
uirevision: {
206+
valType: 'any',
207+
role: 'info',
208+
editType: 'none',
209+
description: [
210+
'Used to allow user interactions with the plot to persist after',
211+
'`Plotly.react` calls that are unaware of these interactions.',
212+
'If `uirevision` is omitted, or if it is given and it changed from',
213+
'the previous `Plotly.react` call, the exact new figure is used.',
214+
'If `uirevision` is truthy and did NOT change, any attribute',
215+
'that has been affected by user interactions and did not receive a',
216+
'different value in the new figure will keep the interaction value.',
217+
'`layout.uirevision` attribute serves as the default for',
218+
'`uirevision` attributes in various sub-containers. For finer',
219+
'control you can set these sub-attributes directly. For example,',
220+
'if your app separately controls the data on the x and y axes you',
221+
'might set `xaxis.uirevision=*time*` and `yaxis.uirevision=*cost*`.',
222+
'Then if only the y data is changed, you can update',
223+
'`yaxis.uirevision=*quantity*` and the y axis range will reset but',
224+
'the x axis range will retain any user-driven zoom.'
225+
].join(' ')
226+
},
227+
editrevision: {
228+
valType: 'any',
229+
role: 'info',
230+
editType: 'none',
231+
description: [
232+
'Controls persistence of user-driven changes in `editable: true`',
233+
'configuration, other than trace names and axis titles.',
234+
'Defaults to `layout.uirevision`.'
235+
].join(' ')
236+
},
205237
template: {
206238
valType: 'any',
207239
role: 'info',
@@ -252,6 +284,16 @@ module.exports = {
252284
editType: 'modebar',
253285
description: 'Sets the color of the active or hovered on icons in the modebar.'
254286
},
287+
uirevision: {
288+
valType: 'any',
289+
role: 'info',
290+
editType: 'none',
291+
description: [
292+
'Controls persistence of user-driven changes related to the modebar,',
293+
'including `hovermode`, `dragmode`, and `showspikes` at both the',
294+
'root level and inside subplots. Defaults to `layout.uirevision`.'
295+
].join(' ')
296+
},
255297
editType: 'modebar'
256298
}
257299
};

src/plots/mapbox/layout_attributes.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var fontAttr = fontAttrs({
2525
});
2626
fontAttr.family.dflt = 'Open Sans Regular, Arial Unicode MS Regular';
2727

28-
module.exports = overrideAll({
28+
var attrs = module.exports = overrideAll({
2929
_arrayAttrRegexps: [Lib.counterRegex('mapbox', '.layers', true)],
3030

3131
domain: domainAttrs({name: 'mapbox'}),
@@ -245,3 +245,14 @@ module.exports = overrideAll({
245245
}
246246
})
247247
}, 'plot', 'from-root');
248+
249+
// set uirevision outside of overrideAll so it can be `editType: 'none'`
250+
attrs.uirevision = {
251+
valType: 'any',
252+
role: 'info',
253+
editType: 'none',
254+
description: [
255+
'Controls persistence of user-driven changes in the view:',
256+
'`center`, `zoom`, `bearing`, `pitch`. Defaults to `layout.uirevision`.'
257+
].join(' ')
258+
};

src/plots/plots.js

+5
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
11401140
coerce('type');
11411141
coerce('name', layout._traceWord + ' ' + traceInIndex);
11421142

1143+
coerce('uirevision', layout.uirevision);
1144+
11431145
// we want even invisible traces to make their would-be subplots visible
11441146
// so coerce the subplot id(s) now no matter what
11451147
var _module = plots.getModule(traceOut);
@@ -1382,12 +1384,15 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
13821384
coerce('colorway');
13831385

13841386
coerce('datarevision');
1387+
var uirevision = coerce('uirevision');
1388+
coerce('editrevision', uirevision);
13851389

13861390
coerce('modebar.orientation');
13871391
coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
13881392
var modebarDefaultColor = Color.contrast(Color.rgb(layoutOut.modebar.bgcolor));
13891393
coerce('modebar.color', Color.addOpacity(modebarDefaultColor, 0.3));
13901394
coerce('modebar.activecolor', Color.addOpacity(modebarDefaultColor, 0.7));
1395+
coerce('modebar.uirevision', uirevision);
13911396

13921397
Registry.getComponentMethod(
13931398
'calendars',

src/plots/polar/layout_attributes.js

+32
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ var radialAxisAttrs = {
118118

119119
hoverformat: axesAttrs.hoverformat,
120120

121+
uirevision: {
122+
valType: 'any',
123+
role: 'info',
124+
editType: 'none',
125+
description: [
126+
'Controls persistence of user-driven changes in axis `range`,',
127+
'`autorange`, `angle`, and `title` if in `editable: true` configuration.',
128+
'Defaults to `polar<N>.uirevision`.'
129+
].join(' ')
130+
},
131+
121132
editType: 'calc'
122133
};
123134

@@ -215,6 +226,16 @@ var angularAxisAttrs = {
215226

216227
hoverformat: axesAttrs.hoverformat,
217228

229+
uirevision: {
230+
valType: 'any',
231+
role: 'info',
232+
editType: 'none',
233+
description: [
234+
'Controls persistence of user-driven changes in axis `rotation`.',
235+
'Defaults to `polar<N>.uirevision`.'
236+
].join(' ')
237+
},
238+
218239
editType: 'calc'
219240
};
220241

@@ -294,5 +315,16 @@ module.exports = {
294315
// TODO maybe?
295316
// annotations:
296317

318+
uirevision: {
319+
valType: 'any',
320+
role: 'info',
321+
editType: 'none',
322+
description: [
323+
'Controls persistence of user-driven changes in axis attributes,',
324+
'if not overridden in the individual axes.',
325+
'Defaults to `layout.uirevision`.'
326+
].join(' ')
327+
},
328+
297329
editType: 'calc'
298330
};

src/plots/polar/layout_defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function handleDefaults(contIn, contOut, coerce, opts) {
6666
var visible = coerceAxis('visible');
6767
setConvert(axOut, contOut, layoutOut);
6868

69+
coerceAxis('uirevision', contOut.uirevision);
70+
6971
var dfltColor;
7072
var dfltFontColor;
7173

src/plots/subplot_defaults.js

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ module.exports = function handleSubplotDefaults(layoutIn, layoutOut, fullData, o
6767

6868
subplotLayoutOut = Template.newContainer(layoutOut, id, baseId);
6969

70+
// All subplot containers get a `uirevision` inheriting from the base.
71+
// Currently all subplots containers have some user interaction
72+
// attributes, but if we ever add one that doesn't, we would need an
73+
// option to skip this step.
74+
coerce('uirevision', layoutOut.uirevision);
75+
7076
var dfltDomains = {};
7177
dfltDomains[partition] = [i / idsLength, (i + 1) / idsLength];
7278
handleDomainDefaults(subplotLayoutOut, layoutOut, coerce, dfltDomains);

src/plots/ternary/layout_attributes.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var ternaryAxesAttrs = {
6666
}
6767
};
6868

69-
module.exports = overrideAll({
69+
var attrs = module.exports = overrideAll({
7070
domain: domainAttrs({name: 'ternary'}),
7171

7272
bgcolor: {
@@ -89,3 +89,26 @@ module.exports = overrideAll({
8989
baxis: ternaryAxesAttrs,
9090
caxis: ternaryAxesAttrs
9191
}, 'plot', 'from-root');
92+
93+
// set uirevisions outside of `overrideAll` so we can get `editType: none`
94+
attrs.uirevision = {
95+
valType: 'any',
96+
role: 'info',
97+
editType: 'none',
98+
description: [
99+
'Controls persistence of user-driven changes in axis `min` and `title`,',
100+
'if not overridden in the individual axes.',
101+
'Defaults to `layout.uirevision`.'
102+
].join(' ')
103+
};
104+
105+
attrs.aaxis.uirevision = attrs.baxis.uirevision = attrs.caxis.uirevision = {
106+
valType: 'any',
107+
role: 'info',
108+
editType: 'none',
109+
description: [
110+
'Controls persistence of user-driven changes in axis `min`,',
111+
'and `title` if in `editable: true` configuration.',
112+
'Defaults to `ternary<N>.uirevision`.'
113+
].join(' ')
114+
};

src/plots/ternary/layout_defaults.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, option
4646
containerOut = Template.newContainer(ternaryLayoutOut, axName);
4747
containerOut._name = axName;
4848

49-
handleAxisDefaults(containerIn, containerOut, options);
49+
handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut);
5050
}
5151

5252
// if the min values contradict each other, set them all to default (0)
@@ -65,13 +65,15 @@ function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, option
6565
}
6666
}
6767

68-
function handleAxisDefaults(containerIn, containerOut, options) {
68+
function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut) {
6969
var axAttrs = layoutAttributes[containerOut._name];
7070

7171
function coerce(attr, dflt) {
7272
return Lib.coerce(containerIn, containerOut, axAttrs, attr, dflt);
7373
}
7474

75+
coerce('uirevision', ternaryLayoutOut.uirevision);
76+
7577
containerOut.type = 'linear'; // no other types allowed for ternary
7678

7779
var dfltColor = coerce('color');

0 commit comments

Comments
 (0)