Skip to content

Commit

Permalink
Merge pull request #250 from episphere/downloadSVG
Browse files Browse the repository at this point in the history
download SVG
  • Loading branch information
Sahar-behpour authored Mar 21, 2024
2 parents f8a1154 + 75e1410 commit 5e79718
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/pages/mapPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Lee Mason <[email protected]>
*/
import { DataTable } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";

import { toSvg } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
import { start } from "../../main.js";
import { EpiTrackerData } from "../utils/EpiTrackerData.js";
import { State } from "../utils/State.js";
Expand Down Expand Up @@ -688,6 +688,7 @@ function addGroupDownloadButton() {
downloadMortalityData(state.mortalityData, baseFilename, "json"),
},
{ label: "Download maps (PNG)", listener: downloadMapGrid },
{ label: "Download maps (SVG)", listener: downloadMapSVG },
]);
groupDownloadContainer.appendChild(downloadButton);
}
Expand Down Expand Up @@ -725,6 +726,17 @@ function resizeMap(mapCellElement, previousSize) {
// console.log(cellWidth, previousSize[0])
}

function downloadMapSVG() {
toSvg(document.getElementById("plots")).then((data) => {
const link = document.createElement('a')
link.download = 'map-svg';
link.href = data;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
}

function downloadMapGrid() {
const mapGrid = document.getElementById("map-grid");
const temporaryGrid = mapGrid.cloneNode();
Expand Down
13 changes: 13 additions & 0 deletions src/pages/quantilePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DataTable } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
import { toSvg } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
import { start } from "../../main.js";
import { EpiTrackerData } from "../utils/EpiTrackerData.js";
import { State } from "../utils/State.js";
Expand Down Expand Up @@ -500,10 +501,22 @@ function addDownloadButton() {
downloadMortalityData(state.mortalityData, baseFilename, "json"),
},
{ label: "Download plot (PNG)", listener: downloadGraph },
{ label: "Download plot (SVG)", listener: downloadGraphSVG },
]);
groupDownloadContainer.appendChild(downloadButton);
}

function downloadGraphSVG() {
toSvg(document.getElementById("plots")).then((data) => {
const link = document.createElement('a')
link.download = 'plot-svg';
link.href = data;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
}

function downloadGraph() {
const temporaryContainer = elements.graphContainer.cloneNode(true);
const temporaryLegend = elements.plotLegend.cloneNode(true);
Expand Down

0 comments on commit 5e79718

Please sign in to comment.