Last active
May 10, 2023 00:09
-
-
Save metormote/6405085 to your computer and use it in GitHub Desktop.
Selector Knob
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
<!DOCTYPE html> | |
<head> | |
<title>Selector</title> | |
<script type="text/javascript" src="http://iop.io/js/vendor/d3.v3.min.js"></script> | |
<script type="text/javascript" src="http://iop.io/js/vendor/polymer/PointerEvents/pointerevents.js"></script> | |
<script type="text/javascript" src="http://iop.io/js/vendor/polymer/PointerGestures/pointergestures.js"></script> | |
<script type="text/javascript" src="http://iop.io/js/iopctrl.js"></script> | |
<style> | |
body { | |
font: 16px arial; | |
background-color: #515151; | |
} | |
.unselectable { | |
-moz-user-select: -moz-none; | |
-khtml-user-select: none; | |
-webkit-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} | |
.knob .cursor { | |
fill: silver; | |
} | |
.knob .tick { | |
fill: silver; | |
font-size: 14px; | |
font-weight: bold; | |
} | |
.knob .major line { | |
stroke: silver; | |
stroke-width: 2px; | |
} | |
.ind .lane, .ind .cursor { | |
opacity: 0; | |
} | |
.ind .tick { | |
fill: silver; | |
font-size: 14px; | |
font-weight: bold; | |
} | |
.ind .major line { | |
stroke: silver; | |
stroke-width: 1px; | |
} | |
.ind .domain { | |
stroke: silver; | |
stroke-width: 1px; | |
} | |
.ind .tick { | |
fill: silver; | |
font-size: 10px; | |
font-weight: normal; | |
} | |
.ind .indicator { | |
stroke: #EE3311; | |
fill: #000; | |
stroke-width: 1px; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<span id="knob" touch-action="none"></span> | |
</div> | |
<script> | |
var svg = d3.select("#knob") | |
.append("svg:svg") | |
.attr("width", 800) | |
.attr("height", 600); | |
function drawInd(g, r) { | |
g.append("path").attr("d", "M0 " + -0.75 * r + " L 0 " + -1.05 * r + ""); | |
} | |
var ind = iopctrl.arcslider() | |
.radius(250) | |
.events(false) | |
.indicator(drawInd); | |
ind.axis().orient("out") | |
.normalize(true) | |
.ticks(6, d3.format(".0f")) | |
.tickSize(10) | |
.scale(d3.scale.log() | |
.domain([1, 100]) | |
.range([-Math.PI/8, Math.PI/8]) | |
.clamp(true)); | |
svg.append("g") | |
.attr("transform", "translate(0, 0)") | |
.attr("class", "ind") | |
.call(ind); | |
function drawKnob(g, r) { | |
g.append("image") | |
.attr("x", -r) | |
.attr("y", -r) | |
.attr("width", 2 * r) | |
.attr("height", 2 * r) | |
.attr("xlink:href", "http://iop.io/demo/iopctrl/knob.png") | |
} | |
var vol = iopctrl.arcslider() | |
.radius(75) | |
.indicator(drawKnob); | |
vol.axis().orient("out") | |
.ticks(10) | |
.tickSubdivide(5) | |
.tickSize(10, 6) | |
.tickPadding(5) | |
.scale(d3.scale.linear() | |
.domain([0, 100]) | |
.range([-3*Math.PI/4, 3*Math.PI/4])); | |
svg.append("g") | |
.attr("transform", "translate(175, 110)") | |
.attr("class", "knob") | |
.call(vol); | |
var sel = iopctrl.arcslider() | |
.radius(50) | |
.indicator(drawKnob) | |
.ease("cubic-in"); | |
sel.axis().orient("out") | |
.normalize(true) | |
.tickSize(10) | |
.scale(d3.scale.ordinal() | |
.domain(["REVERSE", "STEREO", "L+R", "L", "R"]) | |
.rangeBands([-Math.PI/4, 7*Math.PI/8])); | |
svg.append("g") | |
.attr("transform", "translate(200, 325)") | |
.attr("class", "knob") | |
.call(sel); | |
vol.onValueChanged(function(v) { | |
ind.value(v); | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment