xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Adding Padding</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('rect').click(function() {
console.log('clicked a rect');
$(this).attr("fill","#fc9000");
});
$('#hideme').click(function() {
$('#thechart').toggle('fast');
});
});
</script>
<style type="text/css">
body {
background-color: #ddddff;
font-family: Arial;
}
svg {
background-color: white;
}
circle {
fill: orange;
stroke-width: 3px;
stroke: orange;
opacity: 0.3;
stroke-opacity: 0.8;
}
circle.clickable:hover {
fill: yellow;
stroke: black;
opacity: 0.7;
}
g.axis path, g.axis line {
stroke: green;
fill: none;
shape-rendering: crispEdges;
}
g.axis text {
font-family: Arial;
font-size: 14px;
opacity: 0.5;
text-anchor: left;
}
g.tick {
fill: black;
opacity: 0.5;
text-anchor: left;
}
g.axis.y line, g.axis.y path {
stroke: orange;
opacity: 0.5;
}
#databox p {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<h1>Corety RTU-3 Mixed Air Temps</h1>
<p>Date range 2014 January</p>
<p><small><a id="hideme">hideChart</a></small></p>
<div id="thechart" style="border: 1px solid red; width: 800px; float: left;">
<script type="text/javascript">
var col1 = '64651.Corey Building.RTU-3.Mixed AIr Temp';
var col2 = '64601.Corey Building.RTU-3.Discharge Air Temp (°F)';
var radi = '64656.Corey Building.RTU-3.ZN-Q (PPM)';
var w = 800;
var h = 800;
var padding = [40, 220, 80, 80 ]; //Top, right, bottom, left
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[1] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(3)
.tickFormat(function(d) {
return d + '°F';
});
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("right")
.ticks(20)
.tickFormat(function(d) {
return d + '°F';
});
var svg = d3.select("body #thechart")
.append("svg")
.attr("id","svg")
.attr("width", w)
.attr("height", h);
d3.select("svg")
.append("h1")
.attr("width",500)
.attr("height",200)
.attr("fill","yellow")
.text("h1 text inside of svg"); // I didn't expect this to work but thought I should try.
d3.csv("Corey.RTU-3-short-2.csv", function(data) {
//console.log(d3.entries(data));
data.sort(function(a, b) {
return d3.descending(a[radi], b[radi]);
});
//data.push(['Corey.RTU-3','2015-01-02 11:00:00','100','74.27','58.72','410.5','0','19.9','0.25','0','0','0','Th','1','10.68']);
var minco2 = d3.min(data, function(d) {
return +d[radi];
});
console.log(minco2);
xScale.domain([
d3.min(data, function(d) {
return +d[col1];
})
,
d3.max(data, function(d) {
return +d[col1];
})
]);
yScale.domain([
d3.min(data, function(d) {
return +d[col2];
})
,
d3.max(data, function(d) {
return +d[col2];
})
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles
.attr("cx", function(d, i) {
return xScale(+d[col1]);
})
.attr("cy", function(d,i) {
return yScale(+(d[col2]));
})
.attr("r", function(d) {
//return (getr(d));
return (3);
})
//.attr("height", yScale.rangeBand())
.attr("class","clickable")
.append("title")
.text(function(d) {
return "dt=" + d.DateTime + " cx= " + parseFloat(d[col1]).toFixed(2) + ' cy=' + parseFloat(d[col2]).toFixed(2) + " r=" + parseFloat(d[radi]).toFixed(1);
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + "0," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (w - padding[1]) + ",0)")
.call(yAxis);
d3.selectAll('circle').on('click', function(d) {
console.log('clicked a circle');
d3.select(this).style('fill', '#ff0000').style('opacity',0.9);
$('#databox').append('<p>' + d.DateTime + ' ' + parseFloat(d[col1]).toFixed(2) + ',' + parseFloat(d[col2]).toFixed(2) + ',' + parseFloat(d[radi]).toFixed(2) + '</p>');
});
d3.selectAll('circle').on('mouseover', function(d) {
$('#current').html('<p>' + d.DateTime + ' ' + parseFloat(d[col1]).toFixed(2) + ',' + parseFloat(d[col2]).toFixed(2) + ',' + parseFloat(d[radi]).toFixed(2) + '</p>');
d3.select(this)
.transition()
.duration(100)
.attr('r',function(d) {
return getr(d)*1.1;
})
.transition()
.duration(100)
.attr('r',function(d) {
return getr(d)*1.0;
})
});
circles
.sort(function(a,b) {
return d3.ascending(+a[radi],+b[radi]);
})
.transition()
.delay(function(d,i){
return d[radi]-minco2; //300*Math.random();
})
.duration(function(d,i) {
return 40*(d[radi]-minco2); //300*Math.random();
})
.attr('r',function(d) {
return getr(d);
});
function getr(d) {
//console.log(d[col1] + ' ' + d[col2] + ' ' + d[radi]);
//return (10*(Math.pow(d[radi], 0.2)));
return (Math.pow(Math.abs(d[radi]-390), 1.4));
}
});
</script>
</div>
<div id="databox" style="border: 1px solid red; "></div>
<div id="current" style="border: 1px solid red; "></div>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js
https://code.jquery.com/jquery-2.1.3.js