Skip to content

Commit

Permalink
fix(ui): improve exported PNG resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
a-asaad committed Sep 6, 2024
1 parent fa6d9f3 commit f230e8d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ui/src/components/options-menu/ExportPng.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { forwardRef } from "react"
import { getNodesBounds, getViewportForBounds } from "reactflow"
import { useAppActions, useGetNodes } from "../../singletons/store"

const IMAGE_WIDTH = 1024
const IMAGE_HEIGHT = 768
const IMAGE_PADDING = 200

const downloadImage = (dataUrl: string) => {
const a = document.createElement("a")
Expand All @@ -25,10 +24,12 @@ const ExportPng = forwardRef<HTMLElement>(
const handleClick = () => {
clearDiagramSelections()
const nodeBounds = getNodesBounds(nodes)
const imageWidth = nodeBounds.width + IMAGE_PADDING
const imageHeight = nodeBounds.height + IMAGE_PADDING
const transform = getViewportForBounds(
nodeBounds,
IMAGE_WIDTH,
IMAGE_HEIGHT,
imageWidth,
imageHeight,
0.5,
2
)
Expand All @@ -39,11 +40,11 @@ const ExportPng = forwardRef<HTMLElement>(

toPng(viewport, {
backgroundColor: layer01,
width: IMAGE_WIDTH,
height: IMAGE_HEIGHT,
width: imageWidth,
height: imageHeight,
style: {
width: IMAGE_WIDTH.toString(),
height: IMAGE_WIDTH.toString(),
width: imageWidth.toString(),
height: imageHeight.toString(),
transform: `translate(${transform.x}px, ${transform.y}px) scale(${transform.zoom})`,
},
})
Expand Down

0 comments on commit f230e8d

Please sign in to comment.