Skip to content

Commit

Permalink
Fix issue w3c#295
Browse files Browse the repository at this point in the history
  • Loading branch information
almossawi committed Jan 8, 2015
1 parent 1a089f0 commit 2c68b7c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
33 changes: 30 additions & 3 deletions dist/metricsgraphics.js
Expand Up @@ -2502,7 +2502,7 @@
d3.selectAll('.mg-line' + d['line_id'] + '-color.roll_' + id)
.each(function(d, i) {
d3.select(this).on('mouseover')(d,i);
})
})
}

svg.selectAll('text')
Expand Down Expand Up @@ -2572,7 +2572,7 @@
d3.selectAll('.roll_' + id)
.each(function(d, i) {
d3.select(this).on('mouseout')(d);
});
})
}

//remove active datapoint text on mouse out
Expand Down Expand Up @@ -2687,7 +2687,13 @@
var bar = g.selectAll('.mg-bar')
.data(args.data[0])
.enter().append('g')
.attr('class', 'mg-rollover-rects')
.attr('class', function(d, i) {
if(args.linked) {
return 'mg-rollover-rects roll_' + i;
} else {
return 'mg-rollover-rects';
}
})
.attr('transform', function(d) {
return "translate(" + (args.scales.X(d[args.x_accessor])) + "," + 0 + ")";
});
Expand Down Expand Up @@ -2750,6 +2756,17 @@
d3.selectAll($(args.target).find(' svg .mg-bar :eq(' + i + ')'))
.classed('active', true);

//trigger mouseover on all matching bars
if(args.linked && !MG.globals.link) {
MG.globals.link = true;

//trigger mouseover on matching bars in .linked charts
d3.selectAll('.mg-rollover-rects.roll_' + i + ' rect')
.each(function(d) { //use existing i
d3.select(this).on('mouseover')(d,i);
})
}

//update rollover text
if (args.show_rollover_text) {
svg.select('.mg-active-datapoint')
Expand Down Expand Up @@ -2779,6 +2796,16 @@
var svg = d3.select($(args.target).find('svg').get(0));

return function(d, i) {
if(args.linked && MG.globals.link) {
MG.globals.link = false;

//trigger mouseout on matching bars in .linked charts
d3.selectAll('.mg-rollover-rects.roll_' + i + ' rect')
.each(function(d) { //use existing i
d3.select(this).on('mouseout')(d,i);
})
}

//reset active bar
d3.selectAll($(args.target).find('svg .mg-bar :eq(' + i + ')'))
.classed('active', false);
Expand Down
2 changes: 1 addition & 1 deletion dist/metricsgraphics.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/js/main.js
Expand Up @@ -688,6 +688,7 @@ $(document).ready(function() {
height: trunk.height,
right: trunk.right,
target: '#histogram3',
linked: true,
y_extended_ticks: true,
x_accessor:'val1',
mouseover: function(d, i) {
Expand All @@ -706,6 +707,7 @@ $(document).ready(function() {
data: fourth,
chart_type: 'histogram',
width: trunk.width,
linked: true,
height: trunk.height,
right: trunk.right,
target: '#histogram4',
Expand Down
29 changes: 28 additions & 1 deletion src/js/charts/histogram.js
Expand Up @@ -85,7 +85,13 @@ charts.histogram = function(args) {
var bar = g.selectAll('.mg-bar')
.data(args.data[0])
.enter().append('g')
.attr('class', 'mg-rollover-rects')
.attr('class', function(d, i) {
if(args.linked) {
return 'mg-rollover-rects roll_' + i;
} else {
return 'mg-rollover-rects';
}
})
.attr('transform', function(d) {
return "translate(" + (args.scales.X(d[args.x_accessor])) + "," + 0 + ")";
});
Expand Down Expand Up @@ -148,6 +154,17 @@ charts.histogram = function(args) {
d3.selectAll($(args.target).find(' svg .mg-bar :eq(' + i + ')'))
.classed('active', true);

//trigger mouseover on all matching bars
if(args.linked && !MG.globals.link) {
MG.globals.link = true;

//trigger mouseover on matching bars in .linked charts
d3.selectAll('.mg-rollover-rects.roll_' + i + ' rect')
.each(function(d) { //use existing i
d3.select(this).on('mouseover')(d,i);
})
}

//update rollover text
if (args.show_rollover_text) {
svg.select('.mg-active-datapoint')
Expand Down Expand Up @@ -177,6 +194,16 @@ charts.histogram = function(args) {
var svg = d3.select($(args.target).find('svg').get(0));

return function(d, i) {
if(args.linked && MG.globals.link) {
MG.globals.link = false;

//trigger mouseout on matching bars in .linked charts
d3.selectAll('.mg-rollover-rects.roll_' + i + ' rect')
.each(function(d) { //use existing i
d3.select(this).on('mouseout')(d,i);
})
}

//reset active bar
d3.selectAll($(args.target).find('svg .mg-bar :eq(' + i + ')'))
.classed('active', false);
Expand Down
4 changes: 2 additions & 2 deletions src/js/charts/line.js
Expand Up @@ -353,7 +353,7 @@ charts.line = function(args) {
d3.selectAll('.mg-line' + d['line_id'] + '-color.roll_' + id)
.each(function(d, i) {
d3.select(this).on('mouseover')(d,i);
})
})
}

svg.selectAll('text')
Expand Down Expand Up @@ -423,7 +423,7 @@ charts.line = function(args) {
d3.selectAll('.roll_' + id)
.each(function(d, i) {
d3.select(this).on('mouseout')(d);
});
})
}

//remove active datapoint text on mouse out
Expand Down

0 comments on commit 2c68b7c

Please sign in to comment.