@ -19,6 +19,9 @@
chartArc : 'c3-chart-arc' ,
chartArc : 'c3-chart-arc' ,
chartArcs : 'c3-chart-arcs' ,
chartArcs : 'c3-chart-arcs' ,
chartArcsTitle : 'c3-chart-arcs-title' ,
chartArcsTitle : 'c3-chart-arcs-title' ,
gaugeArc : 'c3-gauge-arc' ,
gaugeArcs : 'c3-gauge-arcs' ,
gaugeArcsTitle : 'c3-gauge-arcs-title' ,
selectedCircle : 'c3-selected-circle' ,
selectedCircle : 'c3-selected-circle' ,
selectedCircles : 'c3-selected-circles' ,
selectedCircles : 'c3-selected-circles' ,
eventRect : 'c3-event-rect' ,
eventRect : 'c3-event-rect' ,
@ -36,6 +39,8 @@
shapes : 'c3-shapes' ,
shapes : 'c3-shapes' ,
line : 'c3-line' ,
line : 'c3-line' ,
lines : 'c3-lines' ,
lines : 'c3-lines' ,
step : 'c3-step' ,
steps : 'c3-steps' ,
bar : 'c3-bar' ,
bar : 'c3-bar' ,
bars : 'c3-bars' ,
bars : 'c3-bars' ,
circle : 'c3-circle' ,
circle : 'c3-circle' ,
@ -161,12 +166,20 @@
_ _data _ondragstart = getConfig ( [ 'data' , 'ondragstart' ] , function ( ) { } ) ,
_ _data _ondragstart = getConfig ( [ 'data' , 'ondragstart' ] , function ( ) { } ) ,
_ _data _ondragend = getConfig ( [ 'data' , 'ondragend' ] , function ( ) { } ) ;
_ _data _ondragend = getConfig ( [ 'data' , 'ondragend' ] , function ( ) { } ) ;
// configuration for no plot-able data supplied.
var _ _data _empty _abort = getConfig ( [ 'data' , 'empty' , 'abort' ] , true ) ,
_ _data _empty _label _text = getConfig ( [ 'data' , 'empty' , 'label' , 'text' ] , "" ) ,
_ _data _empty _label _size = getConfig ( [ 'data' , 'empty' , 'label' , 'size' ] , false ) ,
_ _data _empty _label _fill = getConfig ( [ 'data' , 'empty' , 'label' , 'fill' ] , false ) ;
// subchart
// subchart
var _ _subchart _show = getConfig ( [ 'subchart' , 'show' ] , false ) ,
var _ _subchart _show = getConfig ( [ 'subchart' , 'show' ] , false ) ,
_ _subchart _size _height = getConfig ( [ 'subchart' , 'size' , 'height' ] , 60 ) ;
_ _subchart _size _height = getConfig ( [ 'subchart' , 'size' , 'height' ] , 60 ) ;
// color
// color
var _ _color _pattern = getConfig ( [ 'color' , 'pattern' ] , [ ] ) ;
var _ _color _pattern = getConfig ( [ 'color' , 'pattern' ] , [ ] ) ,
_ _color _opacity = getConfig ( [ 'color' , 'opacity' ] , null ) ,
_ _color _values = getConfig ( [ 'color' , 'values' ] , [ ] ) ;
// legend
// legend
var _ _legend _show = getConfig ( [ 'legend' , 'show' ] , true ) ,
var _ _legend _show = getConfig ( [ 'legend' , 'show' ] , true ) ,
@ -215,6 +228,8 @@
_ _axis _y2 _padding = getConfig ( [ 'axis' , 'y2' , 'padding' ] ) ,
_ _axis _y2 _padding = getConfig ( [ 'axis' , 'y2' , 'padding' ] ) ,
_ _axis _y2 _ticks = getConfig ( [ 'axis' , 'y2' , 'ticks' ] , 10 ) ;
_ _axis _y2 _ticks = getConfig ( [ 'axis' , 'y2' , 'ticks' ] , 10 ) ;
var _ _zero _padding = getConfig ( [ 'zeropadding' ] , false ) ;
// grid
// grid
var _ _grid _x _show = getConfig ( [ 'grid' , 'x' , 'show' ] , false ) ,
var _ _grid _x _show = getConfig ( [ 'grid' , 'x' , 'show' ] , false ) ,
_ _grid _x _type = getConfig ( [ 'grid' , 'x' , 'type' ] , 'tick' ) ,
_ _grid _x _type = getConfig ( [ 'grid' , 'x' , 'type' ] , 'tick' ) ,
@ -247,6 +262,19 @@
_ _pie _onmouseover = getConfig ( [ 'pie' , 'onmouseover' ] , function ( ) { } ) ,
_ _pie _onmouseover = getConfig ( [ 'pie' , 'onmouseover' ] , function ( ) { } ) ,
_ _pie _onmouseout = getConfig ( [ 'pie' , 'onmouseout' ] , function ( ) { } ) ;
_ _pie _onmouseout = getConfig ( [ 'pie' , 'onmouseout' ] , function ( ) { } ) ;
// gauge
var _ _gauge _color = getConfig ( [ 'gauge' , 'color' ] , "#e0e0e0" ) ,
_ _gauge _label _show = getConfig ( [ 'gauge' , 'label' , 'show' ] , true ) ,
_ _gauge _label _format = getConfig ( [ 'gauge' , 'label' , 'format' ] ) ,
_ _gauge _max = getConfig ( [ 'gauge' , 'max' ] ) ,
_ _gauge _min = getConfig ( [ 'gauge' , 'min' ] ) ,
_ _gauge _onclick = getConfig ( [ 'gauge' , 'onclick' ] , function ( ) { } ) ,
_ _gauge _onmouseover = getConfig ( [ 'gauge' , 'onmouseover' ] , function ( ) { } ) ,
_ _gauge _onmouseout = getConfig ( [ 'gauge' , 'onmouseout' ] , function ( ) { } ) ,
_ _gauge _style = getConfig ( [ 'gauge' , 'style' ] ) ,
_ _gauge _units = getConfig ( [ 'gauge' , 'units' ] ) ,
_ _gauge _width = getConfig ( [ 'gauge' , 'width' ] , false ) ;
// donut
// donut
var _ _donut _label _show = getConfig ( [ 'donut' , 'label' , 'show' ] , true ) ,
var _ _donut _label _show = getConfig ( [ 'donut' , 'label' , 'show' ] , true ) ,
_ _donut _label _format = getConfig ( [ 'donut' , 'label' , 'format' ] ) ,
_ _donut _label _format = getConfig ( [ 'donut' , 'label' , 'format' ] ) ,
@ -266,7 +294,7 @@
_ _tooltip _contents = getConfig ( [ 'tooltip' , 'contents' ] , function ( d , defaultTitleFormat , defaultValueFormat , color ) {
_ _tooltip _contents = getConfig ( [ 'tooltip' , 'contents' ] , function ( d , defaultTitleFormat , defaultValueFormat , color ) {
var titleFormat = _ _tooltip _format _title ? _ _tooltip _format _title : defaultTitleFormat ,
var titleFormat = _ _tooltip _format _title ? _ _tooltip _format _title : defaultTitleFormat ,
valueFormat = _ _tooltip _format _value ? _ _tooltip _format _value : defaultValueFormat ,
valueFormat = _ _tooltip _format _value ? _ _tooltip _format _value : defaultValueFormat ,
text , i , title , value , name ;
text , i , title , value , name , bgcolor ;
for ( i = 0 ; i < d . length ; i ++ ) {
for ( i = 0 ; i < d . length ; i ++ ) {
if ( ! ( d [ i ] && ( d [ i ] . value || d [ i ] . value === 0 ) ) ) { continue ; }
if ( ! ( d [ i ] && ( d [ i ] . value || d [ i ] . value === 0 ) ) ) { continue ; }
@ -277,9 +305,10 @@
name = d [ i ] . name ;
name = d [ i ] . name ;
value = valueFormat ( d [ i ] . value , d [ i ] . ratio , d [ i ] . id , d [ i ] . index ) ;
value = valueFormat ( d [ i ] . value , d [ i ] . ratio , d [ i ] . id , d [ i ] . index ) ;
bgcolor = ( _ _gauge _style === 'arc' && _ _color _values ) ? levelColor ( d [ i ] . value ) : color ( d [ i ] . id ) ;
text += "<tr class='" + CLASS . tooltipName + "-" + d [ i ] . id + "'>" ;
text += "<tr class='" + CLASS . tooltipName + "-" + d [ i ] . id + "'>" ;
text += "<td class='name'><span style='background-color:" + color ( d [ i ] . id ) + "'></span>" + name + "</td>" ;
text += "<td class='name'><span style='background-color:" + bg color + "'></span>" + name + "</td>" ;
text += "<td class='value'>" + value + "</td>" ;
text += "<td class='value'>" + value + "</td>" ;
text += "</tr>" ;
text += "</tr>" ;
}
}
@ -306,7 +335,8 @@
var dragStart = null , dragging = false , cancelClick = false , mouseover = false , transiting = false ;
var dragStart = null , dragging = false , cancelClick = false , mouseover = false , transiting = false ;
var defaultColorPattern = d3 . scale . category10 ( ) . range ( ) ,
var defaultColorPattern = d3 . scale . category10 ( ) . range ( ) ,
color = generateColor ( _ _data _colors , notEmpty ( _ _color _pattern ) ? _ _color _pattern : defaultColorPattern , _ _data _color ) ;
color = generateColor ( _ _data _colors , notEmpty ( _ _color _pattern ) ? _ _color _pattern : defaultColorPattern , _ _data _color ) ,
levelColor = generateLevelColor ( _ _color _pattern , _ _color _values ) ;
var timeFormat = _ _axis _x _localtime ? d3 . time . format : d3 . time . format . utc ,
var timeFormat = _ _axis _x _localtime ? d3 . time . format : d3 . time . format . utc ,
defaultTimeFormat = timeFormat . multi ( [
defaultTimeFormat = timeFormat . multi ( [
@ -487,7 +517,8 @@
function updateRadius ( ) {
function updateRadius ( ) {
radiusExpanded = Math . min ( arcWidth , arcHeight ) / 2 ;
radiusExpanded = Math . min ( arcWidth , arcHeight ) / 2 ;
radius = radiusExpanded * 0.95 ;
radius = radiusExpanded * 0.95 ;
innerRadius = hasDonutType ( c3 . data . targets ) ? radius * 0.6 : 0 ;
var innerRadiusRatio = _ _gauge _width ? ( ( radius - _ _gauge _width ) / radius ) : 0.6 ;
innerRadius = hasDonutType ( c3 . data . targets ) || hasGaugeType ( c3 . data . targets ) ? radius * innerRadiusRatio : 0 ;
}
}
function getSvgLeft ( ) {
function getSvgLeft ( ) {
var leftAxisClass = _ _axis _rotated ? CLASS . axisX : CLASS . axisY ,
var leftAxisClass = _ _axis _rotated ? CLASS . axisX : CLASS . axisY ,
@ -962,6 +993,15 @@
d = t ;
d = t ;
}
}
} ) ;
} ) ;
if ( isNaN ( d . endAngle ) ) d . endAngle = d . startAngle ;
if ( isGaugeType ( d . data ) ) {
var sA = d . startAngle , eA = d . endAngle ;
var gMin = _ _gauge _min , gMax = _ _gauge _max ,
gF = Math . abs ( gMin ) + gMax , fA = Math . abs ( sA ) + eA ,
aTic = ( Math . PI ) / gF ;
d . startAngle = ( - 1 * ( Math . PI / 2 ) ) + ( aTic * Math . abs ( gMin ) ) ;
d . endAngle = d . startAngle + ( aTic * ( ( d . value > gMax ) ? gMax : d . value ) ) ;
}
return found ? d : null ;
return found ? d : null ;
}
}
@ -996,12 +1036,13 @@
h = Math . sqrt ( x * x + y * y ) ;
h = Math . sqrt ( x * x + y * y ) ;
// TODO: ratio should be an option?
// TODO: ratio should be an option?
ratio = ( 36 / radius > 0.375 ? 1.175 - 36 / radius : 0.8 ) * radius / h ;
ratio = ( 36 / radius > 0.375 ? 1.175 - 36 / radius : 0.8 ) * radius / h ;
translate = "translate(" + ( x * ratio ) + ',' + ( y * ratio ) + ")" ;
translate = _ _gauge _style == 'arc' ? "translate(1,1)" : "translate(" + ( x * ratio ) + ',' + ( y * ratio ) + ")" ;
}
}
return translate ;
return translate ;
}
}
function getArcRatio ( d ) {
function getArcRatio ( d ) {
return d ? ( d . endAngle - d . startAngle ) / ( Math . PI * 2 ) : null ;
var whole = _ _gauge _style == 'arc' ? Math . PI : ( Math . PI * 2 ) ;
return d ? ( d . endAngle - d . startAngle ) / whole : null ;
}
}
function convertToArcData ( d ) {
function convertToArcData ( d ) {
return addName ( {
return addName ( {
@ -1035,36 +1076,52 @@
}
}
} ) ;
} ) ;
}
}
if ( ! withoutFadeOut ) {
if ( ! withoutFadeOut ) {
noneTargets . style ( "opacity" , 0.3 ) ;
noneTargets . style ( "opacity" , 0.3 ) ;
}
}
}
}
function unexpandArc ( id ) {
function unexpandArc ( id ) {
var target = svg . selectAll ( '.' + CLASS . chartArc + selectorTarget ( id ) ) ;
var target = svg . selectAll ( '.' + CLASS . chartArc + selectorTarget ( id ) ) ;
target . selectAll ( 'path' )
target . selectAll ( 'path.c3-arc ' )
. transition ( ) . duration ( 50 )
. transition ( ) . duration ( 50 )
. attr ( "d" , svgArc ) ;
. attr ( "d" , svgArc ) ;
svg . selectAll ( '.' + CLASS . arc )
svg . selectAll ( '.' + CLASS . arc )
. style ( "opacity" , 1 ) ;
. style ( "opacity" , ( _ _color _opacity ) ? _ _color _opacity : 1 ) ;
}
}
function shouldShowArcLable ( ) {
function shouldShowArcLable ( ) {
if ( hasGaugeType ( c3 . data . targets ) ) {
return true ;
}
return hasDonutType ( c3 . data . targets ) ? _ _donut _label _show : _ _pie _label _show ;
return hasDonutType ( c3 . data . targets ) ? _ _donut _label _show : _ _pie _label _show ;
}
}
function getArcLabelFormat ( ) {
function getArcLabelFormat ( ) {
if ( hasGaugeType ( c3 . data . targets ) ) {
return _ _gauge _label _format ;
}
return hasDonutType ( c3 . data . targets ) ? _ _donut _label _format : _ _pie _label _format ;
return hasDonutType ( c3 . data . targets ) ? _ _donut _label _format : _ _pie _label _format ;
}
}
function getArcTitle ( ) {
function getArcTitle ( ) {
return hasDonutType ( c3 . data . targets ) ? _ _donut _title : "" ;
return hasDonutType ( c3 . data . targets ) ? _ _donut _title : "" ;
}
}
function getArcOnClick ( ) {
function getArcOnClick ( ) {
if ( hasGaugeType ( c3 . data . targets ) ) {
return typeof _ _gauge _onclick === 'function' ? _ _gauge _onclick : function ( ) { } ;
}
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onclick : _ _pie _onclick ;
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onclick : _ _pie _onclick ;
return typeof callback === 'function' ? callback : function ( ) { } ;
return typeof callback === 'function' ? callback : function ( ) { } ;
}
}
function getArcOnMouseOver ( ) {
function getArcOnMouseOver ( ) {
if ( hasGaugeType ( c3 . data . targets ) ) {
return typeof _ _gauge _onmouseover === 'function' ? _ _gauge _onmouseover : function ( ) { } ;
}
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onmouseover : _ _pie _onmouseover ;
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onmouseover : _ _pie _onmouseover ;
return typeof callback === 'function' ? callback : function ( ) { } ;
return typeof callback === 'function' ? callback : function ( ) { } ;
}
}
function getArcOnMouseOut ( ) {
function getArcOnMouseOut ( ) {
if ( hasGaugeType ( c3 . data . targets ) ) {
return typeof _ _gauge _onmouseout === 'function' ? _ _gauge _onmouseout : function ( ) { } ;
}
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onmouseout : _ _pie _onmouseout ;
var callback = hasDonutType ( c3 . data . targets ) ? _ _donut _onmouseout : _ _pie _onmouseout ;
return typeof callback === 'function' ? callback : function ( ) { } ;
return typeof callback === 'function' ? callback : function ( ) { } ;
}
}
@ -1172,6 +1229,9 @@
if ( hasBarType ( yTargets ) && ! hasNegativeValueInTargets ( yTargets ) ) {
if ( hasBarType ( yTargets ) && ! hasNegativeValueInTargets ( yTargets ) ) {
padding _bottom = yDomainMin ;
padding _bottom = yDomainMin ;
}
}
if ( _ _zero _padding && ! hasNegativeValueInTargets ( yTargets ) ) {
padding _bottom -= padding _bottom ;
}
return [ yDomainMin - padding _bottom , yDomainMax + padding _top ] ;
return [ yDomainMin - padding _bottom , yDomainMax + padding _top ] ;
}
}
function getXDomainMin ( targets ) {
function getXDomainMin ( targets ) {
@ -1188,6 +1248,8 @@
} else if ( hasBarType ( targets ) ) {
} else if ( hasBarType ( targets ) ) {
maxDataCount = getMaxDataCount ( ) ;
maxDataCount = getMaxDataCount ( ) ;
padding = maxDataCount > 1 ? ( diff / ( maxDataCount - 1 ) ) / 2 : 0.5 ;
padding = maxDataCount > 1 ? ( diff / ( maxDataCount - 1 ) ) / 2 : 0.5 ;
} else if ( _ _zero _padding ) {
padding = diff * 0.001 ;
} else {
} else {
padding = diff * 0.01 ;
padding = diff * 0.01 ;
}
}
@ -1615,6 +1677,8 @@
function classAreas ( d ) { return classShapes ( d ) + generateClass ( CLASS . areas , d . id ) ; }
function classAreas ( d ) { return classShapes ( d ) + generateClass ( CLASS . areas , d . id ) ; }
function classRegion ( d , i ) { return generateClass ( CLASS . region , i ) + ' ' + ( 'class' in d ? d . class : '' ) ; }
function classRegion ( d , i ) { return generateClass ( CLASS . region , i ) + ' ' + ( 'class' in d ? d . class : '' ) ; }
function classEvent ( d , i ) { return generateClass ( CLASS . eventRect , i ) ; }
function classEvent ( d , i ) { return generateClass ( CLASS . eventRect , i ) ; }
function classStep ( d ) { return classShape ( d ) + generateClass ( CLASS . step , d . id ) ; }
function classSteps ( d ) { return classShapes ( d ) + generateClass ( CLASS . steps , d . id ) ; }
function classTarget ( id ) {
function classTarget ( id ) {
var additionalClassSuffix = _ _data _classes [ id ] , additionalClass = '' ;
var additionalClassSuffix = _ _data _classes [ id ] , additionalClass = '' ;
if ( additionalClassSuffix ) {
if ( additionalClassSuffix ) {
@ -1667,8 +1731,8 @@
return widths ;
return widths ;
}
}
function getYFormat ( forArc ) {
function getYFormat ( forArc ) {
var formatForY = forArc ? defaultArcValueFormat : yFormat ,
var formatForY = forArc && ! hasGaugeType ( c3 . data . targets ) ? defaultArcValueFormat : yFormat ,
formatForY2 = forArc ? defaultArcValueFormat : y2Format ;
formatForY2 = forArc && ! hasGaugeType ( c3 . data . targets ) ? defaultArcValueFormat : y2Format ;
return function ( v , ratio , id ) {
return function ( v , ratio , id ) {
var format = getAxisId ( id ) === 'y2' ? formatForY2 : formatForY ;
var format = getAxisId ( id ) === 'y2' ? formatForY2 : formatForY ;
return format ( v , ratio ) ;
return format ( v , ratio ) ;
@ -1821,6 +1885,7 @@
return ;
return ;
}
}
tooltip . html ( _ _tooltip _contents ( selectedData , getXAxisTickFormat ( ) , getYFormat ( forArc ) , color ) ) . style ( "display" , "block" ) ;
tooltip . html ( _ _tooltip _contents ( selectedData , getXAxisTickFormat ( ) , getYFormat ( forArc ) , color ) ) . style ( "display" , "block" ) ;
// Get tooltip dimensions
// Get tooltip dimensions
tWidth = tooltip . property ( 'offsetWidth' ) ;
tWidth = tooltip . property ( 'offsetWidth' ) ;
tHeight = tooltip . property ( 'offsetHeight' ) ;
tHeight = tooltip . property ( 'offsetHeight' ) ;
@ -1896,7 +1961,9 @@
function circleX ( d ) {
function circleX ( d ) {
return d . x || d . x === 0 ? x ( d . x ) : null ;
return d . x || d . x === 0 ? x ( d . x ) : null ;
}
}
function circleY ( d ) {
function circleY ( d , i ) {
var lineIndices = getLineIndices ( ) , getPoint = generateGetLinePoint ( lineIndices ) ;
if ( _ _data _groups . length > 0 ) { var point = getPoint ( d , i ) ; return point [ 0 ] [ 1 ] ; }
return getYScale ( d . id ) ( d . value ) ;
return getYScale ( d . id ) ( d . value ) ;
}
}
@ -1951,6 +2018,102 @@
return typeof _ _bar _width === 'number' ? _ _bar _width : barTargetsNum ? ( axis . tickOffset ( ) * 2 * _ _bar _width _ratio ) / barTargetsNum : 0 ;
return typeof _ _bar _width === 'number' ? _ _bar _width : barTargetsNum ? ( axis . tickOffset ( ) * 2 * _ _bar _width _ratio ) / barTargetsNum : 0 ;
}
}
//-- Area --//
function getAreaIndices ( ) { // replication of getBarIndices
var indices = { } , i = 0 , j , k ;
filterTargetsToShow ( c3 . data . targets . filter ( isAreaType ) ) . forEach ( function ( d ) {
for ( j = 0 ; j < _ _data _groups . length ; j ++ ) {
if ( _ _data _groups [ j ] . indexOf ( d . id ) < 0 ) { continue ; }
for ( k = 0 ; k < _ _data _groups [ j ] . length ; k ++ ) {
if ( _ _data _groups [ j ] [ k ] in indices ) {
indices [ d . id ] = indices [ _ _data _groups [ j ] [ k ] ] ;
break ;
}
}
}
if ( isUndefined ( indices [ d . id ] ) ) { indices [ d . id ] = i ++ ; }
} ) ;
indices . _ _max _ _ = i - 1 ;
return indices ;
}
function getAreaX ( areaTargetsNum , areaIndices , isSub ) { // partial duplication of getBarX
var scale = isSub ? subX : x ;
return function ( d ) {
var areaIndex = d . id in areaIndices ? areaIndices [ d . id ] : 0 ;
return d . x || d . x === 0 ? scale ( d . x ) - 0 * ( areaTargetsNum / 2 - areaIndex ) : 0 ;
} ;
}
function getAreaY ( isSub ) { // replication of getBarY
return function ( d ) {
var scale = isSub ? getSubYScale ( d . id ) : getYScale ( d . id ) ;
return scale ( d . value ) ;
} ;
}
function getAreaOffset ( areaIndices , isSub ) { // partial duplication of getBarOffset
var targets = orderTargets ( filterTargetsToShow ( c3 . data . targets . filter ( isAreaType ) ) ) ,
targetIds = targets . map ( function ( t ) { return t . id ; } ) ;
return function ( d , i ) {
var scale = isSub ? getSubYScale ( d . id ) : getYScale ( d . id ) ,
y0 = scale ( 0 ) , offset = y0 ;
targets . forEach ( function ( t ) {
if ( t . id === d . id || areaIndices [ t . id ] !== areaIndices [ d . id ] ) { return ; }
if ( targetIds . indexOf ( t . id ) < targetIds . indexOf ( d . id ) && t . values [ i ] . value > 0 ) {
offset += scale ( t . values [ i ] . value ) - y0 ;
}
} ) ;
return offset ;
} ;
}
//-- Line --//
function getLineIndices ( ) { // replication of getBarIndices
var indices = { } , i = 0 , j , k ;
filterTargetsToShow ( c3 . data . targets . filter ( isLineType ) ) . forEach ( function ( d ) {
for ( j = 0 ; j < _ _data _groups . length ; j ++ ) {
if ( _ _data _groups [ j ] . indexOf ( d . id ) < 0 ) { continue ; }
for ( k = 0 ; k < _ _data _groups [ j ] . length ; k ++ ) {
if ( _ _data _groups [ j ] [ k ] in indices ) {
indices [ d . id ] = indices [ _ _data _groups [ j ] [ k ] ] ;
break ;
}
}
}
if ( isUndefined ( indices [ d . id ] ) ) { indices [ d . id ] = i ++ ; }
} ) ;
indices . _ _max _ _ = i - 1 ;
return indices ;
}
function getLineX ( lineTargetsNum , lineIndices , isSub ) { // partial duplication of getBarX
var scale = isSub ? subX : x ;
return function ( d ) {
var lineIndex = d . id in lineIndices ? lineIndices [ d . id ] : 0 ;
return d . x || d . x === 0 ? scale ( d . x ) - 0 * ( lineTargetsNum / 2 - lineIndex ) : 0 ;
} ;
}
function getLineY ( isSub ) { // replication of getBarY
return function ( d ) {
var scale = isSub ? getSubYScale ( d . id ) : getYScale ( d . id ) ;
return scale ( d . value ) ;
} ;
}
function getLineOffset ( lineIndices , isSub ) { // partial duplication of getBarOffset
var targets = orderTargets ( filterTargetsToShow ( c3 . data . targets . filter ( isLineType ) ) ) ,
targetIds = targets . map ( function ( t ) { return t . id ; } ) ;
return function ( d , i ) {
var scale = isSub ? getSubYScale ( d . id ) : getYScale ( d . id ) ,
y0 = scale ( 0 ) , offset = y0 ;
targets . forEach ( function ( t ) {
if ( t . id === d . id || lineIndices [ t . id ] !== lineIndices [ d . id ] ) { return ; }
if ( targetIds . indexOf ( t . id ) < targetIds . indexOf ( d . id ) && t . values [ i ] . value > 0 ) {
offset += scale ( t . values [ i ] . value ) - y0 ;
}
} ) ;
return offset ;
} ;
}
//-- Type --//
//-- Type --//
function setTargetType ( targetIds , type ) {
function setTargetType ( targetIds , type ) {
@ -1985,20 +2148,31 @@
function hasPieType ( targets ) {
function hasPieType ( targets ) {
return _ _data _type === 'pie' || hasType ( targets , 'pie' ) ;
return _ _data _type === 'pie' || hasType ( targets , 'pie' ) ;
}
}
function hasGaugeType ( targets ) {
return hasType ( targets , 'gauge' ) ;
}
function hasDonutType ( targets ) {
function hasDonutType ( targets ) {
return _ _data _type === 'donut' || hasType ( targets , 'donut' ) ;
return _ _data _type === 'donut' || hasType ( targets , 'donut' ) ;
}
}
function hasArcType ( targets ) {
function hasArcType ( targets ) {
return hasPieType ( targets ) || hasDonutType ( targets ) ;
return hasPieType ( targets ) || hasDonutType ( targets ) || hasGaugeType ( targets ) ;
}
}
function isLineType ( d ) {
function isLineType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
var id = ( typeof d === 'string' ) ? d : d . id ;
return ! ( id in _ _data _types ) || _ _data _types [ id ] === 'line' || _ _data _types [ id ] === 'spline' || _ _data _types [ id ] === 'area' || _ _data _types [ id ] === 'area-spline' ;
return ! ( id in _ _data _types ) || _ _data _types [ id ] === 'line' || _ _data _types [ id ] === 'spline' || _ _data _types [ id ] === 'area' || _ _data _types [ id ] === 'area-spline' ;
}
}
function isStepType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
return ! ( id in _ _data _types ) || _ _data _types [ id ] === 'step' || _ _data _types [ id ] === 'area-step' ;
}
function isSplineType ( d ) {
function isSplineType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'spline' || _ _data _types [ id ] === 'area-spline' ;
return _ _data _types [ id ] === 'spline' || _ _data _types [ id ] === 'area-spline' ;
}
}
function isAreaType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'area' ;
}
function isBarType ( d ) {
function isBarType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'bar' ;
return _ _data _types [ id ] === 'bar' ;
@ -2011,16 +2185,23 @@
var id = ( typeof d === 'string' ) ? d : d . id ;
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'pie' ;
return _ _data _types [ id ] === 'pie' ;
}
}
function isGaugeType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'gauge' ;
}
function isDonutType ( d ) {
function isDonutType ( d ) {
var id = ( typeof d === 'string' ) ? d : d . id ;
var id = ( typeof d === 'string' ) ? d : d . id ;
return _ _data _types [ id ] === 'donut' ;
return _ _data _types [ id ] === 'donut' ;
}
}
function isArcType ( d ) {
function isArcType ( d ) {
return isPieType ( d ) || isDonutType ( d ) ;
return isPieType ( d ) || isDonutType ( d ) || isGaugeType ( d ) ;
}
}
function lineData ( d ) {
function lineData ( d ) {
return isLineType ( d ) ? [ d ] : [ ] ;
return isLineType ( d ) ? [ d ] : [ ] ;
}
}
function stepData ( d ) {
return isStepType ( d ) ? [ d ] : [ ] ;
}
function arcData ( d ) {
function arcData ( d ) {
return isArcType ( d . data ) ? [ d ] : [ ] ;
return isArcType ( d . data ) ? [ d ] : [ ] ;
}
}
@ -2035,6 +2216,9 @@
function lineOrScatterData ( d ) {
function lineOrScatterData ( d ) {
return isLineType ( d ) || isScatterType ( d ) ? d . values : [ ] ;
return isLineType ( d ) || isScatterType ( d ) ? d . values : [ ] ;
}
}
function lineOrStepData ( d ) {
return isLineType ( d ) || isStepType ( d ) ? [ d ] : [ ] ;
}
function barOrLineData ( d ) {
function barOrLineData ( d ) {
return isBarType ( d ) || isLineType ( d ) ? d . values : [ ] ;
return isBarType ( d ) || isLineType ( d ) ? d . values : [ ] ;
}
}
@ -2068,6 +2252,23 @@
} ;
} ;
}
}
function generateLevelColor ( _colors , _values ) {
var colors = _colors ,
levels = _values ;
return function ( value ) {
for ( var a = 1 ; a < levels . length ; a ++ ) {
if ( levels [ 0 ] === 'percentage' && ( ( value / _ _gauge _max ) * 100 ) < levels [ a ] ) {
return colors [ a - 1 ] ;
}
if ( levels [ 0 ] === 'whole' && value < levels [ a ] ) {
return colors [ a - 1 ] ;
}
}
return colors [ colors . length - 1 ] ;
} ;
}
//-- Date --//
//-- Date --//
function parseDate ( date ) {
function parseDate ( date ) {
@ -2240,42 +2441,45 @@
getBars ( i ) . classed ( CLASS . EXPANDED , false ) ;
getBars ( i ) . classed ( CLASS . EXPANDED , false ) ;
}
}
var lineOnMain = generateDrawLine ( false ) ,
function generateDrawArea ( areaIndices , isSub ) {
lineOnSub = generateDrawLine ( true ) ;
var area ,
getPoint = generateGetAreaPoint ( areaIndices , isSub ) ,
var areaOnMain = ( function ( ) {
yScaleGetter = isSub ? getSubYScale : getYScale ;
var area ;
if ( _ _axis _rotated ) {
if ( _ _axis _rotated ) {
area = d3 . svg . area ( )
area = d3 . svg . area ( )
. x0 ( function ( d , i ) { return yScaleGetter ( d . id ) ( 0 ) ; } )
. x0 ( function ( d ) { return getYScale ( d . id ) ( 0 ) ; } )
. x1 ( function ( d , i ) { return yScaleGetter ( d . id ) ( d . value ) ; } )
. x1 ( function ( d ) { return getYScale ( d . id ) ( d . value ) ; } )
. y ( xx ) ;
. y ( xx ) ;
} else {
} else {
area = d3 . svg . area ( )
area = d3 . svg . area ( )
. x ( xx )
. x ( xx )
. y0 ( function ( d , i ) { if ( _ _data _groups . length > 0 ) { var point = getPoint ( d , i ) ; return point [ 0 ] [ 1 ] ; } return yScaleGetter ( d . id ) ( 0 ) ; } )
. y0 ( function ( d ) { return getYScale ( d . id ) ( 0 ) ; } )
. y1 ( function ( d , i ) { if ( _ _data _groups . length > 0 ) { var point = getPoint ( d , i ) ; return point [ 1 ] [ 1 ] ; } return yScaleGetter ( d . id ) ( d . value ) ; } ) ;
. y1 ( function ( d ) { return getYScale ( d . id ) ( d . value ) ; } ) ;
}
}
return function ( d , i ) {
return function ( d ) {
var data = filterRemoveNull ( d . values ) , x0 , y0 ;
var data = filterRemoveNull ( d . values ) , x0 , y0 ;
if ( hasType ( [ d ] , 'area' ) || hasType ( [ d ] , 'area-spline' ) ) {
if ( hasType ( [ d ] , 'area' ) || hasType ( [ d ] , 'area-spline' ) ) {
isSplineType ( d ) ? area . interpolate ( "cardinal" ) : area . interpolate ( "linear" ) ;
isSplineType ( d ) ? area . interpolate ( "cardinal" ) : area . interpolate ( "linear" ) ;
return area ( data ) ;
return area ( data ) ;
} else if ( hasType ( [ d ] , 'area-step' ) ) {
} else {
isStepType ( d ) ? area . interpolate ( "step-after" ) : area . interpolate ( "linear" ) ;
x0 = data [ 0 ] ? x ( data [ 0 ] . x ) : 0 ;
return area ( data ) ;
y0 = data [ 0 ] ? getYScale ( d . id ) ( data [ 0 ] . value ) : 0 ;
} else {
return _ _axis _rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0 ;
x0 = x ( data [ 0 ] . x ) ;
}
y0 = getYScale ( d . id ) ( data [ 0 ] . value ) ;
} ;
return _ _axis _rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0 ;
} ) ( ) ;
}
} ;
function generateDrawLine ( isSub ) {
}
var yScaleGetter = isSub ? getSubYScale : getYScale ,
xValue = isSub ? xx : subxx ,
function generateDrawLine ( lineIndices , isSub ) {
yValue = function ( d ) { return yScaleGetter ( d . id ) ( d . value ) ; } ,
var getPoint = generateGetLinePoint ( lineIndices , isSub ) ,
yScaleGetter = isSub ? getSubYScale : getYScale ,
xValue = isSub ? subxx : xx ,
yValue = function ( d , i ) { if ( _ _data _groups . length > 0 ) { var point = getPoint ( d , i ) ; return point [ 0 ] [ 1 ] ; } return yScaleGetter ( d . id ) ( d . value ) ; } ,
line = d3 . svg . line ( )
line = d3 . svg . line ( )
. x ( _ _axis _rotated ? yValue : xValue )
. x ( _ _axis _rotated ? yValue : xValue )
. y ( _ _axis _rotated ? xValue : yValue ) ;
. y ( _ _axis _rotated ? xValue : yValue ) ;
@ -2290,6 +2494,9 @@
line . interpolate ( isSplineType ( d ) ? "cardinal" : "linear" ) ;
line . interpolate ( isSplineType ( d ) ? "cardinal" : "linear" ) ;
return line ( data ) ;
return line ( data ) ;
}
}
} else if ( isStepType ( d ) ) {
line . interpolate ( "step-after" ) ;
return line ( data ) ;
} else {
} else {
if ( data [ 0 ] ) {
if ( data [ 0 ] ) {
x0 = x ( data [ 0 ] . x ) ;
x0 = x ( data [ 0 ] . x ) ;
@ -2344,6 +2551,28 @@
}
}
}
}
function generateGetAreaPoint ( areaIndices , isSub ) { // partial duplication of generateGetBarPoints
var areaTargetsNum = areaIndices . _ _max _ _ + 1 ,
x = getAreaX ( areaTargetsNum , areaIndices , ! ! isSub ) ,
y = getAreaY ( ! ! isSub ) ,
areaOffset = getAreaOffset ( areaIndices , ! ! isSub ) ,
yScale = isSub ? getSubYScale : getYScale ;
return function ( d , i ) {
var y0 = yScale ( d . id ) ( 0 ) ,
offset = areaOffset ( d , i ) || y0 , // offset is for stacked area chart
posX = x ( d ) , posY = y ( d ) ;
// fix posY not to overflow opposite quadrant
if ( _ _axis _rotated ) {
if ( ( d . value > 0 && posY < offset ) || ( d . value < 0 && posY > offset ) ) { posY = offset ; }
}
// 1 point that marks the area position
return [
[ posX , offset ] ,
[ posX , posY - ( y0 - offset ) ]
] ;
} ;
}
function generateGetBarPoints ( barIndices , isSub ) {
function generateGetBarPoints ( barIndices , isSub ) {
var barTargetsNum = barIndices . _ _max _ _ + 1 ,
var barTargetsNum = barIndices . _ _max _ _ + 1 ,
barW = getBarW ( xAxis , barTargetsNum ) ,
barW = getBarW ( xAxis , barTargetsNum ) ,
@ -2369,6 +2598,27 @@
} ;
} ;
}
}
function generateGetLinePoint ( lineIndices , isSub ) { // partial duplication of generateGetBarPoints
var lineTargetsNum = lineIndices . _ _max _ _ + 1 ,
x = getLineX ( lineTargetsNum , lineIndices , ! ! isSub ) ,
y = getLineY ( ! ! isSub ) ,
lineOffset = getLineOffset ( lineIndices , ! ! isSub ) ,
yScale = isSub ? getSubYScale : getYScale ;
return function ( d , i ) {
var y0 = yScale ( d . id ) ( 0 ) ,
offset = lineOffset ( d , i ) || y0 , // offset is for stacked area chart
posX = x ( d ) , posY = y ( d ) ;
// fix posY not to overflow opposite quadrant
if ( _ _axis _rotated ) {
if ( ( d . value > 0 && posY < offset ) || ( d . value < 0 && posY > offset ) ) { posY = offset ; }
}
// 1 point that marks the line position
return [
[ posX , posY - ( y0 - offset ) ]
] ;
} ;
}
function lineWithRegions ( d , x , y , _regions ) {
function lineWithRegions ( d , x , y , _regions ) {
var prev = - 1 , i , j ;
var prev = - 1 , i , j ;
var s = "M" , sWithRegion ;
var s = "M" , sWithRegion ;
@ -2595,6 +2845,15 @@
updateLegend ( mapToIds ( c3 . data . targets ) , { withTransform : false , withTransitionForTransform : false } ) ;
updateLegend ( mapToIds ( c3 . data . targets ) , { withTransform : false , withTransitionForTransform : false } ) ;
/*-- Main Region --*/
/*-- Main Region --*/
if ( c3 . data . targets . length == 0 ) {
main . append ( "text" )
. attr ( "class" , CLASS . text )
. attr ( "x" , ( main [ 0 ] [ 0 ] . parentNode . width . baseVal . value / 2 ) - margin . left )
. attr ( "y" , ( main [ 0 ] [ 0 ] . parentNode . height . baseVal . value / 2 ) - margin . top )
. attr ( "text-anchor" , "middle" )
. attr ( "style" , ( _ _data _empty _label _fill ? "fill:" + _ _data _empty _label _fill + "; " : "" ) + ( _ _data _empty _label _size ? "font-size:" + _ _data _empty _label _size + "; " : "" ) )
. text ( _ _data _empty _label _text ) ;
}
// Grids
// Grids
grid = main . append ( 'g' )
grid = main . append ( 'g' )
@ -3097,15 +3356,20 @@
function redraw ( options , transitions ) {
function redraw ( options , transitions ) {
var xgrid , xgridAttr , xgridData , xgridLines , xgridLine , ygrid , ygridLines , ygridLine ;
var xgrid , xgridAttr , xgridData , xgridLines , xgridLine , ygrid , ygridLines , ygridLine ;
var mainLine , mainArea , mainCircle , mainBar , mainArc , mainRegion , mainText , contextLine , contextBar , eventRect , eventRectUpdate ;
var mainLine , mainStep , main Area , mainCircle , mainBar , mainArc , mainRegion , mainText , contextLine , contextStep , contextArea , contextBar , eventRect , eventRectUpdate ;
var barIndices = getBarIndices ( ) , maxDataCountTarget , tickOffset ;
var areaIndices = getAreaIndices ( ) , barIndices = getBarIndices ( ) , lineIndices = getLine Indices ( ) , maxDataCountTarget , tickOffset ;
var rectX , rectW ;
var rectX , rectW ;
var withY , withSubchart , withTransition , withTransitionForExit , withTransitionForAxis , withTransform , withUpdateXDomain , withUpdateOrgXDomain , withLegend , withUpdateTranslate ;
var withY , withSubchart , withTransition , withTransitionForExit , withTransitionForAxis , withTransform , withUpdateXDomain , withUpdateOrgXDomain , withLegend , withUpdateTranslate ;
var hideAxis = hasArcType ( c3 . data . targets ) ;
var hideAxis = hasArcType ( c3 . data . targets ) ;
var drawBar , drawBarOnSub , xForText , yForText ;
var drawArea , drawAreaOnSub , draw Bar , drawBarOnSub , drawLine , drawLine OnSub , xForText , yForText ;
var duration , durationForExit , durationForAxis ;
var duration , durationForExit , durationForAxis ;
var targetsToShow = filterTargetsToShow ( c3 . data . targets ) , tickValues , i , intervalForCulling ;
var targetsToShow = filterTargetsToShow ( c3 . data . targets ) , tickValues , i , intervalForCulling ;
// abort if no targets to show
if ( targetsToShow . length === 0 && _ _data _empty _abort ) {
return ;
}
options = options || { } ;
options = options || { } ;
withY = getOption ( options , "withY" , true ) ;
withY = getOption ( options , "withY" , true ) ;
withSubchart = getOption ( options , "withSubchart" , true ) ;
withSubchart = getOption ( options , "withSubchart" , true ) ;
@ -3212,7 +3476,9 @@
}
}
// setup drawer - MEMO: these must be called after axis updated
// setup drawer - MEMO: these must be called after axis updated
drawArea = generateDrawArea ( areaIndices , false ) ;
drawBar = generateDrawBar ( barIndices ) ;
drawBar = generateDrawBar ( barIndices ) ;
drawLine = generateDrawLine ( lineIndices , false ) ;
xForText = generateXYForText ( barIndices , true ) ;
xForText = generateXYForText ( barIndices , true ) ;
yForText = generateXYForText ( barIndices , false ) ;
yForText = generateXYForText ( barIndices , false ) ;
@ -3352,8 +3618,11 @@
. data ( barData ) ;
. data ( barData ) ;
mainBar . enter ( ) . append ( 'path' )
mainBar . enter ( ) . append ( 'path' )
. attr ( "class" , classBar )
. attr ( "class" , classBar )
. style ( "stroke" , 'none' )
. style ( "stroke" , function ( d ) { return color ( d . id ) ; } ) //'none')
. style ( "fill" , color ) ;
. style ( "stroke-width" , 2 )
. style ( "opacity" , 0 )
. style ( "fill" , function ( d ) { return color ( d . id ) ; } )
. style ( "fill-opacity" , function ( ) { if ( _ _color _opacity ) { return _ _color _opacity ; } return initialOpacity ; } ) ;
mainBar
mainBar
. style ( "opacity" , initialOpacity )
. style ( "opacity" , initialOpacity )
. transition ( ) . duration ( duration )
. transition ( ) . duration ( duration )
@ -3373,15 +3642,30 @@
mainLine
mainLine
. style ( "opacity" , initialOpacity )
. style ( "opacity" , initialOpacity )
. transition ( ) . duration ( duration )
. transition ( ) . duration ( duration )
. attr ( "d" , lineOnMain )
. attr ( "d" , drawLine )
. style ( "stroke" , color )
. style ( "stroke" , color )
. style ( "opacity" , 1 ) ;
. style ( "opacity" , 1 ) ;
mainLine . exit ( ) . transition ( ) . duration ( durationForExit )
mainLine . exit ( ) . transition ( ) . duration ( durationForExit )
. style ( 'opacity' , 0 )
. style ( 'opacity' , 0 )
. remove ( ) ;
. remove ( ) ;
// steps
mainStep = main . selectAll ( '.' + CLASS . steps ) . selectAll ( '.' + CLASS . step )
. data ( stepData ) ;
mainStep . enter ( ) . append ( 'path' )
. attr ( 'class' , classStep )
. style ( "stroke" , color ) ;
mainStep
. style ( "opacity" , initialOpacity )
. transition ( ) . duration ( duration )
. attr ( "d" , drawLine )
. style ( "stroke" , color )
. style ( "opacity" , 1 ) ;
mainStep . exit ( ) . transition ( ) . duration ( durationForExit )
. style ( 'opacity' , 0 )
. remove ( ) ;
// area
mainArea = main . selectAll ( '.' + CLASS . areas ) . selectAll ( '.' + CLASS . area )
mainArea = main . selectAll ( '.' + CLASS . areas ) . selectAll ( '.' + CLASS . area )
. data ( lineData ) ;
. data ( lineOrStep Data ) ;
mainArea . enter ( ) . append ( 'path' )
mainArea . enter ( ) . append ( 'path' )
. attr ( "class" , classArea )
. attr ( "class" , classArea )
. style ( "fill" , color )
. style ( "fill" , color )
@ -3389,7 +3673,7 @@
mainArea
mainArea
. style ( "opacity" , 0 )
. style ( "opacity" , 0 )
. transition ( ) . duration ( duration )
. transition ( ) . duration ( duration )
. attr ( "d" , areaOnMain )
. attr ( "d" , drawArea ) //areaOnMain)
. style ( "fill" , color )
. style ( "fill" , color )
. style ( "opacity" , orgAreaOpacity ) ;
. style ( "opacity" , orgAreaOpacity ) ;
mainArea . exit ( ) . transition ( ) . duration ( durationForExit )
mainArea . exit ( ) . transition ( ) . duration ( durationForExit )
@ -3439,6 +3723,23 @@
// arc
// arc
mainArc = main . selectAll ( '.' + CLASS . arcs ) . selectAll ( '.' + CLASS . arc )
mainArc = main . selectAll ( '.' + CLASS . arcs ) . selectAll ( '.' + CLASS . arc )
. data ( arcData ) ;
. data ( arcData ) ;
if ( _ _gauge _style === "arc" ) {
mainArc . enter ( ) . append ( "path" )
. attr ( "class" , "" )
. style ( "opacity" , 1 )
. style ( "fill" , _ _gauge _color ) // Where background color would receive customization.
. style ( "cursor" , "pointer" )
. attr ( "transform" , "scale(1,1)" )
. attr ( "d" , function ( d ) {
d . value = _ _gauge _max ;
d . startAngle = - 1 * ( Math . PI / 2 ) ;
d . endAngle = Math . PI / 2 ;
return getArc ( d , true ) ;
} ) ;
mainArc . exit ( ) . transition ( ) . duration ( durationForExit )
. style ( 'opacity' , 0 )
. remove ( ) ;
}
mainArc . enter ( ) . append ( 'path' )
mainArc . enter ( ) . append ( 'path' )
. attr ( "class" , classArc )
. attr ( "class" , classArc )
. style ( "fill" , function ( d ) { return color ( d . data ) ; } )
. style ( "fill" , function ( d ) { return color ( d . data ) ; } )
@ -3499,13 +3800,14 @@
} ;
} ;
}
}
* /
* /
if ( isNaN ( this . _current . endAngle ) ) this . _current . endAngle = this . _current . startAngle ;
interpolate = d3 . interpolate ( this . _current , updated ) ;
interpolate = d3 . interpolate ( this . _current , updated ) ;
this . _current = interpolate ( 0 ) ;
this . _current = interpolate ( 0 ) ;
return function ( t ) { return getArc ( interpolate ( t ) , true ) ; } ;
return function ( t ) { return getArc ( interpolate ( t ) , true ) ; } ;
} )
} )
. attr ( "transform" , withTransform ? "scale(1)" : "" )
. attr ( "transform" , withTransform ? "scale(1)" : "" )
. style ( "fill" , function ( d ) { return c olor( d . data ) ; } )
. style ( "fill" , function ( d ) { return ( _ _gauge _style === 'arc' && _ _color _values ) ? levelC olor( d . data . values [ 0 ] . value ) : color ( d . data . id ) ; } ) // Where gauge reading color would receive customization.//color(d.data); })
. style ( "opacity" , 1 )
. style ( "opacity" , ( _ _color _opacity ) ? _ _color _opacity : 1 ) //1)
. call ( endall , function ( ) {
. call ( endall , function ( ) {
transiting = false ;
transiting = false ;
} ) ;
} ) ;
@ -3518,8 +3820,28 @@
. attr ( "transform" , transformForArcLabel )
. attr ( "transform" , transformForArcLabel )
. transition ( ) . duration ( duration )
. transition ( ) . duration ( duration )
. style ( "opacity" , function ( d ) { return isTargetToShow ( d . data . id ) && isArcType ( d . data ) ? 1 : 0 ; } ) ;
. style ( "opacity" , function ( d ) { return isTargetToShow ( d . data . id ) && isArcType ( d . data ) ? 1 : 0 ; } ) ;
if ( _ _gauge _style === "arc" ) {
main . selectAll ( '.' + CLASS . chartArc ) . select ( 'text.units' )
. attr ( "transform" , transformForArcLabel )
. style ( "opacity" , 0 )
. transition ( ) . duration ( duration )
. text ( ( _ _gauge _label _show ) ? _ _gauge _units : '' )
. style ( "opacity" , function ( d ) { return isTargetToShow ( d . data . id ) && isArcType ( d . data ) ? 1 : 0 ; } ) ;
main . selectAll ( '.' + CLASS . chartArc ) . select ( 'text.min' )
. attr ( "transform" , transformForArcLabel )
. style ( "opacity" , 0 )
. transition ( ) . duration ( duration )
. text ( ( _ _gauge _label _show ) ? _ _gauge _min : '' )
. style ( "opacity" , function ( d ) { return isTargetToShow ( d . data . id ) && isArcType ( d . data ) ? 1 : 0 ; } ) ;
main . selectAll ( '.' + CLASS . chartArc ) . select ( 'text.max' )
. attr ( "transform" , transformForArcLabel )
. style ( "opacity" , 0 )
. transition ( ) . duration ( duration )
. text ( ( _ _gauge _label _show ) ? _ _gauge _max : '' )
. style ( "opacity" , function ( d ) { return isTargetToShow ( d . data . id ) && isArcType ( d . data ) ? 1 : 0 ; } ) ;
}
main . select ( '.' + CLASS . chartArcsTitle )
main . select ( '.' + CLASS . chartArcsTitle )
. style ( "opacity" , hasDonutType ( c3 . data . targets ) ? 1 : 0 ) ;
. style ( "opacity" , hasDonutType ( c3 . data . targets ) || hasGaugeType ( c3 . data . targets ) ? 1 : 0 ) ;
// subchart
// subchart
if ( _ _subchart _show ) {
if ( _ _subchart _show ) {
@ -3540,7 +3862,9 @@
brush . extent ( x . orgDomain ( ) ) . update ( ) ;
brush . extent ( x . orgDomain ( ) ) . update ( ) ;
}
}
// setup drawer - MEMO: this must be called after axis updated
// setup drawer - MEMO: this must be called after axis updated
drawAreaOnSub = generateDrawArea ( areaIndices , true ) ;
drawBarOnSub = generateDrawBar ( barIndices , true ) ;
drawBarOnSub = generateDrawBar ( barIndices , true ) ;
drawLineOnSub = generateDrawLine ( lineIndices , true ) ;
// bars
// bars
contextBar = context . selectAll ( '.' + CLASS . bars ) . selectAll ( '.' + CLASS . bar )
contextBar = context . selectAll ( '.' + CLASS . bars ) . selectAll ( '.' + CLASS . bar )
. data ( barData ) ;
. data ( barData ) ;
@ -3565,11 +3889,41 @@
contextLine
contextLine
. style ( "opacity" , initialOpacity )
. style ( "opacity" , initialOpacity )
. transition ( ) . duration ( duration )
. transition ( ) . duration ( duration )
. attr ( "d" , l ineOnSub)
. attr ( "d" , drawL ineOnSub)
. style ( 'opacity' , 1 ) ;
. style ( 'opacity' , 1 ) ;
contextLine . exit ( ) . transition ( ) . duration ( duration )
contextLine . exit ( ) . transition ( ) . duration ( duration )
. style ( 'opacity' , 0 )
. style ( 'opacity' , 0 )
. remove ( ) ;
. remove ( ) ;
// steps
contextStep = context . selectAll ( '.' + CLASS . steps ) . selectAll ( '.' + CLASS . step )
. data ( stepData ) ;
contextStep . enter ( ) . append ( 'path' )
. attr ( 'class' , classLine )
. style ( 'stroke' , color ) ;
contextStep
. style ( "opacity" , initialOpacity )
. transition ( ) . duration ( duration )
. attr ( "d" , drawLineOnSub )
. style ( 'opacity' , 1 ) ;
contextStep . exit ( ) . transition ( ) . duration ( duration )
. style ( 'opacity' , 0 )
. remove ( ) ;
// area
contextArea = context . selectAll ( '.' + CLASS . areas ) . selectAll ( '.' + CLASS . area )
. data ( ( isStepType ? stepData : lineData ) ) ;
contextArea . enter ( ) . append ( 'path' )
. attr ( "class" , classArea )
. style ( "fill" , color )
. style ( "opacity" , function ( ) { orgAreaOpacity = + d3 . select ( this ) . style ( 'opacity' ) ; return 0 ; } ) ;
contextArea
. style ( "opacity" , 0 )
. transition ( ) . duration ( duration )
. attr ( "d" , drawAreaOnSub )
. style ( "fill" , color )
. style ( "opacity" , orgAreaOpacity ) ;
contextArea . exit ( ) . transition ( ) . duration ( durationForExit )
. style ( 'opacity' , 0 )
. remove ( ) ;
}
}
}
}
@ -3614,11 +3968,13 @@
if ( ( isCustomX || isTimeSeries ) && ! isCategorized ) {
if ( ( isCustomX || isTimeSeries ) && ! isCategorized ) {
rectW = function ( d , i ) {
rectW = function ( d , i ) {
var prevX = getPrevX ( i ) , nextX = getNextX ( i ) , dx = c3 . data . xs [ d . id ] [ i ] ;
var prevX = getPrevX ( i ) , nextX = getNextX ( i ) , dx = c3 . data . xs [ d . id ] [ i ] ;
return ( x ( nextX ? nextX : dx * 1.1 ) - x ( prevX ? prevX : dx * 0.9 ) ) / 2 ;
var xnX = x ( nextX ? nextX : dx ) ;
var xpX = x ( prevX ? prevX : dx ) ;
return ( xnX - xpX ) / 2 ;
} ;
} ;
rectX = function ( d , i ) {
rectX = function ( d , i ) {
var prevX = getPrevX ( i ) , dx = c3 . data . xs [ d . id ] [ i ] ;
var prevX = getPrevX ( i ) , dx = c3 . data . xs [ d . id ] [ i ] ;
return ( x ( dx ) + x ( prevX ? prevX : dx * 0.9 ) ) / 2 ;
return ( x ( dx ) + x ( prevX ? prevX : dx ) ) / 2 ;
} ;
} ;
} else {
} else {
rectW = getEventRectWidth ( ) ;
rectW = getEventRectWidth ( ) ;
@ -3792,6 +4148,9 @@
// Lines for each data
// Lines for each data
mainLineEnter . append ( 'g' )
mainLineEnter . append ( 'g' )
. attr ( "class" , classLines ) ;
. attr ( "class" , classLines ) ;
// Steps
mainLineEnter . append ( 'g' )
. attr ( 'class' , classSteps ) ;
// Areas
// Areas
mainLineEnter . append ( 'g' )
mainLineEnter . append ( 'g' )
. attr ( 'class' , classAreas ) ;
. attr ( 'class' , classAreas ) ;
@ -3819,10 +4178,40 @@
mainPieEnter . append ( 'g' )
mainPieEnter . append ( 'g' )
. attr ( 'class' , classArcs ) ;
. attr ( 'class' , classArcs ) ;
mainPieEnter . append ( "text" )
mainPieEnter . append ( "text" )
. attr ( "dy" , ".35em")
. attr ( "dy" , _ _gauge _style === "arc" ? "-0.35em" : ".35em")
. style ( "opacity" , 0 )
. style ( "opacity" , 0 )
. style ( "text-anchor" , "middle" )
. style ( "text-anchor" , "middle" )
. style ( "pointer-events" , "none" ) ;
. style ( "pointer-events" , "none" )
. style ( "font-size" , width / 10 + "px" ) ;
if ( _ _gauge _style === "arc" ) {
mainPieEnter . select ( 'text' ) . style ( 'fill' , '#000' ) ;
mainPieEnter . append ( "text" )
. attr ( "dy" , ".75em" )
. attr ( "class" , "units" )
. style ( "opacity" , 0 )
. style ( "text-anchor" , "middle" )
. style ( "pointer-events" , "none" )
. style ( 'fill' , '#000' )
. style ( "font-size" , width / 15 + "px" ) ;
mainPieEnter . append ( "text" )
. attr ( "dx" , - 1 * ( innerRadius + ( ( radius - innerRadius ) / 2 ) ) + "px" )
. attr ( "dy" , "1em" )
. attr ( "class" , "min" )
. style ( "opacity" , 0 )
. style ( "text-anchor" , "middle" )
. style ( "pointer-events" , "none" )
. style ( 'fill' , '#777' )
. style ( "font-size" , width / 20 + "px" ) ;
mainPieEnter . append ( "text" )
. attr ( "dx" , innerRadius + ( ( radius - innerRadius ) / 2 ) + "px" )
. attr ( "dy" , "1em" )
. attr ( "class" , "max" )
. style ( "opacity" , 0 )
. style ( "text-anchor" , "middle" )
. style ( "pointer-events" , "none" )
. style ( 'fill' , '#777' )
. style ( "font-size" , width / 20 + "px" ) ;
}
// MEMO: can not keep same color..., but not bad to update color in redraw
// MEMO: can not keep same color..., but not bad to update color in redraw
//mainPieUpdate.exit().remove();
//mainPieUpdate.exit().remove();
@ -3848,8 +4237,14 @@
. style ( 'opacity' , 0 )
. style ( 'opacity' , 0 )
. attr ( 'class' , classChartLine ) ;
. attr ( 'class' , classChartLine ) ;
// Lines for each data
// Lines for each data
contextLineEnter . append ( 'g' )
contextLineEnter . append ( "g" )
. attr ( "class" , classLines ) ;
. attr ( "class" , classLines ) ;
// Steps
contextLineEnter . append ( "g" )
. attr ( "class" , classSteps ) ;
// Area
contextLineEnter . append ( "g" )
. attr ( "class" , classAreas ) ;
}
}
/*-- Show --*/
/*-- Show --*/
@ -4656,7 +5051,7 @@
}
}
function generateTicks ( scale ) {
function generateTicks ( scale ) {
var i , domain , ticks = [ ] ;
var i , domain , ticks = [ ] ;
if ( scale . ticks ) {
if ( scale . ticks && tickArguments != undefined ) {
return scale . ticks . apply ( scale , tickArguments ) ;
return scale . ticks . apply ( scale , tickArguments ) ;
}
}
domain = scale . domain ( ) ;
domain = scale . domain ( ) ;