-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from IlIIIIIIlI/feature/export-flow-chart-as-png
Add PNG export functionality for flow charts
- Loading branch information
Showing
8 changed files
with
158 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const IDownload = () => ( | ||
<svg | ||
width="16" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M8 12L3 7L4.4 5.55L7 8.15V0H9V8.15L11.6 5.55L13 7L8 12ZM2 16C1.45 16 0.979333 15.8043 0.588 15.413C0.196666 15.0217 0.000666667 14.5507 0 14V11H2V14H14V11H16V14C16 14.55 15.8043 15.021 15.413 15.413C15.0217 15.805 14.5507 16.0007 14 16H2Z" | ||
fill="black" | ||
/> | ||
</svg> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { toPng } from "html-to-image" | ||
import { getNodesBounds, getViewportForBounds, Node } from "reactflow" | ||
|
||
interface VSCodeAPI { | ||
postMessage(message: SaveImageMessage): void | ||
getState(): unknown | ||
setState(state: unknown): void | ||
} | ||
|
||
interface SaveImageMessage { | ||
command: "saveImage" | ||
data: { | ||
format: "png" | ||
dataUrl: string | ||
} | ||
} | ||
|
||
declare function acquireVsCodeApi(): VSCodeAPI | ||
|
||
const vscode = acquireVsCodeApi() | ||
|
||
export const screenshot = (getNodes: () => Node[]) => { | ||
const nodesBounds = getNodesBounds(getNodes()) | ||
|
||
// 8k resolution | ||
const imageWidth = 7680 | ||
const imageHeight = 4320 | ||
|
||
const transform = getViewportForBounds( | ||
nodesBounds, | ||
imageWidth, | ||
imageHeight, | ||
0, | ||
2, | ||
) | ||
|
||
toPng(document.querySelector(".react-flow__viewport") as HTMLElement, { | ||
filter: (node) => { | ||
const exclude = ["react-flow__minimap", "react-flow__controls"] | ||
return !exclude.some((className) => node.classList?.contains(className)) | ||
}, | ||
backgroundColor: "transparent", | ||
width: imageWidth, | ||
height: imageHeight, | ||
style: { | ||
transform: `translate(${transform.x}px, ${transform.y}px) scale(${transform.zoom})`, | ||
}, | ||
}) | ||
.then((dataUrl) => { | ||
vscode.postMessage({ | ||
command: "saveImage", | ||
data: { format: "png", dataUrl }, | ||
}) | ||
}) | ||
.catch((error) => { | ||
console.error("Error generating image:", error) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"root":["./src/app.tsx","./src/index.tsx","./src/vite-env.d.ts","./src/components/enumnode.tsx","./src/components/modelnode.tsx","./src/components/schemavisualizer.tsx","./src/lib/contexts/theme.tsx","./src/lib/hooks/usegraph.ts","./src/lib/types/schema.ts","./src/lib/utils/colots.ts","./src/lib/utils/layout-utils.ts"],"version":"5.6.2"} | ||
{"root":["./src/app.tsx","./src/index.tsx","./src/vite-env.d.ts","./src/components/enumnode.tsx","./src/components/modelnode.tsx","./src/components/schemavisualizer.tsx","./src/components/icons/idownload.tsx","./src/lib/contexts/theme.tsx","./src/lib/hooks/usegraph.ts","./src/lib/types/schema.ts","./src/lib/utils/colots.ts","./src/lib/utils/layout-utils.ts","./src/lib/utils/screnshot.ts"],"version":"5.6.2"} |