<html>
<head>
<script src="http://d3js.org/d3.v3.js"></script>
<meta charset="utf-8">
</head>
<body>
<input type="range" min="20" max="1000" value="431" onchange="sliderChange()"/>
<label></label>
<br/>
<br/>
</body>
</html>
body {
font: 10px sans-serif;
shape-rendering: crispEdges;
}
.grid-background {
fill: #ddd;
}
.grid line {
stroke: #fff;
}
.grid .minor line {
stroke-opacity: .5;
stroke: red;
}
.grid .minor-minor line {
stroke-opacity: .5;
stroke: blue;
}
.grid text {
display: none;
}
.axis line {
stroke: #fff;
}
.axis text {
fill: #000;
}
.axis path,
.grid path {
display: none;
}
var margin = {top: 0, right: 10, bottom: 25, left: 10},
width = 960 - margin.right - margin.left,
height = 150 - margin.top - margin.bottom;
var x = d3.time.scale()
.domain([1, d3.select('input')[0][0].value])
.range([0, width]);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("rect")
.attr("class", "grid-background")
.attr('y', 0)
.attr("width", width)
.attr("height", height*4);
var realAxisGroup = svg.append("g");
var minorAxisGroup = svg.append('g').attr('class', 'minor');
var now = d3.time.day(new Date());
sliderChange();
// ~
function sliderChange() {
var v = d3.select('input')[0][0].value;
d3.select('label').text(v);
x.domain([now, new Date(now.getTime() + 1000 * 60 * 60 * 1 * v)]);
redraw();
}
function redraw() {
// this is the d3's axis
realAxisGroup
.attr("class", "axis")
.attr("transform", "translate(0,0)")
.call(d3.svg.axis().orient('bottom').scale(x).tickSize(12));
var points = [];
realAxisGroup.selectAll('g').data().forEach(function (d, i) {
points.push(x(d));
});
points.sort(function(a,b) { return a-b; } );
console.log(points);
minorAxisGroup
.attr('class', 'axis')
.selectAll('g')
.remove();
for (var i = 0; i < points.length; i += 1) {
var trans;
if (i === points.length - 1) {
trans = points[i] + (points[i] - points[i - 1]) / 2;
}
else {
trans = points[i] + (points[i + 1] - points[i]) / 2;
}
var grrr = minorAxisGroup.append('g')
.attr('class', 'tick')
.attr('transform', 'translate(' + trans + ')');
grrr.append('line')
.attr('y2', 24)
.attr('x2', 0);
}
}
function toggleReal() {
var ds = d3.select('g.axis')[0][0].style;
ds.display = (ds.display === '') ? 'none' : '';
}
function toggleFake() {
var ds = d3.select('g.fake')[0][0].style;
ds.display = (ds.display === '') ? 'none' : '';
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |