Skip to content
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

[fix drag range value and add exemple] #42

Open
wants to merge 2 commits into
base: rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ <h2>Vertical slider</h2>
<code>d3.slider().value(50).orientation("vertical")</code>
<div id="slider7"></div>

<h2>Slider range with slide event: <span id="slider8text">0</span></h2>
<code>d3.slider().domain([10,90]).on("drag", function(evt, value) {<br>
&nbsp;&nbsp;d3.select('#slider8text').text(value);<br>
})</code>
<div id="slider8"></div>

</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
Expand All @@ -95,6 +101,12 @@ <h2>Vertical slider</h2>

d3.select('#slider7').call(d3.slider().orientation("vertical"));

d3.select('#slider8').call(
d3.slider().value([10,90])
.on("drag", function(evt, value) {
d3.select('#slider8text').text(value);
}));

</script>

</body>
Expand Down
6 changes: 5 additions & 1 deletion src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ d3.slider = function module() {
if (value.length === 2) { // Two handles
if (Math.abs(value[0] - newValue) > Math.abs(value[1] - newValue)) {
moveHandle([value[0], newValue]);
dispatch.drag(d3.event.sourceEvent, [value[0], newValue]);
} else {
moveHandle([newValue, value[1]]);
dispatch.drag(d3.event.sourceEvent, [newValue, value[1]]);
}
} else { // Single handle
moveHandle(newValue);
Expand All @@ -135,8 +137,10 @@ d3.slider = function module() {
//console.log(lowerHandle, newValue, value);
if (lowerHandle && newValue <= value[1]) {
moveHandle([newValue, value[1]]);
dispatch.drag(d3.event.sourceEvent, [newValue, value[1]]);
} else if (!lowerHandle && newValue >= value[0]) {
moveHandle([value[0], newValue]);
dispatch.drag(d3.event.sourceEvent, [value[0], newValue]);
}
} else if (newValue !== value) {
moveHandle(newValue);
Expand Down Expand Up @@ -274,4 +278,4 @@ Other sliders:
http://api.jqueryui.com/slider/
http://refreshless.com/nouislider/

*/
*/