-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Initial rangeslider ranges #473
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e0f7bd
(wip) factor out 'get-autorange' algo from doAutorange,
etpinard 63658e1
Add range attribute and default to rangeslider
mdtusz 9facc51
Use rangeslider range for width and set initial range
mdtusz da32318
Cleanup rangeslider draw and reorder draw call
mdtusz 92d273b
Add tests for initial ranges
mdtusz 454e7c2
Add baseline image for range-slider ranges
b533355
Force calc if relayout with rangeslider and guard against NaN
mdtusz 02cb4e1
Create copy of mock
mdtusz 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 |
---|---|---|
|
@@ -16,11 +16,12 @@ var svgNS = require('../../constants/xmlns_namespaces').svg; | |
|
||
module.exports = function rangePlot(gd, w, h) { | ||
|
||
var traces = gd._fullData, | ||
xaxis = gd._fullLayout.xaxis, | ||
yaxis = gd._fullLayout.yaxis, | ||
minX = xaxis.range[0], | ||
maxX = xaxis.range[1], | ||
var fullLayout = gd._fullLayout, | ||
traces = gd._fullData, | ||
xaxis = fullLayout.xaxis, | ||
yaxis = fullLayout.yaxis, | ||
minX = xaxis.rangeslider.range[0], | ||
maxX = xaxis.rangeslider.range[1], | ||
minY = yaxis.range[0], | ||
maxY = yaxis.range[1]; | ||
|
||
|
@@ -62,7 +63,9 @@ module.exports = function rangePlot(gd, w, h) { | |
var posX = w * (x[k] - minX) / (maxX - minX), | ||
posY = h * (1 - (y[k] - minY) / (maxY - minY)); | ||
|
||
pointPairs.push([posX, posY]); | ||
if(!isNaN(posX) && !isNaN(posY)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be relevant for #472. For the moment, this will guard for thrown errors when passing the |
||
pointPairs.push([posX, posY]); | ||
} | ||
} | ||
|
||
// more trace type range plots can be added here | ||
|
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 |
---|---|---|
|
@@ -110,91 +110,106 @@ axes.minDtick = function(ax,newDiff,newFirst,allow) { | |
} | ||
}; | ||
|
||
axes.doAutoRange = function(ax) { | ||
if(!ax._length) ax.setScale(); | ||
axes.getAutoRange = function(ax) { | ||
var newRange = []; | ||
|
||
if(ax.autorange && ax._min && ax._max && | ||
ax._min.length && ax._max.length) { | ||
var minmin = ax._min[0].val, | ||
maxmax = ax._max[0].val, | ||
i; | ||
|
||
for(i = 1; i < ax._min.length; i++) { | ||
if(minmin !== maxmax) break; | ||
minmin = Math.min(minmin, ax._min[i].val); | ||
} | ||
for(i = 1; i < ax._max.length; i++) { | ||
if(minmin !== maxmax) break; | ||
maxmax = Math.max(maxmax, ax._max[i].val); | ||
} | ||
|
||
var j,minpt,maxpt,minbest,maxbest,dp,dv, | ||
mbest = 0, | ||
axReverse = (ax.range && ax.range[1]<ax.range[0]); | ||
// one-time setting to easily reverse the axis | ||
// when plotting from code | ||
if(ax.autorange==='reversed') { | ||
axReverse = true; | ||
ax.autorange = true; | ||
} | ||
for(i=0; i<ax._min.length; i++) { | ||
minpt = ax._min[i]; | ||
for(j=0; j<ax._max.length; j++) { | ||
maxpt = ax._max[j]; | ||
dv = maxpt.val-minpt.val; | ||
dp = ax._length-minpt.pad-maxpt.pad; | ||
if(dv>0 && dp>0 && dv/dp > mbest) { | ||
minbest = minpt; | ||
maxbest = maxpt; | ||
mbest = dv/dp; | ||
} | ||
var minmin = ax._min[0].val, | ||
maxmax = ax._max[0].val, | ||
i; | ||
|
||
for(i = 1; i < ax._min.length; i++) { | ||
if(minmin !== maxmax) break; | ||
minmin = Math.min(minmin, ax._min[i].val); | ||
} | ||
for(i = 1; i < ax._max.length; i++) { | ||
if(minmin !== maxmax) break; | ||
maxmax = Math.max(maxmax, ax._max[i].val); | ||
} | ||
|
||
var j,minpt,maxpt,minbest,maxbest,dp,dv, | ||
mbest = 0, | ||
axReverse = (ax.range && ax.range[1]<ax.range[0]); | ||
|
||
// one-time setting to easily reverse the axis | ||
// when plotting from code | ||
if(ax.autorange === 'reversed') { | ||
axReverse = true; | ||
ax.autorange = true; | ||
} | ||
|
||
for(i=0; i<ax._min.length; i++) { | ||
minpt = ax._min[i]; | ||
for(j=0; j<ax._max.length; j++) { | ||
maxpt = ax._max[j]; | ||
dv = maxpt.val-minpt.val; | ||
dp = ax._length-minpt.pad-maxpt.pad; | ||
if(dv>0 && dp>0 && dv/dp > mbest) { | ||
minbest = minpt; | ||
maxbest = maxpt; | ||
mbest = dv/dp; | ||
} | ||
} | ||
if(minmin===maxmax) { | ||
ax.range = axReverse ? | ||
[minmin+1, ax.rangemode!=='normal' ? 0 : minmin-1] : | ||
[ax.rangemode!=='normal' ? 0 : minmin-1, minmin+1]; | ||
} | ||
else if(mbest) { | ||
if(ax.type==='linear' || ax.type==='-') { | ||
if(ax.rangemode==='tozero' && minbest.val>=0) { | ||
} | ||
|
||
if(minmin === maxmax) { | ||
newRange = axReverse ? | ||
[minmin+1, ax.rangemode!=='normal' ? 0 : minmin-1] : | ||
[ax.rangemode!=='normal' ? 0 : minmin-1, minmin+1]; | ||
} | ||
else if(mbest) { | ||
if(ax.type==='linear' || ax.type==='-') { | ||
if(ax.rangemode==='tozero' && minbest.val>=0) { | ||
minbest = {val: 0, pad: 0}; | ||
} | ||
else if(ax.rangemode==='nonnegative') { | ||
if(minbest.val - mbest*minbest.pad<0) { | ||
minbest = {val: 0, pad: 0}; | ||
} | ||
else if(ax.rangemode==='nonnegative') { | ||
if(minbest.val - mbest*minbest.pad<0) { | ||
minbest = {val: 0, pad: 0}; | ||
} | ||
if(maxbest.val<0) { | ||
maxbest = {val: 1, pad: 0}; | ||
} | ||
if(maxbest.val<0) { | ||
maxbest = {val: 1, pad: 0}; | ||
} | ||
|
||
// in case it changed again... | ||
mbest = (maxbest.val-minbest.val) / | ||
(ax._length-minbest.pad-maxbest.pad); | ||
} | ||
|
||
ax.range = [ | ||
minbest.val - mbest*minbest.pad, | ||
maxbest.val + mbest*maxbest.pad | ||
]; | ||
// in case it changed again... | ||
mbest = (maxbest.val-minbest.val) / | ||
(ax._length-minbest.pad-maxbest.pad); | ||
} | ||
|
||
// don't let axis have zero size | ||
if(ax.range[0]===ax.range[1]) { | ||
ax.range = [ax.range[0]-1, ax.range[0]+1]; | ||
} | ||
newRange = [ | ||
minbest.val - mbest*minbest.pad, | ||
maxbest.val + mbest*maxbest.pad | ||
]; | ||
|
||
// maintain reversal | ||
if(axReverse) { | ||
ax.range.reverse(); | ||
} | ||
// don't let axis have zero size | ||
if(newRange[0] === newRange[1]) { | ||
newRange = [newRange[0]-1, newRange[0]+1]; | ||
} | ||
|
||
// maintain reversal | ||
if(axReverse) { | ||
newRange.reverse(); | ||
} | ||
} | ||
|
||
return newRange; | ||
}; | ||
|
||
axes.doAutoRange = function(ax) { | ||
if(!ax._length) ax.setScale(); | ||
|
||
// TODO do we really need this? | ||
var hasDeps = (ax._min && ax._max && ax._min.length && ax._max.length); | ||
|
||
if(ax.autorange && hasDeps) { | ||
ax.range = axes.getAutoRange(ax); | ||
|
||
// doAutoRange will get called on fullLayout, | ||
// but we want to report its results back to layout | ||
var axIn = ax._gd.layout[ax._name]; | ||
|
||
if(!axIn) ax._gd.layout[ax._name] = axIn = {}; | ||
if(axIn!==ax) { | ||
|
||
if(axIn !== ax) { | ||
axIn.range = ax.range.slice(); | ||
axIn.autorange = ax.autorange; | ||
} | ||
|
@@ -241,7 +256,8 @@ axes.saveRangeInitial = function(gd, overwrite) { | |
// and make it a tight bound if possible | ||
var FP_SAFE = Number.MAX_VALUE/2; | ||
axes.expand = function(ax, data, options) { | ||
if(!ax.autorange || !data) return; | ||
// if(!(ax.autorange || (ax.rangeslider || {}).visible) || !data) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐄 clean up comment. |
||
if(!(ax.autorange || ax._needsExpand) || !data) return; | ||
if(!ax._min) ax._min = []; | ||
if(!ax._max) ax._max = []; | ||
if(!options) options = {}; | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cldougl wording clear enough?