Skip to content

restyle/relayout refactor #1999

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

Merged
merged 43 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4d3e2ec
test - and fix - most of the relayout doextras
alexcjohnson Aug 18, 2017
95d7d71
test - and fix - most of the doextra calls in restyle
alexcjohnson Aug 29, 2017
3326ecc
test that xaxis-only items are only in the xaxis in the schema
alexcjohnson Aug 30, 2017
a948cce
merge component attribute schemas into core at register time
alexcjohnson Aug 30, 2017
dd52922
fix lib test for undefined -> null in undoqueue
alexcjohnson Sep 1, 2017
f90f079
abstract id/name counter regex and standardize cartesian attrRegex
alexcjohnson Sep 1, 2017
e036fea
fix #1325 - animating multiple axes
alexcjohnson Sep 1, 2017
69e0188
Plotschema getTraceValObject and getLayoutValObject methods
alexcjohnson Sep 1, 2017
bbfe399
relativeAttr
alexcjohnson Sep 12, 2017
29931ec
fix annotation comments/descriptions
alexcjohnson Sep 12, 2017
fad72a2
make common hover label pick up changes quicker
alexcjohnson Sep 13, 2017
e895b32
edit_types.overrideAll
alexcjohnson Sep 13, 2017
7a7dc6d
let PlotSchema.crawl report the complete attribute string
alexcjohnson Sep 13, 2017
c87b01a
better reporting from hover label test
alexcjohnson Sep 13, 2017
658e5cb
fix registry for new circular dep
alexcjohnson Sep 13, 2017
f49ae5e
massive commit to lock in editType and impliedEdits and clean up rest…
alexcjohnson Sep 13, 2017
7ea0d25
lint
alexcjohnson Sep 13, 2017
284c87f
remove obsolete comment in gl3d
alexcjohnson Sep 14, 2017
b9826c8
change overrideAll API to nested/from-root only
alexcjohnson Sep 14, 2017
7c38a4a
clean up restyle/relayout flag names
alexcjohnson Sep 14, 2017
96cc57f
clean up editTypes/impliedEdits and formalize & document their schema…
alexcjohnson Sep 14, 2017
cb94e95
test restrictions on component xaxis/yaxis schemas
alexcjohnson Sep 15, 2017
238e248
preserve impliedEdits: {key: undefined} by extendDeepAll
alexcjohnson Sep 15, 2017
42662ba
comments on relative_attr regexps
alexcjohnson Sep 15, 2017
50aa1ca
include schema in dist
alexcjohnson Sep 15, 2017
62a1392
fix plotschema test for metaKeys
alexcjohnson Sep 15, 2017
87b26d5
test order-independence of trace/transform/component registration
alexcjohnson Sep 18, 2017
040ed1b
test colorbar editing
alexcjohnson Sep 19, 2017
388a7fe
abstract - and fix - automatic axis type clearing
alexcjohnson Sep 19, 2017
6e8a68c
coerceTraceIndices earlier so clearAxisTypes can use it
alexcjohnson Sep 19, 2017
4f8fc66
move clearAxisTypes into helpers
alexcjohnson Sep 19, 2017
97ddf48
update jsdom to v11.2 with new API
alexcjohnson Sep 19, 2017
fe7db79
oops didn't mean to commit that commented out...
alexcjohnson Sep 19, 2017
68f5dbc
fix and test errorbar visibility toggling
alexcjohnson Sep 19, 2017
d15e541
layout.showlegend test
alexcjohnson Sep 19, 2017
7ec1634
closes #615 - something else in this PR fixed it, just nailing a test
alexcjohnson Sep 19, 2017
a107466
fix #358 - restyling orientation
alexcjohnson Sep 20, 2017
42805c2
test histogram changing data type
alexcjohnson Sep 20, 2017
8d9feaf
fix #2020 - editing plots with multiple histograms
alexcjohnson Sep 20, 2017
0a98a6d
lint
alexcjohnson Sep 20, 2017
e4227aa
move checkTicks into custom_assertions
alexcjohnson Sep 20, 2017
0729921
load custom_matchers globally, and refactor negateIf as a method
alexcjohnson Sep 20, 2017
407ae5a
pull custom_matchers out of requirejs bundle test
alexcjohnson Sep 20, 2017
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
5 changes: 4 additions & 1 deletion src/plot_api/edit_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ var isPlainObject = Lib.isPlainObject;
var traceOpts = {
valType: 'flaglist',
extras: ['none'],
flags: ['calc', 'calcIfAutorange', 'plot', 'style', 'colorbars'],
flags: ['calc', 'calcIfAutorange', 'clearAxisTypes', 'plot', 'style', 'colorbars'],
description: [
'trace attributes should include an `editType` string matching this flaglist.',
'*calc* is the most extensive: a full `Plotly.plot` starting by clearing `gd.calcdata`',
'to force it to be regenerated',
'*calcIfAutorange* does a full `Plotly.plot`, but only clears and redoes `gd.calcdata`',
'if there is at least one autoranged axis.',
'*clearAxisTypes* resets the types of the axes this trace is on, because new data could',
'cause the automatic axis type detection to change. Log type will not be cleared, as that',
'is never automatically chosen so must have been user-specified.',
'*plot* calls `Plotly.plot` but without first clearing `gd.calcdata`.',
'*style* only calls `module.style` for all trace modules and redraws the legend.',
'*colorbars* only redraws colorbars.'
Expand Down
48 changes: 35 additions & 13 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,9 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
var specs = _restyle(gd, aobj, traces),
flags = specs.flags;

// clear calcdata if required
// clear calcdata and/or axis types if required so they get regenerated
if(flags.clearCalc) gd.calcdata = undefined;
if(flags.clearAxisTypes) clearAxisTypes(gd, traces, {});

// fill in redraw sequence
var seq = [];
Expand Down Expand Up @@ -1340,12 +1341,6 @@ function _restyle(gd, aobj, _traces) {
axlist,
flagAxForDelete = {};

// these ones may alter the axis type
// (at least if the first trace is involved)
var axtypeAttrs = [
'type', 'x', 'y', 'x0', 'y0', 'orientation', 'xaxis', 'yaxis'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ya ⚾

];

// make a new empty vals array for undoit
function a0() { return traces.map(function() { return undefined; }); }

Expand Down Expand Up @@ -1557,11 +1552,6 @@ function _restyle(gd, aobj, _traces) {
}
}

// check if we need to call axis type
if((traces.indexOf(0) !== -1) && (axtypeAttrs.indexOf(ai) !== -1)) {
Plotly.Axes.clearTypes(gd, traces);
}

// major enough changes deserve autoscale, autobin, and
// non-reversed axes so people don't get confused
if(['orientation', 'type'].indexOf(ai) !== -1) {
Expand Down Expand Up @@ -2101,8 +2091,9 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
var relayoutSpecs = _relayout(gd, Lib.extendFlat({}, layoutUpdate)),
relayoutFlags = relayoutSpecs.flags;

// clear calcdata if required
// clear calcdata and/or axis types if required
if(restyleFlags.clearCalc || relayoutFlags.calc) gd.calcdata = undefined;
if(restyleFlags.clearAxisTypes) clearAxisTypes(gd, traces, layoutUpdate);

// fill in redraw sequence
var seq = [];
Expand Down Expand Up @@ -2157,6 +2148,37 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
});
};

// empty out types for all axes containing these traces
// so we auto-set them again
var axLetters = ['x', 'y', 'z'];
function clearAxisTypes(gd, traces, layoutUpdate) {
if(typeof traces === 'number') traces = [traces];
else if(!Array.isArray(traces) || !traces.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?

traces should be already sanatize helpers.coerceTraceIndices called here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I can move the helpers.coerceTraceIndices call into restyle and update instead of _restyle, then we can get rid of this.

traces = (gd._fullData).map(function(d, i) { return i; });
}
for(var i = 0; i < traces.length; i++) {
var trace = gd._fullData[i];
for(var j = 0; j < 3; j++) {
var ax = Plotly.Axes.getFromTrace(gd, trace, axLetters[j]);

// do not clear log type - that's never an auto result so must have been intentional
if(ax && ax.type !== 'log') {
var axAttr = ax._name;
var sceneName = ax._id.substr(1);
if(sceneName.substr(0, 5) === 'scene') {
if(layoutUpdate[sceneName] !== undefined) continue;
axAttr = sceneName + '.' + axAttr;
}
var typeAttr = axAttr + '.type';

if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
Lib.nestedProperty(gd.layout, typeAttr).set(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better than delete /* */ 👌

}
}
}
}
}

/**
* Animate to a frame, sequence of frame, frame group, or frame definition
*
Expand Down
2 changes: 1 addition & 1 deletion src/plots/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
role: 'info',
values: [], // listed dynamically
dflt: 'scatter',
editType: 'calc'
editType: 'calc+clearAxisTypes'
},
visible: {
valType: 'enumerated',
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
valType: 'subplotid',
role: 'info',
dflt: 'x',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets a reference between this trace\'s x coordinates and',
'a 2D cartesian x axis.',
Expand All @@ -27,7 +27,7 @@ module.exports = {
valType: 'subplotid',
role: 'info',
dflt: 'y',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets a reference between this trace\'s y coordinates and',
'a 2D cartesian y axis.',
Expand Down
13 changes: 0 additions & 13 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,6 @@ axes.getDataToCoordFunc = function(gd, trace, target, targetArray) {
return getDataConversions(gd, trace, target, targetArray).d2c;
};

// empty out types for all axes containing these traces
// so we auto-set them again
axes.clearTypes = function(gd, traces) {
if(!Array.isArray(traces) || !traces.length) {
traces = (gd._fullData).map(function(d, i) { return i; });
}
traces.forEach(function(tracenum) {
var trace = gd.data[tracenum];
delete (axes.getFromId(gd, trace.xaxis) || {}).type;
delete (axes.getFromId(gd, trace.yaxis) || {}).type;
});
};

// get counteraxis letter for this axis (name or id)
// this can also be used as the id for default counter axis
axes.counterLetter = function(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/gl3d/layout/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
valType: 'subplotid',
role: 'info',
dflt: 'scene',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets a reference between this trace\'s 3D coordinate system and',
'a 3D scene.',
Expand Down
2 changes: 1 addition & 1 deletion src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = {
valType: 'enumerated',
role: 'info',
values: ['v', 'h'],
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the orientation of the bars.',
'With *v* (*h*), the value of the each bar spans',
Expand Down
12 changes: 6 additions & 6 deletions src/traces/box/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ var scatterMarkerAttrs = scatterAttrs.marker,
module.exports = {
y: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the y sample data or coordinates.',
'See overview for more info.'
].join(' ')
},
x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the x sample data or coordinates.',
'See overview for more info.'
Expand All @@ -36,7 +36,7 @@ module.exports = {
x0: {
valType: 'any',
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the x coordinate of the box.',
'See overview for more info.'
Expand All @@ -45,7 +45,7 @@ module.exports = {
y0: {
valType: 'any',
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the y coordinate of the box.',
'See overview for more info.'
Expand All @@ -54,7 +54,7 @@ module.exports = {
name: {
valType: 'string',
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the trace name.',
'The trace name appear as the legend item and on hover.',
Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports = {
valType: 'enumerated',
values: ['v', 'h'],
role: 'style',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the orientation of the box(es).',
'If *v* (*h*), the distribution is visualized along',
Expand Down
4 changes: 2 additions & 2 deletions src/traces/carpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
},
x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'A two dimensional array of x coordinates at each carpet point.',
'If ommitted, the plot is a cheater plot and the xaxis is hidden',
Expand All @@ -43,7 +43,7 @@ module.exports = {
},
y: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: 'A two dimensional array of y coordinates at each carpet point.'
},
a: {
Expand Down
4 changes: 2 additions & 2 deletions src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = extendFlat({}, {
valType: 'enumerated',
values: ['array', 'scaled'],
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'If *array*, the heatmap\'s x coordinates are given by *x*',
'(the default behavior when `x` is provided).',
Expand All @@ -55,7 +55,7 @@ module.exports = extendFlat({}, {
valType: 'enumerated',
values: ['array', 'scaled'],
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'If *array*, the heatmap\'s y coordinates are given by *y*',
'(the default behavior when `y` is provided)',
Expand Down
4 changes: 2 additions & 2 deletions src/traces/histogram/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ var barAttrs = require('../bar/attributes');
module.exports = {
x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the sample data to be binned on the x axis.'
].join(' ')
},
y: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the sample data to be binned on the y axis.'
].join(' ')
Expand Down
6 changes: 3 additions & 3 deletions src/traces/mesh3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ var extendFlat = require('../../lib/extend').extendFlat;
module.exports = extendFlat(colorAttrs('', 'calc', false), {
x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the X coordinates of the vertices. The nth element of vectors `x`, `y` and `z`',
'jointly represent the X, Y and Z coordinates of the nth vertex.'
].join(' ')
},
y: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the Y coordinates of the vertices. The nth element of vectors `x`, `y` and `z`',
'jointly represent the X, Y and Z coordinates of the nth vertex.'
].join(' ')
},
z: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the Z coordinates of the vertices. The nth element of vectors `x`, `y` and `z`',
'jointly represent the X, Y and Z coordinates of the nth vertex.'
Expand Down
2 changes: 1 addition & 1 deletion src/traces/ohlc/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {

x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Sets the x coordinates.',
'If absent, linear coordinate will be generated.'
Expand Down
8 changes: 4 additions & 4 deletions src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ var extendFlat = require('../../lib/extend').extendFlat;
module.exports = {
x: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: 'Sets the x coordinates.'
},
x0: {
valType: 'any',
dflt: 0,
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Alternate to `x`.',
'Builds a linear space of x coordinates.',
Expand All @@ -48,14 +48,14 @@ module.exports = {
},
y: {
valType: 'data_array',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: 'Sets the y coordinates.'
},
y0: {
valType: 'any',
dflt: 0,
role: 'info',
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Alternate to `y`.',
'Builds a linear space of y coordinates.',
Expand Down
4 changes: 3 additions & 1 deletion src/traces/scatter3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function makeProjectionAttr(axLetter) {
};
}

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
x: scatterAttrs.x,
y: scatterAttrs.y,
z: {
Expand Down Expand Up @@ -172,3 +172,5 @@ module.exports = overrideAll({
error_y: errorBarAttrs,
error_z: errorBarAttrs,
}, 'calc', 'nested');

attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';
4 changes: 3 additions & 1 deletion src/traces/scattergl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var scatterLineAttrs = scatterAttrs.line,
scatterMarkerAttrs = scatterAttrs.marker,
scatterMarkerLineAttrs = scatterMarkerAttrs.line;

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
x: scatterAttrs.x,
x0: scatterAttrs.x0,
dx: scatterAttrs.dx,
Expand Down Expand Up @@ -86,3 +86,5 @@ module.exports = overrideAll({
error_y: scatterAttrs.error_y,
error_x: scatterAttrs.error_x
}, 'calc', 'nested');

attrs.x.editType = attrs.y.editType = attrs.x0.editType = attrs.y0.editType = 'calc+clearAxisTypes';
4 changes: 3 additions & 1 deletion src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function makeContourAttr(axLetter) {
};
}

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
z: {
valType: 'data_array',
description: 'Sets the z coordinates.'
Expand Down Expand Up @@ -244,3 +244,5 @@ module.exports = overrideAll({
})
}
}, 'calc', 'nested');

attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';
Loading