vis_app_1_axes

by Simon Raper

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-tip/0.6.7/d3-tip.min.js"></script>
<div id ="container">
    <div id ="header">
        <h1>Demo Scatterplot</h1>
    </div>
    <div id ="sidebar">
    </div>
    <div id ="content">
        <svg height="400" width="650">
        </svg>
    </div>
    <div id ="footer">
    </div>
 </div>

CSS

h1 {
  font-family:  'Raleway';
	font-weight: normal;
  font-size: 1.2em;
	letter-spacing: .2em;
	line-height: 1.1em;
	margin:0px;
	text-align: left;
	text-transform: uppercase;
}
#container {
    width:800px;
}

#header {
    width:800px;
    height: 50px;
    padding: 5px;
}

#sidebar {
    height:400px;
    width:150px;
    float:left;
}

#content {
    background-color:#ffffff;
    height:400px;
    width:650px;
    float:left;
}
#footer {
    width:800px;
    height: 50px;
    float:left;
}

circle {
    stroke: #1abc9c;
    stroke-width: 2;
    fill: white;
}

.d3-tip {
    font-family:  'Raleway';
    line-height: 1;
    padding: 1px;
    background: transparent;
    color: #000;
    border-radius: 2px;
}

.axis path, .axis line {
    fill: none;
    stroke: grey;
    shape-rendering: crispEdges;
}
.axis text {
    font-family: 'Raleway';
    font-size: 11px;

JavaScript

//Set up the data

progs = [{
        "name": "Cops",
        "group": 1,
        "audience_size": 34,
        "avg_mins_viewed": 33.5
    }, {
        "name": "The Day This Morning",
        "group": 1,
        "audience_size": 16,
        "avg_mins_viewed": 4.6
    }, {
        "name": "Love Rats",
        "group": 2,
        "audience_size": 11,
        "avg_mins_viewed": 22.2
    }, {
        "name": "Big Feet",
        "group": 2,
        "audience_size": 28,
        "avg_mins_viewed": 33.5
    }, {
        "name": "Another Reality Show",
        "group": 2,
        "audience_size": 10,
        "avg_mins_viewed": 64.1
    }, {
        "name": "Star Wars Makeovers",
        "group": 3,
        "audience_size": 4,
        "avg_mins_viewed": 12.9
    }, {
        "name": "Film Night",
        "group": 3,
        "audience_size": 8,
        "avg_mins_viewed": 10.0
    }, {
        "name": "The Evening News",
        "group": 1,
        "audience_size": 44,
        "avg_mins_viewed": 49.1
    }, {
        "name": "Bored",
        "group": 3,
        "audience_size": 18,
        "avg_mins_viewed": 61.1
    }];
    
    
//Set constants
var w = 420,
    h = 400,
    padding = 30;
    
    
//Create adaptable scales
var xScale = d3.scale.linear()
.domain([0, d3.max(progs, function(d) {return d.audience_size;})])
    .range([padding, w - padding]);
var yScale = d3.scale.linear()
    .domain([0, d3.max(progs, function(d) {return d.avg_mins_viewed;})])
    .range([h - padding, padding]);
    
 //Select the svg
 svg = d3.select("svg");
     
 //Define and set up the tooltip
 var tip = d3.tip()
         .attr('class', 'd3-tip')
         .offset([-10, 0])
         .html(function (d) {
         return d.name;
     });
 svg.call(tip);
     
     
 //Set up the circles
 diag_circles = svg.selectAll("circle");
 diag_circles.data(progs)
     .enter()
     .append("circle")
			.attr("cx", function(d){return xScale(d.audience_size)})
			.attr("cy", function(d){return...