Monday, December 4, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  99] [ 2]  / answers: 1 / hits: 17601  / 15 Years ago, fri, march 27, 2009, 12:00:00

I was wondering if it is possible to include SVG content inside a panel (or whatever would work in GWT), be able to add more to the SVG (like add a circle or a curve) programmatically , and handle mouse events (would this be in SVG or GWT?). I've tried creating an HTML object adding something along the lines of:

<svg xmlns= version=1.1>
<circle cx=50 cy=50 r=30 />

That didn't work (nothing visible in output) but I'm not sure if it was because I did it wrong or it's not allowed.

I was able to do a simple example in GWT with Google Visualization's LineChart but I'd like to move away from Google Visualization and be able to generate the SVG myself and customize it further. I've looked around and many resources points to using Canvas but I'm not sure if that's the best route yet.

I'm also a bit baffled about the example here. I tried a simple copy-paste of it to try locally and it didn't seem to work at all. I was however able to get another sample working with just HTM (embed with src pointing to SVG file) L + separate SVG file but I haven't been able to access it using GWT using RootPanel.get(...).

I've read about SVG not working with Hosted Browser and compiling it does work but I am uncertain how to refer to the SVG (which I have placed into the HTML via ). If I can access it then presumably I can add to its innerHTML. I've tried in RootPanel.get(hi).getElement().setInnerHTML(...) but that doesn't seem to work or did I mess up? I guess the goal is to be able to manipulate a SVG file which I linked somehow (whether in GWT or in HTML) and be able to modify it based on user's input.

2nd EDIT
So far, I've been programming functionality inside of the actual SVG file. In our setup, our SVG is an embedded object and we passed 'document' to the embedded SVG. Passing information from an embed object to and from HTML is quite doable since the HTML has access to our SVG functions and the SVG has access to the 'document'.

There are more transparent ways of doing so (Rapahel) where FireBug could see the SVG directly which is nice but now not quite necessary. Thus far, I don't think any of the solutions I've looked at were IFrames but I could be wrong. A little warning, SVG can be pretty slow sometimes.

I would say my issue is solved (sort of?) but I'm not using Raphael, jQuery, nor GWT at the moment but the method I described in my answer should still work if I want to use GWT.

More From » html


After playing around a bit, I've been most successful with using Raphaël (which handles cross-browser compatibility) though I suspect anything along those lines would work just fine. Basically I do the following in JavaScript:

var r = Raphael(someID, WND_WIDTH, WND_HEIGHT);
// additional configuration and setup if needed....

Then I would do the following in GWT:

public native JavaScriptObject getRaphael() /*-{
return $wnd.r;

// I now have access to the JavaScript object and could do the following:

public native void drawCircle(JavaScriptObject obj, int x, int y, int r) /*-{, y, r);

I've also been reading around and it seems that porting Raphaël into GWT (this article is a good read) will not only increase performance (as per some post I read on Google Groups but can't find at the moment - they mentioned the compiler does quite a bit of work) but also facilitate coding & debugging.

So I accomplished my goal of being able to manipulate the SVG directly (somewhat until I port Raphaël into Java or at least create wrappers). I have yet to look seriously into the Google Visualization API but I suspect it might work just as well but I'm not sure if it is robust enough for my needs.

An important thing I believe I was missing as stated on Raphaël's site was the following:

This means every graphical object you
create is also a DOM object, so you
can attach JavaScript event handlers
or modify them later.

[#99786] Friday, March 20, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 233
Total Questions: 103
Total Answers: 103

Location: Jordan
Member since Thu, Aug 5, 2021
2 Years ago
timothyc questions
Sun, Jun 12, 22, 00:00, 2 Years ago
Sun, May 22, 22, 00:00, 2 Years ago
Fri, Jun 12, 20, 00:00, 4 Years ago