Skip to content

Commit

Permalink
Got tile generation working. Added package for rounding dates
Browse files Browse the repository at this point in the history
Also disabled connect debug logging
  • Loading branch information
atruskie committed Jan 30, 2015
1 parent 0a19e26 commit 8e45b21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ module.exports = function (grunt) {
hostname: '*',
port: 8080,
base: './<%= build_dir %>',
debug: true,
//debug: true,
livereload: true,
middleware: function (connect, options) {

Expand Down
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"modernizr": "~2.8.x",
"momentjs": "~2.8.x",
"objectdiff": "https://github.com/NV/objectDiff.js.git",
"round-date": "~1.0.1",
"sass-bootstrap": "3.0.2"
},
"dependencies": {},
Expand Down
8 changes: 5 additions & 3 deletions buildConfig/build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ module.exports = {
'vendor/momentjs/moment.js',
'vendor/lodash/dist/lodash.js',
'vendor/bowser/bowser.js',
'vendor/humanize-duration/humanize-duration.js'
],
'vendor/humanize-duration/humanize-duration.js',
'vendor/round-date/roundDate.js'
],
js: [
'vendor/jquery/dist/jquery.js',
'vendor/angular/angular.js',
Expand Down Expand Up @@ -121,7 +122,8 @@ module.exports = {
'vendor/bowser/bowser.js',
'vendor/angular-growl-v2/build/angular-growl.js',
'vendor/angular-local-storage/dist/angular-local-storage.js',
'vendor/humanize-duration/humanize-duration.js'
'vendor/humanize-duration/humanize-duration.js',
'vendor/round-date/roundDate.js'
],
css: [
// NOTE: bootstrap css imported in application.tpl.scss
Expand Down
47 changes: 10 additions & 37 deletions src/app/d3Bindings/eventDistribution/distributionVisualisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ angular
"DistributionVisualisation",
[
"d3",
function (d3) {
"roundDate",
function (d3, roundDate) {
return function DistributionVisualisation(target, data, dataFunctions) {
// variables
var that = this,
Expand Down Expand Up @@ -192,49 +193,21 @@ angular
high = new Date(dataFunctions.getHigh(current));

// round down to the lower unit of time, determined by `tileSizeSeconds`
var niceLow = d3.time.second.floor(low);
var niceHigh = d3.time.second.ceil(floor);

var m = roundDate(tileSizePixels, low);
var niceLow = roundDate.floor(tileSizeSeconds, low),
niceHigh = roundDate.ceil(tileSizeSeconds, high),
offset = niceLow;

// use d3's in built range functionality to generate steps
var steps = d3.time.seconds(niceLow, niceHigh, tileSizeSeconds);

while (false /*tileOffset < high*/) {

previous.push()
var steps = [];
while (offset <= niceHigh) {
steps.push(offset);
offset = d3.time.second.offset(offset, tileSizeSeconds);
}

tileSizeSeconds
return steps;
}

function roundDate(roundToSeconds, roundStyle, date) {
if (arguments.length === 2) {
date = roundStyle;
roundStyle = "round";
}
else if (arguments.length !== 3) {
throw new Error("Expected either 2 or 3 arguments");
}

var roundToMilliseconds = roundToSeconds * 1000,
unix = date.getTime(),
remainder = unix % roundToMilliseconds,
result;

if (roundStyle === "round") {
roundStyle = unix / remainder >= 0.5 ? "ceil" : "floor";
}

if (roundStyle === "floor") {
result = new Date(unix - remainder)
}
else if (roundStyle === "ceil") {
result = new Date(unix + (roundToMilliseconds - remainder));
}

return result;
}
}
}
]
Expand Down

0 comments on commit 8e45b21

Please sign in to comment.