Skip to content

Commit

Permalink
fix(visualize): Unit bug fixed for tile generation
Browse files Browse the repository at this point in the history
A value in seconds was subtracted from a date value that was in
milliseconds. This caused extra tiles to be generated. Fixes #244.

Additionally the extra tiles should not have _even been visible_. This
bug was due to the sorting algorithm that determined the order of tiles
in the DOM not taking into account entities' starting date. It now sorts
by offset, and then by entity start date when a conflict occurs.
  • Loading branch information
atruskie committed Feb 15, 2016
1 parent c64411f commit 0fef143
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app/d3Bindings/eventDistribution/tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,18 @@ angular
}

/**
* Order tiles based on their date. This allows elements to be painted in the
* DOM in the right order
* Order tiles based on their offset date, and secondarily, their recorded date.
* This allows elements to be painted in the DOM in the right order
* @param tileA
* @param tileB
*/
sortTiles(tileA, tileB) {
return tileA.offset - tileB.offset;
let delta = tileA.offset - tileB.offset;
if (delta === 0) {
return tileA.source.recordedDateMilliseconds - tileB.source.recordedDateMilliseconds;
}

return delta;
}

/**
Expand All @@ -324,7 +329,9 @@ angular
// round down to the lower unit of time, determined by `tileSizeSeconds`
var niceLow = roundDate.floor(idealTileSizeSeconds, low),
// subtract a 'tile' otherwise we generate one too many
niceHigh = +(new Date(+roundDate.ceil(idealTileSizeSeconds, high) - idealTileSizeSeconds)),
niceHigh = +(new Date(
+roundDate.ceil(idealTileSizeSeconds, high) - (idealTileSizeSeconds * msInS)
)),
offset = +niceLow;

// use d3's in built range functionality to generate steps
Expand Down

0 comments on commit 0fef143

Please sign in to comment.