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
9 changes: 8 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,13 @@ function _restyle(gd, aobj, traces) {
// before we swap everything else
if(ai === 'orientation') {
param.set(newVal);
if(param.get() === undoit[ai][i]) continue;
// obnoxious that we need this level of coupling... but in order to
// properly handle setting orientation to `null` we need to mimic
// the logic inside Bars.supplyDefaults for default orientation
var defaultOrientation = (cont.x && !cont.y) ? 'h' : 'v';
if((param.get() || defaultOrientation) === contFull.orientation) {
continue;
}
}
// orientationaxes has no value,
// it flips everything and the axes
Expand All @@ -1508,6 +1514,7 @@ function _restyle(gd, aobj, traces) {
{v: 'h', h: 'v'}[contFull.orientation];
}
helpers.swapXYData(cont);
flags.calc = flags.clearAxisTypes = true;
}
else if(Plots.dataArrayContainers.indexOf(param.parts[0]) !== -1) {
// TODO: use manageArrays.applyContainerArrayChanges here too
Expand Down
11 changes: 11 additions & 0 deletions test/jasmine/assets/check_ticks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var d3 = require('d3');

module.exports = function checkTicks(axLetter, vals, msg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been trying to centralized common custom assertions like this one in:

https://github.com/plotly/plotly.js/blob/master/test/jasmine/assets/custom_assertions.js

I'll let decide whether separate files or a common module is better for stuff like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh that's nice - yeah, I'll put checkTicks in there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

var selection = d3.selectAll('.' + axLetter + 'tick text');
expect(selection.size()).toBe(vals.length);
selection.each(function(d, i) {
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
});
};
16 changes: 16 additions & 0 deletions test/jasmine/assets/negate_if.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/**
* Conditionally negate an expectation:
*
* negateIf(expect(x), xIsSomethingElse).toBe(0);
*
* is equivalent to:
*
* if(xIsSomethingElse) expect(x).not.toBe(0);
* else expect(x).toBe(0);
*/
module.exports = function negateIf(expectation, negate) {
Copy link
Contributor

@etpinard etpinard Sep 20, 2017

Choose a reason for hiding this comment

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

Non-blocking but I wonder if there's a way to rewrite this as a custom jasmine matcher. So that we have something like:

expect(x).negateIf(negate).toBe(0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

expect(x).negateIf(negate).toBe(0) would definitely be more readable - I'll give it a shot.

if(negate) return expectation.not;
return expectation;
};
192 changes: 130 additions & 62 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var customMatchers = require('../assets/custom_matchers');
var checkTicks = require('../assets/check_ticks');
var negateIf = require('../assets/negate_if');

var d3 = require('d3');

describe('Bar.supplyDefaults', function() {
'use strict';
Expand Down Expand Up @@ -762,10 +766,16 @@ describe('Bar.setPositions', function() {
describe('A bar plot', function() {
'use strict';

var gd;

beforeAll(function() {
jasmine.addMatchers(customMatchers);
});

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function getAllTraceNodes(node) {
Expand Down Expand Up @@ -830,15 +840,13 @@ describe('A bar plot', function() {
}

it('should show bar texts (inside case)', function(done) {
var gd = createGraphDiv(),
data = [{
y: [10, 20, 30],
type: 'bar',
text: ['1', 'Very very very very very long bar text'],
textposition: 'inside',
}],
layout = {
};
var data = [{
y: [10, 20, 30],
type: 'bar',
text: ['1', 'Very very very very very long bar text'],
textposition: 'inside',
}];
var layout = {};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
Expand All @@ -862,16 +870,15 @@ describe('A bar plot', function() {
});

it('should show bar texts (outside case)', function(done) {
var gd = createGraphDiv(),
data = [{
y: [10, -20, 30],
type: 'bar',
text: ['1', 'Very very very very very long bar text'],
textposition: 'outside',
}],
layout = {
barmode: 'relative'
};
var data = [{
y: [10, -20, 30],
type: 'bar',
text: ['1', 'Very very very very very long bar text'],
textposition: 'outside',
}];
var layout = {
barmode: 'relative'
};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
Expand All @@ -896,15 +903,13 @@ describe('A bar plot', function() {
});

it('should show bar texts (horizontal case)', function(done) {
var gd = createGraphDiv(),
data = [{
x: [10, -20, 30],
type: 'bar',
text: ['Very very very very very long bar text', -20],
textposition: 'outside',
}],
layout = {
};
var data = [{
x: [10, -20, 30],
type: 'bar',
text: ['Very very very very very long bar text', -20],
textposition: 'outside',
}];
var layout = {};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
Expand All @@ -929,17 +934,16 @@ describe('A bar plot', function() {
});

it('should show bar texts (barnorm case)', function(done) {
var gd = createGraphDiv(),
data = [{
x: [100, -100, 100],
type: 'bar',
text: [100, -100, 100],
textposition: 'outside',
}],
layout = {
barmode: 'relative',
barnorm: 'percent'
};
var data = [{
x: [100, -100, 100],
type: 'bar',
text: [100, -100, 100],
textposition: 'outside',
}];
var layout = {
barmode: 'relative',
barnorm: 'percent'
};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
Expand All @@ -964,8 +968,7 @@ describe('A bar plot', function() {
});

it('should be able to restyle', function(done) {
var gd = createGraphDiv(),
mock = Lib.extendDeep({}, require('@mocks/bar_attrs_relative'));
var mock = Lib.extendDeep({}, require('@mocks/bar_attrs_relative'));

Plotly.plot(gd, mock.data, mock.layout).then(function() {
var cd = gd.calcdata;
Expand Down Expand Up @@ -1114,27 +1117,26 @@ describe('A bar plot', function() {
});

it('should coerce text-related attributes', function(done) {
var gd = createGraphDiv(),
data = [{
y: [10, 20, 30, 40],
type: 'bar',
text: ['T1P1', 'T1P2', 13, 14],
textposition: ['inside', 'outside', 'auto', 'BADVALUE'],
textfont: {
family: ['"comic sans"'],
color: ['red', 'green'],
},
insidetextfont: {
size: [8, 12, 16],
color: ['black'],
},
outsidetextfont: {
size: [null, 24, 32]
}
}],
layout = {
font: {family: 'arial', color: 'blue', size: 13}
};
var data = [{
y: [10, 20, 30, 40],
type: 'bar',
text: ['T1P1', 'T1P2', 13, 14],
textposition: ['inside', 'outside', 'auto', 'BADVALUE'],
textfont: {
family: ['"comic sans"'],
color: ['red', 'green'],
},
insidetextfont: {
size: [8, 12, 16],
color: ['black'],
},
outsidetextfont: {
size: [null, 24, 32]
}
}];
var layout = {
font: {family: 'arial', color: 'blue', size: 13}
};

var expected = {
y: [10, 20, 30, 40],
Expand Down Expand Up @@ -1194,6 +1196,72 @@ describe('A bar plot', function() {
.catch(fail)
.then(done);
});

it('can change orientation and correctly sets axis types', function(done) {
function checkBarsMatch(dims, msg) {
var bars = d3.selectAll('.bars .point');
var bbox1 = bars.node().getBoundingClientRect();
bars.each(function(d, i) {
if(!i) return;
var bbox = this.getBoundingClientRect();
['left', 'right', 'top', 'bottom', 'width', 'height'].forEach(function(dim) {
negateIf(expect(bbox[dim]), dims.indexOf(dim) === -1)
.toBeWithin(bbox1[dim], 0.1, msg + ' (' + i + '): ' + dim);
});
});
}

Plotly.newPlot(gd, [{
x: ['a', 'b', 'c'],
y: [1, 2, 3],
type: 'bar'
}], {
width: 400, height: 400
})
.then(function() {
checkTicks('x', ['a', 'b', 'c'], 'initial x');
checkTicks('y', ['0', '0.5', '1', '1.5', '2', '2.5', '3'], 'initial y');

checkBarsMatch(['bottom', 'width'], 'initial');

// turn implicit "v" into explicit "v" - a noop but specifically
// for orientation this was broken at one point...
return Plotly.restyle(gd, {orientation: 'v'});
})
.then(function() {
checkTicks('x', ['a', 'b', 'c'], 'explicit v x');
checkTicks('y', ['0', '0.5', '1', '1.5', '2', '2.5', '3'], 'explicit v y');

checkBarsMatch(['bottom', 'width'], 'explicit v');

// back to implicit v
return Plotly.restyle(gd, {orientation: null});
})
.then(function() {
checkTicks('x', ['a', 'b', 'c'], 'implicit v x');
checkTicks('y', ['0', '0.5', '1', '1.5', '2', '2.5', '3'], 'implicit v y');

checkBarsMatch(['bottom', 'width'], 'implicit v');

return Plotly.restyle(gd, {orientation: 'h'});
})
.then(function() {
checkTicks('x', ['0', '1', '2', '3'], 'h x');
checkTicks('y', ['a', 'b', 'c'], 'h y');

checkBarsMatch(['left', 'height'], 'initial');

return Plotly.restyle(gd, {orientation: 'v'});
})
.then(function() {
checkTicks('x', ['a', 'b', 'c'], 'final x');
checkTicks('y', ['0', '0.5', '1', '1.5', '2', '2.5', '3'], 'final y');

checkBarsMatch(['bottom', 'width'], 'final');
})
.catch(fail)
.then(done);
});
});

describe('bar hover', function() {
Expand Down
9 changes: 1 addition & 8 deletions test/jasmine/tests/contour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var fail = require('../assets/fail_test');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var customMatchers = require('../assets/custom_matchers');
var checkTicks = require('../assets/check_ticks');

var d3 = require('d3');

Expand Down Expand Up @@ -359,14 +360,6 @@ describe('contour edits', function() {
});
afterEach(destroyGraphDiv);

function checkTicks(axLetter, vals, msg) {
var selection = d3.selectAll('.' + axLetter + 'tick text');
expect(selection.size()).toBe(vals.length);
selection.each(function(d, i) {
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
});
}

it('can restyle x/y to different types', function(done) {
Plotly.newPlot(gd, [{
type: 'contour',
Expand Down
21 changes: 5 additions & 16 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var customMatchers = require('../assets/custom_matchers');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var checkTicks = require('../assets/check_ticks');
var negateIf = require('../assets/negate_if');


describe('Test plot api', function() {
Expand Down Expand Up @@ -907,11 +909,6 @@ describe('Test plot api', function() {
.then(done);
});

function negateIf(condition, negate) {
if(negate) return condition.not;
return condition;
}

it('turns off zauto when you edit zmin or zmax', function(done) {
var zmin0 = 2;
var zmax1 = 10;
Expand Down Expand Up @@ -1184,31 +1181,23 @@ describe('Test plot api', function() {
});

it('updates box position and axis type when it falls back to name', function(done) {
function checkXTicks(vals, msg) {
var selection = d3.selectAll('.xtick');
expect(selection.size()).toBe(vals.length);
selection.each(function(d, i) {
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
});
}

Plotly.newPlot(gd, [{name: 'A', y: [1, 2, 3, 4, 5], type: 'box'}],
{width: 400, height: 400, xaxis: {nticks: 3}}
)
.then(function() {
checkXTicks(['A'], 'initial');
checkTicks('x', ['A'], 'initial');
expect(gd._fullLayout.xaxis.type).toBe('category');

return Plotly.restyle(gd, {name: 'B'});
})
.then(function() {
checkXTicks(['B'], 'changed category');
checkTicks('x', ['B'], 'changed category');
expect(gd._fullLayout.xaxis.type).toBe('category');

return Plotly.restyle(gd, {x0: 12.3});
})
.then(function() {
checkXTicks(['12', '12.5'], 'switched to numeric');
checkTicks('x', ['12', '12.5'], 'switched to numeric');
expect(gd._fullLayout.xaxis.type).toBe('linear');
})
.catch(fail)
Expand Down