@ -1,5 +1,12 @@
c3 _chart _internal _fn . initAxis = function ( ) {
function Axis ( owner ) {
var $$ = this , config = $$ . config , main = $$ . main ;
API . call ( this , owner ) ;
}
inherit ( API , Axis ) ;
Axis . prototype . init = function init ( ) {
var $$ = this . owner , config = $$ . config , main = $$ . main ;
$$ . axes . x = main . append ( "g" )
$$ . axes . x = main . append ( "g" )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisX )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisX )
. attr ( "clip-path" , $$ . clipPathForXAxis )
. attr ( "clip-path" , $$ . clipPathForXAxis )
@ -8,8 +15,7 @@ c3_chart_internal_fn.initAxis = function () {
$$ . axes . x . append ( "text" )
$$ . axes . x . append ( "text" )
. attr ( "class" , CLASS . axisXLabel )
. attr ( "class" , CLASS . axisXLabel )
. attr ( "transform" , config . axis _rotated ? "rotate(-90)" : "" )
. attr ( "transform" , config . axis _rotated ? "rotate(-90)" : "" )
. style ( "text-anchor" , $$ . textAnchorForXAxisLabel . bind ( $$ ) ) ;
. style ( "text-anchor" , this . textAnchorForXAxisLabel . bind ( this ) ) ;
$$ . axes . y = main . append ( "g" )
$$ . axes . y = main . append ( "g" )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisY )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisY )
. attr ( "clip-path" , config . axis _y _inner ? "" : $$ . clipPathForYAxis )
. attr ( "clip-path" , config . axis _y _inner ? "" : $$ . clipPathForYAxis )
@ -18,7 +24,7 @@ c3_chart_internal_fn.initAxis = function () {
$$ . axes . y . append ( "text" )
$$ . axes . y . append ( "text" )
. attr ( "class" , CLASS . axisYLabel )
. attr ( "class" , CLASS . axisYLabel )
. attr ( "transform" , config . axis _rotated ? "" : "rotate(-90)" )
. attr ( "transform" , config . axis _rotated ? "" : "rotate(-90)" )
. style ( "text-anchor" , $$ . textAnchorForYAxisLabel . bind ( $$ ) ) ;
. style ( "text-anchor" , this . textAnchorForYAxisLabel . bind ( this ) ) ;
$$ . axes . y2 = main . append ( "g" )
$$ . axes . y2 = main . append ( "g" )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisY2 )
. attr ( "class" , CLASS . axis + ' ' + CLASS . axisY2 )
@ -28,20 +34,21 @@ c3_chart_internal_fn.initAxis = function () {
$$ . axes . y2 . append ( "text" )
$$ . axes . y2 . append ( "text" )
. attr ( "class" , CLASS . axisY2Label )
. attr ( "class" , CLASS . axisY2Label )
. attr ( "transform" , config . axis _rotated ? "" : "rotate(-90)" )
. attr ( "transform" , config . axis _rotated ? "" : "rotate(-90)" )
. style ( "text-anchor" , $$ . textAnchorForY2AxisLabel . bind ( $$ ) ) ;
. style ( "text-anchor" , this . textAnchorForY2AxisLabel . bind ( this ) ) ;
} ;
} ;
c3 _chart _internal _fn . getXAxis = function ( scale , orient , tickFormat , tickValues , withOuterTick , withoutTransition ) {
Axis . prototype . getXAxis = function getXAxis ( scale , orient , tickFormat , tickValues , withOuterTick , withoutTransition , withoutRotateTickText ) {
var $$ = this , config = $$ . config ,
var $$ = this . owner , config = $$ . config ,
axisParams = {
axisParams = {
isCategory : $$ . isCategorized ( ) ,
isCategory : $$ . isCategorized ( ) ,
withOuterTick : withOuterTick ,
withOuterTick : withOuterTick ,
tickMultiline : config . axis _x _tick _multiline ,
tickMultiline : config . axis _x _tick _multiline ,
tickWidth : config . axis _x _tick _width ,
tickWidth : config . axis _x _tick _width ,
tickTextRotate : withoutRotateTickText ? 0 : config . axis _x _tick _rotate ,
withoutTransition : withoutTransition ,
withoutTransition : withoutTransition ,
} ,
} ,
axis = c3 _axis ( $$ . d3 , axisParams ) . scale ( scale ) . orient ( orient ) ;
axis = c3 _axis ( $$ . d3 , axisParams ) . scale ( scale ) . orient ( orient ) ;
if ( $$ . isTimeSeries ( ) && tickValues ) {
if ( $$ . isTimeSeries ( ) && tickValues && typeof tickValues !== "function" ) {
tickValues = tickValues . map ( function ( v ) { return $$ . parseDate ( v ) ; } ) ;
tickValues = tickValues . map ( function ( v ) { return $$ . parseDate ( v ) ; } ) ;
}
}
@ -56,10 +63,10 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
return axis ;
return axis ;
} ;
} ;
c3 _chart _internal _fn . updateXAxisTickValues = function ( targets , axis ) {
Axis . prototype . updateXAxisTickValues = function updateXAxisTickValues ( targets , axis ) {
var $$ = this , config = $$ . config , tickValues ;
var $$ = this . owner , config = $$ . config , tickValues ;
if ( config . axis _x _tick _fit || config . axis _x _tick _count ) {
if ( config . axis _x _tick _fit || config . axis _x _tick _count ) {
tickValues = $$ . generateTickValues ( $$ . mapTargetsToUniqueXs ( targets ) , config . axis _x _tick _count , $$ . isTimeSeries ( ) ) ;
tickValues = this . generateTickValues ( $$ . mapTargetsToUniqueXs ( targets ) , config . axis _x _tick _count , $$ . isTimeSeries ( ) ) ;
}
}
if ( axis ) {
if ( axis ) {
axis . tickValues ( tickValues ) ;
axis . tickValues ( tickValues ) ;
@ -69,22 +76,28 @@ c3_chart_internal_fn.updateXAxisTickValues = function (targets, axis) {
}
}
return tickValues ;
return tickValues ;
} ;
} ;
c3 _chart _internal _fn . getYAxis = function ( scale , orient , tickFormat , tickValues , withOuterTick ) {
Axis . prototype . getYAxis = function getYAxis ( scale , orient , tickFormat , tickValues , withOuterTick , withoutTransition ) {
var axisParams = { withOuterTick : withOuterTick } ,
var axisParams = {
axis = c3 _axis ( this . d3 , axisParams ) . scale ( scale ) . orient ( orient ) . tickFormat ( tickFormat ) ;
withOuterTick : withOuterTick ,
if ( this . isTimeSeriesY ( ) ) {
withoutTransition : withoutTransition ,
axis . ticks ( this . d3 . time [ this . config . axis _y _tick _time _value ] , this . config . axis _y _tick _time _interval ) ;
} ,
$$ = this . owner ,
d3 = $$ . d3 ,
config = $$ . config ,
axis = c3 _axis ( d3 , axisParams ) . scale ( scale ) . orient ( orient ) . tickFormat ( tickFormat ) ;
if ( $$ . isTimeSeriesY ( ) ) {
axis . ticks ( d3 . time [ config . axis _y _tick _time _value ] , config . axis _y _tick _time _interval ) ;
} else {
} else {
axis . tickValues ( tickValues ) ;
axis . tickValues ( tickValues ) ;
}
}
return axis ;
return axis ;
} ;
} ;
c3 _chart _internal _fn . getAxisId = function ( id ) {
Axis . prototype . get Id = function getId ( id ) {
var config = this . config ;
var config = this . owner . config ;
return id in config . data _axes ? config . data _axes [ id ] : 'y' ;
return id in config . data _axes ? config . data _axes [ id ] : 'y' ;
} ;
} ;
c3 _chart _internal _fn . getXAxisTickFormat = function ( ) {
Axis . prototype . getXAxisTickFormat = function getXAxisTickFormat ( ) {
var $$ = this , config = $$ . config ,
var $$ = this . owner , config = $$ . config ,
format = $$ . isTimeSeries ( ) ? $$ . defaultAxisTimeFormat : $$ . isCategorized ( ) ? $$ . categoryName : function ( v ) { return v < 0 ? v . toFixed ( 0 ) : v ; } ;
format = $$ . isTimeSeries ( ) ? $$ . defaultAxisTimeFormat : $$ . isCategorized ( ) ? $$ . categoryName : function ( v ) { return v < 0 ? v . toFixed ( 0 ) : v ; } ;
if ( config . axis _x _tick _format ) {
if ( config . axis _x _tick _format ) {
if ( isFunction ( config . axis _x _tick _format ) ) {
if ( isFunction ( config . axis _x _tick _format ) ) {
@ -97,20 +110,20 @@ c3_chart_internal_fn.getXAxisTickFormat = function () {
}
}
return isFunction ( format ) ? function ( v ) { return format . call ( $$ , v ) ; } : format ;
return isFunction ( format ) ? function ( v ) { return format . call ( $$ , v ) ; } : format ;
} ;
} ;
c3 _chart _internal _fn . getAxis TickValues = function ( tickValues , axis ) {
Axis . prototype . getTickValues = function getTickValues ( tickValues , axis ) {
return tickValues ? tickValues : axis ? axis . tickValues ( ) : undefined ;
return tickValues ? tickValues : axis ? axis . tickValues ( ) : undefined ;
} ;
} ;
c3 _chart _internal _fn . getXAxisTickValues = function ( ) {
Axis . prototype . getXAxisTickValues = function getXAxisTickValues ( ) {
return this . getAxis TickValues ( this . config . axis _x _tick _values , this . xAxis ) ;
return this . getTickValues ( this . owner . config . axis _x _tick _values , this . owner . xAxis ) ;
} ;
} ;
c3 _chart _internal _fn . getYAxisTickValues = function ( ) {
Axis . prototype . getYAxisTickValues = function getYAxisTickValues ( ) {
return this . getAxis TickValues ( this . config . axis _y _tick _values , this . yAxis ) ;
return this . getTickValues ( this . owner . config . axis _y _tick _values , this . owner . yAxis ) ;
} ;
} ;
c3 _chart _internal _fn . getY2AxisTickValues = function ( ) {
Axis . prototype . getY2AxisTickValues = function getY2AxisTickValues ( ) {
return this . getAxis TickValues ( this . config . axis _y2 _tick _values , this . y2Axis ) ;
return this . getTickValues ( this . owner . config . axis _y2 _tick _values , this . owner . y2Axis ) ;
} ;
} ;
c3 _chart _internal _fn . getAxis LabelOptionByAxisId = function ( axisId ) {
Axis . prototype . getLabelOptionByAxisId = function getLabelOptionByAxisId ( axisId ) {
var $$ = this , config = $$ . config , option ;
var $$ = this . owner , config = $$ . config , option ;
if ( axisId === 'y' ) {
if ( axisId === 'y' ) {
option = config . axis _y _label ;
option = config . axis _y _label ;
} else if ( axisId === 'y2' ) {
} else if ( axisId === 'y2' ) {
@ -120,13 +133,13 @@ c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) {
}
}
return option ;
return option ;
} ;
} ;
c3 _chart _internal _fn . getAxis LabelText = function ( axisId ) {
Axis . prototype . getLabelText = function getLabelText ( axisId ) {
var option = this . getAxis LabelOptionByAxisId ( axisId ) ;
var option = this . getLabelOptionByAxisId ( axisId ) ;
return isString ( option ) ? option : option ? option . text : null ;
return isString ( option ) ? option : option ? option . text : null ;
} ;
} ;
c3 _chart _internal _fn . setAxis LabelText = function ( axisId , text ) {
Axis . prototype . setLabelText = function setLabelText ( axisId , text ) {
var $$ = this , config = $$ . config ,
var $$ = this . owner , config = $$ . config ,
option = $$ . getAxis LabelOptionByAxisId ( axisId ) ;
option = this . getLabelOptionByAxisId ( axisId ) ;
if ( isString ( option ) ) {
if ( isString ( option ) ) {
if ( axisId === 'y' ) {
if ( axisId === 'y' ) {
config . axis _y _label = text ;
config . axis _y _label = text ;
@ -139,8 +152,8 @@ c3_chart_internal_fn.setAxisLabelText = function (axisId, text) {
option . text = text ;
option . text = text ;
}
}
} ;
} ;
c3 _chart _internal _fn . getAxis LabelPosition = function ( axisId , defaultPosition ) {
Axis . prototype . getLabelPosition = function getLabelPosition ( axisId , defaultPosition ) {
var option = this . getAxis LabelOptionByAxisId ( axisId ) ,
var option = this . getLabelOptionByAxisId ( axisId ) ,
position = ( option && typeof option === 'object' && option . position ) ? option . position : defaultPosition ;
position = ( option && typeof option === 'object' && option . position ) ? option . position : defaultPosition ;
return {
return {
isInner : position . indexOf ( 'inner' ) >= 0 ,
isInner : position . indexOf ( 'inner' ) >= 0 ,
@ -153,131 +166,109 @@ c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) {
isBottom : position . indexOf ( 'bottom' ) >= 0
isBottom : position . indexOf ( 'bottom' ) >= 0
} ;
} ;
} ;
} ;
c3 _chart _internal _fn . getXAxisLabelPosition = function ( ) {
Axis . prototype . getXAxisLabelPosition = function getXAxisLabelPosition ( ) {
return this . getAxis LabelPosition ( 'x' , this . config . axis _rotated ? 'inner-top' : 'inner-right' ) ;
return this . getLabelPosition ( 'x' , this . owner . config . axis _rotated ? 'inner-top' : 'inner-right' ) ;
} ;
} ;
c3 _chart _internal _fn . getYAxisLabelPosition = function ( ) {
Axis . prototype . getYAxisLabelPosition = function getYAxisLabelPosition ( ) {
return this . getAxis LabelPosition ( 'y' , this . config . axis _rotated ? 'inner-right' : 'inner-top' ) ;
return this . getLabelPosition ( 'y' , this . owner . config . axis _rotated ? 'inner-right' : 'inner-top' ) ;
} ;
} ;
c3 _chart _internal _fn . getY2AxisLabelPosition = function ( ) {
Axis . prototype . getY2AxisLabelPosition = function getY2AxisLabelPosition ( ) {
return this . getAxis LabelPosition ( 'y2' , this . config . axis _rotated ? 'inner-right' : 'inner-top' ) ;
return this . getLabelPosition ( 'y2' , this . owner . config . axis _rotated ? 'inner-right' : 'inner-top' ) ;
} ;
} ;
c3 _chart _internal _fn . getAxis LabelPositionById = function ( id ) {
Axis . prototype . getLabelPositionById = function getLabelPositionById ( id ) {
return id === 'y2' ? this . getY2AxisLabelPosition ( ) : id === 'y' ? this . getYAxisLabelPosition ( ) : this . getXAxisLabelPosition ( ) ;
return id === 'y2' ? this . getY2AxisLabelPosition ( ) : id === 'y' ? this . getYAxisLabelPosition ( ) : this . getXAxisLabelPosition ( ) ;
} ;
} ;
c3 _chart _internal _fn . textForXAxisLabel = function ( ) {
Axis . prototype . textForXAxisLabel = function textForXAxisLabel ( ) {
return this . getAxis LabelText ( 'x' ) ;
return this . getLabelText ( 'x' ) ;
} ;
} ;
c3 _chart _internal _fn . textForYAxisLabel = function ( ) {
Axis . prototype . textForYAxisLabel = function textForYAxisLabel ( ) {
return this . getAxis LabelText ( 'y' ) ;
return this . getLabelText ( 'y' ) ;
} ;
} ;
c3 _chart _internal _fn . textForY2AxisLabel = function ( ) {
Axis . prototype . textForY2AxisLabel = function textForY2AxisLabel ( ) {
return this . getAxis LabelText ( 'y2' ) ;
return this . getLabelText ( 'y2' ) ;
} ;
} ;
c3 _chart _internal _fn . xForAxisLabel = function ( forHorizontal , position ) {
Axis . prototype . xForAxisLabel = function xForAxisLabel ( forHorizontal , position ) {
var $$ = this ;
var $$ = this . owner ;
if ( forHorizontal ) {
if ( forHorizontal ) {
return position . isLeft ? 0 : position . isCenter ? $$ . width / 2 : $$ . width ;
return position . isLeft ? 0 : position . isCenter ? $$ . width / 2 : $$ . width ;
} else {
} else {
return position . isBottom ? - $$ . height : position . isMiddle ? - $$ . height / 2 : 0 ;
return position . isBottom ? - $$ . height : position . isMiddle ? - $$ . height / 2 : 0 ;
}
}
} ;
} ;
c3 _chart _internal _fn . dxForAxisLabel = function ( forHorizontal , position ) {
Axis . prototype . dxForAxisLabel = function dxForAxisLabel ( forHorizontal , position ) {
if ( forHorizontal ) {
if ( forHorizontal ) {
return position . isLeft ? "0.5em" : position . isRight ? "-0.5em" : "0" ;
return position . isLeft ? "0.5em" : position . isRight ? "-0.5em" : "0" ;
} else {
} else {
return position . isTop ? "-0.5em" : position . isBottom ? "0.5em" : "0" ;
return position . isTop ? "-0.5em" : position . isBottom ? "0.5em" : "0" ;
}
}
} ;
} ;
c3 _chart _internal _fn . textAnchorForAxisLabel = function ( forHorizontal , position ) {
Axis . prototype . textAnchorForAxisLabel = function textAnchorForAxisLabel ( forHorizontal , position ) {
if ( forHorizontal ) {
if ( forHorizontal ) {
return position . isLeft ? 'start' : position . isCenter ? 'middle' : 'end' ;
return position . isLeft ? 'start' : position . isCenter ? 'middle' : 'end' ;
} else {
} else {
return position . isBottom ? 'start' : position . isMiddle ? 'middle' : 'end' ;
return position . isBottom ? 'start' : position . isMiddle ? 'middle' : 'end' ;
}
}
} ;
} ;
c3 _chart _internal _fn . xForXAxisLabel = function ( ) {
Axis . prototype . xForXAxisLabel = function xForXAxisLabel ( ) {
return this . xForAxisLabel ( ! this . config . axis _rotated , this . getXAxisLabelPosition ( ) ) ;
return this . xForAxisLabel ( ! this . owner . config . axis _rotated , this . getXAxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . xForYAxisLabel = function ( ) {
Axis . prototype . xForYAxisLabel = function xForYAxisLabel ( ) {
return this . xForAxisLabel ( this . config . axis _rotated , this . getYAxisLabelPosition ( ) ) ;
return this . xForAxisLabel ( this . owner . config . axis _rotated , this . getYAxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . xForY2AxisLabel = function ( ) {
Axis . prototype . xForY2AxisLabel = function xForY2AxisLabel ( ) {
return this . xForAxisLabel ( this . config . axis _rotated , this . getY2AxisLabelPosition ( ) ) ;
return this . xForAxisLabel ( this . owner . config . axis _rotated , this . getY2AxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . dxForXAxisLabel = function ( ) {
Axis . prototype . dxForXAxisLabel = function dxForXAxisLabel ( ) {
return this . dxForAxisLabel ( ! this . config . axis _rotated , this . getXAxisLabelPosition ( ) ) ;
return this . dxForAxisLabel ( ! this . owner . config . axis _rotated , this . getXAxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . dxForYAxisLabel = function ( ) {
Axis . prototype . dxForYAxisLabel = function dxForYAxisLabel ( ) {
return this . dxForAxisLabel ( this . config . axis _rotated , this . getYAxisLabelPosition ( ) ) ;
return this . dxForAxisLabel ( this . owner . config . axis _rotated , this . getYAxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . dxForY2AxisLabel = function ( ) {
Axis . prototype . dxForY2AxisLabel = function dxForY2AxisLabel ( ) {
return this . dxForAxisLabel ( this . config . axis _rotated , this . getY2AxisLabelPosition ( ) ) ;
return this . dxForAxisLabel ( this . owner . config . axis _rotated , this . getY2AxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . dyForXAxisLabel = function ( ) {
Axis . prototype . dyForXAxisLabel = function dyForXAxisLabel ( ) {
var $$ = this , config = $$ . config ,
var $$ = this . owner , config = $$ . config ,
position = $$ . getXAxisLabelPosition ( ) ;
position = this . getXAxisLabelPosition ( ) ;
if ( config . axis _rotated ) {
if ( config . axis _rotated ) {
return position . isInner ? "1.2em" : - 25 - $$ . getMaxTickWidth ( 'x' ) ;
return position . isInner ? "1.2em" : - 25 - this . getMaxTickWidth ( 'x' ) ;
} else {
} else {
return position . isInner ? "-0.5em" : config . axis _x _height ? config . axis _x _height - 10 : "3em" ;
return position . isInner ? "-0.5em" : config . axis _x _height ? config . axis _x _height - 10 : "3em" ;
}
}
} ;
} ;
c3 _chart _internal _fn . dyForYAxisLabel = function ( ) {
Axis . prototype . dyForYAxisLabel = function dyForYAxisLabel ( ) {
var $$ = this ,
var $$ = this . owner ,
position = $$ . getYAxisLabelPosition ( ) ;
position = this . getYAxisLabelPosition ( ) ;
if ( $$ . config . axis _rotated ) {
if ( $$ . config . axis _rotated ) {
return position . isInner ? "-0.5em" : "3em" ;
return position . isInner ? "-0.5em" : "3em" ;
} else {
} else {
return position . isInner ? "1.2em" : - 10 - ( $$ . config . axis _y _inner ? 0 : ( $$ . getMaxTickWidth ( 'y' ) + 10 ) ) ;
return position . isInner ? "1.2em" : - 10 - ( $$ . config . axis _y _inner ? 0 : ( this . getMaxTickWidth ( 'y' ) + 10 ) ) ;
}
}
} ;
} ;
c3 _chart _internal _fn . dyForY2AxisLabel = function ( ) {
Axis . prototype . dyForY2AxisLabel = function dyForY2AxisLabel ( ) {
var $$ = this ,
var $$ = this . owner ,
position = $$ . getY2AxisLabelPosition ( ) ;
position = this . getY2AxisLabelPosition ( ) ;
if ( $$ . config . axis _rotated ) {
if ( $$ . config . axis _rotated ) {
return position . isInner ? "1.2em" : "-2.2em" ;
return position . isInner ? "1.2em" : "-2.2em" ;
} else {
} else {
return position . isInner ? "-0.5em" : 15 + ( $$ . config . axis _y2 _inner ? 0 : ( this . getMaxTickWidth ( 'y2' ) + 15 ) ) ;
return position . isInner ? "-0.5em" : 15 + ( $$ . config . axis _y2 _inner ? 0 : ( this . getMaxTickWidth ( 'y2' ) + 15 ) ) ;
}
}
} ;
} ;
c3 _chart _internal _fn . textAnchorForXAxisLabel = function ( ) {
Axis . prototype . textAnchorForXAxisLabel = function textAnchorForXAxisLabel ( ) {
var $$ = this ;
var $$ = this . owner ;
return $$ . textAnchorForAxisLabel ( ! $$ . config . axis _rotated , $$ . getXAxisLabelPosition ( ) ) ;
return this . textAnchorForAxisLabel ( ! $$ . config . axis _rotated , this . getXAxisLabelPosition ( ) ) ;
} ;
c3 _chart _internal _fn . textAnchorForYAxisLabel = function ( ) {
var $$ = this ;
return $$ . textAnchorForAxisLabel ( $$ . config . axis _rotated , $$ . getYAxisLabelPosition ( ) ) ;
} ;
c3 _chart _internal _fn . textAnchorForY2AxisLabel = function ( ) {
var $$ = this ;
return $$ . textAnchorForAxisLabel ( $$ . config . axis _rotated , $$ . getY2AxisLabelPosition ( ) ) ;
} ;
c3 _chart _internal _fn . xForRotatedTickText = function ( r ) {
return 8 * Math . sin ( Math . PI * ( r / 180 ) ) ;
} ;
} ;
c3 _chart _internal _fn . yForRotatedTickText = function ( r ) {
Axis . prototype . textAnchorForYAxisLabel = function textAnchorForYAxisLabel ( ) {
return 11.5 - 2.5 * ( r / 15 ) * ( r > 0 ? 1 : - 1 ) ;
var $$ = this . owner ;
return this . textAnchorForAxisLabel ( $$ . config . axis _rotated , this . getYAxisLabelPosition ( ) ) ;
} ;
} ;
c3 _chart _internal _fn . rotateTickText = function ( axis , transition , rotate ) {
Axis . prototype . textAnchorForY2AxisLabel = function textAnchorForY2AxisLabel ( ) {
if ( axis . classed ( c3 _chart _internal _fn . CLASS . axisY ) && ! this . config . axis _rotated ) {
var $$ = this . owner ;
axis . selectAll ( '.tick text' )
return this . textAnchorForAxisLabel ( $$ . config . axis _rotated , this . getY2AxisLabelPosition ( ) ) ;
. style ( "text-anchor" , rotate > 0 ? "end" : "start" ) ;
} else {
axis . selectAll ( '.tick text' )
. style ( "text-anchor" , rotate > 0 ? "start" : "end" ) ;
}
transition . selectAll ( '.tick text' )
. attr ( "y" , this . yForRotatedTickText ( rotate ) )
. attr ( "transform" , "rotate(" + rotate + ")" )
. selectAll ( 'tspan' )
. attr ( 'dx' , this . xForRotatedTickText ( rotate ) ) ;
} ;
} ;
Axis . prototype . getMaxTickWidth = function getMaxTickWidth ( id , withoutRecompute ) {
c3 _chart _internal _fn . getMaxTickWidth = function ( id , withoutRecompute ) {
var $$ = this . owner , config = $$ . config ,
var $$ = this , config = $$ . config ,
maxWidth = 0 , targetsToShow , scale , axis , dummy , svg ;
maxWidth = 0 , targetsToShow , scale , axis , body , svg ;
if ( withoutRecompute && $$ . currentMaxTickWidths [ id ] ) {
if ( withoutRecompute && $$ . currentMaxTickWidths [ id ] ) {
return $$ . currentMaxTickWidths [ id ] ;
return $$ . currentMaxTickWidths [ id ] ;
}
}
@ -285,71 +276,67 @@ c3_chart_internal_fn.getMaxTickWidth = function (id, withoutRecompute) {
targetsToShow = $$ . filterTargetsToShow ( $$ . data . targets ) ;
targetsToShow = $$ . filterTargetsToShow ( $$ . data . targets ) ;
if ( id === 'y' ) {
if ( id === 'y' ) {
scale = $$ . y . copy ( ) . domain ( $$ . getYDomain ( targetsToShow , 'y' ) ) ;
scale = $$ . y . copy ( ) . domain ( $$ . getYDomain ( targetsToShow , 'y' ) ) ;
axis = $$ . getYAxis ( scale , $$ . yOrient , config . axis _y _tick _format , $$ . yAxisTickValues ) ;
axis = this . getYAxis ( scale , $$ . yOrient , config . axis _y _tick _format , $$ . yAxisTickValues , false , true ) ;
} else if ( id === 'y2' ) {
} else if ( id === 'y2' ) {
scale = $$ . y2 . copy ( ) . domain ( $$ . getYDomain ( targetsToShow , 'y2' ) ) ;
scale = $$ . y2 . copy ( ) . domain ( $$ . getYDomain ( targetsToShow , 'y2' ) ) ;
axis = $$ . getYAxis ( scale , $$ . y2Orient , config . axis _y2 _tick _format , $$ . y2AxisTickValues ) ;
axis = this . getYAxis ( scale , $$ . y2Orient , config . axis _y2 _tick _format , $$ . y2AxisTickValues , false , true ) ;
} else {
} else {
scale = $$ . x . copy ( ) . domain ( $$ . getXDomain ( targetsToShow ) ) ;
scale = $$ . x . copy ( ) . domain ( $$ . getXDomain ( targetsToShow ) ) ;
axis = $$ . getXAxis ( scale , $$ . xOrient , $$ . xAxisTickFormat , $$ . xAxisTickValues ) ;
axis = this . getXAxis ( scale , $$ . xOrient , $$ . xAxisTickFormat , $$ . xAxisTickValues , false , true , true ) ;
$$ . updateXAxisTickValues ( targetsToShow , axis ) ;
this . updateXAxisTickValues ( targetsToShow , axis ) ;
}
}
body = this . d3 . select ( 'body' ) . classed ( 'c3' , true ) ;
dummy = $$ . d3 . select ( 'body' ) . append ( 'div ' ) . classed ( 'c3' , true ) ;
svg = bo dy. append ( 'svg' ) . style ( 'visibility' , 'hidden' ) . style ( 'height ' , 0 ) ;
svg = dumm y . append ( "svg" ) . style ( 'visibility' , 'hidden' ) . style ( 'position' , 'fixed' ) . style ( 'top ' , 0 ) . style ( 'left' , 0 ) ,
svg . append ( 'g' ) . call ( axis ) . each ( function ( ) {
svg . append ( 'g' ) . call ( axis ) . each ( function ( ) {
$$ . d3 . select ( this ) . selectAll ( 'text tspan ' ) . each ( function ( ) {
$$ . d3 . select ( this ) . selectAll ( 'text' ) . each ( function ( ) {
var box = this . getBoundingClientRect ( ) ;
var box = this . getBoundingClientRect ( ) ;
if ( box . left >= 0 && maxWidth < box . width ) { maxWidth = box . width ; }
if ( maxWidth < box . width ) { maxWidth = box . width ; }
} ) ;
} ) ;
dummy . remove ( ) ;
} ) ;
} ) ;
// TODO: time lag to get maxWidth
window . setTimeout ( function ( ) {
svg . remove ( ) ;
} , 100 ) ;
body . classed ( 'c3' , false ) ;
}
}
$$ . currentMaxTickWidths [ id ] = maxWidth <= 0 ? $$ . currentMaxTickWidths [ id ] : maxWidth ;
$$ . currentMaxTickWidths [ id ] = maxWidth <= 0 ? $$ . currentMaxTickWidths [ id ] : maxWidth ;
return $$ . currentMaxTickWidths [ id ] ;
return $$ . currentMaxTickWidths [ id ] ;
} ;
} ;
c3 _chart _internal _fn . updateAxis Labels = function ( withTransition ) {
Axis . prototype . updateLabels = function updateLabels ( withTransition ) {
var $$ = this ;
var $$ = this . owner ;
var axisXLabel = $$ . main . select ( '.' + CLASS . axisX + ' .' + CLASS . axisXLabel ) ,
var axisXLabel = $$ . main . select ( '.' + CLASS . axisX + ' .' + CLASS . axisXLabel ) ,
axisYLabel = $$ . main . select ( '.' + CLASS . axisY + ' .' + CLASS . axisYLabel ) ,
axisYLabel = $$ . main . select ( '.' + CLASS . axisY + ' .' + CLASS . axisYLabel ) ,
axisY2Label = $$ . main . select ( '.' + CLASS . axisY2 + ' .' + CLASS . axisY2Label ) ;
axisY2Label = $$ . main . select ( '.' + CLASS . axisY2 + ' .' + CLASS . axisY2Label ) ;
( withTransition ? axisXLabel . transition ( ) : axisXLabel )
( withTransition ? axisXLabel . transition ( ) : axisXLabel )
. attr ( "x" , $$ . xForXAxisLabel . bind ( $$ ) )
. attr ( "x" , this . xForXAxisLabel . bind ( this ) )
. attr ( "dx" , $$ . dxForXAxisLabel . bind ( $$ ) )
. attr ( "dx" , this . dxForXAxisLabel . bind ( this ) )
. attr ( "dy" , $$ . dyForXAxisLabel . bind ( $$ ) )
. attr ( "dy" , this . dyForXAxisLabel . bind ( this ) )
. text ( $$ . textForXAxisLabel . bind ( $$ ) ) ;
. text ( this . textForXAxisLabel . bind ( this ) ) ;
( withTransition ? axisYLabel . transition ( ) : axisYLabel )
( withTransition ? axisYLabel . transition ( ) : axisYLabel )
. attr ( "x" , $$ . xForYAxisLabel . bind ( $$ ) )
. attr ( "x" , this . xForYAxisLabel . bind ( this ) )
. attr ( "dx" , $$ . dxForYAxisLabel . bind ( $$ ) )
. attr ( "dx" , this . dxForYAxisLabel . bind ( this ) )
. attr ( "dy" , $$ . dyForYAxisLabel . bind ( $$ ) )
. attr ( "dy" , this . dyForYAxisLabel . bind ( this ) )
. text ( $$ . textForYAxisLabel . bind ( $$ ) ) ;
. text ( this . textForYAxisLabel . bind ( this ) ) ;
( withTransition ? axisY2Label . transition ( ) : axisY2Label )
( withTransition ? axisY2Label . transition ( ) : axisY2Label )
. attr ( "x" , $$ . xForY2AxisLabel . bind ( $$ ) )
. attr ( "x" , this . xForY2AxisLabel . bind ( this ) )
. attr ( "dx" , $$ . dxForY2AxisLabel . bind ( $$ ) )
. attr ( "dx" , this . dxForY2AxisLabel . bind ( this ) )
. attr ( "dy" , $$ . dyForY2AxisLabel . bind ( $$ ) )
. attr ( "dy" , this . dyForY2AxisLabel . bind ( this ) )
. text ( $$ . textForY2AxisLabel . bind ( $$ ) ) ;
. text ( this . textForY2AxisLabel . bind ( this ) ) ;
} ;
} ;
Axis . prototype . getPadding = function getPadding ( padding , key , defaultValue , domainLength ) {
c3 _chart _internal _fn . getAxisPadding = function ( padding , key , defaultValue , domainLength ) {
var p = typeof padding === 'number' ? padding : padding [ key ] ;
if ( ! isValue ( padding [ key ] ) ) {
if ( ! isValue ( p ) ) {
return defaultValue ;
return defaultValue ;
}
}
if ( padding . unit === 'ratio' ) {
if ( padding . unit === 'ratio' ) {
return padding [ key ] * domainLength ;
return padding [ key ] * domainLength ;
}
}
// assume padding is pixels if unit is not specified
// assume padding is pixels if unit is not specified
return this . convertPixelsToAxisPadding ( padding [ key ] , domainLength ) ;
return this . convertPixelsToAxisPadding ( p , domainLength ) ;
} ;
} ;
c3 _chart _internal _fn . convertPixelsToAxisPadding = function ( pixels , domainLength ) {
Axis . prototype . convertPixelsToAxisPadding = function convertPixelsToAxisPadding ( pixels , domainLength ) {
var length = this . config . axis _rotated ? this . width : this . height ;
var $$ = this . owner ,
length = $$ . config . axis _rotated ? $$ . width : $$ . height ;
return domainLength * ( pixels / length ) ;
return domainLength * ( pixels / length ) ;
} ;
} ;
Axis . prototype . generateTickValues = function generateTickValues ( values , tickCount , forTimeSeries ) {
c3 _chart _internal _fn . generateTickValues = function ( values , tickCount , forTimeSeries ) {
var tickValues = values , targetCount , start , end , count , interval , i , tickValue ;
var tickValues = values , targetCount , start , end , count , interval , i , tickValue ;
if ( tickCount ) {
if ( tickCount ) {
targetCount = isFunction ( tickCount ) ? tickCount ( ) : tickCount ;
targetCount = isFunction ( tickCount ) ? tickCount ( ) : tickCount ;
@ -375,8 +362,8 @@ c3_chart_internal_fn.generateTickValues = function (values, tickCount, forTimeSe
if ( ! forTimeSeries ) { tickValues = tickValues . sort ( function ( a , b ) { return a - b ; } ) ; }
if ( ! forTimeSeries ) { tickValues = tickValues . sort ( function ( a , b ) { return a - b ; } ) ; }
return tickValues ;
return tickValues ;
} ;
} ;
c3 _chart _internal _fn . generateAxis Transitions = function ( duration ) {
Axis . prototype . generateTransitions = function generateTransitions ( duration ) {
var $$ = this , axes = $$ . axes ;
var $$ = this . owner , axes = $$ . axes ;
return {
return {
axisX : duration ? axes . x . transition ( ) . duration ( duration ) : axes . x ,
axisX : duration ? axes . x . transition ( ) . duration ( duration ) : axes . x ,
axisY : duration ? axes . y . transition ( ) . duration ( duration ) : axes . y ,
axisY : duration ? axes . y . transition ( ) . duration ( duration ) : axes . y ,
@ -384,8 +371,8 @@ c3_chart_internal_fn.generateAxisTransitions = function (duration) {
axisSubX : duration ? axes . subx . transition ( ) . duration ( duration ) : axes . subx
axisSubX : duration ? axes . subx . transition ( ) . duration ( duration ) : axes . subx
} ;
} ;
} ;
} ;
c3 _chart _internal _fn . redrawAxis = function ( transitions , isHidden ) {
Axis . prototype . redraw = function redraw ( transitions , isHidden ) {
var $$ = this , config = $$ . config ;
var $$ = this . owner ;
$$ . axes . x . style ( "opacity" , isHidden ? 0 : 1 ) ;
$$ . axes . x . style ( "opacity" , isHidden ? 0 : 1 ) ;
$$ . axes . y . style ( "opacity" , isHidden ? 0 : 1 ) ;
$$ . axes . y . style ( "opacity" , isHidden ? 0 : 1 ) ;
$$ . axes . y2 . style ( "opacity" , isHidden ? 0 : 1 ) ;
$$ . axes . y2 . style ( "opacity" , isHidden ? 0 : 1 ) ;
@ -394,13 +381,4 @@ c3_chart_internal_fn.redrawAxis = function (transitions, isHidden) {
transitions . axisY . call ( $$ . yAxis ) ;
transitions . axisY . call ( $$ . yAxis ) ;
transitions . axisY2 . call ( $$ . y2Axis ) ;
transitions . axisY2 . call ( $$ . y2Axis ) ;
transitions . axisSubX . call ( $$ . subXAxis ) ;
transitions . axisSubX . call ( $$ . subXAxis ) ;
// rotate tick text if needed
if ( ! config . axis _rotated && config . axis _x _tick _rotate ) {
$$ . rotateTickText ( $$ . axes . x , transitions . axisX , config . axis _x _tick _rotate ) ;
$$ . rotateTickText ( $$ . axes . subx , transitions . axisSubX , config . axis _x _tick _rotate ) ;
}
// we may want to rotate y axis when chart in horizontal
if ( config . axis _y _tick _rotate ) {
$$ . rotateTickText ( $$ . axes . y , transitions . axisY , config . axis _y _tick _rotate ) ;
}
} ;
} ;