-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c3019e
commit 8b946ab
Showing
3 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script src="https://d3js.org/d3.v4.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script> | ||
<script src="../build/d3-simple-slider.js"></script> | ||
|
||
<body> | ||
<p id="value">Move me</p> | ||
<div id="value"></div> | ||
<a id="setValue" href="#">Set value</a> | ||
<a id="changeWidth" href="#">Change width</a> | ||
</body> | ||
|
||
<script> | ||
var data = [0, 0.005, 0.01, 0.015, 0.02, 0.025]; | ||
|
||
var slider = d3Slider.sliderHorizontal() | ||
.domain(d3.extent(data)) | ||
.width(300) | ||
.tickFormat(d3.format('.2%')) | ||
.ticks(5) | ||
.default(0.015) | ||
.on('onchange', val => { | ||
d3.select("p#value").text(d3.format('.2%')(val)); | ||
}); | ||
|
||
var g = d3.select("div#value").append("svg") | ||
.attr("width", 500) | ||
.attr("height", 100) | ||
.append("g") | ||
.attr("transform", "translate(30,30)"); | ||
|
||
g.call(slider); | ||
|
||
d3.select("a#setValue").on("click", () => slider.value(0.01)); | ||
d3.select("a#changeWidth").on("click", () => g.call(slider.width(Math.floor(Math.random() * 500) + 200))); | ||
</script> |
This file contains 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 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