@ -8,15 +8,26 @@
var c3 _chart _fn , c3 _chart _internal _fn ;
var c3 _chart _fn , c3 _chart _internal _fn ;
function Chart ( config ) {
function Chart ( config ) {
var $$ = this . internal = new ChartInternal ( config , this ) ;
var $$ = this . internal = new ChartInternal ( this ) ;
$$ . loadConfig ( config ) ;
$$ . loadConfig ( config ) ;
$$ . init ( ) ;
$$ . init ( ) ;
// bind "this" to nested API
( function bindThis ( fn , target , argThis ) {
for ( var key in fn ) {
target [ key ] = fn [ key ] . bind ( argThis ) ;
if ( Object . keys ( fn [ key ] ) . length > 0 ) {
bindThis ( fn [ key ] , target [ key ] , argThis ) ;
}
}
} ) ( c3 _chart _fn , this , this ) ;
}
}
function ChartInternal ( config , api ) {
function ChartInternal ( api ) {
var $$ = this ;
var $$ = this ;
$$ . d3 = window . d3 ? window . d3 : typeof require !== 'undefined' ? require ( "d3" ) : undefined ;
$$ . d3 = window . d3 ? window . d3 : typeof require !== 'undefined' ? require ( "d3" ) : undefined ;
$$ . api = api ;
$$ . api = api ;
$$ . config = $$ . getDefaultConfig ( ) ;
$$ . data = { } ;
$$ . data = { } ;
$$ . cache = { } ;
$$ . cache = { } ;
$$ . axes = { } ;
$$ . axes = { } ;
@ -59,7 +70,7 @@
} ;
} ;
c3 _chart _internal _fn . initParams = function ( ) {
c3 _chart _internal _fn . initParams = function ( ) {
var $$ = this , d3 = $$ . d3 ;
var $$ = this , d3 = $$ . d3 , config = $$ . config ;
// MEMO: clipId needs to be unique because it conflicts when multiple charts exist
// MEMO: clipId needs to be unique because it conflicts when multiple charts exist
$$ . clipId = "c3-" + ( + new Date ( ) ) + '-clip' ,
$$ . clipId = "c3-" + ( + new Date ( ) ) + '-clip' ,
@ -78,7 +89,7 @@
$$ . color = $$ . generateColor ( ) ;
$$ . color = $$ . generateColor ( ) ;
$$ . levelColor = $$ . generateLevelColor ( ) ;
$$ . levelColor = $$ . generateLevelColor ( ) ;
$$ . dataTimeFormat = config [ _ _data _x _l ocaltime] ? d3 . time . format : d3 . time . format . utc ;
$$ . dataTimeFormat = config [ _ _data _xL ocaltime ] ? d3 . time . format : d3 . time . format . utc ;
$$ . axisTimeFormat = config [ _ _axis _x _localtime ] ? d3 . time . format : d3 . time . format . utc ;
$$ . axisTimeFormat = config [ _ _axis _x _localtime ] ? d3 . time . format : d3 . time . format . utc ;
$$ . defaultAxisTimeFormat = $$ . axisTimeFormat . multi ( [
$$ . defaultAxisTimeFormat = $$ . axisTimeFormat . multi ( [
[ ".%L" , function ( d ) { return d . getMilliseconds ( ) ; } ] ,
[ ".%L" , function ( d ) { return d . getMilliseconds ( ) ; } ] ,
@ -505,6 +516,7 @@
var drawArea , drawBar , drawLine , xForText , yForText ;
var drawArea , drawBar , drawLine , xForText , yForText ;
var duration , durationForExit , durationForAxis , waitForDraw ;
var duration , durationForExit , durationForAxis , waitForDraw ;
var targetsToShow = $$ . filterTargetsToShow ( $$ . data . targets ) , tickValues , i , intervalForCulling ;
var targetsToShow = $$ . filterTargetsToShow ( $$ . data . targets ) , tickValues , i , intervalForCulling ;
var xv , cx , cy ;
xgrid = xgridLines = mainCircle = mainText = d3 . selectAll ( [ ] ) ;
xgrid = xgridLines = mainCircle = mainText = d3 . selectAll ( [ ] ) ;
@ -870,13 +882,13 @@
}
}
}
}
var xv _ = generateCall ( $$ . xv , $$ ) ;
xv = generateCall ( $$ . xv , $$ ) ;
cx = generateCall ( $$ . config [ _ _axis _rotated ] ? $$ . circleY : $$ . circleX , $$ ) ;
cy = generateCall ( $$ . config [ _ _axis _rotated ] ? $$ . circleX : $$ . circleY , $$ ) ;
// transition should be derived from one transition
// transition should be derived from one transition
d3 . transition ( ) . duration ( duration ) . each ( function ( ) {
d3 . transition ( ) . duration ( duration ) . each ( function ( ) {
var transitions = [ ] ,
var transitions = [ ] ;
cx = generateCall ( $$ . config [ _ _axis _rotated ] ? $$ . circleY : $$ . circleX , $$ ) ,
cy = generateCall ( $$ . config [ _ _axis _rotated ] ? $$ . circleX : $$ . circleY , $$ ) ;
transitions . push ( mainBar . transition ( )
transitions . push ( mainBar . transition ( )
. attr ( 'd' , drawBar )
. attr ( 'd' , drawBar )
@ -904,20 +916,20 @@
. style ( "fill" , $$ . color )
. style ( "fill" , $$ . color )
. style ( "fill-opacity" , options . flow ? 0 : generateCall ( $$ . opacityForText , $$ ) ) ) ;
. style ( "fill-opacity" , options . flow ? 0 : generateCall ( $$ . opacityForText , $$ ) ) ) ;
transitions . push ( mainRegion . selectAll ( 'rect' ) . transition ( )
transitions . push ( mainRegion . selectAll ( 'rect' ) . transition ( )
. attr ( "x" , $$ . regionX )
. attr ( "x" , generateCall ( $$ . regionX , $$ ) )
. attr ( "y" , $$ . regionY )
. attr ( "y" , generateCall ( $$ . regionY , $$ ) )
. attr ( "width" , $$ . regionWidth )
. attr ( "width" , generateCall ( $$ . regionWidth , $$ ) )
. attr ( "height" , $$ . regionHeight )
. attr ( "height" , generateCall ( $$ . regionHeight , $$ ) )
. style ( "fill-opacity" , function ( d ) { return isValue ( d . opacity ) ? d . opacity : 0.1 ; } ) ) ;
. style ( "fill-opacity" , function ( d ) { return isValue ( d . opacity ) ? d . opacity : 0.1 ; } ) ) ;
transitions . push ( xgridLines . select ( 'line' ) . transition ( )
transitions . push ( xgridLines . select ( 'line' ) . transition ( )
. attr ( "x1" , config [ _ _axis _rotated ] ? 0 : xv _ )
. attr ( "x1" , config [ _ _axis _rotated ] ? 0 : xv )
. attr ( "x2" , config [ _ _axis _rotated ] ? $$ . width : xv _ )
. attr ( "x2" , config [ _ _axis _rotated ] ? $$ . width : xv )
. attr ( "y1" , config [ _ _axis _rotated ] ? xv _ : $$ . margin . top )
. attr ( "y1" , config [ _ _axis _rotated ] ? xv : $$ . margin . top )
. attr ( "y2" , config [ _ _axis _rotated ] ? xv _ : $$ . height )
. attr ( "y2" , config [ _ _axis _rotated ] ? xv : $$ . height )
. style ( "opacity" , 1 ) ) ;
. style ( "opacity" , 1 ) ) ;
transitions . push ( xgridLines . select ( 'text' ) . transition ( )
transitions . push ( xgridLines . select ( 'text' ) . transition ( )
. attr ( "x" , config [ _ _axis _rotated ] ? $$ . width : 0 )
. attr ( "x" , config [ _ _axis _rotated ] ? $$ . width : 0 )
. attr ( "y" , xv _ )
. attr ( "y" , xv )
. text ( function ( d ) { return d . text ; } )
. text ( function ( d ) { return d . text ; } )
. style ( "opacity" , 1 ) ) ;
. style ( "opacity" , 1 ) ) ;
// Wait for end of transitions if called from flow API
// Wait for end of transitions if called from flow API
@ -1008,11 +1020,11 @@
xgridLines
xgridLines
. attr ( 'transform' , null ) ;
. attr ( 'transform' , null ) ;
xgridLines . select ( 'line' )
xgridLines . select ( 'line' )
. attr ( "x1" , config [ _ _axis _rotated ] ? 0 : xv _ )
. attr ( "x1" , config [ _ _axis _rotated ] ? 0 : xv )
. attr ( "x2" , config [ _ _axis _rotated ] ? $$ . width : xv _ ) ;
. attr ( "x2" , config [ _ _axis _rotated ] ? $$ . width : xv ) ;
xgridLines . select ( 'text' )
xgridLines . select ( 'text' )
. attr ( "x" , config [ _ _axis _rotated ] ? $$ . width : 0 )
. attr ( "x" , config [ _ _axis _rotated ] ? $$ . width : 0 )
. attr ( "y" , xv _ ) ;
. attr ( "y" , xv ) ;
mainBar
mainBar
. attr ( 'transform' , null )
. attr ( 'transform' , null )
. attr ( "d" , drawBar ) ;
. attr ( "d" , drawBar ) ;
@ -1024,8 +1036,8 @@
. attr ( "d" , drawArea ) ;
. attr ( "d" , drawArea ) ;
mainCircle
mainCircle
. attr ( 'transform' , null )
. attr ( 'transform' , null )
. attr ( "cx" , config [ _ _axis _rotated ] ? $$ . circleY : $$ . circleX )
. attr ( "cx" , cx )
. attr ( "cy" , config [ _ _axis _rotated ] ? $$ . circleX : $$ . circleY ) ;
. attr ( "cy" , cy ) ;
mainText
mainText
. attr ( 'transform' , null )
. attr ( 'transform' , null )
. attr ( 'x' , xForText )
. attr ( 'x' , xForText )
@ -1034,8 +1046,8 @@
mainRegion
mainRegion
. attr ( 'transform' , null ) ;
. attr ( 'transform' , null ) ;
mainRegion . select ( 'rect' ) . filter ( $$ . isRegionOnX )
mainRegion . select ( 'rect' ) . filter ( $$ . isRegionOnX )
. attr ( "x" , $$ . regionX )
. attr ( "x" , generateCall ( $$ . regionX , $$ ) )
. attr ( "width" , $$ . regionWidth ) ;
. attr ( "width" , generateCall ( $$ . regionWidth , $$ ) ) ;
eventRectUpdate
eventRectUpdate
. attr ( "x" , config [ _ _axis _rotated ] ? 0 : rectX )
. attr ( "x" , config [ _ _axis _rotated ] ? 0 : rectX )
. attr ( "y" , config [ _ _axis _rotated ] ? rectX : 0 )
. attr ( "y" , config [ _ _axis _rotated ] ? rectX : 0 )
@ -1391,7 +1403,7 @@
c3 _chart _internal _fn . transformAll = function ( withTransition , transitions ) {
c3 _chart _internal _fn . transformAll = function ( withTransition , transitions ) {
var $$ = this ;
var $$ = this ;
$$ . transformMain ( withTransition , transitions ) ;
$$ . transformMain ( withTransition , transitions ) ;
if ( config [ _ _subchart _show ] ) { $$ . transformContext ( withTransition , transitions ) ; }
if ( $$ . config [ _ _subchart _show ] ) { $$ . transformContext ( withTransition , transitions ) ; }
if ( $$ . legend ) { $$ . transformLegend ( withTransition ) ; }
if ( $$ . legend ) { $$ . transformLegend ( withTransition ) ; }
} ;
} ;
@ -1538,7 +1550,7 @@
} else if ( typeof date === 'number' ) {
} else if ( typeof date === 'number' ) {
parsedDate = new Date ( date ) ;
parsedDate = new Date ( date ) ;
} else {
} else {
parsedDate = $$ . dataTimeFormat ( config [ _ _data _x _f ormat] ) . parse ( date ) ;
parsedDate = $$ . dataTimeFormat ( $$ . config [ _ _data _xF ormat ] ) . parse ( date ) ;
}
}
if ( ! parsedDate || isNaN ( + parsedDate ) ) {
if ( ! parsedDate || isNaN ( + parsedDate ) ) {
window . console . error ( "Failed to parse x '" + date + "' to Date object" ) ;
window . console . error ( "Failed to parse x '" + date + "' to Date object" ) ;
@ -1565,9 +1577,9 @@
_ _transition _duration = 'transition_duration' ,
_ _transition _duration = 'transition_duration' ,
_ _data _x = 'data_x' ,
_ _data _x = 'data_x' ,
_ _data _xs = 'data_xs' ,
_ _data _xs = 'data_xs' ,
_ _data _x _format = 'data_x_f ormat',
_ _data _xFormat = 'data_xF ormat' ,
_ _data _x _localtime = 'data_x_l ocaltime',
_ _data _xLocaltime = 'data_xL ocaltime' ,
_ _data _id _converter = 'data_id_c onverter',
_ _data _idConverter = 'data_idC onverter' ,
_ _data _names = 'data_names' ,
_ _data _names = 'data_names' ,
_ _data _classes = 'data_classes' ,
_ _data _classes = 'data_classes' ,
_ _data _groups = 'data_groups' ,
_ _data _groups = 'data_groups' ,
@ -1700,7 +1712,8 @@
_ _tooltip _init _x = 'tooltip_init_x' ,
_ _tooltip _init _x = 'tooltip_init_x' ,
_ _tooltip _init _position = 'tooltip_init_position' ;
_ _tooltip _init _position = 'tooltip_init_position' ;
var config = c3 _chart _internal _fn . config = { } ;
c3 _chart _internal _fn . getDefaultConfig = function ( ) {
var config = { } ;
config [ _ _bindto ] = '#chart' ;
config [ _ _bindto ] = '#chart' ;
config [ _ _size _width ] = undefined ;
config [ _ _size _width ] = undefined ;
config [ _ _size _height ] = undefined ;
config [ _ _size _height ] = undefined ;
@ -1720,9 +1733,9 @@
config [ _ _transition _duration ] = 350 ;
config [ _ _transition _duration ] = 350 ;
config [ _ _data _x ] = undefined ;
config [ _ _data _x ] = undefined ;
config [ _ _data _xs ] = { } ;
config [ _ _data _xs ] = { } ;
config [ _ _data _x _f ormat] = '%Y-%m-%d' ;
config [ _ _data _xF ormat ] = '%Y-%m-%d' ;
config [ _ _data _x _l ocaltime] = true ;
config [ _ _data _xL ocaltime ] = true ;
config [ _ _data _id _c onverter] = function ( id ) { return id ; } ;
config [ _ _data _idC onverter ] = function ( id ) { return id ; } ;
config [ _ _data _names ] = { } ;
config [ _ _data _names ] = { } ;
config [ _ _data _classes ] = { } ;
config [ _ _data _classes ] = { } ;
config [ _ _data _groups ] = [ ] ;
config [ _ _data _groups ] = [ ] ;
@ -1867,18 +1880,21 @@
config [ _ _tooltip _format _name ] = undefined ;
config [ _ _tooltip _format _name ] = undefined ;
config [ _ _tooltip _format _value ] = undefined ;
config [ _ _tooltip _format _value ] = undefined ;
config [ _ _tooltip _contents ] = function ( d , defaultTitleFormat , defaultValueFormat , color ) {
config [ _ _tooltip _contents ] = function ( d , defaultTitleFormat , defaultValueFormat , color ) {
return this . getTooltipContent ? this . getTooltipContent ( d , defaultValu eFormat , defaultValueFormat , color ) : '' ;
return this . getTooltipContent ? this . getTooltipContent ( d , defaultTitl eFormat , defaultValueFormat , color ) : '' ;
} ,
} ,
config [ _ _tooltip _init _show ] = false ;
config [ _ _tooltip _init _show ] = false ;
config [ _ _tooltip _init _x ] = 0 ;
config [ _ _tooltip _init _x ] = 0 ;
config [ _ _tooltip _init _position ] = { top : '0px' , left : '50px' } ;
config [ _ _tooltip _init _position ] = { top : '0px' , left : '50px' } ;
return config ;
} ;
c3 _chart _internal _fn . loadConfig = function ( config ) {
c3 _chart _internal _fn . loadConfig = function ( config ) {
var this _config = this . config , target , keys , read ;
var this _config = this . config , target , keys , read ;
function find ( ) {
function find ( ) {
var key = keys . shift ( ) ;
var key = keys . shift ( ) ;
// console.log("key =>", key, ", target =>", target);
// console.log("key =>", key, ", target =>", target);
if ( key && target && key in target ) {
if ( key && target && typeof target === 'object' && key in target ) {
target = target [ key ] ;
target = target [ key ] ;
return find ( ) ;
return find ( ) ;
}
}
@ -2519,7 +2535,7 @@
} else {
} else {
d = $$ . convertCsvToData ( data . response ) ;
d = $$ . convertCsvToData ( data . response ) ;
}
}
done ( d ) ;
done . call ( $$ , d ) ;
} ) ;
} ) ;
} ;
} ;
c3 _chart _internal _fn . convertCsvToData = function ( csv ) {
c3 _chart _internal _fn . convertCsvToData = function ( csv ) {
@ -2625,6 +2641,7 @@
}
}
} ) ;
} ) ;
// check x is defined
// check x is defined
ids . forEach ( function ( id ) {
ids . forEach ( function ( id ) {
if ( ! $$ . data . xs [ id ] ) {
if ( ! $$ . data . xs [ id ] ) {
@ -2634,7 +2651,7 @@
// convert to target
// convert to target
targets = ids . map ( function ( id , index ) {
targets = ids . map ( function ( id , index ) {
var convertedId = config [ _ _data _id _c onverter] ( id ) ;
var convertedId = config [ _ _data _idC onverter ] ( id ) ;
return {
return {
id : convertedId ,
id : convertedId ,
id _org : id ,
id _org : id ,
@ -3108,13 +3125,13 @@
getPoints = $$ . generateGetBarPoints ( barIndices , false ) ,
getPoints = $$ . generateGetBarPoints ( barIndices , false ) ,
getter = forX ? $$ . getXForText : $$ . getYForText ;
getter = forX ? $$ . getXForText : $$ . getYForText ;
return function ( d , i ) {
return function ( d , i ) {
return getter ( getPoints ( d , i ) , d , this ) ;
return getter . call ( $$ , getPoints ( d , i ) , d , this ) ;
} ;
} ;
} ;
} ;
c3 _chart _internal _fn . getXForText = function ( points , d , textElement ) {
c3 _chart _internal _fn . getXForText = function ( points , d , textElement ) {
var $$ = this ,
var $$ = this ,
box = textElement . getBoundingClientRect ( ) , xPos , padding ;
box = textElement . getBoundingClientRect ( ) , xPos , padding ;
if ( config [ _ _axis _rotated ] ) {
if ( $$ . config [ _ _axis _rotated ] ) {
padding = $$ . isBarType ( d ) ? 4 : 6 ;
padding = $$ . isBarType ( d ) ? 4 : 6 ;
xPos = points [ 2 ] [ 1 ] + padding * ( d . value < 0 ? - 1 : 1 ) ;
xPos = points [ 2 ] [ 1 ] + padding * ( d . value < 0 ? - 1 : 1 ) ;
} else {
} else {
@ -3125,7 +3142,7 @@
c3 _chart _internal _fn . getYForText = function ( points , d , textElement ) {
c3 _chart _internal _fn . getYForText = function ( points , d , textElement ) {
var $$ = this ,
var $$ = this ,
box = textElement . getBoundingClientRect ( ) , yPos ;
box = textElement . getBoundingClientRect ( ) , yPos ;
if ( config [ _ _axis _rotated ] ) {
if ( $$ . config [ _ _axis _rotated ] ) {
yPos = ( points [ 0 ] [ 0 ] + points [ 2 ] [ 0 ] + box . height * 0.6 ) / 2 ;
yPos = ( points [ 0 ] [ 0 ] + points [ 2 ] [ 0 ] + box . height * 0.6 ) / 2 ;
} else {
} else {
yPos = points [ 2 ] [ 1 ] + ( d . value < 0 ? box . height : $$ . isBarType ( d ) ? - 3 : - 6 ) ;
yPos = points [ 2 ] [ 1 ] + ( d . value < 0 ? box . height : $$ . isBarType ( d ) ? - 3 : - 6 ) ;
@ -3366,7 +3383,8 @@
} ;
} ;
c3 _chart _internal _fn . showXGridFocus = function ( selectedData ) {
c3 _chart _internal _fn . showXGridFocus = function ( selectedData ) {
var $$ = this , dataToShow = selectedData . filter ( function ( d ) { return d && isValue ( d . value ) ; } ) ;
var $$ = this , config = $$ . config ,
dataToShow = selectedData . filter ( function ( d ) { return d && isValue ( d . value ) ; } ) ;
if ( ! config [ _ _tooltip _show ] ) { return ; }
if ( ! config [ _ _tooltip _show ] ) { return ; }
// Hide when scatter plot exists
// Hide when scatter plot exists
if ( $$ . hasType ( 'scatter' ) || $$ . hasArcType ( ) ) { return ; }
if ( $$ . hasType ( 'scatter' ) || $$ . hasArcType ( ) ) { return ; }
@ -3537,7 +3555,7 @@
c3 _chart _internal _fn . initLegend = function ( ) {
c3 _chart _internal _fn . initLegend = function ( ) {
var $$ = this ;
var $$ = this ;
$$ . legend = $$ . svg . append ( "g" ) . attr ( "transform" , $$ . getTranslate ( 'legend' ) ) ;
$$ . legend = $$ . svg . append ( "g" ) . attr ( "transform" , $$ . getTranslate ( 'legend' ) ) ;
if ( ! config [ _ _legend _show ] ) {
if ( ! $$ . config [ _ _legend _show ] ) {
$$ . legend . style ( 'visibility' , 'hidden' ) ;
$$ . legend . style ( 'visibility' , 'hidden' ) ;
$$ . hiddenLegendIds = $$ . mapToIds ( $$ . data . targets ) ;
$$ . hiddenLegendIds = $$ . mapToIds ( $$ . data . targets ) ;
}
}
@ -3546,7 +3564,7 @@
$$ . updateLegend ( $$ . mapToIds ( $$ . data . targets ) , { withTransform : false , withTransitionForTransform : false , withTransition : false } ) ;
$$ . updateLegend ( $$ . mapToIds ( $$ . data . targets ) , { withTransform : false , withTransitionForTransform : false , withTransition : false } ) ;
} ;
} ;
c3 _chart _internal _fn . updateSizeForLegend = function ( legendHeight , legendWidth ) {
c3 _chart _internal _fn . updateSizeForLegend = function ( legendHeight , legendWidth ) {
var $$ = this , insetLegendPosition = {
var $$ = this , config = $$ . config , insetLegendPosition = {
top : $$ . isLegendTop ? $$ . getCurrentPaddingTop ( ) + config [ _ _legend _inset _y ] + 5.5 : $$ . currentHeight - legendHeight - $$ . getCurrentPaddingBottom ( ) - config [ _ _legend _inset _y ] ,
top : $$ . isLegendTop ? $$ . getCurrentPaddingTop ( ) + config [ _ _legend _inset _y ] + 5.5 : $$ . currentHeight - legendHeight - $$ . getCurrentPaddingBottom ( ) - config [ _ _legend _inset _y ] ,
left : $$ . isLegendLeft ? $$ . getCurrentPaddingLeft ( ) + config [ _ _legend _inset _x ] + 0.5 : $$ . currentWidth - legendWidth - $$ . getCurrentPaddingRight ( ) - config [ _ _legend _inset _x ] + 0.5
left : $$ . isLegendLeft ? $$ . getCurrentPaddingLeft ( ) + config [ _ _legend _inset _x ] + 0.5 : $$ . currentWidth - legendWidth - $$ . getCurrentPaddingRight ( ) - config [ _ _legend _inset _x ] + 0.5
} ;
} ;
@ -3733,7 +3751,7 @@
. style ( 'visibility' , function ( id ) { return $$ . isLegendToShow ( id ) ? 'visible' : 'hidden' ; } )
. style ( 'visibility' , function ( id ) { return $$ . isLegendToShow ( id ) ? 'visible' : 'hidden' ; } )
. style ( 'cursor' , 'pointer' )
. style ( 'cursor' , 'pointer' )
. on ( 'click' , function ( id ) {
. on ( 'click' , function ( id ) {
isFunction ( config [ _ _legend _item _onclick ] ) ? config [ _ _legend _item _onclick ] . call ( c3 , id ) : $$ . api . toggle ( id ) ;
isFunction ( config [ _ _legend _item _onclick ] ) ? config [ _ _legend _item _onclick ] . call ( $$ , id ) : $$ . api . toggle ( id ) ;
} )
} )
. on ( 'mouseover' , function ( id ) {
. on ( 'mouseover' , function ( id ) {
$$ . d3 . select ( this ) . classed ( CLASS [ _legendItemFocused ] , true ) ;
$$ . d3 . select ( this ) . classed ( CLASS [ _legendItemFocused ] , true ) ;
@ -4379,11 +4397,11 @@
} ;
} ;
c3 _chart _internal _fn . initArc = function ( ) {
c3 _chart _internal _fn . initArc = function ( ) {
var $$ = this , arcs ;
var $$ = this ;
arcs = $$ . main . select ( '.' + CLASS [ _chart ] ) . append ( "g" )
$$ . arcs = $$ . main . select ( '.' + CLASS [ _chart ] ) . append ( "g" )
. attr ( "class" , CLASS [ _chartArcs ] )
. attr ( "class" , CLASS [ _chartArcs ] )
. attr ( "transform" , $$ . getTranslate ( 'arc' ) ) ;
. attr ( "transform" , $$ . getTranslate ( 'arc' ) ) ;
arcs . append ( 'text' )
$$ . arcs . append ( 'text' )
. attr ( 'class' , CLASS [ _chartArcsTitle ] )
. attr ( 'class' , CLASS [ _chartArcsTitle ] )
. style ( "text-anchor" , "middle" )
. style ( "text-anchor" , "middle" )
. text ( $$ . getArcTitle ( ) ) ;
. text ( $$ . getArcTitle ( ) ) ;
@ -4491,7 +4509,7 @@
} ;
} ;
c3 _chart _internal _fn . initGauge = function ( ) {
c3 _chart _internal _fn . initGauge = function ( ) {
var $$ = this , config = $$ . config , arcs ;
var $$ = this , config = $$ . config , arcs = $$ . arcs ;
if ( $$ . hasType ( 'gauge' ) ) {
if ( $$ . hasType ( 'gauge' ) ) {
arcs . append ( 'path' )
arcs . append ( 'path' )
. attr ( "class" , CLASS [ _chartArcsBackground ] )
. attr ( "class" , CLASS [ _chartArcsBackground ] )
@ -4623,7 +4641,7 @@
shape . classed ( CLASS [ _INCLUDED ] , ! isIncluded ) ;
shape . classed ( CLASS [ _INCLUDED ] , ! isIncluded ) ;
// TODO: included/unincluded callback here
// TODO: included/unincluded callback here
shape . classed ( CLASS [ _SELECTED ] , ! isSelected ) ;
shape . classed ( CLASS [ _SELECTED ] , ! isSelected ) ;
$$ . toggle ( ! isSelected , shape , d , i ) ;
toggle . call ( $$ , ! isSelected , shape , d , i ) ;
}
}
} ) ;
} ) ;
} ;
} ;
@ -4655,6 +4673,89 @@
} ;
} ;
c3 _chart _internal _fn . selectPoint = function ( target , d , i ) {
var $$ = this , config = $$ . config ,
cx = generateCall ( config [ _ _axis _rotated ] ? $$ . circleY : $$ . circleX , $$ ) ,
cy = generateCall ( config [ _ _axis _rotated ] ? $$ . circleX : $$ . circleY , $$ ) ;
config [ _ _data _onselected ] . call ( $$ . api , d , target . node ( ) ) ;
// add selected-circle on low layer g
$$ . main . select ( '.' + CLASS [ _selectedCircles ] + $$ . getTargetSelectorSuffix ( d . id ) ) . selectAll ( '.' + CLASS [ _selectedCircle ] + '-' + i )
. data ( [ d ] )
. enter ( ) . append ( 'circle' )
. attr ( "class" , function ( ) { return $$ . generateClass ( CLASS [ _selectedCircle ] , i ) ; } )
. attr ( "cx" , cx )
. attr ( "cy" , cy )
. attr ( "stroke" , function ( ) { return $$ . color ( d ) ; } )
. attr ( "r" , function ( d ) { return $$ . pointSelectR ( d ) * 1.4 ; } )
. transition ( ) . duration ( 100 )
. attr ( "r" , generateCall ( $$ . pointSelectR , $$ ) ) ;
} ;
c3 _chart _internal _fn . unselectPoint = function ( target , d , i ) {
var $$ = this ;
$$ . config [ _ _data _onunselected ] ( d , target . node ( ) ) ;
// remove selected-circle from low layer g
$$ . main . select ( '.' + CLASS [ _selectedCircles ] + $$ . getTargetSelectorSuffix ( d . id ) ) . selectAll ( '.' + CLASS [ _selectedCircle ] + '-' + i )
. transition ( ) . duration ( 100 ) . attr ( 'r' , 0 )
. remove ( ) ;
} ;
c3 _chart _internal _fn . togglePoint = function ( selected , target , d , i ) {
selected ? this . selectPoint ( target , d , i ) : this . unselectPoint ( target , d , i ) ;
} ;
c3 _chart _internal _fn . selectBar = function ( target , d ) {
var $$ = this ;
$$ . config [ _ _data _onselected ] . call ( $$ , d , target . node ( ) ) ;
target . transition ( ) . duration ( 100 )
. style ( "fill" , function ( ) { return $$ . d3 . rgb ( $$ . color ( d ) ) . brighter ( 0.75 ) ; } ) ;
} ;
c3 _chart _internal _fn . unselectBar = function ( target , d ) {
var $$ = this ;
$$ . config [ _ _data _onunselected ] . call ( $$ , d , target . node ( ) ) ;
target . transition ( ) . duration ( 100 )
. style ( "fill" , function ( ) { return $$ . color ( d ) ; } ) ;
} ;
c3 _chart _internal _fn . toggleBar = function ( selected , target , d , i ) {
selected ? this . selectBar ( target , d , i ) : this . unselectBar ( target , d , i ) ;
} ;
c3 _chart _internal _fn . toggleArc = function ( selected , target , d , i ) {
this . toggleBar ( selected , target , d . data , i ) ;
} ;
c3 _chart _internal _fn . getToggle = function ( that ) {
var $$ = this ;
// path selection not supported yet
return that . nodeName === 'circle' ? $$ . togglePoint : ( $$ . d3 . select ( that ) . classed ( CLASS [ _bar ] ) ? $$ . toggleBar : $$ . toggleArc ) ;
} ;
c3 _chart _internal _fn . toggleShape = function ( that , d , i ) {
var $$ = this , d3 = $$ . d3 , config = $$ . config ,
shape = d3 . select ( that ) , isSelected = shape . classed ( CLASS [ _SELECTED ] ) , isWithin , toggle ;
if ( that . nodeName === 'circle' ) {
isWithin = $$ . isWithinCircle ( that , $$ . pointSelectR ( d ) * 1.5 ) ;
toggle = $$ . togglePoint ;
}
else if ( that . nodeName === 'path' ) {
if ( shape . classed ( CLASS [ _bar ] ) ) {
isWithin = $$ . isWithinBar ( that ) ;
toggle = $$ . toggleBar ;
} else { // would be arc
isWithin = true ;
toggle = $$ . toggleArc ;
}
}
if ( config [ _ _data _selection _grouped ] || isWithin ) {
if ( config [ _ _data _selection _enabled ] && config [ _ _data _selection _isselectable ] ( d ) ) {
if ( ! config [ _ _data _selection _multiple ] ) {
$$ . main . selectAll ( '.' + CLASS [ _shapes ] + ( config [ _ _data _selection _grouped ] ? $$ . getTargetSelectorSuffix ( d . id ) : "" ) ) . selectAll ( '.' + CLASS [ _shape ] ) . each ( function ( d , i ) {
var shape = d3 . select ( this ) ;
if ( shape . classed ( CLASS [ _SELECTED ] ) ) { toggle . call ( $$ , false , shape . classed ( CLASS [ _SELECTED ] , false ) , d , i ) ; }
} ) ;
}
shape . classed ( CLASS [ _SELECTED ] , ! isSelected ) ;
toggle . call ( $$ , ! isSelected , shape , d , i ) ;
}
$$ . config [ _ _data _onclick ] . call ( $$ . api , d , that ) ;
}
} ;
c3 _chart _internal _fn . initBrush = function ( ) {
c3 _chart _internal _fn . initBrush = function ( ) {
var $$ = this , d3 = $$ . d3 ;
var $$ = this , d3 = $$ . d3 ;
$$ . brush = d3 . svg . brush ( ) . on ( "brush" , function ( ) { $$ . redrawForBrush ( ) ; } ) ;
$$ . brush = d3 . svg . brush ( ) . on ( "brush" , function ( ) { $$ . redrawForBrush ( ) ; } ) ;
@ -4815,7 +4916,7 @@
withSubchart : false ,
withSubchart : false ,
withUpdateXDomain : true
withUpdateXDomain : true
} ) ;
} ) ;
$$ . config [ _ _subchart _onbrush ] . call ( $$ , x . orgDomain ( ) ) ;
$$ . config [ _ _subchart _onbrush ] . call ( $$ . api , x . orgDomain ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . transformContext = function ( withTransition , transitions ) {
c3 _chart _internal _fn . transformContext = function ( withTransition , transitions ) {
var $$ = this , subXAxis ;
var $$ = this , subXAxis ;
@ -4835,7 +4936,7 @@
. on ( "zoomstart" , function ( ) {
. on ( "zoomstart" , function ( ) {
$$ . zoom . altDomain = d3 . event . sourceEvent . altKey ? $$ . x . orgDomain ( ) : null ;
$$ . zoom . altDomain = d3 . event . sourceEvent . altKey ? $$ . x . orgDomain ( ) : null ;
} )
} )
. on ( "zoom" , $$ . redrawForZoom ) ;
. on ( "zoom" , function ( ) { $$ . redrawForZoom . call ( $$ ) ; } ) ;
$$ . zoom . scale = function ( scale ) {
$$ . zoom . scale = function ( scale ) {
return config [ _ _axis _rotated ] ? this . y ( scale ) : this . x ( scale ) ;
return config [ _ _axis _rotated ] ? this . y ( scale ) : this . x ( scale ) ;
} ;
} ;
@ -4845,8 +4946,8 @@
} ;
} ;
$$ . zoom . updateScaleExtent = function ( ) {
$$ . zoom . updateScaleExtent = function ( ) {
var ratio = diffDomain ( $$ . x . orgDomain ( ) ) / diffDomain ( $$ . orgXDomain ) ,
var ratio = diffDomain ( $$ . x . orgDomain ( ) ) / diffDomain ( $$ . orgXDomain ) ,
extent = $$ . orgScaleExtent ( ) ;
extent = this . orgScaleExtent ( ) ;
$$ . scaleExtent ( [ extent [ 0 ] * ratio , extent [ 1 ] * ratio ] ) ;
this . scaleExtent ( [ extent [ 0 ] * ratio , extent [ 1 ] * ratio ] ) ;
return this ;
return this ;
} ;
} ;
} ;
} ;
@ -4879,7 +4980,7 @@
if ( d3 . event . sourceEvent . type === 'mousemove' ) {
if ( d3 . event . sourceEvent . type === 'mousemove' ) {
$$ . cancelClick = true ;
$$ . cancelClick = true ;
}
}
config [ _ _zoom _onzoom ] . call ( c3 , x . orgDomain ( ) ) ;
config [ _ _zoom _onzoom ] . call ( $$ . api , x . orgDomain ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . generateColor = function ( ) {
c3 _chart _internal _fn . generateColor = function ( ) {
@ -4955,7 +5056,7 @@
return ( ratio * 100 ) . toFixed ( 1 ) + '%' ;
return ( ratio * 100 ) . toFixed ( 1 ) + '%' ;
} ;
} ;
c3 _chart _internal _fn . formatByAxisId = function ( axisId ) {
c3 _chart _internal _fn . formatByAxisId = function ( axisId ) {
var $$ = this . internal , data _labels = $$ . config [ _ _data _labels ] ,
var $$ = this , data _labels = $$ . config [ _ _data _labels ] ,
format = function ( v ) { return isValue ( v ) ? + v : "" ; } ;
format = function ( v ) { return isValue ( v ) ? + v : "" ; } ;
// find format according to axis id
// find format according to axis id
if ( isFunction ( data _labels . format ) ) {
if ( isFunction ( data _labels . format ) ) {
@ -5648,7 +5749,7 @@
} ;
} ;
c3 _chart _fn . ygrids . add = function ( grids ) {
c3 _chart _fn . ygrids . add = function ( grids ) {
var $$ = this . internal ;
var $$ = this . internal ;
return c3 . ygrids ( $$ . config [ _ _grid _y _lines ] . concat ( grids ? grids : [ ] ) ) ;
return this . ygrids ( $$ . config [ _ _grid _y _lines ] . concat ( grids ? grids : [ ] ) ) ;
} ;
} ;
c3 _chart _fn . ygrids . remove = function ( params ) { // TODO: multiple
c3 _chart _fn . ygrids . remove = function ( params ) { // TODO: multiple
var $$ = this . internal ;
var $$ = this . internal ;
@ -5696,8 +5797,7 @@
return config [ _ _regions ] ;
return config [ _ _regions ] ;
} ;
} ;
c3 _chart _fn . data = function ( ) {
c3 _chart _fn . data = function ( ) { } ;
} ;
c3 _chart _fn . data . get = function ( targetId ) {
c3 _chart _fn . data . get = function ( targetId ) {
var target = this . data . getAsTarget ( targetId ) ;
var target = this . data . getAsTarget ( targetId ) ;
return isDefined ( target ) ? target . values . map ( function ( d ) { return d . value ; } ) : undefined ;
return isDefined ( target ) ? target . values . map ( function ( d ) { return d . value ; } ) : undefined ;
@ -5764,8 +5864,7 @@
} ;
} ;
c3 _chart _fn . axis = function ( ) {
c3 _chart _fn . axis = function ( ) { } ;
} ;
c3 _chart _fn . axis . labels = function ( labels ) {
c3 _chart _fn . axis . labels = function ( labels ) {
var $$ = this . internal ;
var $$ = this . internal ;
if ( arguments . length ) {
if ( arguments . length ) {
@ -5810,8 +5909,7 @@
} ;
} ;
c3 _chart _fn . legend = function ( ) {
c3 _chart _fn . legend = function ( ) { } ;
} ;
c3 _chart _fn . legend . show = function ( targetIds ) {
c3 _chart _fn . legend . show = function ( targetIds ) {
var $$ = this . internal ;
var $$ = this . internal ;
$$ . showLegend ( $$ . mapToTargetIds ( targetIds ) ) ;
$$ . showLegend ( $$ . mapToTargetIds ( targetIds ) ) ;