Saving protovis chart as svg

36 views
Skip to first unread message

Pedro Alves

unread,
Apr 4, 2010, 5:11:04 PM4/4/10
to protovis

How do I save the generated chart as svg? I tried, using firebug,
accessing the svg node and saving the .innerHTML to a file, but for some
reason that didn't work (at least, pointing firefox to that saved file
just opened it as a .xml file, not a svg file)

I'm sure this is obvious but I'm missing something


Thanks


-pedro

Jamie Love

unread,
Apr 4, 2010, 5:27:30 PM4/4/10
to prot...@googlegroups.com

That usually would work - check out this thread for a step-by-step:

http://groups.google.com/group/protovis/browse_thread/thread/3169031c3b2aae52/f976d5fb9c893846

Check out how I do it in R-Node (www.squirelove.net/r-node/)

Also:

1/ A bit of PHP code and an ajax request -
http://groups.google.com/group/protovis/browse_thread/thread/81efbb03...

2/ Use Rhino server side. The archives have a demo/test by me that writes
out a protovis generated SVG file to disk - zip of code that shows this is
here:
http://groups.google.com/group/protovis/attach/8a70b0e274255b36/rhino...



--
You received this message because you are subscribed to the Google Groups "protovis" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protovis+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protovis?hl=en.


Timothy M. Shead

unread,
Apr 4, 2010, 5:19:26 PM4/4/10
to prot...@googlegroups.com, Pedro Alves
On 4/4/10 3:11 PM, Pedro Alves wrote:

> How do I save the generated chart as svg? I tried, using firebug,
> accessing the svg node and saving the .innerHTML to a file, but for some
> reason that didn't work (at least, pointing firefox to that saved file
> just opened it as a .xml file, not a svg file)

Pedro:

You have to add the appropriate DTD and namespace information to the XML
before it will be recognized as an SVG file ... here's a function that
we use to do it from C++ using Protovis with QWebKit:

Cheers,
Tim

const vtkStdString vtkQtProtovisView::GetSVG()
{
// We have to insert some boilerplate to our SVG so browsers will
render the image instead of displaying the source ...
std::string svg =
this->Internal->View->page()->mainFrame()->evaluateJavaScript("vis.scene[0].canvas.innerHTML").toString().toAscii().data();
svg.insert(svg.find(">"), " xmlns=\"http://www.w3.org/2000/svg\"
xmlns:xlink=\"http://www.w3.org/1999/xlink\"");

std::stringstream buffer;
buffer << "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?>\n";
buffer << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
buffer << "<!-- Generated by the Titan Informatics Toolkit -->\n";
buffer << svg;

return buffer.str();
}

Mike Bostock

unread,
Apr 4, 2010, 5:50:55 PM4/4/10
to prot...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages