26
26
27
27
import * as d3 from 'd3' ;
28
28
import _ from 'lodash' ;
29
- import '../styles/styles.scss' ;
30
- import isOut from '../util/util' ;
31
29
32
30
require ( 'd3-extended' ) ( d3 ) ;
33
31
@@ -206,8 +204,8 @@ class Graph {
206
204
// Create the X-axis (horizontal)
207
205
this . xAxis = d3 . axisBottom ( this . x ) ;
208
206
209
- // If timescale , set the format of the ticks
210
- if ( this . config . axis . x . scale . type === 'scaleTime' ) {
207
+ // If specified , set the format of the ticks
208
+ if ( this . config . axis . x . scale . format !== null ) {
211
209
this . xAxis . tickFormat ( d3 . timeFormat ( this . config . axis . x . scale . format ) ) ;
212
210
}
213
211
@@ -471,7 +469,8 @@ class Graph {
471
469
selectedElements
472
470
. transition ( )
473
471
. duration ( 250 )
474
- . attr ( 'style' , toggleLegend ? 'opacity: 1' : 'opacity: 0.3' ) ;
472
+ . attr ( 'style' , toggleLegend ? 'opacity: 1' : 'opacity: 0.3' )
473
+ . style ( 'cursor' , 'pointer' ) ;
475
474
} ) ;
476
475
477
476
// Add the legend to the graph and change cursor
@@ -484,7 +483,8 @@ class Graph {
484
483
}
485
484
486
485
// Get the dimensions of the current legend
487
- const legendBox = this . svg . select ( '.igj-legend' ) . node ( ) . getBBox ( ) ;
486
+ const legendBox = d3 . select ( `.${ this . classElement } ` )
487
+ . select ( '.igj-legend' ) . node ( ) . getBBox ( ) ;
488
488
489
489
// Position the legend
490
490
if ( this . config . legend . position === 'bottom' ) {
@@ -552,6 +552,15 @@ class Graph {
552
552
labelY = labels [ 1 ] ;
553
553
}
554
554
555
+ // Helper function to calculate position of tooltip
556
+ function isOut ( valX , valY , w , h ) {
557
+ const out = { } ;
558
+ out . top = ( valY / h ) < 0.15 ;
559
+ out . left = ( valX / w ) < 0.1 ;
560
+ out . right = ( valX / w ) > 0.9 ;
561
+ return out ;
562
+ }
563
+
555
564
this . tooltip = d3 . tip ( )
556
565
. attr ( 'class' , `${ this . classElement } igj-tip` )
557
566
. offset ( ( d ) => {
@@ -609,16 +618,14 @@ class Graph {
609
618
return dir ;
610
619
} )
611
620
. html ( ( d ) => {
612
- let res = '' ;
613
- if ( this . config . axis . x . scale . type === 'scaleTime' ) {
621
+ let res = `
622
+ <strong>${ labelX } :</strong>
623
+ ${ _ . get ( d , keyX ) } </br>` ;
624
+ if ( this . config . axis . x . scale . format !== null ) {
614
625
res = `
615
626
<strong>${ labelX } :</strong>
616
627
${ d3 . timeFormat ( this . config . axis . x . scale . format ) ( _ . get ( d , keyX ) ) } </br>
617
628
` ;
618
- } else {
619
- res = `
620
- <strong>${ labelX } :</strong>
621
- ${ _ . get ( d , keyX ) } </br>` ;
622
629
}
623
630
res += `
624
631
<strong>${ labelY } :</strong>
@@ -662,9 +669,9 @@ class Graph {
662
669
*/
663
670
scaleOnResize ( f ) {
664
671
Graph . resizeHandlers . push ( f ) ;
665
- d3 . select ( window ) . on ( 'resize' , ( ) => {
672
+ d3 . select ( window ) . on ( 'resize' , _ . debounce ( ( ) => {
666
673
Graph . resizeHandlers . forEach ( h => h ( ) ) ;
667
- } ) ;
674
+ } , 150 ) ) ;
668
675
}
669
676
670
677
/**
0 commit comments