if( typeof html5jp == 'undefined' ) {
html5jp = new Object();
}
if( typeof html5jp.graph == 'undefined' ) {
html5jp.graph = new Object();
}
html5jp.graph.circle = function (id) {
var elm = document.getElementById(id);
if(! elm) { return; }
if(elm.nodeName != "CANVAS") { return; }
if(elm.parentNode.nodeName != "DIV") { return; };
this.canvas = elm;
if ( ! this.canvas ){ return; }
if ( ! this.canvas.getContext ){ return; }
this.ctx = this.canvas.getContext('2d');
this.canvas.style.margin = "0";
this.canvas.parentNode.style.position = "relative";
this.canvas.parentNode.style.padding = "0";
};
html5jp.graph.circle.prototype.draw = function(items, inparams) {
if( ! this.ctx ) {return;}
var params = {
backgroundColor: null,
shadow: true,
border: false,
caption: false,
captionNum: true,
captionRate: true,
fontSize: "12px",
fontFamily: "Arial,sans-serif",
textShadow: true,
captionColor: "#ffffff",
startAngle: -90,
legend: true,
legendFontSize: "12px",
legendFontFamily: "Arial,sans-serif",
legendColor: "#000000",
otherCaption: "other"
};
if( inparams && typeof(inparams) == 'object' ) {
for( var key in inparams ) {
params[key] = inparams[key];
}
}
this.params = params;
if( params.backgroundColor ) {
this.ctx.beginPath();
this.ctx.fillStyle = params.backgroundColor;
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
}
if(this.canvas.width / this.canvas.height < 1.5 || this.canvas.height < 200) {
params.legend == false;
}
var canvas_pos = this._getElementAbsPos(this.canvas);
var cpos = {
x: this.canvas.width / 2,
y: this.canvas.height / 2,
r: Math.min(this.canvas.width, this.canvas.height) * 0.8 / 2
};
items = this._fold_items(items);
var item_num = items.length;
if(params.legend == true) {
cpos.x = this.canvas.height * 0.1 + cpos.r;
var tmpdiv = document.createElement('DIV');
tmpdiv.appendChild( document.createTextNode('あTEST') );
tmpdiv.style.fontSize = params.legendFontSize;
tmpdiv.style.fontFamily = params.legendFontFamily;
tmpdiv.style.color = params.legendColor;
tmpdiv.style.margin = "0";
tmpdiv.style.padding = "0";
tmpdiv.style.visible = "hidden";
tmpdiv.style.position = "absolute";
tmpdiv.style.left = canvas_pos.x.toString() + "px";
tmpdiv.style.top = canvas_pos.y.toString() + "px";
this.canvas.parentNode.appendChild(tmpdiv);
var lpos = {
x: this.canvas.height * 0.2 + cpos.r * 2,
y: ( this.canvas.height - ( tmpdiv.offsetHeight * item_num + tmpdiv.offsetHeight * 0.2 * (item_num - 1) ) ) / 2,
h: tmpdiv.offsetHeight
};
lpos.cx = lpos.x + lpos.h * 1.4;
lpos.cw = this.canvas.width - lpos.cx;
tmpdiv.parentNode.removeChild(tmpdiv);
}
if( params.shadow == true ) {
this._make_shadow(cpos);
}
this.ctx.beginPath();
this.ctx.arc(cpos.x, cpos.y, cpos.r, 0, Math.PI*2, false)
this.ctx.closePath();
this.ctx.fillStyle = "black";
this.ctx.fill();
var sum = 0;
for(var i=0; i