IQ Distribution with Mean and Standard Deviation Sliders
Last active
November 3, 2016 19:24
-
-
Save herbps10/46795d53f73058a08d81e5f95435dc5a to your computer and use it in GitHub Desktop.
IQ Distribution Mean/SD Slider
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
license: mit | |
border: no |
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> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.line { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
.area { | |
fill: red; | |
} | |
.label { | |
fill: red; | |
} | |
.mean-label { | |
font-weight: bold; | |
font-size: 12px; | |
} | |
.mean-container { | |
width: 165px; | |
padding-left: 413px; | |
} | |
</style> | |
<div class='mean-container'> | |
<input id='mean' type='range' min='90' max='110' value='100'> | |
<br/> | |
</div> | |
<svg></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/jstat/latest/jstat.min.js"></script> | |
<script type='text/javascript'> | |
console.log("here"); | |
//setting up empty data array | |
var data = []; | |
var dataBelowCutoff = []; | |
var cutoffCdf = 0; | |
var mean; | |
var sd = 15; | |
getData(); // popuate data | |
// line chart based on http://bl.ocks.org/mbostock/3883245 | |
var margin = { | |
top: 20, | |
right: 20, | |
bottom: 30, | |
left: 50 | |
}, | |
width = 960 - margin.left - margin.right, | |
height = 400 - margin.top - margin.bottom; | |
var x = d3.scaleLinear() | |
.range([0, width]); | |
var y = d3.scaleLinear() | |
.range([height, 0]); | |
var xAxis = d3.axisBottom() | |
.scale(x); | |
var yAxis = d3.axisLeft() | |
.scale(y); | |
var line = d3.line() | |
.x(function(d) { | |
return x(d.q); | |
}) | |
.y(function(d) { | |
return y(d.p); | |
}); | |
var svg = d3.select("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
x.domain([40, 160]); | |
y.domain(d3.extent(data, function(d) { | |
return d.p; | |
})); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis); | |
var path = svg.append("path") | |
.datum(data) | |
.attr("class", "line") | |
.attr("d", line); | |
var meanLabel = svg.append('text') | |
.attr('class', 'mean-label') | |
.attr('y', -10) | |
.attr('text-anchor', 'middle'); | |
update(); | |
function update() { | |
path.datum(data).attr("d", line); | |
meanLabel | |
.attr('x', x(mean)) | |
.text(mean); | |
} | |
d3.select('#mean').on('input', function() { | |
getData(); | |
update(); | |
}); | |
function getData() { | |
mean = parseFloat(document.getElementById('mean').value); | |
sd = 15; | |
data = []; | |
// loop to populate data array with | |
// probabily - quantile pairs | |
for (var i = 40; i < 160; i += 1) { | |
q = i | |
p = jStat.normal.pdf(i, mean, sd); | |
el = { | |
"q": q, | |
"p": p | |
} | |
data.push(el); | |
}; | |
} | |
</script> | |
<style type='text/css'> | |
input[type=range] { | |
-webkit-appearance: none; | |
margin: 18px 0; | |
width: 100%; | |
} | |
input[type=range]:focus { | |
outline: none; | |
} | |
input[type=range]::-webkit-slider-runnable-track { | |
width: 100%; | |
height: 8.4px; | |
cursor: pointer; | |
animate: 0.2s; | |
background: steelblue; | |
box-shadow: inset 0px 0px 5px rgba(0, 0, 0, 0.3); | |
border-radius: 8px; | |
} | |
input[type=range]::-webkit-slider-thumb { | |
border: 1px solid #000000; | |
height: 36px; | |
width: 16px; | |
border-radius: 3px; | |
background: #ffffff; | |
cursor: pointer; | |
-webkit-appearance: none; | |
margin-top: -14px; | |
} | |
input[type=range]:focus::-webkit-slider-runnable-track { | |
background: steelblue; | |
} | |
input[type=range]::-moz-range-track { | |
width: 100%; | |
height: 8.4px; | |
cursor: pointer; | |
animate: 0.2s; | |
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | |
background: steelblue; | |
border-radius: 1.3px; | |
} | |
input[type=range]::-moz-range-thumb { | |
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | |
border: 1px solid #000000; | |
height: 36px; | |
width: 16px; | |
border-radius: 3px; | |
background: #ffffff; | |
cursor: pointer; | |
} | |
input[type=range]::-ms-track { | |
width: 100%; | |
height: 8.4px; | |
cursor: pointer; | |
animate: 0.2s; | |
background: transparent; | |
border-color: transparent; | |
border-width: 16px 0; | |
color: transparent; | |
} | |
input[type=range]::-ms-fill-lower { | |
background: #2a6495; | |
border: 0.2px solid #010101; | |
border-radius: 2.6px; | |
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | |
} | |
input[type=range]::-ms-fill-upper { | |
background: #3071a9; | |
border: 0.2px solid #010101; | |
border-radius: 2.6px; | |
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | |
} | |
input[type=range]::-ms-thumb { | |
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | |
border: 1px solid #000000; | |
height: 36px; | |
width: 16px; | |
border-radius: 3px; | |
background: #ffffff; | |
cursor: pointer; | |
} | |
input[type=range]:focus::-ms-fill-lower { | |
background: #3071a9; | |
} | |
input[type=range]:focus::-ms-fill-upper { | |
background: #367ebd; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment