Skip to content

Commit 67d0c5e

Browse files
#857 Update link and icon on export (#882)
1 parent 05d8a9f commit 67d0c5e

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

public/logo.svg

Lines changed: 7 additions & 0 deletions
Loading

src/util/download.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { languageToFontsCss } from '../components/svgs/nodes/text';
44
import { EdgeAttributes, GraphAttributes, NodeAttributes, NodeType } from '../constants/constants';
55
import { MiscNodeType } from '../constants/nodes';
66
import { StationType } from '../constants/stations';
7+
import i18n from '../i18n/config';
78
import { FONTS_CSS, makeBase64EncodedFontsStyle } from './fonts';
89
import { findNodesExist } from './graph';
910
import { calculateCanvasSize } from './helpers';
@@ -46,7 +47,7 @@ export const makeRenderReadySVGElement = async (
4647

4748
const elem = document.getElementById('canvas')!.cloneNode(true) as SVGSVGElement;
4849
// append rmp info if user does not want to share rmp info
49-
if (!generateRMPInfo) elem.appendChild(generateRmpInfo(xMax - 400, yMax - 120));
50+
if (!generateRMPInfo) elem.appendChild(await generateRmpInfo(xMax - 400, yMax - 120));
5051
// reset svg viewBox to display all the nodes in the graph
5152
// otherwise the later drawImage won't be able to show all of them
5253
elem.setAttribute('viewBox', `${xMin} ${yMin} ${width} ${height}`);
@@ -228,29 +229,37 @@ const loadFacilitiesSvg = async (
228229
}
229230
};
230231

231-
const generateRmpInfo = (x: number, y: number) => {
232+
const generateRmpInfo = async (x: number, y: number) => {
232233
const info = document.createElementNS('http://www.w3.org/2000/svg', 'g');
233234
info.setAttribute('transform', `translate(${x}, ${y})scale(2)`);
234235

235-
const logo = document.createElementNS('http://www.w3.org/2000/svg', 'image');
236-
// FIXME: return after image is loaded
237-
// logo.setAttribute('href', 'https://uat-railmapgen.github.io/rmp/logo192.png');
238-
// logo.setAttribute('href', logoImg);
239-
logo.setAttribute('width', '40');
240-
logo.setAttribute('height', '40');
241-
logo.setAttribute('x', '-50');
242-
logo.setAttribute('y', '-20');
236+
const logoSVGRep = await fetch(import.meta.env.BASE_URL + `/logo.svg`);
237+
const logoSVG = await logoSVGRep.text();
238+
const temp = document.createElement('div');
239+
temp.innerHTML = logoSVG;
240+
const svg = temp.querySelector('svg')!;
241+
const logo = document.createElement('g');
242+
logo.setAttribute('transform', `translate(-60, -25)scale(0.1)`);
243+
logo.setAttribute('font-family', 'Arial, sans-serif');
244+
logo.innerHTML = svg.innerHTML;
245+
info.appendChild(logo);
243246

244247
const rmp = document.createElementNS('http://www.w3.org/2000/svg', 'text');
245248
rmp.setAttribute('font-family', 'Arial, sans-serif');
246249
rmp.setAttribute('font-size', '16');
247-
rmp.appendChild(document.createTextNode('Rail Map Painter'));
250+
const appName = i18n.t('Rail Map Painter');
251+
rmp.appendChild(document.createTextNode(appName));
248252

249253
const link = document.createElementNS('http://www.w3.org/2000/svg', 'text');
250254
link.setAttribute('font-family', 'Arial, sans-serif');
251255
link.setAttribute('font-size', '10');
252256
link.setAttribute('y', '10');
253-
link.appendChild(document.createTextNode('https://railmapgen.github.io/rmp/'));
257+
const origin = window.location.origin;
258+
let url = 'https://railmapgen.org/';
259+
if (origin.includes('github')) url = 'https://railmapgen.github.io/';
260+
else if (origin.includes('gitlab')) url = 'https://railmapgen.gitlab.io/';
261+
url += '?app=rmp';
262+
link.appendChild(document.createTextNode(url));
254263

255264
info.appendChild(logo);
256265
info.appendChild(rmp);

0 commit comments

Comments
 (0)