/// image stuff image = document.getElementById('photo'); //// slider stuff formatDate = d3.time.format("%b %d"); // parameters var margin = { top: 50, right: 50, bottom: 50, left: 50 }, width = 960 - margin.left - margin.right, height = 500 - margin.bottom - margin.top; // scale function var timeScale = d3.time.scale() .domain([new Date('2012-01-02'), new Date('2013-01-01')]) .range([0, width]) .clamp(true); // initial value var startValue = timeScale(new Date('2012-03-20')); startingValue = new Date('2012-03-20'); ////////// // defines brush var brush = d3.svg.brush() .x(timeScale) .extent([startingValue, startingValue]) .on("brush", brushed); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") // classic transform to position g .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); svg.append("g") .attr("class", "x axis") // put in middle of screen .attr("transform", "translate(0," + height / 2 + ")") // inroduce axis .call(d3.svg.axis() .scale(timeScale) .orient("bottom") .tickFormat(function(d) { return formatDate(d); }) .tickSize(0) .tickPadding(12) .tickValues([timeScale.domain()[0], timeScale.domain()[1]])) .select(".domain") .select(function() { console.log(this); return this.parentNode.appendChild(this.cloneNode(true)); }) .attr("class", "halo"); var slider = svg.append("g") .attr("class", "slider") .call(brush); slider.selectAll(".extent,.resize") .remove(); slider.select(".background") .attr("height", height); var handle = slider.append("g") .attr("class", "handle") handle.append("path") .attr("transform", "translate(0," + height / 2 + ")") .attr("d", "M 0 -20 V 20") handle.append('text') .text(startingValue) .attr("transform", "translate(" + (-18) + " ," + (height / 2 - 25) + ")"); slider .call(brush.event) function brushed() { var value = brush.extent()[0]; if (d3.event.sourceEvent) { // not a programmatic event value = timeScale.invert(d3.mouse(this)[0]); brush.extent([value, value]); } handle.attr("transform", "translate(" + timeScale(value) + ",0)"); handle.select('text').text(formatDate(value)); console.log(d3.event.sourceEvent.type) if(d3.event.sourceEvent.type == 'mousemove' || d3.event.sourceEvent.type == 'touchend'){ if (photos[MonthDaytoNumDay(value.getMonth()+1,value.getDate())][(value.getHours() + 8) % 24][0]['URL']){ console.log(photos[MonthDaytoNumDay(value.getMonth()+1,value.getDate())][(value.getHours() + 8) % 24][0]['URL']) image.innerHTML = 'shiza' } else { console.log(MonthDaytoNumDay(value.getMonth()+1,value.getDate()), (value.getHours() + 8) % 24, photos[MonthDaytoNumDay(value.getMonth()+1,value.getDate())][(value.getHours() + 8) % 24]) } } } function MonthDaytoNumDay(month, day){ var daysInMonth = [1, 32, 60, 91, 121, 152, 182, 213, 244, 274,305,335]; var dayNum = daysInMonth[month -1] + day - 1; return dayNum } // helper functions function dayToMonth(day) { var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug","Sep","Oct","Nov","Dec"]; var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; var i = 0; while(day > 0){ day = day - daysInMonth[i]; i++ } return months[i-1] } function dayToMonthDay(day) { var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug","Sep","Oct","Nov","Dec"]; var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; var i = 0; while(day > 0){ day = day - daysInMonth[i]; i++ } day = day + daysInMonth[i-1] return months[i-1] + " " + day }