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

Renderfix needlessly moving chart #614

Open
arski opened this issue Aug 29, 2012 · 1 comment
Open

Renderfix needlessly moving chart #614

arski opened this issue Aug 29, 2012 · 1 comment

Comments

@arski
Copy link

arski commented Aug 29, 2012

Hi there,

I've a weird one - not sure quite exactly what the motivation behind the R.prototype.renderfix function was, but it's actually breaking things for me in Chrome/FF by adding left: -0.5px where everything is just fine the way it is.

Any idea what could be causing this? Will be happy to provide any more details if you let me know what's relevant, i.e. paddings, margins, borders etc. of the chart container, maybe something else?

Thanks

@stevetauber
Copy link

I had the same problem. This was caused because renderfix wants to fix half pixels which cause SVG drawing errors. renderfix calls createSVGMatrix() which gets the placement offset then translates the object onto a whole pixel.

The -0.5px occurs in the following case.

  • My document.width was 109 pixels wide.
  • I had a container width of 100 pixels with margin set to auto. This corresponds to margins of 4.5px on each side.

The browser cannot draw subpixels so it will draw 5px on the left and 4px on the right. Javascript on the other hand DOES accept a float here. When createSVGMatrix() is called, it sees a left translation of 4.5px.

Raphael decided to check: if we are on a half pixel, let's shift the SVGSVGElement to a whole pixel, so that things look right. The result is a translation of -0.5px.

My code to fix this included:

function makeSVG() {
    var paper = new Raphael(myContainer, myContainer,width, myContainer,height);
    paper._left = 0;
    paper._top = 0;
    paper.canvas.style.left = '';
    paper.canvas.style.top = '';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants