forked from eleyine's block: Visa requirements in Arab countries
forked from sohaibghani1's block: chord test
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Species Chord Diagram</title>
<style>
@import url(style.css);
#circle circle {
fill: none;
pointer-events: all;
}
.group path {
fill-opacity: 1;
stroke: #000;
stroke-width: .25px;
}
path.chord {
stroke: #000;
stroke-width: .25px;
fill-opacity: .45;
stroke-opacity: .8;
}
#circle:hover path.fade {
display: none;
}
</style>
</head>
<!-- <p>Built with <a href="https://d3js.org/">d3.js</a>. -->
<body>
<div>
<button id='saveButton'>Export my D3 visualization to PNG</button>
</div>
<div id="crowbar-workspace">
</div>
</body>
<script src="https://d3js.org/d3.v2.min.js?2.8.1"></script>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/gh/eligrey/canvas-toblob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toblob.js"></script>
<script src="https://cdn.jsdelivr.net/gh/eligrey/filesaver.js/e9d941381475b5df8b7d7691013401e171014e89/filesaver.min.js"></script>
<!-- <script src="imagesave.js"></script> -->
<script type="text/javascript">
var width = 1200,
height = $(window).height()-20,
outerRadius = Math.min(width, height) / 2 - 80,
innerRadius = outerRadius - 24;
var formatPercent = d3.format(".3f");
var arc = d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius);
var layout = d3.layout.chord()
.padding(.045)
.sortSubgroups(d3.descending)
.sortChords(d3.ascending);
var path = d3.svg.chord()
.radius(innerRadius-5);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("id", "circle")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
svg.append("circle")
.attr("r", outerRadius);
var cities = ["X","Y","Z","Dummy","C","B","A","Dummy"];
// var matrix = [
// [0,1,0,0,1,1,1,0], //X
// [1,0,0,0,1,1,1,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
// Compute the chord layout.
layout.matrix(matrix);
// Add a group per neighborhood.
var group = svg.selectAll(".group")
.data(layout.groups)
.enter().append("g")
.attr("class", "group")
.on("mouseover", mouseover);
// Add a mouseover title.
group.append("title").text(function(d, i) {
return cities[i].name + ", Total Value:" + formatPercent(d.value)
});
// Add the group arc.
var groupPath = group.append("path")
.attr("id", function(d, i) { return "group" + i; })
.attr("d", arc)
.style("fill", function(d, i) { return cities[i].color; });
// Add a text label.
var groupText = group.append("text")
//.attr("x", function(d, i){console.log( groupPath[0][i].getTotalLength()/2);}) //6
.attr("dy", 15)
// groupText.append("textPath")
// .attr("xlink:href", function(d, i) { return "#group" + i; })
// .text(function(d, i) { return cities[i].name; });
// Remove the labels that don't fit. :(
// groupText.filter(function(d, i) { return groupPath[0][i].getTotalLength() / 2 - 30 < this.getComputedTextLength(); })
// .remove();
group.append("svg:text")
.each(function(d,i) { d.angle = (d.startAngle + d.endAngle) / 2; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
.attr("transform", function(d) {
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")"
+ "translate(" + (innerRadius + 30) + ")"
+ (d.angle > Math.PI ? "rotate(180)" : "");
})
.text(function(d,i) { return cities[i].name; })
.style("fill", function(d, i) { return cities[i].color; })
.attr("shape-rendering","crispEdges")
.attr("font-family","cursive")
.attr("font-size","15px");
// Add the chords.
var chord = svg.selectAll(".chord")
.data(layout.chords)
.enter().append("path")
.attr("class", "chord")
.style("fill", function(d,i) {
//console.log(d);
//console.log(matrix2[d.source.index][d.target.index]);
if(matrix2[d.source.index][d.target.index] < 0) return 'red';
else return 'green';
//return cities[d.source.index].color;
})
.attr("d", path);
//Add an elaborate mouseover title for each chord.
chord.append("title").text(function(d) {
return cities[d.source.index].name
+ " → " + cities[d.target.index].name
+ ": " + formatPercent(d.source.value)
+ "\n" + cities[d.target.index].name
+ " → " + cities[d.source.index].name
+ ": " + formatPercent(d.target.value);
});
function mouseover(d, i) {
chord.classed("fade", function(p) {
return p.source.index != i
&& p.target.index != i;
});
}
//Append Legend
var teams = [
"Invasive Marines" ,
"Native Marines",
"Terrestrial Marines",
"Positive Chords",
"Negative Chords",
];
var colors = [ "#DF7C00", "#BFAE40", "#083E77","green","red"];
var color = d3.scale.ordinal() //custom color scale for teams
.range(colors)
.domain(teams);
svg.append("rect")
.attr("x",-width/2)
.attr("y",-height/2)
.attr("width",150)
.attr("height",120)
.attr("style","fill-opacity:0;stroke:black;stroke-width:1.5px");
var legend = svg.append("g")
.attr("class", "legend")
.attr("width", 150)
.attr("height", 150)
.attr("transform", "translate(-"+ ((width/2)-5) + ",-"+ ((height/2)-10) +" )");
var gs = legend.selectAll("g.keybox")
.data(teams).enter().append("g")
.attr("class", "keybox")
.attr("width", 80)
.attr("height", 15);
gs.append("text")
.attr("class","keybox").attr("x",function(d,i){
if(i<5){return 15;}
else{return 90;}})
.attr("y",function(d,i){
if(i<5){return i*20 +9;}
else{return (i-4)*20 +9;}})
.text(function(d,i){
return teams[i];})
;
gs.append("rect")
.attr("x",function(d,i){
if(i<5){return 0;}
else{return 75;}})
.attr("y",function(d,i){
if(i<5){return i*20;}
else{return (i-4) * 20;}})
.attr("width",10)
.attr("height",10)
.style("fill",function(d, i){
return colors[i];});
});
});
d3.select("#saveButton").on("click", download_png)
function download_png () {
// this is a shitty hack that should probably be embedded in the
// svg_crowbar function
var svg_el = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "https://www.w3.org/2000/svg")
.node();
// this is the main thing that does the work
svg_crowbar(svg.node(), {
filename: "export-me.png",
width: 100,
height: 100,
crowbar_el: d3.select("#crowbar-workspace").node(),
})
}
</script>
</html>
Modified http://d3js.org/d3.v2.min.js?2.8.1 to a secure url
Updated missing url https://cdn.rawgit.com/eligrey/canvas-toBlob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toBlob.js to https://cdn.jsdelivr.net/gh/eligrey/canvas-toblob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toblob.js
Updated missing url https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js to https://cdn.jsdelivr.net/gh/eligrey/filesaver.js/e9d941381475b5df8b7d7691013401e171014e89/filesaver.min.js
https://d3js.org/d3.v2.min.js?2.8.1
https://cdn.rawgit.com/eligrey/canvas-toBlob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toBlob.js
https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js