Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option halfPie to pie type chart #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/js/Examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Examples.prototype = {
"basic-bar-stacked",
"basic-stacked-horizontal",
"basic-pie",
"half-pie",
"basic-radar",
"basic-bubble",
"basic-candle",
Expand Down
47 changes: 47 additions & 0 deletions examples/js/examples/half-pie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(function () {

Flotr.ExampleList.add({
key : 'half-pie',
name : 'Half Pie',
callback : half_pie
});

function half_pie (container) {

var
d1 = [[0, 4]],
d2 = [[0, 3]],
d3 = [[0, 1.03]],
d4 = [[0, 3.5]],
graph;

graph = Flotr.draw(container, [
{ data : d1, label : 'Republican' },
{ data : d2, label : 'Democratic' },
{ data : d3, label : 'Green'},
{ data : d4, label : 'Pirates' }
], {
HtmlText : true,
grid : {
verticalLines : false,
horizontalLines : false
},
xaxis : { showLabels : false },
yaxis : { showLabels : false },
pie : {
show : true,
explode : 6,
startAngle: 0.5,
labelFormatter: function(){
},
halfPie: true
},
mouse : { track : true },
legend : {
position : 'se',
backgroundColor : '#D2E8FF'
}
});
}

})();
1 change: 1 addition & 0 deletions examples/js/includes.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ yepnope([
'js/examples/basic-bars.js',
'js/examples/basic-bars-stacked.js',
'js/examples/basic-pie.js',
'js/examples/half-pie.js',
'js/examples/basic-radar.js',
'js/examples/basic-bubble.js',
'js/examples/basic-candle.js',
Expand Down
27 changes: 16 additions & 11 deletions js/types/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Flotr.addType('pie', {
pie3D: false, // => whether to draw the pie in 3 dimenstions or not (ineffective)
pie3DviewAngle: (Math.PI/2 * 0.8),
pie3DspliceThickness: 20,
epsilon: 0.1 // => how close do you have to get to hit empty slice
epsilon: 0.1, // => how close do you have to get to hit empty slice
halfPie: false
},

draw : function (options) {
Expand All @@ -42,17 +43,18 @@ Flotr.addType('pie', {
lineWidth = options.lineWidth,
shadowSize = options.shadowSize,
sizeRatio = options.sizeRatio,
height = options.height,
width = options.width,
circleRatio = options.halfPie ? 1 : 2,
height = options.height ,
width = options.width ,
explode = options.explode,
color = options.color,
fill = options.fill,
fillStyle = options.fillStyle,
radius = Math.min(canvas.width, canvas.height) * sizeRatio / 2,
radius = Math.min(canvas.width, canvas.height) * sizeRatio /circleRatio,
value = data[0][1],
html = [],
vScale = 1,//Math.cos(series.pie.viewAngle);
measure = Math.PI * 2 * value / this.total,
measure = Math.PI * circleRatio * value / this.total,
startAngle = this.startAngle || (2 * Math.PI * options.startAngle), // TODO: this initial startAngle is already in radians (fixing will be test-unstable)
endAngle = startAngle + measure,
bisection = startAngle + measure / 2,
Expand All @@ -67,7 +69,7 @@ Flotr.addType('pie', {
x, y;

context.save();
context.translate(width / 2, height / 2);
context.translate(width / 2, height / circleRatio);
context.scale(1, vScale);

x = Math.cos(bisection) * explode;
Expand Down Expand Up @@ -146,11 +148,12 @@ Flotr.addType('pie', {
mouse = args[0],
n = args[1],
slice = this.slices[index],
x = mouse.relX - options.width / 2,
y = mouse.relY - options.height / 2,
circleRatio = options.halfPie ? 1 : 2,
x = mouse.relX - options.width / circleRatio,
y = mouse.relY - options.height/ circleRatio,
r = Math.sqrt(x * x + y * y),
theta = Math.atan(y / x),
circle = Math.PI * 2,
circle = Math.PI * circleRatio,
explode = slice.explode || options.explode,
start = slice.start % circle,
end = slice.end % circle,
Expand Down Expand Up @@ -184,23 +187,25 @@ Flotr.addType('pie', {
drawHit: function (options) {
var
context = options.context,
circleRatio = options.halfPie ? 1 : 2,
slice = this.slices[options.args.seriesIndex];

context.save();
context.translate(options.width / 2, options.height / 2);
context.translate(options.width/circleRatio, options.height/circleRatio);
this.plotSlice(slice.x, slice.y, slice.radius, slice.start, slice.end, context);
context.stroke();
context.restore();
},
clearHit : function (options) {
var
context = options.context,
circleRatio = options.halfPie ? 1 : 2,
slice = this.slices[options.args.seriesIndex],
padding = 2 * options.lineWidth,
radius = slice.radius + padding;

context.save();
context.translate(options.width / 2, options.height / 2);
context.translate(options.width/circleRatio, options.height/circleRatio);
context.clearRect(
slice.x - radius,
slice.y - radius,
Expand Down