-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make dragmode 'lasso' & 'select' work with fixedrange axes #728
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
6 commits
Select commit
Hold shift + click to select a range
0d3fe54
lint: flattern Fx test suite
etpinard fdb0c3c
update 'dragmode' cursor in relayout NOT modebar
etpinard 5f80b6e
dry: check for if dragbox is main-drag only once
etpinard 57d6980
fixup flatten
etpinard f0110ee
fx: make mainDrag active if 'lasso' / 'select' even w/ fixed ranges
etpinard 7f9bc9c
test: check main drag update on relayout
etpinard 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,135 @@ | ||
var Fx = require('@src/plots/cartesian/graph_interact'); | ||
var Plotly = require('@lib/index'); | ||
var Plots = require('@src/plots/plots'); | ||
|
||
var Fx = require('@src/plots/cartesian/graph_interact'); | ||
|
||
var d3 = require('d3'); | ||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
|
||
describe('Fx defaults', function() { | ||
'use strict'; | ||
|
||
var layoutIn, layoutOut, fullData; | ||
|
||
beforeEach(function() { | ||
layoutIn = {}; | ||
layoutOut = { | ||
_has: Plots._hasPlotType | ||
}; | ||
fullData = [{}]; | ||
}); | ||
|
||
it('should default (blank version)', function() { | ||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (cartesian version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
expect(layoutOut._isHoriz).toBe(false, 'isHoriz to false'); | ||
}); | ||
|
||
it('should default (cartesian horizontal version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }]; | ||
fullData[0] = { orientation: 'h' }; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('y', 'hovermode to y'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true'); | ||
}); | ||
|
||
it('should default (gl3d version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'gl3d' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (geo version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'geo' }]; | ||
|
||
describe('Test FX', function() { | ||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (multi plot type version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }, { name: 'gl3d' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
}); | ||
|
||
describe('relayout', function() { | ||
'use strict'; | ||
|
||
describe('defaults', function() { | ||
|
||
var layoutIn, layoutOut, fullData; | ||
|
||
beforeEach(function() { | ||
layoutIn = {}; | ||
layoutOut = { | ||
_has: Plots._hasPlotType | ||
}; | ||
fullData = [{}]; | ||
}); | ||
|
||
it('should default (blank version)', function() { | ||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (cartesian version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
expect(layoutOut._isHoriz).toBe(false, 'isHoriz to false'); | ||
}); | ||
|
||
it('should default (cartesian horizontal version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }]; | ||
fullData[0] = { orientation: 'h' }; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('y', 'hovermode to y'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true'); | ||
}); | ||
|
||
it('should default (gl3d version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'gl3d' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (geo version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'geo' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
|
||
it('should default (multi plot type version)', function() { | ||
layoutOut._basePlotModules = [{ name: 'cartesian' }, { name: 'gl3d' }]; | ||
|
||
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); | ||
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); | ||
}); | ||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
it('should update main drag with correct', function(done) { | ||
|
||
function assertMainDrag(cursor, isActive) { | ||
expect(d3.selectAll('rect.nsewdrag').size()).toEqual(1, 'number of nodes'); | ||
var mainDrag = d3.select('rect.nsewdrag'), | ||
node = mainDrag.node(); | ||
|
||
expect(mainDrag.classed('cursor-' + cursor)).toBe(true, 'cursor ' + cursor); | ||
expect(mainDrag.style('pointer-events')).toEqual('all', 'pointer event'); | ||
expect(!!node.onmousedown).toBe(isActive, 'mousedown handler'); | ||
} | ||
|
||
Plotly.plot(gd, [{ | ||
y: [2, 1, 2] | ||
}]).then(function() { | ||
assertMainDrag('crosshair', true); | ||
|
||
return Plotly.relayout(gd, 'dragmode', 'pan'); | ||
}).then(function() { | ||
assertMainDrag('move', true); | ||
|
||
return Plotly.relayout(gd, 'dragmode', 'drag'); | ||
}).then(function() { | ||
assertMainDrag('crosshair', true); | ||
|
||
return Plotly.relayout(gd, 'xaxis.fixedrange', true); | ||
}).then(function() { | ||
assertMainDrag('ns-resize', true); | ||
|
||
return Plotly.relayout(gd, 'yaxis.fixedrange', true); | ||
}).then(function() { | ||
assertMainDrag('pointer', false); | ||
|
||
return Plotly.relayout(gd, 'dragmode', 'drag'); | ||
}).then(function() { | ||
assertMainDrag('pointer', false); | ||
|
||
return Plotly.relayout(gd, 'dragmode', 'lasso'); | ||
}).then(function() { | ||
assertMainDrag('pointer', true); | ||
|
||
return Plotly.relayout(gd, 'dragmode', 'select'); | ||
}).then(function() { | ||
assertMainDrag('pointer', true); | ||
|
||
return Plotly.relayout(gd, 'xaxis.fixedrange', false); | ||
}).then(function() { | ||
assertMainDrag('ew-resize', true); | ||
}).then(done); | ||
}); | ||
}); |
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.
?
Why is this in the
domodebar
block?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.
domodebar
(i.e. when only thedragmode
or thehovermode
changes) by-passes a bunch of things. So instead of running the wholePlots.supplyDefaults
it only need to call theFx
defaults step and re-initialise the drag boxes.