Skip to content

Instantly share code, notes, and snippets.

@walkerjeffd
Created October 5, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkerjeffd/f106208f55304c0b18d7bbe68a18a591 to your computer and use it in GitHub Desktop.
Save walkerjeffd/f106208f55304c0b18d7bbe68a18a591 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.axis--x path {
display: none;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
function compute(params) {
var Zc = params.Zc, // control depth (cm)
Zw = params.Zw, // weir depth (cm)
W = params.W, // mean cell width = area / flow path length (km)
a = params.a, // empirical
b = params.b, // empirical
pump_capacity = params.pump_capacity;
var Z_arr = d3.range(0, 100, 1);
var Q_arr = Z_arr.map(function (Z) {
var Q = W * a * Math.pow((Z - Zw), b);
// console.log(Z, Q)
return Z < Zc && Z < Zw ? 0 :
Q > pump_capacity ? pump_capacity : Q;
});
return d3.zip(Z_arr, Q_arr);
}
var data = compute({Zc: 40, Zw: 40, W: 1, a: 1, b: 1.5, pump_capacity: 100});
var x = d3.scaleLinear()
.domain([0, 100])
.range([0]);
var y = d3.scaleLinear()
.domain([0, 110])
.range([height, 0]);
var line = d3.line()
.x(function(d) { return x(d[0]); })
.y(function(d) { return y(d[1]); });
var svg = d3.select("body").append("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(d3.extent(data, function(d) { return d[0]; }));
y.domain(d3.extent(data, function(d) { return d[1]; }));
svg.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
svg.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y))
.append("text")
.attr("class", "axis-title")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Q");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment