@@ -41,6 +41,52 @@ var C3Chart = function (_React$Component) {
4141 key : 'componentDidMount' ,
4242 value : function componentDidMount ( ) {
4343 c3 = require ( 'c3' ) ;
44+
45+ // function override
46+ c3 . chart . internal . fn . tooltipPosition = function ( dataToShow , tWidth , tHeight , element ) {
47+ var $$ = this ,
48+ config = $$ . config ,
49+ d3 = $$ . d3 ;
50+ var svgLeft , tooltipLeft , tooltipRight , tooltipTop , chartRight ;
51+ var forArc = $$ . hasArcType ( ) ,
52+ mouse = d3 . mouse ( element ) ;
53+ if ( navigator . userAgent . indexOf ( "Firefox" ) != - 1 ) {
54+ // this works in Firefox
55+ mouse = [ d3 . event . offsetX - 80 , d3 . event . offsetY - 80 ] ;
56+ }
57+ // Determin tooltip position
58+ if ( forArc ) {
59+ tooltipLeft = ( $$ . width - ( $$ . isLegendRight ? $$ . getLegendWidth ( ) : 0 ) ) / 2 + mouse [ 0 ] ;
60+ tooltipTop = $$ . height / 2 + mouse [ 1 ] + 20 ;
61+ } else {
62+ svgLeft = $$ . getSvgLeft ( true ) ;
63+ if ( config . axis_rotated ) {
64+ tooltipLeft = svgLeft + mouse [ 0 ] + 100 ;
65+ tooltipRight = tooltipLeft + tWidth ;
66+ chartRight = $$ . currentWidth - $$ . getCurrentPaddingRight ( ) ;
67+ tooltipTop = $$ . x ( dataToShow [ 0 ] . x ) + 20 ;
68+ } else {
69+ tooltipLeft = svgLeft + $$ . getCurrentPaddingLeft ( true ) + $$ . x ( dataToShow [ 0 ] . x ) + 20 ;
70+ tooltipRight = tooltipLeft + tWidth ;
71+ chartRight = svgLeft + $$ . currentWidth - $$ . getCurrentPaddingRight ( ) ;
72+ tooltipTop = mouse [ 1 ] + 15 ;
73+ }
74+
75+ if ( tooltipRight > chartRight ) {
76+ // 20 is needed for Firefox to keep tooltip width
77+ tooltipLeft -= tooltipRight - chartRight + 20 ;
78+ }
79+ if ( tooltipTop + tHeight > $$ . currentHeight ) {
80+ tooltipTop -= tHeight + 30 ;
81+ }
82+ }
83+ if ( tooltipTop < 0 ) {
84+ tooltipTop = 0 ;
85+ }
86+
87+ return { top : tooltipTop , left : tooltipLeft } ;
88+ } ;
89+
4490 this . updateChart ( this . props ) ;
4591 }
4692 } , {
0 commit comments