Skip to content

Commit

Permalink
Fix #32 (left slider goes past right slider)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorawee authored and johnwalley committed May 26, 2019
1 parent efef27e commit 018af64
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ function slider(orientation, scale) {

fadeTickText();

function computeDragNewValue(pos) {
var adjustedValue = alignedValue(scale.invert(pos));
return value.map(function(d, i) {
if (value.length === 2) {
return i === handleIndex
? handleIndex === 0
? Math.min(adjustedValue, alignedValue(value[1]))
: Math.max(adjustedValue, alignedValue(value[0]))
: d;
} else {
return i === handleIndex ? adjustedValue : d;
}
});
}

function dragstarted() {
select(this).classed('active', true);

Expand Down Expand Up @@ -386,20 +401,7 @@ function slider(orientation, scale) {
var pos = identityClamped(
orientation === bottom || orientation === top ? event.x : event.y
);

var adjustedValue = alignedValue(scale.invert(pos));

var newValue = value.map(function(d, i) {
if (value.length === 2) {
return i === handleIndex
? handleIndex === 0
? Math.min(adjustedValue, alignedValue(value[1]))
: Math.max(adjustedValue, alignedValue(value[0]))
: d;
} else {
return i === handleIndex ? adjustedValue : d;
}
});
var newValue = computeDragNewValue(pos);

updateHandle(newValue);
listeners.call(
Expand All @@ -416,10 +418,7 @@ function slider(orientation, scale) {
var pos = identityClamped(
orientation === bottom || orientation === top ? event.x : event.y
);

var newValue = value.map(function(d, i) {
return i === handleIndex ? alignedValue(scale.invert(pos)) : d;
});
var newValue = computeDragNewValue(pos);

updateHandle(newValue);
listeners.call(
Expand Down

0 comments on commit 018af64

Please sign in to comment.