Skip to content

Commit 2d205e7

Browse files
authored
Merge pull request #3423 from plotly/fix3419-rename-colorscale
Renaming old attributes should not replace existing current attributes if both provided
2 parents cabe0c6 + 168bb68 commit 2d205e7

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/plot_api/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ exports.cleanData = function(data) {
318318
}
319319

320320
// scl->scale, reversescl->reversescale
321-
if('scl' in trace) {
321+
if('scl' in trace && !('colorscale' in trace)) {
322322
trace.colorscale = trace.scl;
323323
delete trace.scl;
324324
}
325-
if('reversescl' in trace) {
325+
if('reversescl' in trace && !('reversescale' in trace)) {
326326
trace.reversescale = trace.reversescl;
327327
delete trace.reversescl;
328328
}

test/jasmine/tests/plot_api_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,52 @@ describe('Test plot api', function() {
22542254

22552255
afterEach(destroyGraphDiv);
22562256

2257+
it('should rename \'scl\' to \'colorscale\' when colorscale is not defined', function() {
2258+
var data = [{
2259+
type: 'heatmap',
2260+
scl: 'Blues'
2261+
}];
2262+
2263+
Plotly.plot(gd, data);
2264+
expect(gd.data[0].colorscale).toBe('Blues');
2265+
expect(gd.data[0].scl).toBe(undefined);
2266+
});
2267+
2268+
it('should not delete rename \'scl\' to \'colorscale\' when colorscale is defined ', function() {
2269+
var data = [{
2270+
type: 'heatmap',
2271+
colorscale: 'Greens',
2272+
scl: 'Reds'
2273+
}];
2274+
2275+
Plotly.plot(gd, data);
2276+
expect(gd.data[0].colorscale).toBe('Greens');
2277+
expect(gd.data[0].scl).not.toBe(undefined);
2278+
});
2279+
2280+
it('should rename \'reversescl\' to \'reversescale\' when colorscale is not defined', function() {
2281+
var data = [{
2282+
type: 'heatmap',
2283+
reversescl: true
2284+
}];
2285+
2286+
Plotly.plot(gd, data);
2287+
expect(gd.data[0].reversescale).toBe(true);
2288+
expect(gd.data[0].reversescl).toBe(undefined);
2289+
});
2290+
2291+
it('should not delete & rename \'reversescl\' to \'reversescale\' when colorscale is defined', function() {
2292+
var data = [{
2293+
type: 'heatmap',
2294+
reversescale: true,
2295+
reversescl: false
2296+
}];
2297+
2298+
Plotly.plot(gd, data);
2299+
expect(gd.data[0].reversescale).toBe(true);
2300+
expect(gd.data[0].reversescl).not.toBe(undefined);
2301+
});
2302+
22572303
it('should rename \'YIGnBu\' colorscales YlGnBu (2dMap case)', function() {
22582304
var data = [{
22592305
type: 'heatmap',

0 commit comments

Comments
 (0)