-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
copy histogram autobinx/y back to the input trace #1901
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,13 +137,17 @@ describe('Test histogram2d', function() { | |
}); | ||
}); | ||
|
||
describe('relayout interaction', function() { | ||
describe('restyle / relayout interaction', function() { | ||
|
||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
it('should update paths on zooms', function(done) { | ||
var gd = createGraphDiv(); | ||
|
||
Plotly.newPlot(gd, [{ | ||
type: 'histogram2dcontour', | ||
x: [1, 1, 2, 2, 3], | ||
|
@@ -156,6 +160,75 @@ describe('Test histogram2d', function() { | |
.then(done); | ||
}); | ||
|
||
|
||
it('handles autobin correctly on restyles', function() { | ||
var x1 = [ | ||
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, | ||
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]; | ||
var y1 = [ | ||
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, | ||
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]; | ||
Plotly.newPlot(gd, [{type: 'histogram2d', x: x1, y: y1}]); | ||
expect(gd._fullData[0].xbins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].ybins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].autobinx).toBe(true); | ||
expect(gd._fullData[0].autobiny).toBe(true); | ||
|
||
// same range but fewer samples increases sizes | ||
Plotly.restyle(gd, {x: [[1, 3, 4]], y: [[1, 2, 4]]}); | ||
expect(gd._fullData[0].xbins).toEqual({start: -0.5, end: 5.5, size: 2}); | ||
expect(gd._fullData[0].ybins).toEqual({start: -0.5, end: 5.5, size: 2}); | ||
expect(gd._fullData[0].autobinx).toBe(true); | ||
expect(gd._fullData[0].autobiny).toBe(true); | ||
|
||
// larger range | ||
Plotly.restyle(gd, {x: [[10, 30, 40]], y: [[10, 20, 40]]}); | ||
expect(gd._fullData[0].xbins).toEqual({start: -0.5, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].ybins).toEqual({start: -0.5, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].autobinx).toBe(true); | ||
expect(gd._fullData[0].autobiny).toBe(true); | ||
|
||
// explicit changes to bin settings | ||
Plotly.restyle(gd, 'xbins.start', 12); | ||
expect(gd._fullData[0].xbins).toEqual({start: 12, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].ybins).toEqual({start: -0.5, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].autobinx).toBe(false); | ||
expect(gd._fullData[0].autobiny).toBe(true); | ||
|
||
Plotly.restyle(gd, {'ybins.end': 12, 'ybins.size': 3}); | ||
expect(gd._fullData[0].xbins).toEqual({start: 12, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].ybins).toEqual({start: -0.5, end: 12, size: 3}); | ||
expect(gd._fullData[0].autobinx).toBe(false); | ||
expect(gd._fullData[0].autobiny).toBe(false); | ||
|
||
// restart autobin | ||
Plotly.restyle(gd, {autobinx: true, autobiny: true}); | ||
expect(gd._fullData[0].xbins).toEqual({start: -0.5, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].ybins).toEqual({start: -0.5, end: 59.5, size: 20}); | ||
expect(gd._fullData[0].autobinx).toBe(true); | ||
expect(gd._fullData[0].autobiny).toBe(true); | ||
}); | ||
|
||
it('respects explicit autobin: false as a one-time autobin', function() { | ||
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. That's cool 👍 |
||
var x1 = [ | ||
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, | ||
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]; | ||
var y1 = [ | ||
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, | ||
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]; | ||
Plotly.newPlot(gd, [{type: 'histogram2d', x: x1, y: y1, autobinx: false, autobiny: false}]); | ||
expect(gd._fullData[0].xbins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].ybins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].autobinx).toBe(false); | ||
expect(gd._fullData[0].autobiny).toBe(false); | ||
|
||
// with autobin false this will no longer update the bins. | ||
Plotly.restyle(gd, {x: [[1, 3, 4]], y: [[1, 2, 4]]}); | ||
expect(gd._fullData[0].xbins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].ybins).toEqual({start: 0.5, end: 4.5, size: 1}); | ||
expect(gd._fullData[0].autobinx).toBe(false); | ||
expect(gd._fullData[0].autobiny).toBe(false); | ||
}); | ||
}); | ||
|
||
}); |
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
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.
note that
cleanBins
provides asize
even if there are nostart
orend
. This also doesn't allow you to specify astart
and noend
or things like that. So partial bin definition might do strange things... but that I would definitely consider a feature we could propose to add, rather than a bug to fix.Also note that
!(binAttr in trace)
in the old version never failed, since we default tonull
forstart
andend
(which might have been important to enablecleanBins
?) - so in principle I could omit!binspec
here, just thought it prudent in case there's some context I'm not aware of that can call thiscalc
.