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

Histogram autobin #3044

Merged
merged 10 commits into from
Oct 4, 2018
4 changes: 3 additions & 1 deletion src/lib/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ function includeTime(dateStr, h, m, s, msec10) {
// a Date object or milliseconds
// optional dflt is the return value if cleaning fails
exports.cleanDate = function(v, dflt, calendar) {
if(exports.isJSDate(v) || typeof v === 'number') {
// let us use cleanDate to provide a missing default without an error
if(v === BADNUM) return dflt;
if(exports.isJSDate(v) || (typeof v === 'number' && isFinite(v))) {
// do not allow milliseconds (old) or jsdate objects (inherently
// described as gregorian dates) with world calendars
if(isWorldCalendar(calendar)) {
Expand Down
5 changes: 4 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,10 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
}

// trace module layout defaults
var modules = layoutOut._visibleModules;
// use _modules rather than _visibleModules so that even
// legendonly traces can include settings - eg barmode, which affects
// legend.traceorder default value.
var modules = layoutOut._modules;
etpinard marked this conversation as resolved.
Show resolved Hide resolved
for(i = 0; i < modules.length; i++) {
_module = modules[i];

Expand Down
12 changes: 12 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ describe('bar visibility toggling:', function() {
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();

_assert('base', [0.5, 3.5], [-2.222, 2.222], 0);
expect(gd._fullLayout.legend.traceorder).toBe('normal');
return Plotly.restyle(gd, 'visible', false, [1]);
})
.then(function() {
Expand All @@ -1369,6 +1370,11 @@ describe('bar visibility toggling:', function() {
})
.then(function() {
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
expect(gd._fullLayout.legend.traceorder).toBe('normal');
return Plotly.restyle(gd, 'visible', true, [1]);
})
.then(function() {
Expand All @@ -1391,6 +1397,7 @@ describe('bar visibility toggling:', function() {
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();

_assert('base', [0.5, 3.5], [0, 5.263], 0);
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
return Plotly.restyle(gd, 'visible', false, [1]);
})
.then(function() {
Expand All @@ -1399,6 +1406,11 @@ describe('bar visibility toggling:', function() {
})
.then(function() {
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
return Plotly.restyle(gd, 'visible', true, [1]);
})
.then(function() {
Expand Down
8 changes: 5 additions & 3 deletions test/jasmine/tests/lib_date_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,22 @@ describe('dates', function() {
errors.push(msg);
});

[
var cases = [
new Date(-20000, 0, 1),
new Date(20000, 0, 1),
new Date('fail'),
undefined, null, NaN,
[], {}, [0], {1: 2}, '',
'2001-02-29' // not a leap year
].forEach(function(v) {
];
cases.forEach(function(v) {
expect(Lib.cleanDate(v)).toBeUndefined();
if(!isNumeric(+v)) expect(Lib.cleanDate(+v)).toBeUndefined();
expect(Lib.cleanDate(v, '2000-01-01')).toBe('2000-01-01');
});

expect(errors.length).toBe(16);
// two errors for each case except `undefined`
expect(errors.length).toBe(2 * (cases.length - 1));
});

it('should not alter valid date strings, even to truncate them', function() {
Expand Down