Skip to content

Commit af768a5

Browse files
committed
pref(HtmlContent): amend svg viewBox
1 parent 7889d01 commit af768a5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/html.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function getHtmlContent(dot?:string){
1+
export function getHtmlContent(dot?: string) {
22
return `<!DOCTYPE html>
33
<html lang="en">
44
@@ -19,12 +19,22 @@ export function getHtmlContent(dot?:string){
1919
</div>
2020
</body>
2121
<script>
22+
function attributer(datum) {
23+
if (datum.tag == "svg") {
24+
const width = window.innerWidth
25+
const height = window.innerHeight
26+
datum.attributes.width = width
27+
datum.attributes.height = height
28+
datum.attributes.viewBox = [0, 0, width, height].join(" ")
29+
}
30+
}
31+
2232
(async function () {
2333
const vscode = acquireVsCodeApi()
2434
const dot='${dot}'
2535
vscode.setState(dot)
2636
const res =await (await fetch(dot)).text()
27-
const gv = d3.select('#app').graphviz().renderDot(res)
37+
const gv = d3.select('#app').graphviz().renderDot(res).attributer(attributer)
2838
2939
d3.select('#downloadSvg').on('click',()=>{
3040
const serializer = new XMLSerializer()

0 commit comments

Comments
 (0)