Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created April 7, 2015 11:18
Show Gist options
  • Save timruffles/e1f14572412f43d09da4 to your computer and use it in GitHub Desktop.
Save timruffles/e1f14572412f43d09da4 to your computer and use it in GitHub Desktop.
custom d3 multi format time scale - get your own formats/intervals into axis
// array of [format string, useFormat]. formats are accessed in order, return true to use the format
// - this is the default - it pretty much just finds the smallest time period that's non-zero
var multiScale = d3.time.format.utc.multi([
[".%L", function(d) { return d.getUTCMilliseconds(); }],
[":%S", function(d) { return d.getUTCSeconds(); }],
["%I:%M", function(d) { return d.getUTCMinutes(); }],
["%I %p", function(d) { return d.getUTCHours(); }],
["%a %d", function(d) { return d.getUTCDay() && d.getUTCDate() != 1; }],
["%b %d", function(d) { return d.getUTCDate() != 1; }],
["%B", function(d) { return d.getUTCMonth(); }],
["%Y", function(){ return true }]
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment