Skip to content

Commit

Permalink
add and coerce uirevision attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Nov 9, 2018
1 parent 10ddbb9 commit 4af2bf8
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,14 @@ module.exports = {
'or *bottom* of the legend.'
].join(' ')
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of legend-driven changes in trace and pie label',
'visibility. Defaults to `layout.uirevision`.'
].join(' ')
},
editType: 'legend'
};
6 changes: 5 additions & 1 deletion src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
basePlotLayoutAttributes, 'showlegend',
legendReallyHasATrace && legendTraceCount > 1);

if(showLegend === false) return;
if(showLegend === false && !containerIn.uirevision) return;

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

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

coerce('uirevision', layoutOut.uirevision);

if(showLegend === false) return;

coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
coerce('borderwidth');
Expand Down
12 changes: 12 additions & 0 deletions src/plots/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,17 @@ module.exports = {
'An array of operations that manipulate the trace data,',
'for example filtering or sorting the data arrays.'
].join(' ')
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes to the trace:',
'interactions like `selectedpoints` and type-specific ones such as',
'`constraintrange` in `parcoords` traces, as well as some',
'`editable: true` modifications such as `name` and `colorbar.title`.',
'Defaults to `layout.uirevision`.'
].join(' ')
}
};
10 changes: 10 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,16 @@ module.exports = {
'Used with `categoryorder`.'
].join(' ')
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis `range`,',
'`autorange`, and `title` if in `editable: true` configuration.',
'Defaults to `layout.uirevision`.'
].join(' ')
},
editType: 'calc',

_deprecated: {
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
};

coerce('uirevision', layoutOut.uirevision);

handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);

Expand Down
13 changes: 12 additions & 1 deletion src/plots/geo/layout/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var geoAxesAttrs = {
}
};

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
domain: domainAttrs({name: 'geo'}, {
description: [
'Note that geo subplots are constrained by domain.',
Expand Down Expand Up @@ -311,3 +311,14 @@ module.exports = overrideAll({
lonaxis: geoAxesAttrs,
lataxis: geoAxesAttrs
}, 'plot', 'from-root');

// set uirevision outside of overrideAll so it can be `editType: 'none'`
attrs.uirevision = {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in the view',
'(projection and center). Defaults to `layout.uirevision`.'
].join(' ')
};
9 changes: 9 additions & 0 deletions src/plots/gl3d/layout/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ module.exports = {
'Determines the mode of hover interactions for this scene.'
].join(' ')
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in camera attributes.',
'Defaults to `layout.uirevision`.'
].join(' ')
},
editType: 'plot',

_deprecated: {
Expand Down
42 changes: 42 additions & 0 deletions src/plots/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ module.exports = {
'different identity from its predecessor contains new data.'
].join(' ')
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Used to allow user interactions with the plot to persist after',
'`Plotly.react` calls that are unaware of these interactions.',
'If `uirevision` is omitted, or if it is given and it changed from',
'the previous `Plotly.react` call, the exact new figure is used.',
'If `uirevision` is truthy and did NOT change, any attribute',
'that has been affected by user interactions and did not receive a',
'different value in the new figure will keep the interaction value.',
'`layout.uirevision` attribute serves as the default for',
'`uirevision` attributes in various sub-containers. For finer',
'control you can set these sub-attributes directly. For example,',
'if your app separately controls the data on the x and y axes you',
'might set `xaxis.uirevision=*time*` and `yaxis.uirevision=*cost*`.',
'Then if only the y data is changed, you can update',
'`yaxis.uirevision=*quantity*` and the y axis range will reset but',
'the x axis range will retain any user-driven zoom.'
].join(' ')
},
editrevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in `editable: true`',
'configuration, other than trace names and axis titles.',
'Defaults to `layout.uirevision`.'
].join(' ')
},
template: {
valType: 'any',
role: 'info',
Expand Down Expand Up @@ -252,6 +284,16 @@ module.exports = {
editType: 'modebar',
description: 'Sets the color of the active or hovered on icons in the modebar.'
},
uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes related to the modebar,',
'including `hovermode`, `dragmode`, and `showspikes` at both the',
'root level and inside subplots. Defaults to `layout.uirevision`.'
].join(' ')
},
editType: 'modebar'
}
};
13 changes: 12 additions & 1 deletion src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var fontAttr = fontAttrs({
});
fontAttr.family.dflt = 'Open Sans Regular, Arial Unicode MS Regular';

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

domain: domainAttrs({name: 'mapbox'}),
Expand Down Expand Up @@ -245,3 +245,14 @@ module.exports = overrideAll({
}
})
}, 'plot', 'from-root');

// set uirevision outside of overrideAll so it can be `editType: 'none'`
attrs.uirevision = {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in the view:',
'`center`, `zoom`, `bearing`, `pitch`. Defaults to `layout.uirevision`.'
].join(' ')
};
5 changes: 5 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,8 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
coerce('type');
coerce('name', layout._traceWord + ' ' + traceInIndex);

coerce('uirevision', layout.uirevision);

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

coerce('datarevision');
var uirevision = coerce('uirevision');
coerce('editrevision', uirevision);

coerce('modebar.orientation');
coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
var modebarDefaultColor = Color.contrast(Color.rgb(layoutOut.modebar.bgcolor));
coerce('modebar.color', Color.addOpacity(modebarDefaultColor, 0.3));
coerce('modebar.activecolor', Color.addOpacity(modebarDefaultColor, 0.7));
coerce('modebar.uirevision', uirevision);

Registry.getComponentMethod(
'calendars',
Expand Down
32 changes: 32 additions & 0 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ var radialAxisAttrs = {

hoverformat: axesAttrs.hoverformat,

uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis `range`,',
'`autorange`, `angle`, and `title` if in `editable: true` configuration.',
'Defaults to `polar<N>.uirevision`.'
].join(' ')
},

editType: 'calc'
};

Expand Down Expand Up @@ -215,6 +226,16 @@ var angularAxisAttrs = {

hoverformat: axesAttrs.hoverformat,

uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis `rotation`.',
'Defaults to `polar<N>.uirevision`.'
].join(' ')
},

editType: 'calc'
};

Expand Down Expand Up @@ -294,5 +315,16 @@ module.exports = {
// TODO maybe?
// annotations:

uirevision: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis attributes,',
'if not overridden in the individual axes.',
'Defaults to `layout.uirevision`.'
].join(' ')
},

editType: 'calc'
};
2 changes: 2 additions & 0 deletions src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function handleDefaults(contIn, contOut, coerce, opts) {
var visible = coerceAxis('visible');
setConvert(axOut, contOut, layoutOut);

coerceAxis('uirevision', contOut.uirevision);

var dfltColor;
var dfltFontColor;

Expand Down
6 changes: 6 additions & 0 deletions src/plots/subplot_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ module.exports = function handleSubplotDefaults(layoutIn, layoutOut, fullData, o

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

// All subplot containers get a `uirevision` inheriting from the base.
// Currently all subplots containers have some user interaction
// attributes, but if we ever add one that doesn't, we would need an
// option to skip this step.
coerce('uirevision', layoutOut.uirevision);

var dfltDomains = {};
dfltDomains[partition] = [i / idsLength, (i + 1) / idsLength];
handleDomainDefaults(subplotLayoutOut, layoutOut, coerce, dfltDomains);
Expand Down
25 changes: 24 additions & 1 deletion src/plots/ternary/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var ternaryAxesAttrs = {
}
};

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
domain: domainAttrs({name: 'ternary'}),

bgcolor: {
Expand All @@ -89,3 +89,26 @@ module.exports = overrideAll({
baxis: ternaryAxesAttrs,
caxis: ternaryAxesAttrs
}, 'plot', 'from-root');

// set uirevisions outside of `overrideAll` so we can get `editType: none`
attrs.uirevision = {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis `min` and `title`,',
'if not overridden in the individual axes.',
'Defaults to `layout.uirevision`.'
].join(' ')
};

attrs.aaxis.uirevision = attrs.baxis.uirevision = attrs.caxis.uirevision = {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Controls persistence of user-driven changes in axis `min`,',
'and `title` if in `editable: true` configuration.',
'Defaults to `ternary<N>.uirevision`.'
].join(' ')
};
6 changes: 4 additions & 2 deletions src/plots/ternary/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, option
containerOut = Template.newContainer(ternaryLayoutOut, axName);
containerOut._name = axName;

handleAxisDefaults(containerIn, containerOut, options);
handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut);
}

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

function handleAxisDefaults(containerIn, containerOut, options) {
function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut) {
var axAttrs = layoutAttributes[containerOut._name];

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

coerce('uirevision', ternaryLayoutOut.uirevision);

containerOut.type = 'linear'; // no other types allowed for ternary

var dfltColor = coerce('color');
Expand Down

0 comments on commit 4af2bf8

Please sign in to comment.