Skip to content
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

fix #2529 - box plot with one jittered outlier #2530

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/traces/box/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function plotPoints(sel, axes, trace, t) {
maxJitterFactor = Math.max(jitterFactor, maxJitterFactor);
}
}
newJitter = trace.jitter * 2 / maxJitterFactor;
newJitter = trace.jitter * 2 / (maxJitterFactor || 1);
}

// fills in 'x' and 'y' in calcdata 'pts' item
Expand Down
35 changes: 33 additions & 2 deletions test/jasmine/tests/box_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Box = require('@src/traces/box');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var failTest = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');

var customAssertions = require('../assets/custom_assertions');
Expand Down Expand Up @@ -313,7 +313,38 @@ describe('Test box hover:', function() {
name: ''
}].forEach(function(specs) {
it('should generate correct hover labels ' + specs.desc, function(done) {
run(specs).catch(fail).then(done);
run(specs).catch(failTest).then(done);
});
});
});

describe('Box edge cases', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

it('does not barf on a single outlier with jitter', function(done) {
var trace = {
boxpoints: 'outliers',
jitter: 0.7,
type: 'box',
y: [46.505, 0.143, 0.649, 0.059, 513, 90, 234]
};

Plotly.newPlot(gd, [trace])
.then(function() {
var outliers = [];
gd.calcdata[0][0].pts.forEach(function(pt) {
if(pt.x !== undefined) outliers.push(pt);
});
expect(outliers.length).toBe(1);
expect(outliers[0].x).toBe(0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was NaN before the fix

})
.catch(failTest)
.then(done);
});
});