Skip to content

Commit

Permalink
Merge pull request #3 from alesgenova/fix-drag
Browse files Browse the repository at this point in the history
Improve select by dragging interaction
  • Loading branch information
alesgenova committed Nov 12, 2018
2 parents e055ada + d4761fb commit 7d7be85
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/plots/ternary.ts
Expand Up @@ -67,8 +67,18 @@ class TernaryPlot {
.style('font-family', 'sans-serif')
.style('font-size', 'small');

this.svg.addEventListener('mousedown', () => {this.mouseDown = true});
this.svg.addEventListener('mouseup', () => {this.mouseDown = false});
this.svg.addEventListener(
'mousedown', () => {
this.mouseDown = true;

const mouseUpListener = () => {
window.removeEventListener('mouseup', mouseUpListener);
this.mouseDown = false;
};

window.addEventListener('mouseup', mouseUpListener);
}
);
// dragging randomly gets in the way
this.svg.addEventListener('dragstart', (e) => {e.preventDefault()});
}
Expand Down Expand Up @@ -269,8 +279,8 @@ class TernaryPlot {
`)
this.dataTooltip
.style('opacity', 0.9)
.style('left', `${x}px`)
.style('top', `${y}px`)
.style('left', `${x+10}px`)
.style('top', `${y-10}px`)
.style('transform', `translateY(-100%)`);
}

Expand Down

0 comments on commit 7d7be85

Please sign in to comment.