-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Lasso & rectangular selections #154
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
Changes from 1 commit
d6f983e
e536a91
5cad4ff
ca60e63
76926d7
78d2867
f0e6cfb
c0a94f7
12b43c6
07e5cef
b1a1c24
1958475
3c40c41
188a0db
8d0afb5
1c5f325
d0203c8
5be72de
057e4ac
556cb83
7b07a25
2a970fc
d7abd18
7addcec
d02d612
698376e
89c1655
d8ed7a7
7d897a4
96e01b6
bc04a15
710791d
342f991
b5c090f
1d7745f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,11 @@ | |
|
||
|
||
'use strict'; | ||
var polygon = require('../../lib/polygon'); | ||
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. @alexcjohnson a couple (still un-documented) 🐄s
i.e. in increasing locality. So, the 'use strict';
var polygon = require('../../lib/polygon');
var axes = require('./axes');
var filteredPolygon = polygon.filter;
var polygonTester = polygon.tester;
var BENDPX = 1.5; // max pixels off straight before a line counts as bent 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. roger doger. |
||
var filteredPolygon = polygon.filter; | ||
var BENDPX = 1.5; // max pixels off straight before a line counts as bent | ||
|
||
module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | ||
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. Nice. How hard would it be the split up the 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. Probably pretty easy, but I'll leave that as an exercise to the reader 😄 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.
Haha. Hopefully this comes with bonus points ;) |
||
console.log('select start', e, startX, startY, dragOptions, mode); | ||
var plot = dragOptions.plotinfo.plot, | ||
dragBBox = dragOptions.element.getBoundingClientRect(), | ||
x0 = startX - dragBBox.left, | ||
|
@@ -19,35 +21,34 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
y1 = y0, | ||
path0 = 'M' + x0 + ',' + y0, | ||
pw = dragOptions.xaxes[0]._length, | ||
ph = dragOptions.yaxes[0]._length, | ||
pts = [[x0, y0]], | ||
outlines = plot.selectAll('path.select-outline').data([1,2]); | ||
ph = dragOptions.yaxes[0]._length; | ||
if(mode === 'lasso') { | ||
var pts = filteredPolygon([[x0, y0]], BENDPX); | ||
} | ||
|
||
// TODO initial dimming of selectable points | ||
var outlines = plot.selectAll('path.select-outline').data([1,2]); | ||
|
||
outlines.enter() | ||
.append('path') | ||
.attr('class', function(d) { return 'select-outline select-outline-' + d; }) | ||
.attr('d', path0 + 'Z'); | ||
|
||
dragOptions.moveFn = function(dx0, dy0) { | ||
console.log('select move', dx0, dy0); | ||
x1 = Math.max(0, Math.min(pw, dx0 + x0)); | ||
y1 = Math.max(0, Math.min(ph, dy0 + y0)); | ||
|
||
if(mode === 'select') { | ||
outlines.attr('d', path0 + 'H' + x1 + 'V' + y1 + 'H' + x0 + 'Z'); | ||
} | ||
else { | ||
pts.push([x1, y1]); // TODO: filter this down to something reasonable | ||
outlines.attr('d', 'M' + pts.join('L')); | ||
else if(mode === 'lasso') { | ||
pts.addPt([x1, y1]); | ||
outlines.attr('d', 'M' + pts.filtered.join('L')); | ||
} | ||
|
||
// TODO - actual selection and dimming! | ||
}; | ||
|
||
dragOptions.doneFn = function(dragged, numclicks) { | ||
console 52B4 .log('select done', dragged, numclicks); | ||
if(!dragged && numclicks === 2) dragOptions.doubleclick(); | ||
else { | ||
// TODO - select event | ||
|
@@ -56,3 +57,4 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
// TODO - remove dimming | ||
}; | ||
}; | ||
|
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.
Used to simplify the lasso polygon. This is pretty similar to the scatter line decimation algorithm, so not super 🌴 but line decimation has a few other quirks that made it seem annoying to combine.
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.
polygon.js is ~150 lines of code. Nothing to worry here.