Skip to content

Commit

Permalink
update colorscale tests to provide a layout object to calcColorscale
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Nov 21, 2018
1 parent 0c13592 commit 93ce241
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 78 deletions.
4 changes: 4 additions & 0 deletions test/jasmine/assets/supply_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

var Plots = require('@src/plots/plots');

// The following is used to fill up the Registry module
/* eslint-ignore */
var Plotly = require('@lib');

/**
* supplyDefaults that fills in necessary _context
*/
Expand Down
103 changes: 25 additions & 78 deletions test/jasmine/tests/colorscale_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ var Plots = require('@src/plots/plots');
var Heatmap = require('@src/traces/heatmap');
var Scatter = require('@src/traces/scatter');

var supplyAllDefaults = require('../assets/supply_defaults');

function _supply(trace, layout) {
var gd = {
data: [trace],
layout: layout || {}
};

supplyAllDefaults(gd);

return gd;
}

describe('Test colorscale:', function() {
'use strict';
Expand Down Expand Up @@ -296,41 +308,6 @@ describe('Test colorscale:', function() {
handleDefaults(traceIn, traceOut, layout, coerce, opts);
expect(traceOut.showscale).toBe(false);
});

it('should use global colorscale.diverging if no colorscale is specified', function() {
traceIn = {
zmin: -10,
zmax: 10
};
var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
var layout2 = {
colorscale: {
diverging: divergingScale
},
_dfltTitle: {colorbar: 'cb'}
};
handleDefaults(traceIn, traceOut, layout2, coerce, opts);
expect(traceOut.colorscale).toBe(divergingScale);
});

it('should not use layout colorscale.diverging if colorscale is specified', function() {
var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']];
traceIn = {
zmin: -10,
zmax: 10,
colorscale: traceColorscale
};

var layout2 = {
colorscale: {
diverging: divergingScale
},
_dfltTitle: {colorbar: 'cb'}
};
handleDefaults(traceIn, traceOut, layout2, coerce, opts);
expect(traceOut.colorscale).toBe(traceColorscale);
});
});

describe('handleDefaults (scatter-like version)', function() {
Expand Down Expand Up @@ -384,61 +361,28 @@ describe('Test colorscale:', function() {
expect(traceOut.marker.showscale).toBe(true);
});

it('should use layout colorscale.diverging if no colorscale is specified', function() {
traceIn = {
zmin: -10,
zmax: 10
};
var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
var layout2 = {
colorscale: {
diverging: divergingScale
},
_dfltTitle: {colorbar: 'cb'}
};
handleDefaults(traceIn, traceOut, layout2, coerce, opts);
expect(traceOut.marker.colorscale).toBe(divergingScale);
});

it('should not use layout colorscale.diverging if colorscale is specified', function() {
var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']];
traceIn = {
marker: {
colorscale: traceColorscale
}
};

var layout2 = {
colorscale: {
diverging: divergingScale
},
_dfltTitle: {colorbar: 'cb'}
};
handleDefaults(traceIn, traceOut, layout2, coerce, opts);
expect(traceOut.marker.colorscale).toBe(traceColorscale);
});
});

describe('calc', function() {
var calcColorscale = Colorscale.calc;
var trace, z;
var gd;

beforeEach(function() {
trace = {};
z = {};
gd = {};
});

it('should be RdBuNeg when autocolorscale and z <= 0', function() {
trace = {
type: 'heatmap',
z: [[0, -1.5], [-2, -10]],
z: [[-0, -1.5], [-2, -10]],
autocolorscale: true,
_input: {autocolorscale: true}
};

z = [[0, -1.5], [-2, -10]];
calcColorscale(trace, z, '', 'z');
gd = _supply(trace);
calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
});
Expand All @@ -452,8 +396,8 @@ describe('Test colorscale:', function() {
autocolorscale: true,
_input: {}
};
z = [[0, -1.5], [-2, -10]];
calcColorscale(trace, z, '', 'z');
gd = _supply(trace);
calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(false);
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
});
Expand All @@ -466,7 +410,8 @@ describe('Test colorscale:', function() {
_input: {autocolorscale: true}
};
z = [[undefined, undefined], [-0.5, undefined]];
calcColorscale(trace, z, '', 'z');
gd = _supply(trace);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
});
Expand All @@ -479,7 +424,8 @@ describe('Test colorscale:', function() {
_input: {autocolorscale: true}
};
z = [[undefined, undefined], [0.5, undefined]];
calcColorscale(trace, z, '', 'z');
gd = _supply(trace);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale[0]).toEqual([0, 'rgb(220,220,220)']);
});
Expand All @@ -493,7 +439,8 @@ describe('Test colorscale:', function() {
_input: {autocolorscale: true}
};
z = [[undefined, undefined], [0.5, undefined]];
calcColorscale(trace, z, '', 'z');
gd = _supply(trace);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale[trace.colorscale.length - 1])
.toEqual([1, 'rgb(220,220,220)']);
Expand Down

0 comments on commit 93ce241

Please sign in to comment.