@ -2,16 +2,20 @@ describe('c3 chart tooltip', function () {
'use strict' ;
'use strict' ;
var chart ;
var chart ;
var tooltipConfiguration ;
var tooltipConfiguration = { } ;
var dataOrder = 'desc' ;
var dataGroups ;
var args = function ( ) {
var args = function ( ) {
return {
return {
data : {
data : {
columns : [
columns : [
[ 'data1' , 30 , 200 , 100 , 400 , 150 , 250 ] ,
[ 'data1' , 30 , 200 , 100 , 400 , 150 , 250 ] , // 1130
[ 'data2' , 50 , 20 , 10 , 40 , 15 , 25 ] ,
[ 'data2' , 50 , 20 , 10 , 40 , 15 , 25 ] , // 160
[ 'data3' , 150 , 120 , 110 , 140 , 115 , 125 ]
[ 'data3' , 150 , 120 , 110 , 140 , 115 , 125 ] // 760
] ,
] ,
order : dataOrder ,
groups : dataGroups
} ,
} ,
tooltip : tooltipConfiguration
tooltip : tooltipConfiguration
} ;
} ;
@ -19,6 +23,8 @@ describe('c3 chart tooltip', function () {
beforeEach ( function ( done ) {
beforeEach ( function ( done ) {
chart = window . initChart ( chart , args ( ) , done ) ;
chart = window . initChart ( chart , args ( ) , done ) ;
dataOrder = 'desc' ;
dataGroups = undefined ;
} ) ;
} ) ;
describe ( 'tooltip position' , function ( ) {
describe ( 'tooltip position' , function ( ) {
@ -99,24 +105,320 @@ describe('c3 chart tooltip', function () {
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'tooltip getTooltipContent' , function ( ) {
describe ( 'tooltip with data_order as desc with grouped data' , function ( ) {
beforeAll ( function ( ) {
beforeAll ( function ( ) {
dataOrder = 'desc' ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each data in descending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 1130
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 760
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 160
} ) ;
} ) ;
describe ( 'tooltip with data_order as asc with grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = 'asc' ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each data in ascending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 160
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 760
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 1130
} ) ;
} ) ;
describe ( 'tooltip with data_order as NULL with grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = null ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each data in given order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with data_order as Function with grouped data' , function ( ) {
beforeAll ( function ( ) {
var order = [ 'data2' , 'data1' , 'data3' ] ;
dataOrder = function ( data1 , data2 ) {
return order . indexOf ( data1 . id ) - order . indexOf ( data2 . id ) ;
} ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each data in order given by function' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with data_order as Array with grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = [ 'data2' , 'data1' , 'data3' ] ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each data in order given by array' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with data_order as desc with un-grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = 'desc' ;
} ) ;
it ( 'should display each tooltip value descending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 110
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 100
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 10
} ) ;
} ) ;
describe ( 'tooltip with data_order as asc with un-grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = 'asc' ;
} ) ;
it ( 'should display each tooltip value in ascending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 10
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 100
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 110
} ) ;
} ) ;
describe ( 'tooltip with data_order as NULL with un-grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = null ;
} ) ;
it ( 'should display each tooltip value in given data order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with data_order as Function with un-grouped data' , function ( ) {
beforeAll ( function ( ) {
var order = [ 'data2' , 'data1' , 'data3' ] ;
dataOrder = function ( data1 , data2 ) {
return order . indexOf ( data1 . id ) - order . indexOf ( data2 . id ) ;
} ;
} ) ;
it ( 'should display each tooltip value in data order given by function' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with data_order as Array with un-grouped data' , function ( ) {
beforeAll ( function ( ) {
dataOrder = [ 'data2' , 'data1' , 'data3' ] ;
} ) ;
it ( 'should display each tooltip value in data order given by array' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with tooltip_order as desc' , function ( ) {
beforeAll ( function ( ) {
tooltipConfiguration = {
tooltipConfiguration = {
data _order : 'desc'
order : 'desc'
} ;
} ;
// this should be ignored
dataOrder = 'asc' ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each tooltip value descending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 110
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 100
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 10
} ) ;
} ) ;
} ) ;
describe ( 'tooltip with tooltip_order as asc' , function ( ) {
beforeAll ( function ( ) {
tooltipConfiguration = {
order : 'asc'
} ;
it ( 'should sort values desc' , function ( ) {
// this should be ignored
var eventRect = d3 . select ( '.c3-event-rect-2' ) . node ( ) ;
dataOrder = 'desc' ;
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , eventRect ) ;
dataGroups = [ [ 'data1' , 'data2' , 'data3' ] ] ;
} ) ;
it ( 'should display each tooltip value in ascending order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
var tooltipTable = d3 . select ( '.c3-tooltip' ) [ 0 ] ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
var expected = [ "" , "c3-tooltip-name--data3" ,
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ; // 10
"c3-tooltip-name--data1" , "c3-tooltip-name--data2" ] ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ; // 100
var i ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ; // 110
for ( i = 0 ; i < tooltipTable [ 0 ] . rows . length ; i ++ ) {
} ) ;
expect ( tooltipTable [ 0 ] . rows [ i ] . className ) . toBe ( expected [ i ] ) ;
} ) ;
}
describe ( 'tooltip with tooltip_order as NULL' , function ( ) {
beforeAll ( function ( ) {
tooltipConfiguration = {
order : null
} ;
} ) ;
it ( 'should display each tooltip value in given order' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with tooltip_order as Function' , function ( ) {
beforeAll ( function ( ) {
var order = [ 'data2' , 'data1' , 'data3' ] ;
tooltipConfiguration = {
order : function ( data1 , data2 ) {
return order . indexOf ( data1 . id ) - order . indexOf ( data2 . id ) ;
}
} ;
} ) ;
it ( 'should display each tooltip value in data order given by function' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
describe ( 'tooltip with tooltip_order as Array' , function ( ) {
beforeAll ( function ( ) {
tooltipConfiguration = {
order : [ 'data2' , 'data1' , 'data3' ]
} ;
} ) ;
it ( 'should display each tooltip value in data order given by array' , function ( ) {
window . setMouseEvent ( chart , 'mousemove' , 100 , 100 , d3 . select ( '.c3-event-rect-2' ) . node ( ) ) ;
var classes = d3 . selectAll ( '.c3-tooltip tr' ) [ 0 ] . map ( function ( node ) {
return node . className ;
} ) ;
expect ( classes [ 0 ] ) . toBe ( '' ) ; // header
expect ( classes [ 1 ] ) . toBe ( 'c3-tooltip-name--data2' ) ;
expect ( classes [ 2 ] ) . toBe ( 'c3-tooltip-name--data1' ) ;
expect ( classes [ 3 ] ) . toBe ( 'c3-tooltip-name--data3' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;