//////////////////////////////////////////////////////////// //////////////////////// Set-up //////////////////////////// //////////////////////////////////////////////////////////// var screenWidth = $(window).width(); var margin = {left: 50, top: 10, right: 50, bottom: 10}, width = Math.min(screenWidth, 837) - margin.left - margin.right, height = Math.min(screenWidth, 1000)*5/6 - margin.top - margin.bottom; var svg = d3.select("#chart").append("svg") .attr("width", (width + margin.left + margin.right)) .attr("height", (height + margin.top + margin.bottom)); var wrapper = svg.append("g").attr("class", "chordWrapper") .attr("transform", "translate(" + (width / 2 + margin.left) + "," + (height / 2 + margin.top) + ")");; var outerRadius = Math.min(width, height) / 2 - 38, innerRadius = outerRadius * 0.95, opacityDefault = 0.7; //default opacity of chords //////////////////////////////////////////////////////////// ////////////////////////// Data //////////////////////////// //////////////////////////////////////////////////////////// var Names = ["JP_C_rice","JP_C_vege","JP_C_beet","JP_C_crop","JP_C_catt","JP_C_poul","JP_C_milk","JP_C_log","JP_C_fish","JP_P_catt","JP_P_pigs","JP_P_poul","JP_P_meat","JP_P_veol","JP_P_milk","JP_P_rice","JP_P_sugr","JP_P_food","JP_M_beve","JP_M_fish","JP_M_toba","JP_M_text","JP_M_wear","JP_M_lead","JP_MaL","JP_MaH","JP_EW","JP_SV","JP_WS","CN_C_rice","CN_C_whet","CN_C_cere","CN_C_vege","CN_C_veol","CN_C_beet","CN_C_fibe","CN_C_crop","CN_C_catt","CN_C_milk","CN_C_fish","CN_M_text","CN_M_wear","CN_MaL","CN_MaH","CN_SV","CN_WS"]; var matrix = [ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.24456896239267,2.48625986641241,6.87104300249218,6.49665258620817,0,3.24343024996437,1.37279212903782,1.78374973058659,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.37062395809914,0,1.44326929535257,1.55444932251103,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.48682061812272,5.5882210645631,15.2112396387516,6.10586460806787,0,1.10902854447763,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.82638586548896,1.34182929963808,3.65636627621685,1.52255832670813,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.23923231528867,0,1.89844022616676,1.97088065428454,0,1.01606369071913,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.51455310453536,1.38975488006952,3.86300237920274,3.72134141683419,1.00512024771531,2.12441641278176,1.45460792466876,1.01973545125683,0,0,3.75179176496191,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11.4087366038014,8.38260412902086,22.8676120618158,9.5805226310117,1.28928826806732,1.98186939273706,0,1.1841864535369,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12.2530407277062,9.06003559125539,24.6647334652793,10.214591141594,1.39759875063445,2.03383221401411,0,1.2279418699117,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.1738950902391,3.8322156812337,10.4335485819825,4.29647622288538,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.56820401247785,1.10890692800984,3.03694610828744,1.38921320851016,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.41130995529293,0,2.4632304588302,1.49006923059892,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.9435831255757,11.6072016801681,31.6112591240808,14.0946429070114,1.866764864189,3.55997877647611,0,1.95218889745668,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.74498857799882,1.81833606822414,5.05208672333949,4.5376214135313,0,2.23583716794977,1.08760160525134,1.26445625094264,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.87045523999298,1.32168760590215,3.59844181348678,1.55651750012923,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205.191495713843,145.166625880213,397.937142378002,167.925203247507,27.5582103852424,37.6410079611191,5.80619305890774,21.5514812345716,1.87739833629345,4.12425363982979,34.064544822925,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73.1356746785657,53.3178076566732,145.089836289274,66.8764467020215,8.32632193140644,16.9347610218779,2.48031323876608,9.70363343842062,0,1.57392576697525,1.87929108158798,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65.0124135015832,22.2712915947929,61.6337517211791,37.2152952242375,22.9193040435054,21.3058582996204,4.14114290754717,8.64467485181164,1.82974955336578,5.4512489189914,111.462581731058,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.58013165219703,0,1.95664754625559,2.41109261253383,0,1.37570611021604,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20.7524336804936,8.04805767132282,23.0000299893952,51.005689983255,4.18399562915068,31.8346673576344,45.8353530796487,15.8408373023976,2.22985136029268,4.06957574421984,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52.4834854138442,20.5940784881788,58.7741828496682,126.545909724458,10.4937167474703,78.8426134334199,111.551687669837,39.3729846008022,5.50963414279785,10.1242169147074,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.48193588287732,2.61175286212843,7.48869310850198,19.2662683319822,1.47839411244285,12.3421575354208,7.52603010809188,6.07435699472985,0,1.58967693731648,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47.7229983843322,22.0107848992266,61.3570257790307,79.8842860464119,9.9384451327269,45.9771597106406,13.6411880962715,26.005062127368,2.99059270111031,5.9209685455179,2.26018403558776,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,437.191940177834,183.171826808092,513.686007792141,791.835416885096,93.2910264759785,466.995882505598,165.460879889612,252.893182228988,31.0375848520704,60.1058888018537,22.3485427285945,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.396594167157,6.86830552158484,19.2061223098879,26.1025399668284,3.24828680259096,15.1375651916974,2.84085737970673,8.1553512595711,1.04836644938222,2.01769739358629,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,778.839008553452,405.665376025526,1119.65746095728,976.233766376056,156.3095545306,492.844165400431,200.065406811737,264.487871270658,32.7373429579711,69.070737729377,243.445899603837,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,183.917052085557,89.2825261245316,248.052821601758,271.737814923964,37.0428226891698,149.180106450422,92.1261402507195,78.198603515369,10.0133838871328,20.6155911886803,43.5988202938571,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,1.13910136439848,0,0,1.3279361378114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,1.39150453125183,0,0,2.49494170609481,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,1.65724647879036,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [2.77809612376032,3.44260309842666,1.71321353489778,11.8911223805324,4.40765995386462,0,5.41691964671411,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [4.97294974724892,8.30105718836724,3.11804152792467,8.01870596787135,4.5433489565773,0,5.63724170592827,0,1.83979866311464,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,1.00107289007028,0,1.24856615179079,0,0,1.11149989458434,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ]; var chord = d3.layout.chord() .padding(.02) .sortSubgroups(d3.descending) //sort the chords inside an arc from high to low .sortChords(d3.descending) //which chord should be shown on top when chords cross. Now the biggest chord is at the bottom .matrix(matrix); var arc = d3.svg.arc() .innerRadius(innerRadius) .outerRadius(outerRadius); var path = d3.svg.chord() .radius(innerRadius); var fill = d3.scale.ordinal() .domain(d3.range(Names.length)) .range(["#9fe901","#01e8fd","#fb31dd","#f9fd01","#7701fd"]); //////////////////////////////////////////////////////////// //////////////////// Draw outer Arcs /////////////////////// //////////////////////////////////////////////////////////// var g = wrapper.selectAll("g.group") .data(chord.groups) .enter().append("g") .attr("class", "group");; g.append("path") .style("stroke", function(d) { return fill(d.index); }) .style("fill", function(d) { return fill(d.index); }) .attr("d", arc); //////////////////////////////////////////////////////////// ////////////////////// Append Names //////////////////////// //////////////////////////////////////////////////////////// g.append("text") .each(function(d) { d.angle = ((d.startAngle + d.endAngle) / 2);}) .attr("dy", ".35em") .attr("class", "titles") .attr("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; }) .attr("transform", function(d,i) { var c = arc.centroid(d); return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")" + "translate(" + (innerRadius + 27) + ")" + (d.angle > Math.PI ? "rotate(180)" : "") }) .text(function(d,i) { return Names[i]; }); //+ "translate(" + (innerRadius + 55) + ")" //////////////////////////////////////////////////////////// //////////////////// Draw inner chords ///////////////////// //////////////////////////////////////////////////////////// var colors = ["#3fcf73","#ead63d","#01e8fd","#fc2f2f","#843fcf"]; var chords = wrapper.selectAll("path.chord") .data(chord.chords) .enter().append("path") .attr("class", "chord") .style("stroke", "none") .style("fill", function(d,i) { return fill(d.target.index); }) .style("opacity", opacityDefault) .attr("d", path); //////////////////////////////////////////////////////////// ///////////////////////// Tooltip ////////////////////////// //////////////////////////////////////////////////////////// //Arcs g.append("title") .text(function(d, i) {return Math.round(d.value) + " food in " + Names[i];}); //Chords chords.append("title") .text(function(d) { return [Math.round(d.source.value), " food from ", Names[d.target.index], " to ", Names[d.source.index]].join(""); });