I have several D3.js graphs on a webpage. When the user clicks on a button, the new graph will slide down, while the old one will slide up. I did some research, and found a few links. The one that does what I want to do is here: http://d3export.cancan.cshl.edu/. However, I cannot get it to work. Here is a JSFiddle with some code that is very similar to mine
Here is the JS code
$(function () {
$(".show").click(function () {
$(".targetDiv").slideUp("fast");
if ($("#graph" + $(this).attr("target")).css("display") != "block") {
$("#graph" + $(this).attr("target")).slideDown("fast");
}
});
});
(function () {
// Graph 1 code
show_svg_code();
}) ();
(function () {
// Graph 2 code
show_svg_code();
}) ();
// ... etc.
function submit_download_form(output_format) {
var tmp = document.getElementById(/* What ID goes here? */);
var svg = tmp.getElementsByTagName("svg")[0];
var svg_xml = (new XMLSerializer).serializeToString(svg);
var form = document.getElementById("svgform");
form['output_format'].value = output_format;
form['data'].value = svg_xml ;
form.submit();
}
function show_svg_code() {
var tmp = document.getElementById("#graph1");
var svg = tmp.getElementsByTagName("svg")[0];
var svg_xml = (new XMLSerializer).serializeToString(svg);
$("#svg_code").text(svg_xml);
}
$(document).ready(function() {
$("#save_as_svg").click(function() { submit_download_form("svg"); });
$("#save_as_pdf").click(function() { submit_download_form("pdf"); });
$("#save_as_png").click(function() { submit_download_form("png"); });
});
Here is similar HTML to mine
<a class="show" target="1">Chart 1</a>
<a class="show" target="2">Chart 2</a>
// ... etc.
<button type="button" onclick="javascript:submit_download_form('svg')">SVG</button>
<button type="button" onclick="javascript:submit_download_form('pdf')">PDF</button>
<button type="button" onclick="javascript:submit_download_form('png')">PNG</button>
<div id="graph1" class="targetDiv"></div>
<div id="graph2" class="targetDiv"></div>
// ... etc.
<form id="svgform" method="post" action="download.pl">
<input type="hidden" id="output_format" name="output_format" value="">
<input type="hidden" id="data" name="data" value="">
</form>
The problem that I am having is that I have more than 1 chart on the page. I have close to 30 graphs, with all of them hidden (besides the one that is shown). How would I get around this? In the JS, it asks for the ID of the target graph. How do I get it to target only the graph that is shown? This also has to work in IE, Chrome, Firefox and Safari, preferably.
Thanks for all the help
EDIT: I see that there is a Perl script that he links to. I saved the file to my server, and it still does not work (I saved it as download.pl, and I tried to save it in the same folder as the .html file, and then I tried to save it in the same folder as the .js file).
EDIT 2: I am missing the libRSVG plugin on my server. I downloaded the folder (V. 2.37.0.tar.xz), but there is about a hundred files in it. What do I do with it?