Last active
August 29, 2015 13:56
-
-
Save VisDockHub/8971488 to your computer and use it in GitHub Desktop.
Zoomable Layout
This file contains hidden or 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> | |
| <meta charset="utf-8"> | |
| <style> | |
| .background { | |
| fill: none; | |
| pointer-events: all; | |
| } | |
| #states { | |
| fill: #aaa; | |
| } | |
| #states .active { | |
| fill: orange; | |
| } | |
| #state-borders { | |
| fill: none; | |
| stroke: #fff; | |
| stroke-width: 1.5px; | |
| stroke-linejoin: round; | |
| stroke-linecap: round; | |
| pointer-events: none; | |
| } | |
| </style> | |
| <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://d3js.org/topojson.v1.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> | |
| var width = 960, | |
| height = 500, | |
| centered; | |
| VisDock.init("body", {width: 960, height: 700}); | |
| var viewport = VisDock.getViewport(); | |
| var projection = d3.geo.albersUsa() | |
| .scale(1070) | |
| .translate([width / 2, height / 2]); | |
| var path = d3.geo.path() | |
| .projection(projection); | |
| var svg = viewport; | |
| svg.append("rect") | |
| .attr("class", "background") | |
| .attr("width", width) | |
| .attr("height", height) | |
| .on("click", clicked); | |
| var g = svg.append("g"); | |
| d3.json("us.json", function(error, us) { | |
| g.append("g") | |
| .attr("id", "states") | |
| .selectAll("path") | |
| .data(topojson.feature(us, us.objects.states).features) | |
| .enter().append("path") | |
| .attr("d", path) | |
| .on("click", clicked); | |
| g.append("path") | |
| .datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; })) | |
| .attr("id", "state-borders") | |
| .attr("d", path); | |
| }); | |
| function clicked(d) { | |
| VisDock.startChrome(); | |
| var x, y, k; | |
| if (d && centered !== d) { | |
| var centroid = path.centroid(d); | |
| x = centroid[0]; | |
| y = centroid[1]; | |
| k = 4; | |
| centered = d; | |
| } else { | |
| x = width / 2; | |
| y = height / 2; | |
| k = 1; | |
| centered = null; | |
| } | |
| g.selectAll("path") | |
| .classed("active", centered && function(d) { return d === centered; }); | |
| g.transition() | |
| .duration(750) | |
| .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")") | |
| .style("stroke-width", 1.5 / k + "px"); | |
| VisDock.finishChrome(); | |
| } | |
| // VisDock Event Handler | |
| VisDock.eventHandler = { | |
| getHitsPolygon : function(points, inclusive) { | |
| var shapebound = new createPolygon(points); | |
| return shapebound.intersectPath(d3.selectAll("#states").selectAll("path")[0], inclusive) | |
| }, | |
| getHitsLine : function(points, inclusive) { | |
| var shapebound = new createLine(points); | |
| return shapebound.intersectPath(d3.selectAll("#states").selectAll("path")[0], inclusive) | |
| }, | |
| getHitsEllipse : function(points, inclusive) { | |
| var shapebound = new createEllipse(points); | |
| return shapebound.intersectPath(d3.selectAll("#states").selectAll("path")[0], inclusive) | |
| }, | |
| setColor : function(hits) { | |
| QueryManager.layers[num - 1] = []; | |
| for (var i = 0; i < hits.length; i++) { | |
| var str = hits[i].getAttributeNS(null, "d") | |
| QueryManager.layers[num - 1][i] = d3.selectAll("#states").append("path").attr("d", str) | |
| .attr("style", "fill: " + VisDock.color[num - 1] + "; opacity: 0.5; pointer-events: none"); | |
| } | |
| }, | |
| changeColor : function(color, query, index) { | |
| var vis = VisDock.utils.getQueryVisibility(index); | |
| for (var i = 0; i < query.length; i++) { | |
| query[i][0][0].setAttributeNS(null, "style", "fill: " + color + "; opacity: " + vis) | |
| } | |
| }, | |
| changeVisibility : function(vis, query) { | |
| var color = VisDock.utils.getQueryColor(index); | |
| for (var i = 0; i < query.length; i++) { | |
| query[i][0][0].setAttributeNS(null, "style", "fill: " + color + "; opacity: " + vis) | |
| } | |
| }, | |
| removeColor : function(hits, index) { | |
| for (var i = 0; i < hits.length; i++) { | |
| hits[i].remove(); | |
| } | |
| }, | |
| QueryClick : function(query, index) { | |
| } | |
| } | |
| BirdView.init(viewport, 960, 700) | |
| d3.select(self.frameElement).style("width", "960px") | |
| d3.select(self.frameElement).style("height", "700px") | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment