index.html 4.58 KB
Newer Older
Daniel Teixeira's avatar
Daniel Teixeira committed
1 2
<!DOCTYPE html>
<meta charset="utf-8"/>
Daniel Teixeira's avatar
Daniel Teixeira committed
3
<title>SIB Core Resources</title>
Daniel Teixeira's avatar
Daniel Teixeira committed
4 5
<link href="css/matrix.css" rel="stylesheet" type="text/css" />

Daniel Teixeira's avatar
Daniel Teixeira committed
6
<p>This wheel shows how some SIB resources are connected together (based on Google Analytics).</p>
Daniel Teixeira's avatar
Daniel Teixeira committed
7
<p>It is a demo for the service <a href="https://pages.sib.swiss">pages.sib.swiss</a> that shows how a static webpage (html/javascript/css) can be served from GitLab (even with D3 libary as it is the case here).</p>
Daniel Teixeira's avatar
Daniel Teixeira committed
8

Daniel Teixeira's avatar
Daniel Teixeira committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>

<aside></aside>

<div id="info"> </div>
<script type="text/javascript" src="https://d3js.org/d3.v2.js"></script>
<script>

var width = 840,
    height = 840,
    outerRadius = Math.min(width, height) / 3.5,
    innerRadius = outerRadius - 20;

var formatPercent = d3.format(",.2f");

var arc = d3.svg.arc()
    .innerRadius(innerRadius)
    .outerRadius(outerRadius);

var layout = d3.layout.chord()
    .padding(.05)
    .sortSubgroups(d3.descending)
    .sortChords(d3.ascending);

var path = d3.svg.chord()
    .radius(innerRadius);

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 + ")");

  var info = d3.select("#info");



svg.append("circle")
    .attr("r", outerRadius);

function setHeader(xhr) {
        xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
}

$.ajax({
          url: 'data.json',
          type: 'GET',
          dataType: 'json',
          success: function(data) { process(data); },
          error: function() { alert('boo!'); },
          beforeSend: setHeader
  });

function colores_google(n) {
  var colores_g = ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707", "#651067", "#329262", "#5574a6", "#3b3eac"];
  return colores_g[n % colores_g.length];
}

var process = function(data) {

    var apps = [];

    for(var i=0; i<data.header.length; i++){
      apps.push({"feeType" : "Payments", "name": data.header[i], "color": colores_google(i)})
    }

    console.log(apps);

    // Compute the chord layout.
    layout.matrix(data.matrix);

    // Add a group per neighborhood.
    var group = svg.selectAll(".group")
        .data(layout.groups)
      .enter().append("g")
        .attr("class", "group")
        .on("mouseover", mouseover)
        .on("mouseout", mouseout);

    // Add the group arc.
    var groupPath = group.append("path")
        .attr("id", function(d, i) { return "group" + i; })
        .attr("d", arc)
        .attr("class", "arc")
        .style("fill", function(d, i) { return apps[i].color; });

  group.append("svg:text")
      .each(function(d) { 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(" + (outerRadius + 6) + ")"
            + (d.angle > Math.PI ? "rotate(180)" : "");
      })
      .style("fill", function(d, i) { return apps[i].color; })
      .text(function(d, i) { return apps[i].name; });

    // Add the chords.
    var chord = svg.selectAll(".chord")
        .data(layout.chords)
      .enter().append("path")
        .attr("class", "chord")
        .style("fill", function(d) { return apps[d.target.index].color; })
        .attr("d", path)
        .on("mouseover", chordMouseover)
        .on("mouseout", mouseout);

    // Add an elaborate mouseover title for each chord.
    chord.append("title").html(function(d) {
Daniel Teixeira's avatar
Daniel Teixeira committed
123
      var text = apps[d.target.index].name + " contains HTTP links to " +  apps[d.source.index].name + " <br/> ";
Daniel Teixeira's avatar
Daniel Teixeira committed
124 125

      if(d.target.value > 0){
Daniel Teixeira's avatar
Daniel Teixeira committed
126
        text+= apps[d.source.index].name + " contains HTTP links to " + apps[d.target.index].name ;
Daniel Teixeira's avatar
Daniel Teixeira committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
      }
      return text;
    });

    function mouseover(d, i) {
      chord.classed("fade", function(p) {
        return p.source.index != i
            && p.target.index != i;
      });

      chord.classed("show", function(p) {
        return p.source.index == i
            || p.target.index == i;
      });

      d3.select("#info")
        .text(this.textContent);
    }

    function mouseout(d, i) {

      d3.select("#info").text("");
    }

    function chordMouseover(d, i) {

      d3.select("#info")
      	.text(this.textContent);
    }
  };

</script>

</html>