This is an attempt to integrate VisDock into Mike Bostock's Square Circle Spiral Illusion. A few modifications and addition of lines allow users to query rotating squares. For more about VisDock, click here.
Last active
August 29, 2015 13:56
-
-
Save VisDockHub/9214036 to your computer and use it in GitHub Desktop.
VisDock in Square Circle Spiral Illusion
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> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
<style type="text/css"> | |
body { | |
} | |
.square:nth-child(2n + 1) rect { | |
stroke: #000; | |
stroke-width: 2.5px; | |
} | |
.square:nth-child(2n) rect { | |
stroke: #fff; | |
stroke-width: 2.5px; | |
} | |
</style> | |
</head> | |
<body> | |
<link href="http://rawgithub.com/VisDockHub/NewVisDock/master/master/visdock.css" rel="stylesheet" type="text/css"/> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://rawgithub.com/VisDockHub/NewVisDock/master/master/visdock.js"></script> | |
<script src="http://rawgithub.com/VisDockHub/NewVisDock/master/master/2D.js"></script> | |
<script src="http://rawgithub.com/VisDockHub/NewVisDock/master/master/IntersectionUtilities.js"></script> | |
<script src="http://rawgithub.com/VisDockHub/NewVisDock/master/master/visdock.utils.js"></script> | |
<script type="text/javascript"> | |
var w = 960, | |
h = 500, | |
start = Date.now(); | |
var rings = [ | |
{radius: 65 * 1, width: 16, speed: -3e-2}, | |
{radius: 65 * 2, width: 16, speed: -2e-2}, | |
{radius: 65 * 3, width: 16, speed: -1e-2}, | |
{radius: 65 * 4, width: 16, speed: 1e-2}, | |
{radius: 65 * 5, width: 16, speed: 2e-2}, | |
{radius: 65 * 6, width: 16, speed: 3e-2} | |
]; | |
VisDock.init("body", {width: 960, height: 700}); | |
AnnotatedByData.layerTypes = [".squareElement"]; | |
var viewport = VisDock.getViewport(); | |
var svg = viewport | |
.append("svg:g") | |
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")scale(.6)"); | |
var ring = svg.selectAll("g") | |
.data(rings) | |
.enter().append("svg:g") | |
.attr("class", "ring") | |
.each(ringEnter); | |
d3.timer(function() { | |
VisDock.startChrome(); | |
var elapsed = Date.now() - start, | |
rotate = function(d) { return "rotate(" + d.speed * elapsed + ")"; }; | |
ring | |
.attr("transform", rotate) | |
.selectAll("rect") | |
.attr("transform", rotate); | |
AnnotatedByData.update(); | |
VisDock.finishChrome(); | |
}); | |
function ringEnter(d, i) { | |
var n = Math.floor(2 * Math.PI * d.radius / d.width * Math.SQRT1_2), | |
k = 360 / n; | |
d3.selectAll(".panel")[0][0].setAttribute("style", "fill: #888"); | |
var square = d3.select(this).selectAll("g") | |
.data(d3.range(n).map(function() { return d; })) | |
.enter().append("svg:g") | |
.attr("class", "square") | |
.attr("transform", function(_, i) { return "rotate(" + i * k + ")translate(" + d.radius + ")"; }); | |
square.append("svg:rect") | |
.attr("class", "squareElement") | |
.attr("x", -d.width / 2) | |
.attr("y", -d.width / 2) | |
.attr("fill", "none") | |
.attr("width", d.width) | |
.attr("height", d.width); | |
} | |
VisDock.eventHandler = { | |
getHitsPolygon : function(points, inclusive) { | |
var shapebound = new createPolygon(points); | |
return shapebound.intersectPolygon(d3.selectAll(".squareElement")[0], inclusive); | |
}, | |
getHitsLine : function(points, inclusive) { | |
var shapebound = new createLine(points); | |
return shapebound.intersectPolygon(d3.selectAll(".squareElement")[0], inclusive); | |
}, | |
getHitsEllipse : function(points, inclusive) { | |
var shapebound = new createEllipse(points); | |
return shapebound.intersectPolygon(d3.selectAll(".squareElement")[0], inclusive); | |
}, | |
setColor : function(hits) { | |
QueryManager.layers[num - 1] = []; | |
for (var i = 0; i < hits.length; i++) { | |
var str = hits[i].getAttributeNS(null, "transform"); | |
var width = hits[i].getAttributeNS(null, "width"); | |
var height = hits[i].getAttributeNS(null, "height"); | |
QueryManager.layers[num - 1][i] = d3.select(hits[i].parentNode).append("rect") | |
.attr("width", width).attr("height", height).attr("x", -8).attr("y", -8) | |
.attr("style", "fill: " + VisDock.color[num - 1] + "; opacity: 1; pointer-events: none"); | |
} | |
}, | |
changeColor : function(color, query, index) { | |
VisDock.utils.changeQueryColor(index, color) | |
var visibility = VisDock.utils.getQueryVisibility(index); | |
for (var i = 0; i < query.length; i++) { | |
query[i].attr("style", "opacity: " + visibility + "; fill: " + color); | |
} | |
}, | |
changeVisibility : function(vis, query, index) { | |
var color = VisDock.utils.getQueryColor(index); | |
for (var i = 0; i < query.length; i++) { | |
query[i].attr("style", "opacity: " + vis + "; fill: " + color); | |
} | |
}, | |
removeColor : function(hits, index) { | |
for (var i = 0; i < hits.length; i++) { | |
hits[i].remove(); | |
} | |
} | |
}; | |
BirdView.init(viewport, 960, 700); | |
d3.select(self.frameElement).style("width", "960px"); | |
d3.select(self.frameElement).style("height", "700px") ; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment