Interactive interface for browsing global, full-resolution satellite imagery
Cleaned up panning
Taylor Gunnoee9a952ac2ddc
diff --git a/web/index.html b/web/index.htmlindex 5c78f3432..bd33602f2 100644--- a/web/index.html+++ b/web/index.html@@ -158,6 +158,7 @@<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.timeline.data.js"></script><!-- 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.wheels.js"></script>diff --git a/web/js/date/wv.date.timeline.js b/web/js/date/wv.date.timeline.jsindex 425659a80..c11c9177e 100644--- a/web/js/date/wv.date.timeline.js+++ b/web/js/date/wv.date.timeline.js@@ -23,6 +23,8 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {var self = {};var model = models.date;+ self.enabled = false;+self.margin = {top: 0,right: 30,@@ -44,19 +46,74 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {self.isCropped = true;self.toggle = function(){-+ var tl = $('#timeline-footer');+ var tlz = $('#timeline-zoom');+ var tlg = self.boundary;+ var gp = d3.select('#guitarpick');+ if(tl.is(':hidden')){+ var afterShow = function() {+ tlz.show();+ $('#timeline').css('right','10px');+ tlg.attr('style','clip-path:url("#timeline-boundary")');+ gp.attr("style","display:block;clip-path:url(#guitarpick-boundary);");+ };+ if ( now ) {+ tl.show();+ afterShow();+ } else {+ tl.show('slow', afterShow);+ }+ }+ else{+ tlg.attr('style','clip-path:none');+ gp.attr("style","display:none;clip-path:none");+ tlz.hide();+ tl.hide('slow');+ $('#timeline').css('right','auto');+ }};self.expand = function(){-+ now = now || false;+ var tl = $('#timeline-footer, #timeline-zoom');+ if (tl.is(":hidden")){+ self.toggle(now);+ }};self.expandNow = function(){-+ self.expand(true);};self.collapse = function(){-+ var tl = $('#timeline-footer, #timeline-zoom');+ if (!tl.is(":hidden")){+ self.toggle();+ }+ };++ var resize = function(){+ var small = wv.util.browser.small || wv.util.browser.constrained;+ if ( self.enabled && small ) {+ self.enabled = false;+ $("#timeline").hide();+ } else if ( !self.enabled && !small ) {+ self.enabled = true;+ $("#timeline").show();+ }+ //TODO: Below+ /*+ if ( self.enabled ) {+ getTimelineWidth();+ d3.select('#timeline-footer svg')+ .attr('width', width);// + margin.left + margin.right);+ d3.select('#timeline-boundary rect').attr('width',width);//+margin.left+margin.right);+ d3.select('#guitarpick-boundary rect').attr('width',width+margin.left+margin.right);//+margin.left+margin.right);+ timeline.select(".x.axis line:first-child").attr("x2",width);//+margin.left+margin.right);++ setZoom(zoomLvl);+ }+ */};var drawContainers = function(){@@ -111,6 +168,8 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {.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")@@ -132,6 +191,9 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {drawContainers();+ $('#timeline-footer').css('margin-left',self.margin.left-1 + 'px');+ $('#timeline-footer').css('margin-right',self.margin.right-1 + 'px');+self.x = d3.time.scale.utc();self.xAxis = d3.svg.axis()@@ -142,6 +204,8 @@ wv.date.timeline = wv.date.timeline || function(models, config, ui) {self.axisZoom = d3.behavior.zoom().scale(1).scaleExtent([1,1]);++ resize();};init();diff --git a/web/js/date/wv.date.timeline.pan.js b/web/js/date/wv.date.timeline.pan.jsnew file mode 100644index 000000000..f7774ecf1--- /dev/null+++ b/web/js/date/wv.date.timeline.pan.js@@ -0,0 +1,71 @@+/*+ * 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 || {};++/**+ * Perform timeline panning functions+ *+ * @class wv.date.timeline.pan+ */+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.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];+ }+ }+ else{+ xPosition = tl.axisZoom.translate()[0];+ }+ tl.axis.call(tl.xAxis);++ tl.zoom.lvl.configure();++ tl.ticks.boundary.update();+ tl.ticks.normal.update();+ };++ 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]);+ };++ var init = function(){++ };++ init();+ return self;+};diff --git a/web/js/date/wv.date.timeline.ticks.js b/web/js/date/wv.date.timeline.ticks.jsindex 4fd347ece..8f9dfaee4 100644--- a/web/js/date/wv.date.timeline.ticks.js+++ b/web/js/date/wv.date.timeline.ticks.js@@ -54,6 +54,39 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)self.normal.lastDate = all.data()[all.data().length-1];self.normal.lastElem = all[0][all.length-1];},+ update: function(){+ var ticks = self.normal.all;++ ticks.each(function(){+ var current = d3.select(this);+ var currentData = current.data()[0];+ var nextData = tl.zoom.current.ticks.normal.next(currentData);+ //var normalTickLine = normalTick.select('line'); What's this for?++ //FIXME: Calculate actual width of tick line+ nWidth = tl.x(nextData) - tl.x(currentData) + 1;++ if(($(this).find('line').attr('y1') !== '-2')){+ current.select('line')+ .attr("y1","-2");+ }++ if(($(this).find('text').length)){+ current.select("text").remove();+ }++ if(!$(this).find('rect').length){+ self.normal.insert.rect(current, nWidth);+ }+ else{+ current.select('rect.normaltick-background')+ .attr("width",nWidth);+ }+ });++ self.normal.set();+ self.normal.bind();+ },init: function(){var ticks = self.normal.all;ticks.selectAll('line')@@ -67,15 +100,21 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)var nextData = tl.zoom.current.ticks.normal.next(currentData);//var normalTickLine = normalTick.select('line'); What's this for?- nWidth = tl.x(nextData) - tl.x(currentData) + 1; //FIXME: Calculate actual width of tick line+ //FIXME: Calculate actual width of tick line+ nWidth = tl.x(nextData) - tl.x(currentData) + 1;+ self.normal.insert.rect(current, nWidth);+ });+ },+ insert: {+ rect: function(current, nWidth){current.append("svg:rect").attr("class","normaltick-background").attr("height",tl.height-1).attr("y",-tl.height).attr("x",-0.5).attr("width",nWidth);- });+ }},set: function(){self.normal.background = self.all.selectAll('rect.normaltick-background');@@ -101,19 +140,66 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)});},hover: function(d){- var label = tl.zoom.current.ticks.normal.label(d);+ var label = tl.zoom.current.ticks.normal.hover(d);self.label.show.call(this,label);},click: function(d){var date = tl.zoom.current.ticks.normal.clickDate(d);model.select(date);+ console.log(model.selected);},};self.boundary = {update: function(){-- },+ var ticks = self.boundary.all;++ ticks.each(function(){+ //This is a repeat, maybe fix?+ var current = d3.select(this);+ var currentData = current.data()[0];+ var nextData = tl.zoom.current.ticks.boundary.next(currentData);+ var nextNormalData = tl.zoom.current.ticks.normal.next(currentData);+ var bWidth = tl.x(nextData) - tl.x(currentData);+ var nWidth = tl.x(nextNormalData) - tl.x(currentData) + 1;+ var subLabel = tl.zoom.current.ticks.boundary.subLabel(currentData);+ //end repeat++ if (($(this).find('line').attr('y1') !== '20')){+ current.select('line')+ .attr("y1","20")+ .attr("y2","-50");+ }+ if(!$(this).find('text').hasClass('tick-label')){+ current.select('text')+ .attr('class','tick-label')+ .attr('x',7)+ .attr('style','text-anchor:left;');+ if(subLabel){+ current.select('text').append("tspan")+ .text(" " + subLabel)+ .attr("class","sub-label");+ }+ }+ if(!$(this).find('circle').length)+ current.insert("svg:circle","text").attr("r","6");++ if(!$(this).find('rect').length){+ self.boundary.insert.rect(current, bWidth, nWidth);+ }+ else{+ current.select('rect.boundarytick-background')+ .attr("width", bWidth);+ current.select('rect.boundarytick-foreground')+ .attr("width", bWidth);+ current.select('rect.normaltick-background')+ .attr("width", bWidth);+ }+ });++ self.boundary.set();+ self.boundary.bind();+ },init: function(){var ticks = self.boundary.all;@@ -129,22 +215,35 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)var currentData = current.data()[0];var nextData = tl.zoom.current.ticks.boundary.next(currentData);var nextNormalData = tl.zoom.current.ticks.normal.next(currentData);- var bWidth,nWidth;- var subLabel;-- bWidth = tl.x(nextData) - tl.x(currentData);-- nWidth = tl.x(nextNormalData) - tl.x(currentData) + 1;+ var bWidth = tl.x(nextData) - tl.x(currentData);+ var nWidth = tl.x(nextNormalData) - tl.x(currentData) + 1;+ var subLabel = tl.zoom.current.ticks.boundary.subLabel(currentData);++ self.boundary.insert.rect(current, bWidth, nWidth);++ //TODO: Sublabel+ if(subLabel){+ current.select('text').append("tspan")+ .text(" " + subLabel)+ .attr("class","sub-label");+ }+ });- //subLabel = getSubLabel(boundaryTickData);+ ticks.selectAll('text')+ .attr('class','tick-label')+ .attr('x',7)+ .attr('style','text-anchor:left;');+ },+ insert: {+ rect: function(current, bWidth, nWidth){current.insert("svg:rect", "text").attr("x","0").attr("y","0").attr("width",bWidth).attr("height",tl.height).attr("class","boundarytick-background");-+current.append("svg:rect").attr("x","0").attr("y","0")@@ -158,20 +257,7 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui).attr("y",-tl.height).attr("x",-0.5).attr("width",nWidth);- /*- if(subLabel){- boundaryTick.select('text').append("tspan")- .text(" " + subLabel)- .attr("class","sub-label");- }*/-- });-- ticks.selectAll('text')- .attr('class','tick-label')- .attr('x',7)- .attr('style','text-anchor:left;');-+ }},set: function(){self.boundary.background = self.boundary.all@@ -191,17 +277,19 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)clearTimeout(cancelClick);if(clicked){d = d3.select(this.parentNode).data()[0];- clickBoundaryTick.call(this,d);+ self.boundary.click.call(this,d);}clicked = true;});},hover: function(d){- var label = tl.zoom.current.ticks.boundary.label(d);+ var label = tl.zoom.current.ticks.boundary.hover(d);+ console.log(d);self.label.show.call(this,label);},click: function(d){-+ var date = tl.zoom.current.ticks.boundary.clickDate(d);+ model.select(date);}};@@ -219,12 +307,10 @@ wv.date.timeline.ticks = wv.date.timeline.ticks || function(models, config, ui)var tick = tl.axis.insert('g', elem).data([data]).attr('class','tick')- .attr('transform','translate(' + x(data) + ',0)')+ .attr('transform','translate(' + tl.x(data) + ',0)').classed('label-only',true); //if add function is for label only- var text = data.getUTCFullYear() +- ' ' + models.date.monthAbbr[data.getUTCMonth()] +- ' ' + data.getUTCDate();+ var text = tl.zoom.current.ticks.boundary.label(data);tick.append('line').attr('y2',-tl.height);diff --git a/web/js/date/wv.date.timeline.zoom.js b/web/js/date/wv.date.timeline.zoom.jsindex 2918bc853..97138a2ef 100644--- a/web/js/date/wv.date.timeline.zoom.js+++ b/web/js/date/wv.date.timeline.zoom.js@@ -23,6 +23,7 @@ wv.date.timeline = wv.date.timeline || {};wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {var tl = ui.timeline;+ var model = models.date;var self = {};@@ -38,6 +39,22 @@ wv.date.timeline.zoom = wv.date.timeline.zoom || function(models, config, ui) {},};+ self.change = function(amount, event) {+ console.log('changing zoom!');+ //TODO: Below+ /*+ zoomLvl += -amount;+ if ( zoomLvl < 0 ) {+ zoomLvl = 0;+ }+ if ( zoomLvl > 2 ) {+ zoomLvl = 2;+ }++ setZoom.call(this, zoomLvl, event);+ */+ };+self.drawTicks = function(count, max, aEnd, w, i, s, f){var d1 = tl.data.start(),d2,@@ -72,12 +89,20 @@ 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);+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]));+};var init = function(){@@ -168,33 +193,54 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, config});};+ //Calculated next boundary tick by datetl.zoom.current.ticks.boundary.next = function(current){var next = new Date(current);return new Date(next.setUTCMonth(next.getUTCMonth()+1));};+ //Calculated next normal tick by datetl.zoom.current.ticks.normal.next = function(current){var next = new Date(current);return new Date(next.setUTCDate(next.getUTCDate()+1));};- tl.zoom.current.ticks.normal.label = function(d){- //No modifications at this zoom level+ //Value for hovered normal label+ tl.zoom.current.ticks.normal.hover = function(d){+ //No modifications to date obj at this zoom levelreturn d;};+ //Value for clicked normal ticktl.zoom.current.ticks.normal.clickDate = function(d){return new Date(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate());};++ //Value for hovered boundary tick+ tl.zoom.current.ticks.boundary.hover = function(d){+ return new Date(d.getUTCFullYear(),d.getUTCMonth(),model.selected.getUTCDate());+ };+tl.zoom.current.ticks.boundary.label = function(d){+ return model.monthAbbr[d.getUTCMonth()];+ };++ //Displayed default sub-label (if any)+ tl.zoom.current.ticks.boundary.subLabel = function(d){+ return d.getUTCFullYear();+ };++ //Value for clicked boundary tick+ tl.zoom.current.ticks.boundary.clickDate = function(d){return new Date(d.getUTCFullYear(),d.getUTCMonth(),model.selected.getUTCDate());};- self.update();+ self.configure();+ initTicks();};- self.update = function(){+ self.configure = function(){var first, last, proto, end;tl.ticks.setAll();@@ -217,13 +263,14 @@ 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(),1));tl.ticks.add(proto, 'g.tick');}-+//FIXME: Passing from d3 to jQuery to d3 in order to check if its the last tick elem. WAT.if(d3.select($(tl.ticks.normal.lastElem).next()[0]).classed('domain')){@@ -235,17 +282,22 @@ wv.date.timeline.zoom.lvl = wv.date.timeline.zoom.lvl || function(models, config}// } End terrible+ tl.ticks.setAll();+//update boundary tickstl.zoom.current.ticks.boundary.all();+tl.ticks.boundary.all.classed('tick-labeled',true);+ };++ var initTicks = function(){tl.ticks.boundary.init();tl.ticks.normal.init();tl.ticks.normal.set(); //could probably combine set and bindtl.ticks.normal.bind();tl.ticks.boundary.set();tl.ticks.boundary.bind();-};var init = function(){diff --git a/web/js/ui/wv.ui.mouse.js b/web/js/ui/wv.ui.mouse.jsindex 93f3e8bba..5e7f4814c 100644--- a/web/js/ui/wv.ui.mouse.js+++ b/web/js/ui/wv.ui.mouse.js@@ -75,6 +75,7 @@ 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 ) {@@ -85,8 +86,9 @@ wv.ui.mouse.wheel = wv.ui.mouse.wheel || function(element, ui, options) {update(evt);}else if ((Math.abs(evt.deltaX) >= Math.abs(evt.deltaY))){- if(!(ui.timeline.smallSize())){- ui.timeline.panAxis(d3.event);+ if( ui.timeline.isCropped ){+ console.log('pan with trackpad');+ ui.timeline.pan.axis(d3.event);timeout = true;clearTimeout(timer);timer = setTimeout(function(){@@ -95,8 +97,9 @@ wv.ui.mouse.wheel = wv.ui.mouse.wheel || function(element, ui, options) {}}else{- if ( !(ui.timeline.smallSize()) ){- ui.timeline.panAxis();+ 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 d86646430..956a14d12 100644--- a/web/js/wv.main.js+++ b/web/js/wv.main.js@@ -157,6 +157,7 @@ $(function() {ui.timeline.data = wv.date.timeline.data(models, config, ui);ui.timeline.zoom = wv.date.timeline.zoom(models, config, ui);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.dateLabel = wv.date.label(models);ui.dateWheels = wv.date.wheels(models, config);