block by davo c5239219b1c808bd7e02

Bono Scale

Full Screen

Learning how to make a threshold scale while making a tribute to the lead singer of U2 and his well-known proficent spanish.

Built with blockbuilder.org

index.html

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
  <style>
    body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
    svg { width: 100%; height: 100%; font-family: Helvetica, Arial, _sans; font-size: .75em; }
		
    .axis text {
      font: 10px sans-serif;
    }

    .axis path, .axis line {
      fill: none;
      stroke: #000;
      shape-rendering: crispEdges;
    }
    .caption {
      font-weight: bold;
    }
  </style>
</head>

<body>
  <script>
    
    var vertigo = [1,2,3,14];
    
    var width = 960,
        height = 500;

    var threshold = d3.scale.threshold()
    	.domain(vertigo)
    
    var x = d3.scale.linear()
        .domain([1, 14])
        .range([1, 600])

    var xAxis = d3.svg.axis()
        .scale(x).tickSize(13).tickValues(threshold.domain())
        .orient("bottom");

    var svg = d3.select("body").append("svg")
        .attr("width", width)
        .attr("height", height)
      .append("g")
    		.attr("transform", "translate(" + (width-600) / 2 + "," + height / 2 + ")");
    svg.append("g")
        .attr("class", "x axis")
        .call(xAxis);

    svg.call(xAxis).append("text")
        .attr("class", "caption")
        .attr("y", -9)
        .text("Bono Scale");
    
  </script>
</body>