This resolves#534 by handling the case where data is a string, whether
it is provided alone or as a pair. We can also eliminate the old and
unnecessary check for undefined values.
The canvasWidth, canvasHeight, legendWidth and legendHeight variables
existed only to share data between the setupPie and draw functions. Now
that setupPie has been folded into draw, they're no longer necessary.
This code is only used to prepare the plot for drawing; inlining it is
cleaner and will allow us to get rid of some plugin-global variables
that existed only to give setupPie a way to share data with the draw
function.
The redraw flag starts out as true, then is immediately set to false on
draw. If labels are enabled, drawPie calls drawLabels, which calls
drawLabel for each label. Any label that can't fit sets redraw back to
true, so the whole process can repeat.
This isn't the most obvious mechanism, and forces one to remember to do
things like setting redraw back to true after drawing, so the plot can
redraw itself on resize or when setting new data.
Instead we now have drawPie return true when it drew successfully, and
false otherwise, which the same happening in drawLabels and drawLabel.
Instead of checking the flag, we now just check the return value.
This has the added benefit of slightly improving performance in the case
where several redraws are necessary, since it now short-circuits out of
the draw loop as soon as one label fails to fit.
In plugins we should never add hooks conditionally; the condition should
remain within individual hooks, so the plugin can be toggled at any
time.
Ideally we should also 'inline' the hook functions, since they're used
nowhere else. But since that would involve a lot of code changes, we'll
put it off until the broader cleanup effort scheduled for 0.9.0.
After shrinking the global example placeholder size, ones with
additional content within the demo area needed to be tweaked
individually, to prevent the other content from wrapping down or
extending off the side of the container.
Since the Canvas .text object is jQuery-wrapped, it was not preserved as
expected when clearing the canvas of junk. I've replaced the selection
with one based on element classes.
Instead of giving the axis its own font property, we simply look at its
options, where the font comes from in the first place. A separate
property is unnecessary and inconsistent with the way other axis options
are handled.