Commit a1757067 authored by Lau Bech Lauritzen's avatar Lau Bech Lauritzen Committed by David Schnur

Use placeholder dimensions instead og canvas dimensions in calculations which...

Use placeholder dimensions instead og canvas dimensions in calculations which fixes draw bug after introducing Retina support in Flot core
parent 82eb3fd7
...@@ -63,6 +63,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -63,6 +63,8 @@ More detail and specific examples can be found in the included HTML file.
function init(plot) // this is the "body" of the plugin function init(plot) // this is the "body" of the plugin
{ {
var canvas = null; var canvas = null;
var canvasWidth = 0;
var canvasHeight = 0;
var target = null; var target = null;
var maxRadius = null; var maxRadius = null;
var centerLeft = null; var centerLeft = null;
...@@ -180,6 +182,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -180,6 +182,9 @@ More detail and specific examples can be found in the included HTML file.
target = $(canvas).parent(); target = $(canvas).parent();
options = plot.getOptions(); options = plot.getOptions();
canvasWidth = plot.getPlaceholder().width();
canvasHeight = plot.getPlaceholder().height();
plot.setData(combine(plot.getData())); plot.setData(combine(plot.getData()));
} }
} }
...@@ -189,9 +194,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -189,9 +194,9 @@ More detail and specific examples can be found in the included HTML file.
legendWidth = target.children().filter('.legend').children().width(); legendWidth = target.children().filter('.legend').children().width();
// calculate maximum radius and center point // calculate maximum radius and center point
maxRadius = Math.min(canvas.width,(canvas.height/options.series.pie.tilt))/2; maxRadius = Math.min(canvasWidth,(canvasHeight/options.series.pie.tilt))/2;
centerTop = (canvas.height/2)+options.series.pie.offset.top; centerTop = (canvasHeight/2)+options.series.pie.offset.top;
centerLeft = (canvas.width/2); centerLeft = (canvasWidth/2);
if (options.series.pie.offset.left=='auto') if (options.series.pie.offset.left=='auto')
if (options.legend.position.match('w')) if (options.legend.position.match('w'))
...@@ -203,8 +208,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -203,8 +208,8 @@ More detail and specific examples can be found in the included HTML file.
if (centerLeft<maxRadius) if (centerLeft<maxRadius)
centerLeft = maxRadius; centerLeft = maxRadius;
else if (centerLeft>canvas.width-maxRadius) else if (centerLeft>canvasWidth-maxRadius)
centerLeft = canvas.width-maxRadius; centerLeft = canvasWidth-maxRadius;
} }
function fixData(data) function fixData(data)
...@@ -304,7 +309,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -304,7 +309,7 @@ More detail and specific examples can be found in the included HTML file.
function clear() function clear()
{ {
ctx.clearRect(0,0,canvas.width,canvas.height); ctx.clearRect(0,0,canvasWidth,canvasHeight);
target.children().filter('.pieLabel, .pieLabelBackground').remove(); target.children().filter('.pieLabel, .pieLabelBackground').remove();
} }
...@@ -321,7 +326,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -321,7 +326,7 @@ More detail and specific examples can be found in the included HTML file.
else else
var radius = maxRadius * options.series.pie.radius; var radius = maxRadius * options.series.pie.radius;
if (radius>=(canvas.width/2)-shadowLeft || radius*options.series.pie.tilt>=(canvas.height/2)-shadowTop || radius<=edge) if (radius>=(canvasWidth/2)-shadowLeft || radius*options.series.pie.tilt>=(canvasHeight/2)-shadowTop || radius<=edge)
return; // shadow would be outside canvas, so don't draw it return; // shadow would be outside canvas, so don't draw it
ctx.save(); ctx.save();
...@@ -466,7 +471,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -466,7 +471,7 @@ More detail and specific examples can be found in the included HTML file.
label.css('left', labelLeft); label.css('left', labelLeft);
// 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 || canvas.height-(labelTop+label.height())<0 || canvas.width-(labelLeft+label.width())<0) if (0-labelTop>0 || 0-labelLeft>0 || canvasHeight-(labelTop+label.height())<0 || canvasWidth-(labelLeft+label.width())<0)
redraw = true; redraw = true;
if (options.series.pie.label.background.opacity != 0) { if (options.series.pie.label.background.opacity != 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment