From 1e4c4a588b7e00b9bbdd6de6449719e7cdf38a33 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Wed, 14 Jan 2026 10:03:15 +0100 Subject: Use SVG rendering --- src/wmap.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/wmap.js b/src/wmap.js index 4532368..6e9606e 100644 --- a/src/wmap.js +++ b/src/wmap.js @@ -1,5 +1,5 @@ import { parse } from "wmap-parser"; -import { renderToCanvas, StageType } from "wmap-renderer-canvas"; +import { renderToSVG, StageType } from "wmap-renderer-svg"; import DOMPurify from "isomorphic-dompurify"; const internals = { @@ -45,17 +45,13 @@ const internals = { async renderImage(source, dimensions) { const parsedText = parse(source); - const canvas = document.createElement("canvas"); - canvas.width = dimensions.map.mapWidth + 2 * dimensions.map.padding; - canvas.height = dimensions.map.mapHeight + 2 * dimensions.map.padding; - // Further Improvements. The zoomed version could have a drop down // to show the different StageTypes and allow one to see the image // with the different types. // This could also potentially be in the toolbar that appears // on hover to also show this in the download. It requires some // thought on what the right interaction model would be. - await renderToCanvas(parsedText, canvas, StageType.ACTIVITIES, { + return await renderToSVG(parsedText, StageType.ACTIVITIES, { theme: { sizes: { ...dimensions.map, @@ -65,30 +61,32 @@ const internals = { }, }, }); - return canvas.toDataURL(); }, // Starts a download of the image. download(filename, text) { + const svgWithNamespace = text.replace( + " img.remove()); - - const image = document.createElement("img"); - image.src = imageData; - image.alt = "Wardley map rendered from source."; - $container.appendChild(image); + $container.innerHTML = imageData; } catch (error) { console.error( "wmap: Could not replace image. The DOM wasn't ready!", @@ -148,7 +146,7 @@ const bind = async function bind($item, item) { internals.kDimensions.full, ); const slug = $item.parents(".page").attr("id"); - internals.download(`${slug}.png`, imageData); + internals.download(`${slug}.svg`, imageData); } break; case "zoom": @@ -202,7 +200,7 @@ const bind = async function bind($item, item) { internals.kDimensions.thumbnail, ); $item.find(".viewer").html(` -
+
${thumbnailData}
`); + + $item.find('svg text:gt(7)').on('click', function(event) { + const title = this.innerHTML; + let $page = $item.parents('.page') + wiki.pageHandler.context = wiki.lineup.atKey($page.data('key')).getContext() + wiki.doInternalLink(title, event.shiftKey ? null : $page) + }); } catch (err) { console.log("Failed to parse wardley map: ", err); $item.html(internals.message(err.message)); -- cgit