@ -74,7 +74,6 @@ More detail and specific examples can be found in the included HTML file.
maxRadius = null ,
maxRadius = null ,
centerLeft = null ,
centerLeft = null ,
centerTop = null ,
centerTop = null ,
redraw = true ,
legendWidth = 0 ,
legendWidth = 0 ,
processed = false ,
processed = false ,
raw = false ,
raw = false ,
@ -302,11 +301,13 @@ More detail and specific examples can be found in the included HTML file.
ctx = newCtx ;
ctx = newCtx ;
setupPie ( ) ;
setupPie ( ) ;
var slices = plot . getData ( ) ;
var slices = plot . getData ( ) ,
var attempts = 0 ;
attempts = 0 ;
// Keep shrinking the pie's radius until drawPie returns true,
// indicating that all the labels fit, or we try too many times.
while ( redraw && attempts < REDRAW _ATTEMPTS ) {
do {
redraw = false ;
if ( attempts > 0 ) {
if ( attempts > 0 ) {
maxRadius *= REDRAW _SHRINK ;
maxRadius *= REDRAW _SHRINK ;
}
}
@ -315,20 +316,13 @@ More detail and specific examples can be found in the included HTML file.
if ( options . series . pie . tilt <= 0.8 ) {
if ( options . series . pie . tilt <= 0.8 ) {
drawShadow ( ) ;
drawShadow ( ) ;
}
}
drawPie ( ) ;
} while ( ! drawPie ( ) && attempts < REDRAW _ATTEMPTS )
}
if ( attempts >= REDRAW _ATTEMPTS ) {
if ( attempts >= REDRAW _ATTEMPTS ) {
clear ( ) ;
clear ( ) ;
target . prepend ( "<div class='error'>Could not draw pie with labels contained inside canvas</div>" ) ;
target . prepend ( "<div class='error'>Could not draw pie with labels contained inside canvas</div>" ) ;
}
}
// Reset the redraw flag on success, so the loop above can run
// again in the event of a resize or other update.
// TODO: We should remove this redraw system entirely!
redraw = true ;
if ( plot . setSeries && plot . insertLegend ) {
if ( plot . setSeries && plot . insertLegend ) {
plot . setSeries ( slices ) ;
plot . setSeries ( slices ) ;
plot . insertLegend ( ) ;
plot . insertLegend ( ) ;
@ -413,14 +407,13 @@ More detail and specific examples can be found in the included HTML file.
drawDonutHole ( ctx ) ;
drawDonutHole ( ctx ) ;
// draw labels
ctx . restore ( ) ;
if ( options . series . pie . label . show ) {
// Draw the labels, returning true if they fit within the plot
drawLabels ( ) ;
}
// restore to original state
if ( options . series . pie . label . show ) {
ctx . restore ( ) ;
return drawLabels ( ) ;
} else return true ;
function drawSlice ( angle , color , fill ) {
function drawSlice ( angle , color , fill ) {
@ -461,14 +454,19 @@ More detail and specific examples can be found in the included HTML file.
for ( var i = 0 ; i < slices . length ; ++ i ) {
for ( var i = 0 ; i < slices . length ; ++ i ) {
if ( slices [ i ] . percent >= options . series . pie . label . threshold * 100 ) {
if ( slices [ i ] . percent >= options . series . pie . label . threshold * 100 ) {
drawLabel ( slices [ i ] , currentAngle , i ) ;
if ( ! drawLabel ( slices [ i ] , currentAngle , i ) ) {
return false ;
}
}
}
currentAngle += slices [ i ] . angle ;
currentAngle += slices [ i ] . angle ;
}
}
return true ;
function drawLabel ( slice , startAngle , index ) {
function drawLabel ( slice , startAngle , index ) {
if ( slice . data [ 0 ] [ 1 ] == 0 ) {
if ( slice . data [ 0 ] [ 1 ] == 0 ) {
return ;
return true ;
}
}
// format label text
// format label text
@ -502,7 +500,7 @@ More detail and specific examples can be found in the included HTML file.
// check to make sure that the label is not outside the canvas
// check to make sure that the label is not outside the canvas
if ( 0 - labelTop > 0 || 0 - labelLeft > 0 || canvasHeight - ( labelTop + label . height ( ) ) < 0 || canvasWidth - ( labelLeft + label . width ( ) ) < 0 ) {
if ( 0 - labelTop > 0 || 0 - labelLeft > 0 || canvasHeight - ( labelTop + label . height ( ) ) < 0 || canvasWidth - ( labelLeft + label . width ( ) ) < 0 ) {
redraw = tru e;
return fals e;
}
}
if ( options . series . pie . label . background . opacity != 0 ) {
if ( options . series . pie . label . background . opacity != 0 ) {
@ -520,6 +518,8 @@ More detail and specific examples can be found in the included HTML file.
. css ( "opacity" , options . series . pie . label . background . opacity )
. css ( "opacity" , options . series . pie . label . background . opacity )
. insertBefore ( label ) ;
. insertBefore ( label ) ;
}
}
return true ;
} // end individual label function
} // end individual label function
} // end drawLabels function
} // end drawLabels function
} // end drawPie function
} // end drawPie function