Skip to content

Commit

Permalink
feat(dependencies-of): Limit graph scaling to 2x
Browse files Browse the repository at this point in the history
If there's a single module, it doesn't need to be friggen' huge
  • Loading branch information
danopia committed Jan 24, 2022
1 parent 205205e commit 900bcc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion feat/dependencies-of/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ async function serveHtmlGraphPage(req: Request, modUrl: string, modSlug: string,
.then(dotProc => dotProc.captureAllOutput())
.then(raw => {
const fullSvg = new TextDecoder().decode(raw);
const attrs = [`id="graph"`];
const svgWidth = fullSvg.match(/viewBox="(?:([0-9.-]+) ){3}/)?.[1];
if (svgWidth) attrs.push(`style="max-width: ${parseInt(svgWidth)*2}px;"`);
return fullSvg
.slice(fullSvg.indexOf('<!--'))
.replace(/<svg width="[^"]+" height="[^"]+"/, '<svg id="graph"');
.replace(/<svg width="[^"]+" height="[^"]+"/, '<svg '+attrs.join(' '));
})

).catch(err => {
Expand Down
1 change: 1 addition & 0 deletions public/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ input.url {
svg#graph {
grid-area: graph;
max-height: 100%;
justify-self: center;
}
#graph text {
fill: #111;
Expand Down

0 comments on commit 900bcc4

Please sign in to comment.