Skip to content

Commit

Permalink
Some work toward speced#598. Rollover code seems a bit janky / not pr…
Browse files Browse the repository at this point in the history
…operly ironed-out for these kinds of use cases
  • Loading branch information
hamilton committed Jan 21, 2016
1 parent a2b7388 commit efda636
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
41 changes: 25 additions & 16 deletions dist/metricsgraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,7 @@ function mg_append_aggregate_rollover_text (args, textContainer, formatted_x, d,

function mg_update_rollover_text (args, svg, fmt, shape, d, i) {
var num = format_rollover_number(args);
if (args.chart_type === 'bar') num = function(d){return d};
var textContainer = mg_reset_active_datapoint_text(svg);
var formatted_y = mg_format_y_rollover(args, num, d);
var formatted_x = mg_format_x_rollover(args, fmt, d);
Expand All @@ -2341,13 +2342,17 @@ function mg_update_rollover_text (args, svg, fmt, shape, d, i) {
.color(args, d);
}

if (args.chart_type === 'bar' && args.group_accessor) mouseover_tspan(textContainer, d[args.group_accessor] + ' ', 'mg-bar-group-rollover-text').bold();

// shape to accompany rollover.
if (args.data.length > 1 || args.chart_type === 'point') {
mouseover_tspan(textContainer, shape + ' ').color(args, d);
}
// rollover text.
mouseover_tspan(textContainer, formatted_x, args.time_series ? 'mg-x-rollover-text' : null);
mouseover_tspan(textContainer, formatted_y, args.time_series ? 'mg-y-rollover-text' : null);
if (args.chart_type === 'bar' && args.predictor_accessor) mouseover_tspan(textContainer, ' ' + args.predictor_accessor + ': ' + d[args.predictor_accessor], 'mg-bar-predictor-rollover-text')
if (args.chart_type === 'bar' && args.baseline_accessor) mouseover_tspan(textContainer, ' ' + args.baseline_accessor + ': ' + d[args.baseline_accessor], 'mg-bar-baseline-rollover-text')
}
}

Expand Down Expand Up @@ -4288,11 +4293,11 @@ MG.button_layout = function(target) {
var label_units = this.is_vertical ? args.yax_units : args.xax_units;

return function(d, i) {
svg.selectAll('text')
.filter(function(g, j) {
return d === g;
})
.attr('opacity', 0.3);
// svg.selectAll('text')
// .filter(function(g, j) {
// return d === g;
// })
// .attr('opacity', 0.3);

var fmt = MG.time_format(args.utc_time, '%b %e, %Y');
var num = format_rollover_number(args);
Expand All @@ -4306,17 +4311,21 @@ MG.button_layout = function(target) {

//update rollover text
if (args.show_rollover_text) {
svg.select('.mg-active-datapoint')
.text(function() {
if (args.time_series) {
var dd = new Date(+d[data_accessor]);
dd.setDate(dd.getDate());

return fmt(dd) + ' ' + label_units + num(d[label_accessor]);
} else {
return d[label_accessor] + ': ' + num(d[data_accessor]);
}
});


//svg.select('.mg-active-datapoint')
mg_update_rollover_text(args, svg, fmt, '\u2014 ', d, i);
// .text(function() {
// if (args.time_series) {
// var dd = new Date(+d[data_accessor]);
// dd.setDate(dd.getDate());

// return fmt(dd) + ' ' + label_units + num(d[label_accessor]);
// } else {
// return d[label_accessor] + ': ' + num(d[data_accessor]);
// }
// });
}

if (args.mouseover) {
Expand Down Expand Up @@ -5462,7 +5471,7 @@ function mg_format_x_rollover(args, fmt, d) {

formatted_x = fmt(date) + ' ';
} else {
formatted_x = args.x_accessor + ': ' + d[args.x_accessor] + ', ';
formatted_x = args.x_accessor + ': ' + d[args.x_accessor] + ' ';
}
}
return formatted_x;
Expand Down
6 changes: 3 additions & 3 deletions dist/metricsgraphics.min.js

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions src/js/charts/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@
var label_units = this.is_vertical ? args.yax_units : args.xax_units;

return function(d, i) {
svg.selectAll('text')
.filter(function(g, j) {
return d === g;
})
.attr('opacity', 0.3);
// svg.selectAll('text')
// .filter(function(g, j) {
// return d === g;
// })
// .attr('opacity', 0.3);

var fmt = MG.time_format(args.utc_time, '%b %e, %Y');
var num = format_rollover_number(args);
Expand All @@ -312,17 +312,21 @@

//update rollover text
if (args.show_rollover_text) {
svg.select('.mg-active-datapoint')
.text(function() {
if (args.time_series) {
var dd = new Date(+d[data_accessor]);
dd.setDate(dd.getDate());

return fmt(dd) + ' ' + label_units + num(d[label_accessor]);
} else {
return d[label_accessor] + ': ' + num(d[data_accessor]);
}
});



//svg.select('.mg-active-datapoint')
mg_update_rollover_text(args, svg, fmt, '\u2014 ', d, i);
// .text(function() {
// if (args.time_series) {
// var dd = new Date(+d[data_accessor]);
// dd.setDate(dd.getDate());

// return fmt(dd) + ' ' + label_units + num(d[label_accessor]);
// } else {
// return d[label_accessor] + ': ' + num(d[data_accessor]);
// }
// });
}

if (args.mouseover) {
Expand Down
5 changes: 5 additions & 0 deletions src/js/common/rollover.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function mg_append_aggregate_rollover_text (args, textContainer, formatted_x, d,

function mg_update_rollover_text (args, svg, fmt, shape, d, i) {
var num = format_rollover_number(args);
if (args.chart_type === 'bar') num = function(d){return d};
var textContainer = mg_reset_active_datapoint_text(svg);
var formatted_y = mg_format_y_rollover(args, num, d);
var formatted_x = mg_format_x_rollover(args, fmt, d);
Expand All @@ -126,12 +127,16 @@ function mg_update_rollover_text (args, svg, fmt, shape, d, i) {
.color(args, d);
}

if (args.chart_type === 'bar' && args.group_accessor) mouseover_tspan(textContainer, d[args.group_accessor] + ' ', 'mg-bar-group-rollover-text').bold();

// shape to accompany rollover.
if (args.data.length > 1 || args.chart_type === 'point') {
mouseover_tspan(textContainer, shape + ' ').color(args, d);
}
// rollover text.
mouseover_tspan(textContainer, formatted_x, args.time_series ? 'mg-x-rollover-text' : null);
mouseover_tspan(textContainer, formatted_y, args.time_series ? 'mg-y-rollover-text' : null);
if (args.chart_type === 'bar' && args.predictor_accessor) mouseover_tspan(textContainer, ' ' + args.predictor_accessor + ': ' + d[args.predictor_accessor], 'mg-bar-predictor-rollover-text')
if (args.chart_type === 'bar' && args.baseline_accessor) mouseover_tspan(textContainer, ' ' + args.baseline_accessor + ': ' + d[args.baseline_accessor], 'mg-bar-baseline-rollover-text')
}
}
2 changes: 1 addition & 1 deletion src/js/misc/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function mg_format_x_rollover(args, fmt, d) {

formatted_x = fmt(date) + ' ';
} else {
formatted_x = args.x_accessor + ': ' + d[args.x_accessor] + ', ';
formatted_x = args.x_accessor + ': ' + d[args.x_accessor] + ' ';
}
}
return formatted_x;
Expand Down

0 comments on commit efda636

Please sign in to comment.