Skip to content

Commit

Permalink
rely on jquery to get padding - jquery widths are actually unreliable…
Browse files Browse the repository at this point in the history
… depending on quirks mode and ie vs. w3c content width, but the computed pixel size of padding appears to be correct across browsers

git-svn-id: http://simile-widgets.googlecode.com/svn/timeplot/trunk/src/webapp/api@1240 579c892a-5248-0410-a714-2bcf037eb5bf
  • Loading branch information
ryanlee committed Jan 4, 2008
1 parent 3c41ded commit f77e434
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions scripts/timeplot.js
Expand Up @@ -395,17 +395,18 @@ Timeplot._Impl.prototype = {
_prepareCanvas: function() {
var canvas = this.getCanvas();

var s = SimileAjax.DOM.getSize(this._containerDiv);
// using jQuery. note we calculate the average padding; if your
// padding settings are not symmetrical, the labels will be off
// since they expect to be centered on the canvas.
var con = $('#' + this._containerDiv.id);
this._paddingX = (parseInt(con.css('paddingLeft')) +
parseInt(con.css('paddingRight'))) / 2;
this._paddingY = (parseInt(con.css('paddingTop')) +
parseInt(con.css('paddingBottom'))) / 2;

canvas.width = this.getWidth() - (this._paddingX * 2);
canvas.height = this.getHeight() - (this._paddingY * 2);

// bug in getsize, should also check for ie's "auto" value
if (s.w == 'auto' && this._containerDiv.offsetWidth) s.w = this._containerDiv.offsetWidth;
if (s.h == 'auto' && this._containerDiv.offsetHeight) s.h = this._containerDiv.offsetHeight;
canvas.width = s.w;
canvas.height = s.h;

this._paddingX = (this.getWidth() - canvas.width) / 2;
this._paddingY = (this.getHeight() - canvas.height) / 2;

var ctx = canvas.getContext('2d');
this._setUpright(ctx, canvas);
ctx.globalCompositeOperation = 'source-over';
Expand Down

0 comments on commit f77e434

Please sign in to comment.