Skip to content

Commit

Permalink
Merge pull request w3c#480 from Tchanders/utc-option
Browse files Browse the repository at this point in the history
Fix issue w3c#479
  • Loading branch information
almossawi committed Aug 10, 2015
2 parents a78f7d6 + 011b21e commit 85caba4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/js/charts/bar.js
Expand Up @@ -299,7 +299,7 @@
})
.attr('opacity', 0.3);

var fmt = d3.time.format('%b %e, %Y');
var fmt = MG.time_format(args.utc_time, '%b %e, %Y');
var num = format_rollover_number(args);

//highlight active bar
Expand Down
4 changes: 2 additions & 2 deletions src/js/charts/histogram.js
Expand Up @@ -130,7 +130,7 @@

this.rolloverOn = function(args) {
var svg = mg_get_svg_child_of(args.target);
var x_formatter = d3.time.format('%Y-%m-%d');
var x_formatter = MG.time_format(args.utc_time, '%Y-%m-%d');

return function(d, i) {
svg.selectAll('text')
Expand All @@ -139,7 +139,7 @@
})
.attr('opacity', 0.3);

var fmt = d3.time.format('%b %e, %Y');
var fmt = MG.time_format(args.utc_time, '%b %e, %Y');
var num = format_rollover_number(args);

svg.selectAll('.mg-bar rect')
Expand Down
18 changes: 9 additions & 9 deletions src/js/charts/line.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/js/charts/point.js
Expand Up @@ -141,7 +141,7 @@
});
}

var fmt = d3.time.format('%b %e, %Y');
var fmt = MG.time_format(args.utc_time, '%b %e, %Y');
var num = format_rollover_number(args);

//update rollover text
Expand Down
1 change: 1 addition & 0 deletions src/js/common/data_graphic.js
Expand Up @@ -74,6 +74,7 @@ MG.data_graphic = function(args) {
markers: null, // sets the marker lines
scalefns: {},
scales: {},
utc_time: false,
show_year_markers: false,
show_secondary_x_label: true,
target: '#viz',
Expand Down
28 changes: 16 additions & 12 deletions src/js/common/x_axis.js
Expand Up @@ -67,8 +67,12 @@ function x_axis(args) {

mg_find_min_max_x(args);

var time_scale = (args.utc_time)
? d3.time.scale.utc()
: d3.time.scale();

args.scales.X = (args.time_series)
? d3.time.scale()
? time_scale
: d3.scale.linear();

args.scales.X
Expand Down Expand Up @@ -303,15 +307,15 @@ function mg_get_time_frame(diff){
return time_frame;
}

function mg_get_time_format(diff){
function mg_get_time_format(utc, diff){
if (diff < 60) {
main_time_format = d3.time.format('%M:%S');
main_time_format = MG.time_format(utc, '%M:%S');
} else if (diff / (60 * 60) <= 24) {
main_time_format = d3.time.format('%H:%M');
main_time_format = MG.time_format(utc, '%H:%M');
} else if (diff / (60 * 60) <= 24 * 4) {
main_time_format = d3.time.format('%H:%M');
main_time_format = MG.time_format(utc, '%H:%M');
} else {
main_time_format = d3.time.format('%b %d');
main_time_format = MG.time_format(utc, '%b %d');
}
return main_time_format;
}
Expand All @@ -331,13 +335,13 @@ function mg_default_xax_format(args) {
diff = (args.processed.max_x - args.processed.min_x) / 1000;

time_frame = mg_get_time_frame(diff);
main_time_format = mg_get_time_format(diff);
main_time_format = mg_get_time_format(args.utc_time, diff);
}

args.processed.main_x_time_format = main_time_format;
args.processed.x_time_frame = time_frame;

var df = d3.time.format('%b %d');
var df = MG.time_format(args.utc_time, '%b %d');
var pf = d3.formatPrefix(d);

// format as date or not, of course user can pass in
Expand Down Expand Up @@ -439,19 +443,19 @@ function mg_add_x_tick_labels(g, args) {
switch(time_frame) {
case 'seconds':
secondary_function = d3.time.days;
yformat = d3.time.format('%I %p');
yformat = MG.time_format(args.utc_time, '%I %p');
break;
case 'less-than-a-day':
secondary_function = d3.time.days;
yformat = d3.time.format('%b %d');
yformat = MG.time_format(args.utc_time, '%b %d');
break;
case 'four-days':
secondary_function = d3.time.days;
yformat = d3.time.format('%b %d');
yformat = MG.time_format(args.utc_time, '%b %d');
break;
default:
secondary_function = d3.time.years;
yformat = d3.time.format('%Y');
yformat = MG.time_format(args.utc_time, '%Y');
}

var years = secondary_function(args.processed.min_x, args.processed.max_x);
Expand Down
3 changes: 3 additions & 0 deletions src/js/misc/utility.js
Expand Up @@ -22,6 +22,9 @@ MG.convert.number = function(data, accessor) {
return data;
};

MG.time_format = function(utc, specifier) {
return utc ? d3.time.format.utc(specifier) : d3.time.format(specifier);
};

function is_array(thing){
return Object.prototype.toString.call(thing) === '[object Array]';
Expand Down

0 comments on commit 85caba4

Please sign in to comment.