Re: Canvas and Interactivity

On Tue, Jul 14, 2009 at 12:27 PM, Anthony Grasso <
anthony.grasso@cisra.canon.com.au> wrote:

> I agree it would be good to reuse existing markups and DOM if possible.
> From the IRC discussion, I'm not sure which part or aspect of SVG is
> considered "crappy". Finding that out would be a good start.


Some of the issues are browser implementation issues.

Many of the issues are around the SVG DOM APIs. For example, consider adding
a circle to the page:
var c = document.createElementNS(... SVG namespace that I can never remember
..., "circle");
c.cx.baseVal.value = 20;
c.cy.baseVal.value = 20;
c.r.baseVal.value = 20;
c.style.fill = "lime";
svgContainer.appendChild(c);

With canvas:
ctx.fillStyle = "lime";
ctx.beginPath();
ctx.arc(20, 20, 20, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();

Some of the DOM issues are generic DOM issues, but some of them are
SVG-specific. In particular setting the three circle attributes via the SVG
API requires 6 getters and 3 setters --- 9 round trips from JS to browser
and back. Even worse, it requires creation of 6 temporary objects!
(Actually, in every implementation I know of, it creates at least 12
temporary objects, a "native object" and some kind of JS wrappper.)

I think it would have been a good idea to forget about units in SVG
coordinates, just have user space. Then since access to animated values is
rare, move it to a separate interface (e.g. c.animated.cx). Then you could
write
c.cx = 20;
c.cy = 20;
c.r = 20;
Much better... Oh well.

Rob
-- 
"He was pierced for our transgressions, he was crushed for our iniquities;
the punishment that brought us peace was upon him, and by his wounds we are
healed. We all, like sheep, have gone astray, each of us has turned to his
own way; and the LORD has laid on him the iniquity of us all." [Isaiah
53:5-6]

Received on Wednesday, 15 July 2009 02:51:00 UTC