Skip to content

Transform react #2577

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 26 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bbe3533
remove no longer needed hack for finance in findArrayAttributes
alexcjohnson Apr 18, 2018
ed24765
_commonLength -> _length
alexcjohnson Apr 18, 2018
fcc459d
fix #2508, fix #2470 - problems with Plotly.react and aggregate trans…
alexcjohnson Apr 18, 2018
7044a13
standardize transforms handling of _length
alexcjohnson Apr 19, 2018
88b7b43
:racehorse: refactor sort transform from O(n^2) to O(n)
alexcjohnson Apr 19, 2018
cf4c9c3
heatmap&carpet/has_columns -> Lib.is1D
alexcjohnson Apr 20, 2018
e84d4b9
close #1410 - yes, stop pruning in nestedProperty
alexcjohnson Apr 20, 2018
b436d52
ensure every trace defines _length in supplyDefaults, and abort trans…
alexcjohnson Apr 22, 2018
2a41f9e
react+transforms PR review edits
alexcjohnson Apr 24, 2018
965bcfb
fixes and test for checklist in #2508
alexcjohnson Apr 24, 2018
6fae229
some fixes and tests for empty data arrays
alexcjohnson Apr 24, 2018
79295f1
rename violins mock that doesn't contain violin traces
alexcjohnson Apr 25, 2018
5e9aa65
transforms mock
alexcjohnson Apr 26, 2018
690eb95
clean up keyedContainer for possibly missing array
alexcjohnson Apr 26, 2018
a244cec
violin should not explicitly set whiskerwidth
alexcjohnson Apr 26, 2018
92bd5d2
add _length and stop slicing in scattercarpet
alexcjohnson Apr 26, 2018
dc6de2f
clean up handling of colorscale defaults
alexcjohnson Apr 26, 2018
03956e1
include count aggregates in _arrayAttrs - so they remap correctly
alexcjohnson Apr 26, 2018
f439e41
in diffData I had _fullInput in the new trace, but not the old!
alexcjohnson Apr 26, 2018
e47e6a9
_compareAsJSON for groupby styles
alexcjohnson Apr 26, 2018
aa30ad6
update plot_api_test to :lock: recent changes in react/transforms etc
alexcjohnson Apr 26, 2018
4c70826
lint
alexcjohnson Apr 26, 2018
7279b55
+shapes & annotations3d in react-noop test
alexcjohnson Apr 26, 2018
3e250df
tweak docs & remove commented-out code
alexcjohnson Apr 26, 2018
cd08479
reactWith -> reactTo
alexcjohnson Apr 26, 2018
0414147
separate svg and gl traces in react-noop tests
alexcjohnson Apr 26, 2018
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
7 changes: 2 additions & 5 deletions src/traces/histogram/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

var x = coerce('x');
var y = coerce('y');
var hasX = x && x.length;
var hasY = y && y.length;

var cumulative = coerce('cumulative.enabled');
if(cumulative) {
Expand All @@ -35,12 +33,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var orientation = coerce('orientation', (hasY && !hasX) ? 'h' : 'v');
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v');
var sampleLetter = orientation === 'v' ? 'x' : 'y';
var aggLetter = orientation === 'v' ? 'y' : 'x';
var sample = traceOut[sampleLetter];

var len = (hasX && hasY) ? Math.min(x.length && y.length) : (sample || []).length;
var len = (x && y) ? Math.min(x.length && y.length) : (traceOut[sampleLetter] || []).length;

if(!len) {
traceOut.visible = false;
Expand Down
9 changes: 7 additions & 2 deletions src/traces/pie/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
var len;

var vals = coerce('values');
var hasVals = Lib.isArrayOrTypedArray(vals) && vals.length;
var hasVals = Lib.isArrayOrTypedArray(vals);
var labels = coerce('labels');
if(Array.isArray(labels) && labels.length) {
if(Array.isArray(labels)) {
len = labels.length;
if(hasVals) len = Math.min(len, vals.length);
}
Expand All @@ -39,6 +39,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('label0');
coerce('dlabel');
}

if(!len) {
traceOut.visible = false;
return;
}
traceOut._length = len;

var lineWidth = coerce('marker.line.width');
Expand Down
17 changes: 17 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ describe('Bar.supplyDefaults', function() {
expect(traceOut.visible).toBe(false);
});

[{letter: 'y', counter: 'x'}, {letter: 'x', counter: 'y'}].forEach(function(spec) {
var l = spec.letter;
var c = spec.counter;
var c0 = c + '0';
var dc = 'd' + c;
it('should be visible using ' + c0 + '/' + dc + ' if ' + c + ' is missing completely but ' + l + ' is present', function() {
traceIn = {};
traceIn[l] = [1, 2];
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.visible).toBe(undefined, l); // visible: true gets set above the module level
expect(traceOut._length).toBe(2, l);
expect(traceOut[c0]).toBe(0, c0);
expect(traceOut[dc]).toBe(1, dc);
expect(traceOut.orientation).toBe(l === 'x' ? 'h' : 'v', l);
});
});

it('should not set base, offset or width', function() {
traceIn = {
y: [1, 2, 3]
Expand Down
13 changes: 12 additions & 1 deletion test/jasmine/tests/finance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('finance charts defaults:', function() {
expect(out._fullData[1]._fullInput.x).toBeDefined();
});

it('should set visible to *false* when minimum supplied length is 0', function() {
it('should set visible to *false* when a component (other than x) is missing', function() {
var trace0 = Lib.extendDeep({}, mock0, { type: 'ohlc' });
trace0.close = undefined;

Expand All @@ -160,6 +160,17 @@ describe('finance charts defaults:', function() {
expect(visibilities).toEqual([false, false]);
});

it('should return visible: false if any data component is empty', function() {
['ohlc', 'candlestick'].forEach(function(type) {
['open', 'high', 'low', 'close', 'x'].forEach(function(attr) {
var trace = Lib.extendDeep({}, mock1, {type: type});
trace[attr] = [];
var out = _supply([trace]);
expect(out._fullData[0].visible).toBe(false, type + ' - ' + attr);
});
});
});

it('direction *showlegend* should be inherited from trace-wide *showlegend*', function() {
var trace0 = Lib.extendDeep({}, mock0, {
type: 'ohlc',
Expand Down
25 changes: 24 additions & 1 deletion test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,30 @@ describe('Test histogram', function() {
traceIn = {
y: []
};
traceOut = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
});

it('should set visible to false when x or y is empty AND the other is present', function() {
traceIn = {
x: [],
y: [1, 2, 2]
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);

traceIn = {
x: [1, 2, 2],
y: []
};
traceOut = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
});

it('should set visible to false when type is histogram2d(contour) and x or y are empty', function() {
traceIn = {
type: 'histogram2d',
x: [],
y: [1, 2, 2]
};
Expand All @@ -51,20 +68,23 @@ describe('Test histogram', function() {
x: [1, 2, 2],
y: []
};
traceOut = {};
supplyDefaults2D(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);

traceIn = {
x: [],
y: []
};
traceOut = {};
supplyDefaults2D(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);

traceIn = {
x: [],
y: [1, 2, 2]
};
traceOut = {};
supplyDefaults2DC(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
});
Expand All @@ -80,6 +100,7 @@ describe('Test histogram', function() {
x: [1, 2, 2],
y: [1, 2, 2]
};
traceOut = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.orientation).toBe('v');
});
Expand Down Expand Up @@ -111,6 +132,7 @@ describe('Test histogram', function() {
traceIn = {
x: [1, 2, 2]
};
traceOut = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.autobinx).toBeUndefined();
});
Expand All @@ -130,6 +152,7 @@ describe('Test histogram', function() {
traceIn = {
y: [1, 2, 2]
};
traceOut = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.autobiny).toBeUndefined();
});
Expand Down
46 changes: 46 additions & 0 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,57 @@ var failTest = require('../assets/fail_test');
var click = require('../assets/click');
var getClientPosition = require('../assets/get_client_position');
var mouseEvent = require('../assets/mouse_event');
var supplyAllDefaults = require('../assets/supply_defaults');

var customAssertions = require('../assets/custom_assertions');
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;


describe('Pie defaults', function() {
function _supply(trace) {
var gd = {
data: [trace],
layout: {}
};

supplyAllDefaults(gd);

return gd._fullData[0];
}

it('finds the minimum length of labels & values', function() {
var out = _supply({type: 'pie', labels: ['A', 'B'], values: [1, 2, 3]});
expect(out._length).toBe(2);

out = _supply({type: 'pie', labels: ['A', 'B', 'C'], values: [1, 2]});
expect(out._length).toBe(2);
});

it('allows labels or values to be missing but not both', function() {
var out = _supply({type: 'pie', values: [1, 2]});
expect(out.visible).toBe(true);
expect(out._length).toBe(2);
expect(out.label0).toBe(0);
expect(out.dlabel).toBe(1);

out = _supply({type: 'pie', labels: ['A', 'B']});
expect(out.visible).toBe(true);
expect(out._length).toBe(2);

out = _supply({type: 'pie'});
expect(out.visible).toBe(false);
});

it('is marked invisible if either labels or values is empty', function() {
var out = _supply({type: 'pie', labels: [], values: [1, 2]});
expect(out.visible).toBe(false);

out = _supply({type: 'pie', labels: ['A', 'B'], values: []});
expect(out.visible).toBe(false);
});
});

describe('Pie traces:', function() {
'use strict';

Expand Down
16 changes: 16 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ describe('Test scatter', function() {
expect(traceOut.visible).toBe(false);
});

[{letter: 'y', counter: 'x'}, {letter: 'x', counter: 'y'}].forEach(function(spec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice test(s) here 😃

var l = spec.letter;
var c = spec.counter;
var c0 = c + '0';
var dc = 'd' + c;
it('should be visible using ' + c0 + '/' + dc + ' if ' + c + ' is missing completely but ' + l + ' is present', function() {
traceIn = {};
traceIn[spec.letter] = [1, 2];
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(undefined, l); // visible: true gets set above the module level
expect(traceOut._length).toBe(2, l);
expect(traceOut[c0]).toBe(0, c0);
expect(traceOut[dc]).toBe(1, dc);
});
});

it('should correctly assign \'hoveron\' default', function() {
traceIn = {
x: [1, 2, 3],
Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/scatterternary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ describe('scatterternary defaults', function() {
expect(traceOut._length).toBe(1);
});

it('is set visible: false if a, b, or c is empty', function() {
var trace0 = {
a: [1, 2],
b: [2, 1],
c: [2, 2]
};

['a', 'b', 'c'].forEach(function(letter) {
traceIn = Lib.extendDeep({}, trace0);
traceIn[letter] = [];
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false, letter);
});
});

it('should include \'name\' in \'hoverinfo\' default if multi trace graph', function() {
traceIn = {
type: 'scatterternary',
Expand Down