-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Histogram autobin #3044
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
Histogram autobin #3044
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5cb42c
fix up cleanDate error reporting
alexcjohnson e066bb9
fix `legend.traceorder` when all traces are `legendonly`
alexcjohnson ab20fae
pull out tick0/dtick validation logic for reuse
alexcjohnson a8e4802
extend Axes.autoBin to find start/end with fixed size
alexcjohnson 536ce48
new histogram autobin algo
alexcjohnson c0b8c6f
test invisible bars and traceorder
alexcjohnson 76eee4b
flesh out bin attribute descriptions and let autobin(x|y) pass validate
alexcjohnson 5d930ce
_module.cleanData -> crossTraceDefaults
alexcjohnson 7514592
updated test description
alexcjohnson 7909f53
new histogram autobin mock
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var isNumeric = require('fast-isnumeric'); | ||
var Lib = require('../../lib'); | ||
var ONEDAY = require('../../constants/numerical').ONEDAY; | ||
|
||
/** | ||
* Return a validated dtick value for this axis | ||
* | ||
* @param {any} dtick: the candidate dtick. valid values are numbers and strings, | ||
* and further constrained depending on the axis type. | ||
* @param {string} axType: the axis type | ||
*/ | ||
exports.dtick = function(dtick, axType) { | ||
var isLog = axType === 'log'; | ||
var isDate = axType === 'date'; | ||
var isCat = axType === 'category'; | ||
var dtickDflt = isDate ? ONEDAY : 1; | ||
|
||
if(!dtick) return dtickDflt; | ||
|
||
if(isNumeric(dtick)) { | ||
dtick = Number(dtick); | ||
if(dtick <= 0) return dtickDflt; | ||
if(isCat) { | ||
// category dtick must be positive integers | ||
return Math.max(1, Math.round(dtick)); | ||
} | ||
if(isDate) { | ||
// date dtick must be at least 0.1ms (our current precision) | ||
return Math.max(0.1, dtick); | ||
} | ||
return dtick; | ||
} | ||
|
||
if(typeof dtick !== 'string' || !(isDate || isLog)) { | ||
return dtickDflt; | ||
} | ||
|
||
var prefix = dtick.charAt(0); | ||
var dtickNum = dtick.substr(1); | ||
dtickNum = isNumeric(dtickNum) ? Number(dtickNum) : 0; | ||
|
||
if((dtickNum <= 0) || !( | ||
// "M<n>" gives ticks every (integer) n months | ||
(isDate && prefix === 'M' && dtickNum === Math.round(dtickNum)) || | ||
// "L<f>" gives ticks linearly spaced in data (not in position) every (float) f | ||
(isLog && prefix === 'L') || | ||
// "D1" gives powers of 10 with all small digits between, "D2" gives only 2 and 5 | ||
(isLog && prefix === 'D' && (dtickNum === 1 || dtickNum === 2)) | ||
)) { | ||
return dtickDflt; | ||
} | ||
|
||
return dtick; | ||
}; | ||
|
||
/** | ||
* Return a validated tick0 for this axis | ||
* | ||
* @param {any} tick0: the candidate tick0. Valid values are numbers and strings, | ||
* further constrained depending on the axis type | ||
* @param {string} axType: the axis type | ||
* @param {string} calendar: for date axes, the calendar to validate/convert with | ||
* @param {any} dtick: an already valid dtick. Only used for D1 and D2 log dticks, | ||
* which do not support tick0 at all. | ||
*/ | ||
exports.tick0 = function(tick0, axType, calendar, dtick) { | ||
if(axType === 'date') { | ||
return Lib.cleanDate(tick0, Lib.dateTick0(calendar)); | ||
} | ||
if(dtick === 'D1' || dtick === 'D2') { | ||
// D1 and D2 modes ignore tick0 entirely | ||
return undefined; | ||
} | ||
// Aside from date axes, tick0 must be numeric | ||
return isNumeric(tick0) ? Number(tick0) : 0; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.