Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Made timeline update viewed range when new product is added, cleaned code

Taylor Gunnoe4267ce04ead5
diff --git a/src/js/date/wv.date.timeline.js b/src/js/date/wv.date.timeline.js
index f2c972aee..b83030d9c 100644
--- a/src/js/date/wv.date.timeline.js
+++ b/src/js/date/wv.date.timeline.js
@@ -40,27 +40,9 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
var endDateMs = model.end.getTime();
//this is where the data would go for showing available dates
- var data = [
- {
- "date": startDateMs,
- "value": "5"
- }, {
- "date": endDateMs,
- "value": "5"
- }
- ];
- //Current date line
- var data2 = [
- {
- "date": model.selected.getTime(),
- "value": "0"
- }, {
- "date": model.selected.getTime(),
- "value": "6"
- }
- ];
-
-
+ var data = [];
+ var data2 = [];
+ var x,y,line,zoom,xAxis;
//margins for the timeline
margin = {
top: 0,
@@ -81,26 +63,74 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
var incrementBtn = $("#right-arrow-group");
var decrementBtn = $("#left-arrow-group");
- var x = d3.time.scale()
+
+ var setData = function(){
+ data = [
+ {
+ "date": model.start,
+ "value": "5"
+ },
+ {
+ "date": model.end,
+ "value": "5"
+ }
+ ];
+ //Current date line
+ data2 = [
+ {
+ "date": model.selected.getTime(),
+ "value": "0"
+ },
+ {
+ "date": model.selected.getTime(),
+ "value": "6"
+ }
+ ];
+ x = d3.time.scale()
.domain([
d3.min(data, function(d) { return d.date; }),
d3.max(data, function(d) { return d.date; })
])
.range([0, width]);
- var y = d3.scale.linear()
+ y = d3.scale.linear()
.domain(d3.extent(data2, function (d) {
return d.value;
}))
.range([height, 0]);
-
- var line = d3.svg.line()
+ line = d3.svg.line()
.x(function (d) {
return x(d.date);
})
.y(function (d) {
return y(d.value);
});
+ zoom = d3.behavior.zoom()
+ .x(x)
+ .scaleExtent([1, 100])
+ .on("zoom", zoomed);
+
+ xAxis = d3.svg.axis()
+ .scale(x)
+ .orient("bottom")
+ .ticks(10);
+ try{
+ redrawAxis();
+ }
+ catch(e){
+ console.log("error is following:" + e);
+ }
+
+ };
+ var redrawAxis = function(){
+ d3.select(".axis").call(xAxis);
+ d3.select(".grid").call(make_x_axis(x).tickSize(-60, 0, 0));
+ d3.selectAll('.x.axis .tick text').attr('x',5).attr('style','text-anchor:left;');
+
+ d3.select(".line").datum(data).attr("d", line);
+ d3.select(".line2").datum(data2).attr("d", line);
+ updateTime();
+ };
var redraw = function(){
//resizing window redrawing goes here
@@ -116,14 +146,9 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
x.range([0, width]);
- d3.select(".axis").call(xAxis);
- d3.select(".grid").call(make_x_axis(x).tickSize(-60, 0, 0));
- d3.selectAll('.x.axis .tick text').attr('x',5).attr('style','text-anchor:left;');
+ redrawAxis();
- d3.select(".line").datum(data).attr("d", line);
- d3.select(".line2").datum(data2).attr("d", line);
- updateTimeline();
};
@@ -164,11 +189,6 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
};
- var zoom = d3.behavior.zoom()
- .x(x)
- .scaleExtent([1, 100])
- .on("zoom", zoomed);
-
var make_x_axis = function (x) {
return d3.svg.axis()
.scale(x)
@@ -176,13 +196,11 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
.ticks(10);
};
- var xAxis = d3.svg.axis()
- .scale(x)
- .orient("bottom")
- .ticks(10);
var init = function() {
-
+ console.log("setting data...");
+ setData();
+ console.log("data set!");
svg = d3.select('#timeline footer')
.append("svg:svg")
.attr('width', width + margin.left + margin.right)
@@ -344,10 +362,12 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
model.events.on("select", function(){
updateTime();
});
+ models.layers.events.on("change",function(){
+ setData();
+ });
updateTime();
$('#day-input-group').addClass('button-input-group-selected');
bindBtnsToDay();
- console.log("time = " + model.selected);
}; // /init
var bindUpdateOnFooter = function(){
@@ -452,7 +472,6 @@ wv.date.timeline = wv.date.timeline || function(models, config) {
}
console.log("%%%%%%%%%%%%%%% " + timelineJumpInPix);
};
-
init();
$(window).resize(redraw);