ICC-Profile
view release on metacpan or search on metacpan
lib/ICC/Javascripts/rgraph/RGraph.pie.js view on Meta::CPAN
* Turn the shadow off
*/
RG.noShadow(this);
co.fillStyle = 'black';
co.beginPath();
/**
* Draw the labels
*/
if (labels && labels.length) {
for (i=0; i<this.angles.length; ++i) {
var segment = this.angles[i];
if (typeof labels[i] != 'string' && typeof labels[i] != 'number') {
continue;
}
// Move to the centre
co.moveTo(cx,cy);
var a = segment[0] + ((segment[1] - segment[0]) / 2),
angle = ((segment[1] - segment[0]) / 2) + segment[0];
/**
* Handle the additional "explosion" offset
*/
if (typeof prop['chart.exploded'] === 'object' && prop['chart.exploded'][i] || typeof prop['chart.exploded'] == 'number') {
var t = ((segment[1] - segment[0]) / 2),
seperation = typeof(prop['chart.exploded']) == 'number' ? prop['chart.exploded'] : prop['chart.exploded'][i];
// Adjust the angles
var explosion_offsetx = (Math.cos(angle) * seperation),
explosion_offsety = (Math.sin(angle) * seperation);
} else {
var explosion_offsetx = 0,
explosion_offsety = 0;
}
/**
* Allow for the label sticks
*/
if (prop['chart.labels.sticks']) {
explosion_offsetx += (ma.cos(angle) * (typeof prop['chart.labels.sticks.length'] === 'object' ? prop['chart.labels.sticks.length'][i] : prop['chart.labels.sticks.length']) );
explosion_offsety += (ma.sin(angle) * (typeof prop['chart.labels.sticks.length'] === 'object' ? prop['chart.labels.sticks.length'][i] : prop['chart.labels.sticks.length']) );
}
/**
* Coords for the text
*/
var x = cx + explosion_offsetx + ((r + 10)* Math.cos(a)) + (prop['chart.labels.sticks'] ? (a < RG.HALFPI || a > (RG.TWOPI + RG.HALFPI) ? 2 : -2) : 0),
y = cy + explosion_offsety + (((r + 10) * Math.sin(a)));
/**
* If sticks are enabled use the endpoints that have been saved
*/
if (this.coordsSticks && this.coordsSticks[i]) {
var x = this.coordsSticks[i][4][0] + (x < cx ? -5 : 5),
y = this.coordsSticks[i][4][1];
}
/**
* Alignment
*/
//vAlignment = y < cy ? 'center' : 'center';
vAlignment = 'center';
hAlignment = x < cx ? 'right' : 'left';
co.fillStyle = prop['chart.text.color'];
if ( typeof prop['chart.labels.colors'] === 'object' && prop['chart.labels.colors'] && prop['chart.labels.colors'][i]) {
co.fillStyle = prop['chart.labels.colors'][i];
}
RG.text2(this, {
font: font,
size: text_size,
x: x,
y: y,
text: labels[i],
valign: vAlignment,
halign: hAlignment,
tag: 'labels',
bold: bold,
color: prop['chart.labels.sticks.usecolors'] ? prop['chart.colors'][i] : 'black'
});
}
co.fill();
}
};
//
// A new way of spacing out labels
//
this.drawLabelsList = function ()
{
var segment = this.angles[i],
labels = prop['chart.labels'],
labels_right = [],
labels_left = [],
text_font = prop['chart.text.font'],
text_size = prop['chart.text.size'],
text_color = prop['chart.text.color'],
left = [],
right = [],
centerx = this.centerx,
centery = this.centery,
radius = this.radius,
offset = 50
//
// Draw the right hand side labels first
//
for (var i=0; i<this.angles.length; ++i) {
var angle = this.angles[i][0] + ((this.angles[i][1] - this.angles[i][0]) / 2), // Midpoint
endpoint_inner = RG.getRadiusEndPoint(centerx, centery, angle, radius + 5),
endpoint_outer = RG.getRadiusEndPoint(centerx, centery, angle, radius + 10),
explosion = [
(typeof prop['chart.exploded'] === 'number' ? prop['chart.exploded'] : prop['chart.exploded'][i]),
(ma.cos(angle) * (typeof prop['chart.exploded'] === 'number' ? prop['chart.exploded'] : prop['chart.exploded'][i])),
(ma.sin(angle) * (typeof prop['chart.exploded'] === 'number' ? prop['chart.exploded'] : prop['chart.exploded'][i]))
]
//
// Work out the color
//
if ( typeof prop['chart.labels.sticks.colors'] === 'object' && prop['chart.labels.sticks.colors'] && prop['chart.labels.sticks.colors'][i] ) {
var color = prop['chart.labels.sticks.colors'][i];
} else if ( prop['chart.labels.sticks.usecolors'] && prop['chart.colors'][i] ) {
var color = prop['chart.colors'][i];
} else {
var color = prop['chart.text.color'];
}
if (angle > (-1 * RG.HALFPI) && angle < RG.HALFPI) {
labels_right.push([
i,
angle,
labels[i] ? labels[i] : '',
endpoint_inner,
endpoint_outer,
color,
RG.arrayClone(explosion)
]);
} else {
labels_left.push([
i,
angle,
labels[i] ? labels[i] : '',
endpoint_inner,
endpoint_outer,
color,
RG.arrayClone(explosion)
]);
}
}
//
// Draw the right hand side labels first
//
// Calculate how much space there is for each label
var vspace_right = (ca.height - prop['chart.gutter.top'] - prop['chart.gutter.bottom']) / labels_right.length
for (var i=0,y=(prop['chart.gutter.top'] + (vspace_right / 2)); i<labels_right.length; y+=vspace_right,i++) {
if (labels_right[i][2]) {
var x = this.centerx + this.radius + offset,
idx = labels_right[i][0],
explosionX = labels_right[i][6][0] ? labels_right[i][6][1] : 0,
explosionY = labels_right[i][6][0] ? labels_right[i][6][2] : 0
var ret = RG.text2(this, {
font: text_font,
size: text_size,
x: x + explosionX,
y: y + explosionY,
text: labels_right[i][2],
valign: 'center',
halign: 'left',
tag: 'labels',
color: labels_right[i][5]
});
if (ret && ret.node) {
ret.node.__index__ = labels_right[i][0];
}
pa2(co, 'lc round lw % b m % % l % % l % % l % % s %',
prop['chart.labels.sticks.linewidth'],
labels_right[i][3][0] + explosionX,
labels_right[i][3][1] + explosionY,
labels_right[i][4][0] + explosionX,
labels_right[i][4][1] + explosionY,
this.centerx + this.radius + 25 + explosionX,
ma.round(labels_right[i][4][1] + explosionY),
ret.x - 5 ,
ret.y + (ret.height / 2),
labels_right[i][5]
( run in 0.645 second using v1.01-cache-2.11-cpan-524268b4103 )