Skip to content

Commit ef6b1de

Browse files
committed
a some test material
1 parent 71d3151 commit ef6b1de

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed

src/plots/plots.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
13731373
var basePlotModules = layoutOut._basePlotModules;
13741374
var component, i, _module;
13751375

1376-
13771376
var Cartesian = Registry.subplotsRegistry.cartesian;
13781377

13791378
// check if any components need to add more base plot modules

src/traces/splom/defaults.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2222
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2323
}
2424

25-
var dimLen = handleDimensionsDefaults(traceIn, traceOut);
26-
if(!dimLen) {
25+
var dimLength = handleDimensionsDefaults(traceIn, traceOut);
26+
if(!dimLength) {
2727
traceOut.visible = false;
2828
return;
2929
}
@@ -79,7 +79,7 @@ function handleDimensionsDefaults(traceIn, traceOut) {
7979
if(!visible) continue;
8080

8181
var values = coerce('values');
82-
if(!values.length) {
82+
if(!values || values.length) {
8383
dimOut.visible = false;
8484
continue;
8585
}
@@ -101,20 +101,20 @@ function handleDimensionsDefaults(traceIn, traceOut) {
101101
}
102102

103103
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
104-
var dimLen = traceOut.dimensions.length;
105-
var xaxesDflt = new Array(dimLen);
106-
var yaxesDflt = new Array(dimLen);
104+
var dimLength = traceOut.dimensions.length;
105+
var xaxesDflt = new Array(dimLength);
106+
var yaxesDflt = new Array(dimLength);
107107
var i;
108108

109-
for(i = 0; i < dimLen; i++) {
109+
for(i = 0; i < dimLength; i++) {
110110
xaxesDflt[i] = 'x' + (i ? i + 1 : '');
111111
yaxesDflt[i] = 'y' + (i ? i + 1 : '');
112112
}
113113

114114
var xaxes = coerce('xaxes', xaxesDflt);
115115
var yaxes = coerce('yaxes', yaxesDflt);
116116

117-
// TODO what to do when xaxes.length or yaxes.length !== dimLen ???
117+
// TODO what to do when xaxes.length or yaxes.length !== dimLength ???
118118

119119
for(i = 0; i < xaxes.length; i++) {
120120
Lib.pushUnique(layout._splomXaxes, xaxes[i]);

test/image/baselines/splom_0.png

15.8 KB
Loading

test/image/mocks/splom_0.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"data": [{
3+
"type": "splom",
4+
"dimensions": [{
5+
"values": [1, 2, 1]
6+
}, {
7+
"values": [2, 5, 0]
8+
}]
9+
}]
10+
}

test/jasmine/tests/splom_test.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
var Lib = require('@src/lib');
2+
var supplyAllDefaults = require('../assets/supply_defaults');
3+
4+
describe('Test splom trace defaults:', function() {
5+
var gd;
6+
7+
function _supply(opts, layout) {
8+
gd = {};
9+
opts = Array.isArray(opts) ? opts : [opts];
10+
11+
gd.data = opts.map(function(o) {
12+
return Lib.extendFlat({type: 'splom'}, o || {});
13+
});
14+
gd.layout = layout || {};
15+
16+
supplyAllDefaults(gd);
17+
}
18+
19+
it('should set to `visible: false` dimensions-less traces', function() {
20+
_supply([{}, {dimensions: []}]);
21+
22+
expect(gd._fullData[0].visible).toBe(false);
23+
expect(gd._fullData[1].visible).toBe(false);
24+
});
25+
26+
it('should set to `visible: false` to values-less dimensions', function() {
27+
_supply({
28+
dimensions: [
29+
'not-an-object',
30+
{other: 'stuff'}
31+
]
32+
});
33+
34+
expect(gd._fullData[0].dimensions[0].visible).toBe(false);
35+
expect(gd._fullData[0].dimensions[1].visible).toBe(false);
36+
});
37+
38+
it('should set `grid.xaxes` and `grid.yaxes` default using the new of dimensions', function() {
39+
_supply({
40+
dimensions: [
41+
{values: [1, 2, 3]},
42+
{values: [2, 1, 2]}
43+
]
44+
});
45+
46+
var fullTrace = gd._fullData[0];
47+
expect(fullTrace.xaxes).toEqual(['x', 'x2']);
48+
expect(fullTrace.yaxes).toEqual(['y', 'y2']);
49+
50+
var fullLayout = gd._fullLayout;
51+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.47]);
52+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.53, 1]);
53+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.53, 1]);
54+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.47]);
55+
56+
var subplots = fullLayout._subplots;
57+
expect(subplots.xaxis).toEqual(['x', 'x2']);
58+
expect(subplots.yaxis).toEqual(['y', 'y2']);
59+
expect(subplots.cartesian).toEqual(['xy', 'xy2', 'x2y', 'x2y2']);
60+
});
61+
62+
it('should honor `grid.xaxes` and `grid.yaxes` settings', function() {
63+
_supply({
64+
dimensions: [
65+
{values: [1, 2, 3]},
66+
{values: [2, 1, 2]}
67+
]
68+
}, {
69+
grid: {domain: {x: [0, 0.5], y: [0, 0.5]}}
70+
});
71+
72+
var fullLayout = gd._fullLayout;
73+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.24]);
74+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.26, 0.5]);
75+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.26, 0.5]);
76+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.24]);
77+
});
78+
79+
it('should honor xaxis and yaxis settings', function() {
80+
_supply({
81+
dimensions: [
82+
{values: [1, 2, 3]},
83+
{values: [2, 1, 2]}
84+
]
85+
}, {
86+
xaxis: {domain: [0, 0.4]},
87+
yaxis2: {domain: [0, 0.3]}
88+
});
89+
90+
var fullLayout = gd._fullLayout;
91+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.4]);
92+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.53, 1]);
93+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.53, 1]);
94+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.3]);
95+
});
96+
97+
it('should set axis title default using dimensions *label*', function() {
98+
// TODO
99+
});
100+
});

0 commit comments

Comments
 (0)