Interactive interface for browsing global, full-resolution satellite imagery
cleaned up selection pick code
Taylor Gunnoe5abdd91bb138
diff --git a/web/index.html b/web/index.htmlindex bd33602f2..4b68e6052 100644--- a/web/index.html+++ b/web/index.html@@ -159,6 +159,7 @@<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.timeline.ticks.js"></script><!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.timeline.zoom.js"></script><!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.timeline.pan.js"></script>+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.timeline.pick.js"></script><!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.wheels.js"></script>diff --git a/web/js/date/wv.date.timeline.data.js b/web/js/date/wv.date.timeline.data.jsindex 48e8581f5..0a1928fc2 100644--- a/web/js/date/wv.date.timeline.data.js+++ b/web/js/date/wv.date.timeline.data.js@@ -28,21 +28,21 @@ wv.date.timeline.data = wv.date.timeline.data || function(models, config, ui) {var self = {};self.start = function(){- return new Date(config.startDate);+ return new Date( config.startDate );};self.end = function(){return new Date(- new Date(wv.util.today())- .setUTCDate(wv.util.today()- .getUTCDate()+1));+ new Date( wv.util.today() )+ .setUTCDate( wv.util.today()+ .getUTCDate() + 1 ) );};self.set = function(){};var init = function(){tl.axisZoom- .xExtent([self.start(),self.end()]);+ .xExtent( [self.start(), self.end()] );};init();diff --git a/web/js/date/wv.date.timeline.js b/web/js/date/wv.date.timeline.jsindex c11c9177e..8b16a1bc7 100644--- a/web/js/date/wv.date.timeline.js+++ b/web/js/date/wv.date.timeline.js@@ -163,28 +163,6 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {.attr("class", "y axis").attr("transform", "translate(0,0)");- self.guitarPick = d3.select("#timeline-footer svg")- .append("svg:g")- .attr("id","guitarpick")- .attr("style","clip-path:url(#guitarpick-boundary);");-- self.guitarPick.append("svg:path")- .attr("d", "M 7.3151,0.7426 C 3.5507,0.7426 0.5,3.7926 0.5,7.5553 l 0,21.2724 14.6038,15.7112 14.6039,15.7111 14.6038,-15.7111 14.6037,-15.7112 0,-21.2724 c 0,-3.7627 -3.051,-6.8127 -6.8151,-6.8127 l -44.785,0 z");- self.guitarPick.append("svg:rect")- .attr("width","4")- .attr("height","20")- .attr("x","21")- .attr("y","11");- self.guitarPick.append("svg:rect")- .attr("width","4")- .attr("height","20")- .attr("x","28")- .attr("y","11");- self.guitarPick.append("svg:rect")- .attr("width","4")- .attr("height","20")- .attr("x","35")- .attr("y","11");};var init = function(){diff --git a/web/js/date/wv.date.timeline.pan.js b/web/js/date/wv.date.timeline.pan.jsindex f7774ecf1..32210ffd0 100644--- a/web/js/date/wv.date.timeline.pan.js+++ b/web/js/date/wv.date.timeline.pan.js@@ -25,22 +25,23 @@ wv.date.timeline.pan = wv.date.timeline.pan || function(models, config, ui) {var tl = ui.timeline;var model = models.date;- var xPosition = tl.axisZoom.translate()[0];var self = {};+ self.xPosition = tl.axisZoom.translate()[0];+self.axis = function(event){- console.log('axis');+if(event){var evt = event.sourceEvent || event;var delX = evt.deltaX;if((evt.type === "wheel") && ((evt.deltaX < 0) || (evt.deltaX > 0))){- tl.axisZoom.translate([xPosition-delX,0]);- xPosition = tl.axisZoom.translate()[0];+ tl.axisZoom.translate([self.xPosition-delX,0]);+ self.xPosition = tl.axisZoom.translate()[0];}}else{- xPosition = tl.axisZoom.translate()[0];+ self.xPosition = tl.axisZoom.translate()[0];}tl.axis.call(tl.xAxis);@@ -51,15 +52,15 @@ wv.date.timeline.pan = wv.date.timeline.pan || function(models, config, ui) {};self.toSelection = function(){- console.log('panning');- console.log(tl.axisZoom.translate());- //tl.axisZoom.translate([-2000,0]);+tl.axisZoom.translate([-tl.x(model.selected) +(tl.width -tl.margin.left -tl.margin.right) /2,0]);- console.log(tl.axisZoom.translate()[0]);++ self.xPosition = tl.axisZoom.translate()[0];+};var init = function(){diff --git a/web/js/date/wv.date.timeline.pick.js b/web/js/date/wv.date.timeline.pick.jsnew file mode 100644index 000000000..fdb2bd99d--- /dev/null+++ b/web/js/date/wv.date.timeline.pick.js@@ -0,0 +1,170 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 - 2014 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++/**+ * @module wv.date.timeline+ */+var wv = wv || {};+wv.date = wv.date || {};+wv.date.timeline = wv.date.timeline || {};++/**+ * Implements the timeline pick+ *+ * @class wv.date.timeline.pick+ */+wv.date.timeline.pick = wv.date.timeline.pick || function(models, config, ui) {++ var tl = ui.timeline;+ var model = models.date;++ var self = {};++ var width = 60;+ var offset = tl.x(model.selected) - width/2;++ var mousedown = false;+ var nextChange, prevChange;+ var tipDate;++ //FIXME: Optimize a lot, this is terrible+ var dragmove = function(d){+ var tempPickOffset = Math.max( -(width / 2),+ Math.min( tl.width - (width / 2), d3.event.x ) );+ var tempPickTipOffset = tempPickOffset + (width / 2);+ var tempPickTipDate = tl.x.invert(tempPickTipOffset);++ if( d3.event.dx > 0 ) {+ if( nextChange === undefined ) {+ updateChanges(tempPickTipDate);+ }+ else if( ( tempPickTipDate >= nextChange ) &&+ ( nextChange <= tl.data.end() ) &&+ ( nextChange > tl.data.start() ) )+ {+ offset = tl.x(nextChange) - width / 2;+ tipDate = nextChange;+ change.call(this);+ updateChanges(tempPickTipDate);+ }+ else if( nextChange > tl.data.end() ) {+ tipDate = new Date( Date.UTC( tl.data.end().getUTCFullYear(),+ model.selected.getUTCMonth(),+ model.selected.getUTCDate() ) );+ offset = tl.x(pickTipDate) - width / 2;+ change.call(this);+ updateChanges(tempPickTipDate);+ }+ else if( nextChange < tl.data.start() ) {+ nextChange = new Date( Date.UTC( tl.data.start().getUTCFullYear(),+ model.selected.getUTCMonth(),+ model.selected.getUTCDate() ) );+ }+ }+ else if( d3.event.dx < 0 ) {+ if( prevChange === undefined ){+ updateChanges(tempPickTipDate);+ }+ else if( ( tempPickTipDate <= prevChange ) &&+ ( prevChange >= tl.data.start() ) &&+ ( prevChange < tl.data.end() ) )+ {+ offset = tl.x(prevChange) - width / 2;+ tipDate = prevChange;+ change.call(this);+ updateChanges(tempPickTipDate);+ }+ else {+ updateChanges(tempPickTipDate);+ }+ }+ };++ var drag = d3.behavior.drag()+ .origin(function(d) { return d; })+ .on("dragstart", function(){+ mousedown = true;+ d3.event.sourceEvent.preventDefault();+ d3.event.sourceEvent.stopPropagation();+ tl.guitarPick.classed('pick-clicked',true);+ })+ .on("drag", dragmove)+ .on("dragend",function(){+ mousedown = false;+ prevChange = undefined;+ nextChange = undefined;+ tl.guitarPick.classed('pick-clicked',false);+ });++ var change = function(){+ var d;+ var newDate = tipDate;+ var tick, tickBg;++ d3.select(this)+ .attr("transform", 'translate('+ offset +','+ 0 +')');++ tl.guitarPick+ .data([{x: offset, y:0}])+ .call(drag);++ model.select(newDate);++ tl.zoom.current.pick.hoverTick(newDate);++ tickBg = tl.zoom.current.pick.hoveredTick+ .select('rect.normaltick-background')[0][0];++ d = d3.select(tl.zoom.current.pick.hoveredTick[0][0]).data()[0];++ tl.ticks.label.remove();+ tl.ticks.normal.hover.call(tickBg,d);++ };++ var updateChanges = function(d){+ prevChange = tl.zoom.current.pick.prevChange(d);+ nextChange = tl.zoom.current.pick.nextChange(d);+ };++ var init = function(){+ //Draw the pick+ tl.guitarPick = tl.svg+ .append("svg:g")+ .data( [{ x: offset, y: 0 }] )+ .attr("id","guitarpick")+ .attr("style","clip-path:url(#guitarpick-boundary);")+ .attr("transform","translate(" + offset + ",0)")+ .call(drag);++ tl.guitarPick.append("svg:path")+ .attr("d", "M 7.3151,0.7426 C 3.5507,0.7426 0.5,3.7926 0.5,7.5553 l 0,21.2724 14.6038,15.7112 14.6039,15.7111 14.6038,-15.7111 14.6037,-15.7112 0,-21.2724 c 0,-3.7627 -3.051,-6.8127 -6.8151,-6.8127 l -44.785,0 z");+ tl.guitarPick.append("svg:rect")+ .attr("width","4")+ .attr("height","20")+ .attr("x","21")+ .attr("y","11");+ tl.guitarPick.append("svg:rect")+ .attr("width","4")+ .attr("height","20")+ .attr("x","28")+ .attr("y","11");+ tl.guitarPick.append("svg:rect")+ .attr("width","4")+ .attr("height","20")+ .attr("x","35")+ .attr("y","11");++ };++ init();+ return self;+};diff --git a/web/js/date/wv.date.timeline.ticks.js b/web/js/date/wv.date.timeline.ticks.jsindex 8f9dfaee4..a87e407da 100644--- a/web/js/date/wv.date.timeline.ticks.js+++ b/web/js/date/wv.date.timeline.ticks.js@@ -80,7 +80,7 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)}else{current.select('rect.normaltick-background')- .attr("width",nWidth);+ .attr("width", nWidth);}});@@ -146,7 +146,6 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)click: function(d){var date = tl.zoom.current.ticks.normal.clickDate(d);model.select(date);- console.log(model.selected);},};@@ -193,13 +192,13 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)current.select('rect.boundarytick-foreground').attr("width", bWidth);current.select('rect.normaltick-background')- .attr("width", bWidth);+ .attr("width", nWidth);}});self.boundary.set();self.boundary.bind();- },+ },init: function(){var ticks = self.boundary.all;@@ -284,7 +283,6 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)},hover: function(d){var label = tl.zoom.current.ticks.boundary.hover(d);- console.log(d);self.label.show.call(this,label);},click: function(d){diff --git a/web/js/date/wv.date.timeline.zoom.js b/web/js/date/wv.date.timeline.zoom.jsindex 97138a2ef..900f1d173 100644--- a/web/js/date/wv.date.timeline.zoom.js+++ b/web/js/date/wv.date.timeline.zoom.js@@ -29,7 +29,7 @@ wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {self.current = {ticks: {- //Empty for filling+ //Placeholdersboundary: {},@@ -37,10 +37,13 @@ wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {},},+ pick: {+ //Placeholder+ }};self.change = function(amount, event) {- console.log('changing zoom!');+ //console.log('changing zoom!');//TODO: Below/*zoomLvl += -amount;@@ -89,19 +92,14 @@ wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {tl.axisZoom.x(tl.x);- wv.ui.mouse.wheel(tl.axisZoom,ui).change(self.change);+ wv.ui.mouse.wheel(tl.axisZoom, ui).change(self.change);tl.svg.call(tl.axisZoom);tl.pan.toSelection();- //console.log(tl.x.invert(tl.axisZoom.translate()[0]));- //tl.axisZoom.translate([-tl.x(model.selected),0]);//??need to remove first?- tl.boundary.select(".x.axis")- .call(tl.xAxis);-- console.log(tl.x.invert(tl.axisZoom.translate()[0]));+ tl.axis.call(tl.xAxis);};@@ -122,6 +120,8 @@ wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {** @class wv.date.timeline.zoom.lvl*/++//TODO: Maybe reorganize this somewhere else/in another filewv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, config, ui) {var self = {};var tl = ui.timeline;@@ -158,15 +158,22 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, configself.level3 = function(){var altEnd,fNormData,+ //format of the labellabelFormat = d3.time.format.utc("%b"),+ //printed type of tickdateInterval = d3.time.day.utc,+ //step of the ticksdateStep = 1,+ //number of ticks total of data range, in daystickCount = (tl.data.end() - tl.data.start())/1000/60/60/24,tickCountMax,+ //width in pixels of each ticktickWidth = 11;+ //Max number of ticks able to be shown on this resolutiontickCountMax = Math.ceil(tl.width/tickWidth);+ //end tick date if tickCount is less than tickCountMaxaltEnd = new Date(tl.data.start().getUTCFullYear(),tl.data.start().getUTCMonth(),tl.data.start().getUTCDate() + tickCountMax);@@ -178,15 +185,16 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, configdateInterval,dateStep,labelFormat);-++ //Filters ticks for nonboundaries that have the following attributetl.zoom.current.ticks.normal.all = function(){tl.ticks.normal.all = tl.ticks.all.filter(function(d){return d.getUTCDate() !== 1;});tl.ticks.normal.setEnds();-};+ //Filters ticks for boundaries that have the following attributetl.zoom.current.ticks.boundary.all = function(){tl.ticks.boundary.all = tl.ticks.all.filter(function(d){return d.getUTCDate() === 1;@@ -221,6 +229,7 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, configreturn new Date(d.getUTCFullYear(),d.getUTCMonth(),model.selected.getUTCDate());};+ //Displayed default labeltl.zoom.current.ticks.boundary.label = function(d){return model.monthAbbr[d.getUTCMonth()];};@@ -235,6 +244,25 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, configreturn new Date(d.getUTCFullYear(),d.getUTCMonth(),model.selected.getUTCDate());};+ //When the date updates while dragging the pick forward+ tl.zoom.current.pick.nextChange = function(d){+ return new Date(Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate()+1));+ };++ //When the date updates while dragging the pick backward+ tl.zoom.current.pick.prevChange = function(d){+ return new Date(Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate()));+ };++ tl.zoom.current.pick.hoverTick = function(newDate){+ tl.zoom.current.pick.hoveredTick = d3.selectAll('.x.axis>g.tick')+ .filter(function(d){+ return (d.getUTCFullYear() === newDate.getUTCFullYear()) &&+ (d.getUTCMonth() === newDate.getUTCMonth() &&+ (d.getUTCDate() === newDate.getUTCDate()));+ });+ };+self.configure();initTicks();@@ -263,7 +291,6 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, config//FIXME: Section below is terrible {//For determining needed boundary ticksif($(tl.ticks.normal.firstElem).is(':nth-child(2)')){- console.log(true);first = tl.ticks.normal.firstDate;proto = new Date(Date.UTC(first.getUTCFullYear(),first.getUTCMonth(),diff --git a/web/js/ui/wv.ui.mouse.js b/web/js/ui/wv.ui.mouse.jsindex 5e7f4814c..9f55af6d6 100644--- a/web/js/ui/wv.ui.mouse.js+++ b/web/js/ui/wv.ui.mouse.js@@ -75,7 +75,6 @@ wv.ui.mouse.wheel = wv.ui.mouse.wheel || function(element, ui, options) {var wheel = function() {var evt = d3.event.sourceEvent;if((Math.abs(evt.deltaX) <= Math.abs(evt.deltaY)) && timeout===false){- console.log('zoom with mousewheel');lastEvent = evt;delta += evt.deltaY;if ( !timer ) {@@ -87,7 +86,6 @@ wv.ui.mouse.wheel = wv.ui.mouse.wheel || function(element, ui, options) {}else if ((Math.abs(evt.deltaX) >= Math.abs(evt.deltaY))){if( ui.timeline.isCropped ){- console.log('pan with trackpad');ui.timeline.pan.axis(d3.event);timeout = true;clearTimeout(timer);@@ -98,7 +96,6 @@ wv.ui.mouse.wheel = wv.ui.mouse.wheel || function(element, ui, options) {}else{if ( ui.timeline.isCropped ){- console.log('pan with mouse');ui.timeline.pan.axis();}}diff --git a/web/js/wv.main.js b/web/js/wv.main.jsindex 956a14d12..d52e83817 100644--- a/web/js/wv.main.js+++ b/web/js/wv.main.js@@ -159,6 +159,7 @@ $(function() {ui.timeline.ticks = wv.date.timeline.ticks(models, config, ui);ui.timeline.pan = wv.date.timeline.pan(models, config, ui);ui.timeline.zoom.lvl = wv.date.timeline.zoom.lvl(models, config, ui);+ ui.timeline.pick = wv.date.timeline.pick(models, config, ui);ui.dateLabel = wv.date.label(models);ui.dateWheels = wv.date.wheels(models, config);}