Skip to content

Commit 135d434

Browse files
committed
Fixed tooltip position relative to the parent element, taking labels into account.
1 parent 4a04e00 commit 135d434

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

calendar-heatmap.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ angular.module('g1b.calendar-heatmap', []).
8282

8383
dayCircles.on('mouseover', function (d) {
8484
var circle = d3.select(this);
85+
var circle_xpos = parseInt(circle.attr('cx'));
86+
var circle_ypos = parseInt(circle.attr('cy'));
8587
(function repeat() {
8688
circle = circle.transition()
8789
.duration(500)
@@ -95,12 +97,12 @@ angular.module('g1b.calendar-heatmap', []).
9597
})();
9698
tooltip.html(scope.tooltipHTMLForDate(d))
9799
.style('left', function () {
98-
if ( (parseInt(svg.style('width')) - d3.event.pageX ) < TOOLTIP_WIDTH ) {
99-
return (d3.event.pageX - CIRCLE_RADIUS*4 - TOOLTIP_WIDTH) + 'px';
100+
if ( (parseInt(svg.style('width')) - circle_xpos ) < TOOLTIP_WIDTH ) {
101+
return (circle_xpos - TOOLTIP_WIDTH) + 'px';
100102
}
101-
return (d3.event.pageX + CIRCLE_RADIUS) + 'px';
103+
return (circle_xpos + TOOLTIP_WIDTH/2) + 'px';
102104
})
103-
.style('top', (d3.event.pageY - CIRCLE_RADIUS) + 'px')
105+
.style('top', (circle_ypos + CIRCLE_RADIUS*3 + MONTH_LABEL_PADDING) + 'px')
104106
.transition()
105107
.duration(250)
106108
.ease('ease-in')

0 commit comments

Comments
 (0)