Created
October 20, 2011 04:31
-
-
Save ZJONSSON/1300420 to your computer and use it in GitHub Desktop.
Contour Test using Jason Davis implementation with D3
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
<html> | |
<head> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script> | |
<script type="text/javascript" src="http://paulbourke.net/papers/conrec/conrec.js"></script> | |
<script type="text/javascript" src="multiplot.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var c = new Conrec(), | |
xs = d3.range(0, data[0].length), | |
ys = d3.range(0, data.length), | |
zs = d3.range(-5, 3, .5), | |
w = 500, h = 500, | |
x=d3.scale.linear().range([0,w]).domain([0,data[0].length]), | |
y=d3.scale.linear().range([0,h]).domain([0,data.length]), | |
colours = d3.scale.linear().domain([-5, 3]).range(["#fff", "red"]); | |
c.contour(data, 0, xs.length-1, 0, ys.length-1, xs, ys, zs.length, zs); | |
svg=d3.select("body").append("svg:svg") | |
.attr("width",w) | |
.attr("height",h) | |
svg.selectAll("g") | |
.data(d3.nest().key(function(d) { return d.level}).entries(c.contourList())) | |
.enter() | |
.append("svg:g") | |
.attr("class",function(d) { return "level_"+d.key}) | |
.style("fill",function(d) { console.log(d);return colours(d.key);}) | |
.style("stroke","black") | |
.style("opacity",0.5) | |
.selectAll("path") | |
.data(function(d) { return d.values}) | |
.enter() | |
.append("svg:path") | |
.attr("d",d3.svg.line() | |
.x(function(d) { return x(d.x)}) | |
.y(function(d) { return y(d.y)}) | |
) | |
</script> | |
</body> | |
</html> |
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
/** | |
* Originally from http://www2.warwick.ac.uk/fac/sci/moac/currentstudents/peter_cock/r/matrix_contour/ | |
*/ | |
var data = [ | |
[ | |
0.4, | |
0.4, | |
0.7, | |
-1.0, | |
-0.1, | |
0.6, | |
-0.4, | |
0.6, | |
-0.4, | |
1.3, | |
0.7, | |
-0.4, | |
1.1, | |
1.3, | |
0.6, | |
0.1, | |
-0.0, | |
-0.8, | |
-0.8, | |
-1.0 | |
], | |
[ | |
0.4, | |
-0.4, | |
0.4, | |
-1.2, | |
-0.7, | |
0.4, | |
-0.9, | |
0.5, | |
-0.9, | |
1.2, | |
0.5, | |
-1.0, | |
1.3, | |
1.1, | |
0.5, | |
-0.0, | |
-0.1, | |
-1.2, | |
-1.0, | |
-0.9 | |
], | |
[ | |
0.7, | |
0.4, | |
0.1, | |
-1.2, | |
-0.2, | |
0.5, | |
-0.6, | |
0.6, | |
-0.2, | |
0.9, | |
0.6, | |
-0.5, | |
1.1, | |
0.8, | |
0.6, | |
0.1, | |
-0.4, | |
-0.9, | |
-0.7, | |
-0.8 | |
], | |
[ | |
-1.0, | |
-1.2, | |
-1.2, | |
-4.4, | |
-1.9, | |
-0.8, | |
-2.2, | |
-1.0, | |
-2.2, | |
0.0, | |
-0.3, | |
-2.0, | |
-0.2, | |
0.2, | |
-0.8, | |
-1.6, | |
-1.9, | |
-2.4, | |
-2.3, | |
-2.6 | |
], | |
[ | |
-0.1, | |
-0.7, | |
-0.2, | |
-1.9, | |
-2.0, | |
-0.5, | |
-1.9, | |
-0.3, | |
-1.7, | |
0.4, | |
-0.2, | |
-1.9, | |
0.3, | |
0.4, | |
-0.3, | |
-0.8, | |
-0.9, | |
-2.1, | |
-1.8, | |
-2.0 | |
], | |
[ | |
0.6, | |
0.4, | |
0.5, | |
-0.8, | |
-0.5, | |
-0.1, | |
-0.8, | |
0.6, | |
-0.5, | |
1.0, | |
0.5, | |
-0.7, | |
0.8, | |
1.0, | |
0.5, | |
0.1, | |
-0.3, | |
-0.9, | |
-0.7, | |
-1.1 | |
], | |
[ | |
-0.4, | |
-0.9, | |
-0.6, | |
-2.2, | |
-1.9, | |
-0.8, | |
-2.7, | |
-0.6, | |
-2.0, | |
0.3, | |
-0.3, | |
-2.3, | |
-0.0, | |
-0.0, | |
-0.6, | |
-1.1, | |
-1.3, | |
-2.4, | |
-2.0, | |
-2.2 | |
], | |
[ | |
0.6, | |
0.5, | |
0.6, | |
-1.0, | |
-0.3, | |
0.6, | |
-0.6, | |
0.1, | |
-0.8, | |
1.3, | |
0.8, | |
-0.8, | |
1.1, | |
1.3, | |
0.4, | |
0.1, | |
0.1, | |
-0.8, | |
-1.0, | |
-1.0 | |
], | |
[ | |
-0.4, | |
-0.9, | |
-0.2, | |
-2.2, | |
-1.7, | |
-0.5, | |
-2.0, | |
-0.8, | |
-2.9, | |
0.3, | |
-0.4, | |
-2.2, | |
-0.0, | |
-0.0, | |
-0.7, | |
-0.7, | |
-1.3, | |
-2.4, | |
-2.1, | |
-2.6 | |
], | |
[ | |
1.3, | |
1.2, | |
0.9, | |
0.0, | |
0.4, | |
1.0, | |
0.3, | |
1.3, | |
0.3, | |
1.1, | |
1.0, | |
0.2, | |
0.7, | |
1.9, | |
0.9, | |
-0.2, | |
0.3, | |
0.1, | |
-0.4, | |
-0.2 | |
], | |
[ | |
0.7, | |
0.5, | |
0.6, | |
-0.3, | |
-0.2, | |
0.5, | |
-0.3, | |
0.8, | |
-0.4, | |
1.0, | |
0.3, | |
-0.3, | |
1.0, | |
1.1, | |
0.6, | |
0.1, | |
0.3, | |
-0.7, | |
-0.5, | |
-0.6 | |
], | |
[ | |
-0.4, | |
-1.0, | |
-0.5, | |
-2.0, | |
-1.9, | |
-0.7, | |
-2.3, | |
-0.8, | |
-2.2, | |
0.2, | |
-0.3, | |
-2.7, | |
0.0, | |
-0.0, | |
-0.6, | |
-1.0, | |
-1.1, | |
-2.3, | |
-2.1, | |
-2.4 | |
], | |
[ | |
1.1, | |
1.3, | |
1.1, | |
-0.2, | |
0.3, | |
0.8, | |
-0.0, | |
1.1, | |
-0.0, | |
0.7, | |
1.0, | |
0.0, | |
1.6, | |
0.8, | |
1.0, | |
0.8, | |
0.7, | |
-0.2, | |
-0.2, | |
-0.2 | |
], | |
[ | |
1.3, | |
1.1, | |
0.8, | |
0.2, | |
0.4, | |
1.0, | |
-0.0, | |
1.3, | |
-0.0, | |
1.9, | |
1.1, | |
-0.0, | |
0.8, | |
1.2, | |
1.1, | |
0.0, | |
0.2, | |
-0.1, | |
-0.4, | |
0.0 | |
], | |
[ | |
0.6, | |
0.5, | |
0.6, | |
-0.8, | |
-0.3, | |
0.5, | |
-0.6, | |
0.4, | |
-0.7, | |
0.9, | |
0.6, | |
-0.6, | |
1.0, | |
1.1, | |
-0.2, | |
0.1, | |
-0.0, | |
-0.9, | |
-0.6, | |
-1.2 | |
], | |
[ | |
0.1, | |
-0.0, | |
0.1, | |
-1.6, | |
-0.8, | |
0.1, | |
-1.1, | |
0.1, | |
-0.7, | |
-0.2, | |
0.1, | |
-1.0, | |
0.8, | |
0.0, | |
0.1, | |
-0.6, | |
-0.4, | |
-1.2, | |
-1.3, | |
-1.4 | |
], | |
[ | |
-0.0, | |
-0.1, | |
-0.4, | |
-1.9, | |
-0.9, | |
-0.3, | |
-1.3, | |
0.1, | |
-1.3, | |
0.3, | |
0.3, | |
-1.1, | |
0.7, | |
0.2, | |
-0.0, | |
-0.4, | |
-1.3, | |
-1.4, | |
-1.6, | |
-1.9 | |
], | |
[ | |
-0.8, | |
-1.2, | |
-0.9, | |
-2.4, | |
-2.1, | |
-0.9, | |
-2.4, | |
-0.8, | |
-2.4, | |
0.1, | |
-0.7, | |
-2.3, | |
-0.2, | |
-0.1, | |
-0.9, | |
-1.2, | |
-1.4, | |
-3.0, | |
-2.3, | |
-2.5 | |
], | |
[ | |
-0.8, | |
-1.0, | |
-0.7, | |
-2.3, | |
-1.8, | |
-0.7, | |
-2.0, | |
-1.0, | |
-2.1, | |
-0.4, | |
-0.5, | |
-2.1, | |
-0.2, | |
-0.4, | |
-0.6, | |
-1.3, | |
-1.6, | |
-2.3, | |
-2.3, | |
-2.4 | |
], | |
[ | |
-1.0, | |
-0.9, | |
-0.8, | |
-2.6, | |
-2.0, | |
-1.1, | |
-2.2, | |
-1.0, | |
-2.6, | |
-0.2, | |
-0.6, | |
-2.4, | |
-0.2, | |
0.0, | |
-1.2, | |
-1.4, | |
-1.9, | |
-2.5, | |
-2.4, | |
-3.3 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment