Skip to content

Commit e99a5a6

Browse files
committed
add ternary defaults tests
1 parent f7d9c66 commit e99a5a6

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/jasmine/tests/ternary_test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var Plotly = require('@lib');
22
var Lib = require('@src/lib');
33
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
44

5+
var supplyLayoutDefaults = require('@src/plots/ternary/layout/defaults');
6+
57
var d3 = require('d3');
68
var createGraphDiv = require('../assets/create_graph_div');
79
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -221,3 +223,76 @@ describe('ternary plots', function() {
221223
expect(actual).toBeCloseToArray(expected);
222224
}
223225
});
226+
227+
describe('ternary defaults', function() {
228+
'use strict';
229+
230+
var layoutIn, layoutOut, fullData;
231+
232+
beforeEach(function() {
233+
// if hasTernary is not at this stage, the default step is skipped
234+
layoutOut = {
235+
_hasTernary: true,
236+
font: { color: 'red' }
237+
};
238+
239+
// needs a ternary-ref in a trace in order to be detected
240+
fullData = [{ type: 'scatterternary', subplot: 'ternary' }];
241+
});
242+
243+
it('should fill empty containers', function() {
244+
layoutIn = {};
245+
246+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
247+
expect(layoutIn).toEqual({ ternary: {} });
248+
expect(layoutOut.ternary.aaxis.type).toEqual('linear');
249+
expect(layoutOut.ternary.baxis.type).toEqual('linear');
250+
expect(layoutOut.ternary.caxis.type).toEqual('linear');
251+
});
252+
253+
it('should coerce \'min\' values to 0 and delete them for user data if they contradict', function() {
254+
layoutIn = {
255+
ternary: {
256+
aaxis: { min: 1 },
257+
baxis: { min: 1 },
258+
caxis: { min: 1 },
259+
sum: 2
260+
}
261+
};
262+
263+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
264+
expect(layoutOut.ternary.aaxis.min).toEqual(0);
265+
expect(layoutOut.ternary.baxis.min).toEqual(0);
266+
expect(layoutOut.ternary.caxis.min).toEqual(0);
267+
expect(layoutOut.ternary.sum).toEqual(2);
268+
expect(layoutIn.ternary.aaxis.min).toBeUndefined();
269+
expect(layoutIn.ternary.baxis.min).toBeUndefined();
270+
expect(layoutIn.ternary.caxis.min).toBeUndefined();
271+
});
272+
273+
it('should default \'title\' to Component + _name', function() {
274+
layoutIn = {};
275+
276+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
277+
expect(layoutOut.ternary.aaxis.title).toEqual('Component A');
278+
expect(layoutOut.ternary.baxis.title).toEqual('Component B');
279+
expect(layoutOut.ternary.caxis.title).toEqual('Component C');
280+
});
281+
282+
it('should default \'gricolor\' to 60% dark', function() {
283+
layoutIn = {
284+
ternary: {
285+
aaxis: { showgrid: true, color: 'red' },
286+
baxis: { showgrid: true },
287+
caxis: { gridcolor: 'black' },
288+
bgcolor: 'blue'
289+
},
290+
paper_bgcolor: 'green'
291+
};
292+
293+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
294+
expect(layoutOut.ternary.aaxis.gridcolor).toEqual('rgb(102, 0, 153)');
295+
expect(layoutOut.ternary.baxis.gridcolor).toEqual('rgb(27, 27, 180)');
296+
expect(layoutOut.ternary.caxis.gridcolor).toEqual('black');
297+
});
298+
});

0 commit comments

Comments
 (0)