Skip to content

Commit

Permalink
Merge pull request #27 from Gehbt:patch-1
Browse files Browse the repository at this point in the history
perf(HtmlContent): amend svg viewBox
  • Loading branch information
beicause authored Nov 25, 2024
2 parents 7889d01 + af768a5 commit f64695e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/html.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getHtmlContent(dot?:string){
export function getHtmlContent(dot?: string) {
return `<!DOCTYPE html>
<html lang="en">
Expand All @@ -19,12 +19,22 @@ export function getHtmlContent(dot?:string){
</div>
</body>
<script>
function attributer(datum) {
if (datum.tag == "svg") {
const width = window.innerWidth
const height = window.innerHeight
datum.attributes.width = width
datum.attributes.height = height
datum.attributes.viewBox = [0, 0, width, height].join(" ")
}
}
(async function () {
const vscode = acquireVsCodeApi()
const dot='${dot}'
vscode.setState(dot)
const res =await (await fetch(dot)).text()
const gv = d3.select('#app').graphviz().renderDot(res)
const gv = d3.select('#app').graphviz().renderDot(res).attributer(attributer)
d3.select('#downloadSvg').on('click',()=>{
const serializer = new XMLSerializer()
Expand Down

0 comments on commit f64695e

Please sign in to comment.