Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add daysInYear utility, calculate timeline days & output to hover label

ZachTRice4792dd0739d5
diff --git a/web/js/date/timeline-ticks.js b/web/js/date/timeline-ticks.js
index 9dc4c9cbf..f5935ab93 100644
--- a/web/js/date/timeline-ticks.js
+++ b/web/js/date/timeline-ticks.js
@@ -1,5 +1,6 @@
import $ from 'jquery';
import d3 from 'd3';
+import util from '../util/util';
/**
* Perform timeline tick functions
*/
@@ -368,6 +369,7 @@ export function timelineTicks(models, config, ui) {
var $boundaryTick;
var tick = this.parentNode;
var boundaryTick, boundaryTickWidth;
+ var hoverDay = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
// Using jquery to precise select as it's easier than d3
if (d3.select(tick)
@@ -396,7 +398,6 @@ export function timelineTicks(models, config, ui) {
// trigger hover state
boundaryTick.select('rect.boundarytick-background')
.classed('bg-hover', true);
-
boundaryTick.append('svg:text')
.attr('class', 'hover-tick-label')
.attr('y', '15')
@@ -405,7 +406,8 @@ export function timelineTicks(models, config, ui) {
.attr('width', boundaryTickWidth)
.text(d.getUTCFullYear() +
' ' + model.monthAbbr[d.getUTCMonth()] +
- ' ' + d.getUTCDate()); // Add hover Label
+ ' ' + d.getUTCDate() +
+ ' (' + util.daysInYear(hoverDay) + ')'); // Add hover Label
},
remove: function () { // TODO: update
tl.boundary.selectAll('.tick-label, .sub-label')
diff --git a/web/js/util/util.js b/web/js/util/util.js
index cc2dc510b..a1503f194 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -297,6 +297,7 @@ export default (function (self) {
}
return newDate;
};
+
self.daysInMonth = function (d) {
var y;
var m;
@@ -310,6 +311,15 @@ export default (function (self) {
var lastDay = new Date(Date.UTC(y, m + 1, 0));
return lastDay.getUTCDate();
};
+
+ self.daysInYear = function (time) {
+ var start = new Date(time.getUTCFullYear(), 0, 0);
+ var diff = (time - start) + ((start.getTimezoneOffset() - time.getTimezoneOffset()) * 60 * 1000);
+ var oneDay = 1000 * 60 * 60 * 24;
+ var day = Math.floor(diff / oneDay);
+ return day;
+ };
+
self.objectLength = function (obj) {
return Object.keys(obj)
.length;