8000 Skip undefined props on restyle by rreusser · Pull Request #844 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Skip undefined props on restyle #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Skip undefined props on restyle
  • Loading branch information
rreusser committed Aug 11, 2016
commit abf8ec5a2c73c7c9b30105dd6dd9c726036c9afe
2 changes: 2 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
oldVal = param.get();
newVal = Array.isArray(vi) ? vi[i % vi.length] : vi;

if(newVal === undefined) continue;

// setting bin or z settings should turn off auto
// and setting auto should save bin or z settings
if(zscl.indexOf(ai) !== -1) {
Expand Down
58 changes: 58 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,64 @@ describe('Test plot api', function() {
expect(gd.calcdata).toBeDefined();
});

it('ignores undefined values', function() {
var gd = {
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
layout: {}
};

mockDefaultsAndCalc(gd);

// Check to see that the color is updated:
Plotly.restyle(gd, {'marker.color': 'blue'});
expect(gd._fullData[0].marker.color).toBe('blue');

// Check to see that the color is unaffected:
Plotly.restyle(gd, {'marker.color': undefined});
expect(gd._fullData[0].marker.color).toBe('blue');
});

it('restores null values to defaults', function() {
var gd = {
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
layout: {}
};

mockDefaultsAndCalc(gd);
var colorDflt = gd._fullData[0].marker.color;

// Check to see that the color is updated:
Plotly.restyle(gd, {'marker.color': 'blue'});
expect(gd._fullData[0].marker.color).toBe('blue');

// Check to see that the color is restored to the original default:
Plotly.restyle(gd, {'marker.color': null});
expect(gd._fullData[0].marker.color).toBe(colorDflt);
});

it('can target specific traces by leaving properties undefined', function() {
var gd = {
data: [
{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'},
{x: [1, 2, 3], y: [3, 4, 5], type: 'scatter'}
],
layout: {}
};

mockDefaultsAndCalc(gd);
var colorDflt = [gd._fullData[0].marker.color, gd._fullData[1].marker.color];

// Check only second trace's color has been changed:
Plotly.restyle(gd, {'marker.color': [undefined, 'green']});
expect(gd._fullData[0].marker.color).toBe(colorDflt[0]);
expect(gd._fullData[1].marker.color).toBe('green');

// Check both colors restored to the original default:
Plotly.restyle(gd, {'marker.color': [null, null]});
expect(gd._fullData[0].marker.color).toBe(colorDflt[0]);
expect(gd._fullData[1].marker.color).toBe(colorDflt[1]);
});

});

describe('Plotly.deleteTraces', function() {
Expand Down
0