[ Launch: Hexbin experiments ] 5640887 by Mimieam
[ Launch: Hexbin experiments ] 5574625 by enjalot
[ Launch: Hexbin experiments ] 5574274 by biovisualize
-
-
Save Mimieam/5640887 to your computer and use it in GitHub Desktop.
Hexbin experiments
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
{"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":600,"height":300,"hide":false},"description":"Hexbin experiments","endpoint":"","display":"svg","public":true,"require":[{"name":"hexbin","url":"http://d3js.org/d3.hexbin.v0.min.js?5c6e4f0"}],"fileconfigs":{"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
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
//Change these values | |
var hexRadius = 43; | |
var radiusOffset = 12.35728; | |
var drag = d3.behavior.drag() | |
.on('drag',dragmove); | |
var margin = {top: -1, right: 14, bottom: 0, left: 35}, | |
width = tributary.sw | |
height = tributary.sh | |
var dx = (hexRadius * 2 * Math.sin(Math.PI / 3)); | |
var dy = hexRadius * 1.34501892096 | |
var points = []; | |
var colNum = ~~(width / hexRadius)-1; | |
var rowNum = ~~(height / hexRadius)-5; | |
for (var i = 0; i < rowNum; i++) { | |
for (var j = 0; j < colNum; j++) { | |
var offset = (i%2 === 0)? 0 : -dx/2; | |
points.push([dx * j + offset, dy * i]); | |
} | |
} | |
var hexbin = d3.hexbin() | |
.size([width, height]) | |
.radius(hexRadius-radiusOffset); | |
var svg = d3.select("svg") | |
svg.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
svg.append("clipPath") | |
.attr("id", "clip") | |
.append("rect") | |
.attr("class", "mesh") | |
.attr("width", width) | |
.attr("height", height); | |
var clippedGroup = svg.append("g") | |
.attr("clip-path", "url(#clip)"); | |
clippedGroup.selectAll(".hexagon") | |
.data(hexbin(points)) | |
.enter().append("path") | |
.attr("class", "hexagon") | |
.attr("d", hexbin.hexagon()) | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) | |
.style("stroke", function(d) { return 'red' ; }); | |
clippedGroup.selectAll('circle') | |
.data(points) | |
.enter().append('circle') | |
.attr({ | |
cx: function(d, i){return d[0];}, | |
cy: function(d, i){return d[1];}, | |
r: 18.92 | |
}) | |
.call(drag); | |
function dragmove(d) { | |
d3.select(this) | |
.attr("y", d3.event.y) | |
.attr("x", d3.event.x) | |
} |
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
.axis text { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.hexagon { | |
fill: orange; | |
stroke: #000; | |
stroke-width: 1px; | |
} | |
circle{ | |
fill: green; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment