Skip to content

Commit b2e1786

Browse files
committed
rename colorscales YIGnBu -> YlGnBu and YIOrRd -> YlOrRd :
- add backward compatible clean data step - add cleanData tests
1 parent de10c1b commit b2e1786

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/components/colorscale/scales.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']
1515
],
1616

17-
'YIGnBu': [
17+
'YlGnBu': [
1818
[0, 'rgb(8, 29, 88)'], [0.125, 'rgb(37, 52, 148)'],
1919
[0.25, 'rgb(34, 94, 168)'], [0.375, 'rgb(29, 145, 192)'],
2020
[0.5, 'rgb(65, 182, 196)'], [0.625, 'rgb(127, 205, 187)'],
@@ -30,7 +30,7 @@ module.exports = {
3030
[1, 'rgb(247, 252, 245)']
3131
],
3232

33-
'YIOrRd': [
33+
'YlOrRd': [
3434
[0, 'rgb(128, 0, 38)'], [0.125, 'rgb(189, 0, 38)'],
3535
[0.25, 'rgb(227, 26, 28)'], [0.375, 'rgb(252, 78, 42)'],
3636
[0.5, 'rgb(253, 141, 60)'], [0.625, 'rgb(254, 178, 76)'],

src/plot_api/plot_api.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ function cleanData(data, existingData) {
670670

671671
for(var tracei = 0; tracei < data.length; tracei++) {
672672
var trace = data[tracei];
673+
673674
// assign uids to each trace and detect collisions.
674675
if(!('uid' in trace) || suids.indexOf(trace.uid) !== -1) {
675676
var newUid, i;
@@ -750,6 +751,17 @@ function cleanData(data, existingData) {
750751
}
751752
}
752753

754+
// fix typo in colorscale definition
755+
if(Plots.traceIs(trace, '2dMap')) {
756+
if(trace.colorscale === 'YIGnBu') trace.colorscale = 'YlGnBu';
757+
if(trace.colorscale === 'YIOrRd') trace.colorscale = 'YlOrRd';
758+
}
759+
if(Plots.traceIs(trace, 'markerColorscale') && trace.marker) {
760+
var cont = trace.marker;
761+
if(cont.colorscale === 'YIGnBu') cont.colorscale = 'YlGnBu';
762+
if(cont.colorscale === 'YIOrRd') cont.colorscale = 'YlOrRd';
763+
}
764+
753765
// prune empty containers made before the new nestedProperty
754766
if(emptyContainer(trace, 'line')) delete trace.line;
755767
if('marker' in trace) {

test/jasmine/tests/plot_api_test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ var Bar = require('@src/traces/bar');
77
var Legend = require('@src/components/legend');
88
var pkg = require('../../../package.json');
99

10+
var createGraphDiv = require('../assets/create_graph_div');
11+
var destroyGraphDiv = require('../assets/destroy_graph_div');
12+
1013

1114
describe('Test plot api', function() {
1215
'use strict';
@@ -616,4 +619,54 @@ describe('Test plot api', function() {
616619
expect(gd.data).toEqual(cachedData);
617620
});
618621
});
622+
623+
describe('cleanData', function() {
624+
var gd;
625+
626+
beforeEach(function() {
627+
gd = createGraphDiv();
628+
});
629+
630+
afterEach(destroyGraphDiv);
631+
632+
it('should rename \'YIGnBu\' colorscales YlGnBu (2dMap case)', function() {
633+
var data = [{
634+
type: 'heatmap',
635+
colorscale: 'YIGnBu'
636+
}];
637+
638+
Plotly.plot(gd, data);
639+
expect(gd.data[0].colorscale).toBe('YlGnBu');
640+
});
641+
642+
it('should rename \'YIGnBu\' colorscales YlGnBu (markerColorscale case)', function() {
643+
var data = [{
644+
type: 'scattergeo',
645+
marker: { colorscale: 'YIGnBu' }
646+
}];
647+
648+
Plotly.plot(gd, data);
649+
expect(gd.data[0].marker.colorscale).toBe('YlGnBu');
650+
});
651+
652+
it('should rename \'YIOrRd\' colorscales YlOrRd (2dMap case)', function() {
653+
var data = [{
654+
type: 'contour',
655+
colorscale: 'YIOrRd'
656+
}];
657+
658+
Plotly.plot(gd, data);
659+
expect(gd.data[0].colorscale).toBe('YlOrRd');
660+
});
661+
662+
it('should rename \'YIOrRd\' colorscales YlOrRd (markerColorscale case)', function() {
663+
var data = [{
664+
type: 'scattergeo',
665+
marker: { colorscale: 'YIOrRd' }
666+
}];
667+
668+
Plotly.plot(gd, data);
669+
expect(gd.data[0].marker.colorscale).toBe('YlOrRd');
670+
});
671+
});
619672
});

0 commit comments

Comments
 (0)