Skip to content

Commit

Permalink
test layout.colorscale inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Nov 22, 2018
1 parent 84f0ea8 commit ee222d5
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions test/jasmine/tests/colorscale_test.js
Expand Up @@ -387,6 +387,25 @@ describe('Test colorscale:', function() {
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
});

it('should be layout.colorscale.sequentialminus when autocolorscale and z <= 0', function() {
var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
trace = {
type: 'heatmap',
z: [[-0, -1.5], [-2, -10]],
autocolorscale: true,
_input: {autocolorscale: true}
};
var layout = {
colorscale: {
sequentialminus: colorscale
}
};
gd = _supply(trace, layout);
calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale).toEqual(colorscale);
});

it('should set autocolorscale to false if it wasn\'t explicitly set true in input', function() {
trace = {
type: 'heatmap',
Expand Down Expand Up @@ -416,6 +435,26 @@ describe('Test colorscale:', function() {
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
});

it('should be layout.colorscale.sequentialminus when autocolorscale and the only numerical z <= -0.5', function() {
var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
trace = {
type: 'heatmap',
z: [['a', 'b'], [-0.5, 'd']],
autocolorscale: true,
_input: {autocolorscale: true}
};
z = [[undefined, undefined], [-0.5, undefined]];
var layout = {
colorscale: {
sequentialminus: colorscale
}
};
gd = _supply(trace, layout);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale).toEqual(colorscale);
});

it('should be Reds when the only numerical z >= 0.5', function() {
trace = {
type: 'heatmap',
Expand All @@ -430,6 +469,68 @@ describe('Test colorscale:', function() {
expect(trace.colorscale[0]).toEqual([0, 'rgb(220,220,220)']);
});

it('should be layout.colorscale.sequential when autocolorscale and the only numerical z >= 0.5', function() {
var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
trace = {
type: 'heatmap',
z: [['a', 'b'], [0.5, 'd']],
autocolorscale: true,
_input: {autocolorscale: true}
};
z = [[undefined, undefined], [0.5, undefined]];
var layout = {
colorscale: {
sequential: colorscale
}
};
gd = _supply(trace, layout);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale).toEqual(colorscale);
});

it('should be layout.colorscale.diverging when autocolorscale and there are positive and negative values', function() {
var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
trace = {
type: 'heatmap',
z: [[-1.0, 'b'], [0.5, 'd']],
autocolorscale: true,
_input: {autocolorscale: true}
};
z = [[-1.0, undefined], [0.5, undefined]];
var layout = {
colorscale: {
diverging: colorscale
}
};
gd = _supply(trace, layout);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale).toEqual(colorscale);
});

it('should ignore layout.colorscale.diverging when colorscale is defined at trace-level', function() {
var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
var layoutColorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']];
trace = {
type: 'heatmap',
z: [[-1.0, 'b'], [0.5, 'd']],
autocolorscale: true,
_input: {autocolorscale: true},
colorscale: colorscale
};
z = [[-1.0, undefined], [0.5, undefined]];
var layout = {
colorscale: {
diverging: layoutColorscale
}
};
gd = _supply(trace, layout);
calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'});
expect(trace.autocolorscale).toBe(true);
expect(trace.colorscale).toEqual(colorscale);
});

it('should be reverse the auto scale when reversescale is true', function() {
trace = {
type: 'heatmap',
Expand Down

0 comments on commit ee222d5

Please sign in to comment.