From b2dc9a920e7a45616cd05ce2e75eb2b03a88f2c4 Mon Sep 17 00:00:00 2001 From: Chris Viau Date: Wed, 5 Aug 2015 09:43:03 -0400 Subject: [PATCH] Sort contours to get smaller on top on example.html --- example/example.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/example/example.html b/example/example.html index fa22560..7325118 100644 --- a/example/example.html +++ b/example/example.html @@ -27,12 +27,23 @@ 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); +// Sort contours by size so small ones get on top +var contourList = c.contourList() + .sort(function(a, b){ + var extentXA = d3.extent(a.map(function(d){ return d.x; })); + var extentYA = d3.extent(a.map(function(d){ return d.y; })); + var areaA = (extentXA[1] - extentXA[0]) * (extentYA[1] - extentYA[0]); + var extentXB = d3.extent(b.map(function(d){ return d.x; })); + var extentYB = d3.extent(b.map(function(d){ return d.y; })); + var areaB = (extentXB[1] - extentXB[0]) * (extentYB[1] - extentYB[0]); + return areaB - areaA; + }); d3.select("body").append("svg") .attr("width", width) .attr("height", height) .selectAll("path") - .data(c.contourList()) + .data(contourList) .enter().append("path") .style("fill",function(d) { return colours(d.level);}) .style("stroke","black")