-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8a3798
commit 69ce76a
Showing
21 changed files
with
195 additions
and
100 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
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,4 +1,4 @@ | ||
import { FFTheme } from "../FFTheme"; | ||
import type { FFTheme } from "shared"; | ||
|
||
export const content = ` | ||
Database | ||
|
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
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,31 @@ | ||
import { FFTheme } from "shared"; | ||
import { theme as defaultTheme } from "./templates/default-template"; | ||
import { useDoc } from "./useDoc"; | ||
import { getThemeEditor } from "./toTheme"; | ||
|
||
export function useThemeEditor() { | ||
return useDoc( | ||
(state) => (state.meta?.themeEditor as FFTheme) || defaultTheme | ||
); | ||
} | ||
|
||
export function useBackground() { | ||
return useThemeEditor().background; | ||
} | ||
|
||
export function updateThemeEditor(theme: Partial<FFTheme>) { | ||
useDoc.setState((doc) => ({ | ||
...doc, | ||
meta: { | ||
...doc.meta, | ||
themeEditor: { | ||
...getThemeEditor(doc), | ||
...theme, | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
export function getBackground() { | ||
return getThemeEditor(useDoc.getState()).background; | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./src/ImportDataFormType"; | ||
export * from "./src/FFTheme"; |
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 @@ | ||
{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"definitions":{"ArrowShape":{"enum":["none","triangle","vee","triangle-backcurve","circle"],"type":"string"},"CurveStyle":{"enum":["bezier","taxi"],"type":"string"},"Direction":{"enum":["RIGHT","LEFT","DOWN","UP"],"type":"string"},"LayoutName":{"description":"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! NOTICE !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nIf you change this file, you need to run `pnpm -F shared schema:generate` to update the json schema file in `src/FFTheme.schema.json`.","enum":["dagre","klay","breadthfirst","cose","concentric","circle","layered","mrtree","stress","radial"],"type":"string"},"Shape":{"enum":["rectangle","roundrectangle","ellipse"],"type":"string"}},"properties":{"arrowScale":{"type":"number"},"background":{"type":"string"},"borderColor":{"type":"string"},"borderWidth":{"description":"The width of the border used on nodes.","type":"number"},"curveStyle":{"$ref":"#/definitions/CurveStyle"},"direction":{"$ref":"#/definitions/Direction"},"edgeColor":{"type":"string"},"edgeTextSize":{"type":"number"},"edgeWidth":{"type":"number"},"fixedHeight":{"description":"The height of the node when `useFixedHeight` is true. Ideal range is between 75 - 250.","type":"number"},"fontFamily":{"type":"string"},"layoutName":{"$ref":"#/definitions/LayoutName"},"lineHeight":{"type":"number"},"nodeBackground":{"type":"string"},"nodeForeground":{"type":"string"},"padding":{"type":"number"},"rotateEdgeLabel":{"type":"boolean"},"shape":{"$ref":"#/definitions/Shape"},"sourceArrowShape":{"$ref":"#/definitions/ArrowShape"},"sourceDistanceFromNode":{"type":"number"},"spacingFactor":{"type":"number"},"targetArrowShape":{"$ref":"#/definitions/ArrowShape"},"targetDistanceFromNode":{"type":"number"},"textMarginY":{"type":"number"},"textMaxWidth":{"type":"number"},"useFixedHeight":{"description":"Whether the node's height should be fixed. Creates a more aesthetically pleasing graph in some cases.","type":"boolean"}},"required":["fontFamily","background","lineHeight","layoutName","direction","spacingFactor","shape","textMaxWidth","padding","curveStyle","textMarginY","borderWidth","borderColor","nodeBackground","nodeForeground","useFixedHeight","fixedHeight","edgeTextSize","edgeWidth","sourceArrowShape","targetArrowShape","edgeColor","sourceDistanceFromNode","targetDistanceFromNode","arrowScale","rotateEdgeLabel"],"type":"object"} |
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,80 @@ | ||
/** | ||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
* !!!!!!!!!!!! NOTICE !!!!!!!!!!!!!!!! | ||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
* | ||
* If you change this file, you need to run `pnpm -F shared schema:generate` to update the | ||
* json schema file in `src/FFTheme.schema.json`. | ||
*/ | ||
|
||
export type LayoutName = | ||
| "dagre" | ||
| "klay" | ||
| "breadthfirst" | ||
| "cose" | ||
| "concentric" | ||
| "circle" | ||
| "layered" | ||
| "mrtree" | ||
| "stress" | ||
| "radial"; | ||
|
||
export type LayoutDirection = "TB" | "LR" | "RL" | "BT"; | ||
|
||
export type Direction = "RIGHT" | "LEFT" | "DOWN" | "UP"; | ||
|
||
export type Shape = "rectangle" | "roundrectangle" | "ellipse"; | ||
|
||
export type CurveStyle = "bezier" | "taxi"; | ||
|
||
export type Border = "none" | "solid" | "dashed" | "dotted" | "double"; | ||
|
||
export type ArrowShape = | ||
| "none" | ||
| "triangle" | ||
| "vee" | ||
| "triangle-backcurve" | ||
| "circle"; | ||
|
||
export type FFTheme = { | ||
// Global Style | ||
fontFamily: string; | ||
background: string; | ||
lineHeight: number; | ||
// Layout | ||
layoutName: LayoutName; | ||
direction: Direction; | ||
spacingFactor: number; | ||
// Node | ||
shape: Shape; | ||
textMaxWidth: number; | ||
padding: number; | ||
curveStyle: CurveStyle; | ||
textMarginY: number; | ||
/** | ||
* The width of the border used on nodes. | ||
*/ | ||
borderWidth: number; | ||
borderColor: string; | ||
nodeBackground: string; | ||
nodeForeground: string; | ||
/** | ||
* Whether the node's height should be fixed. Creates a more aesthetically pleasing graph | ||
* in some cases. | ||
*/ | ||
useFixedHeight: boolean; | ||
/** | ||
* The height of the node when `useFixedHeight` is true. Ideal range is between 75 - 250. | ||
*/ | ||
fixedHeight: number; | ||
// Text size on edge labels relative to node | ||
edgeTextSize: number; | ||
edgeWidth: number; | ||
sourceArrowShape: ArrowShape; | ||
targetArrowShape: ArrowShape; | ||
edgeColor: string; | ||
sourceDistanceFromNode: number; | ||
targetDistanceFromNode: number; | ||
arrowScale: number; | ||
rotateEdgeLabel: boolean; | ||
}; |
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,56 +1 @@ | ||
import { getPage } from "./src/getPage"; | ||
import { readFileSync } from "fs"; | ||
import { join } from "path"; | ||
import type { ElementDefinition } from "cytoscape"; | ||
|
||
/** | ||
* Returns a base64 encoded PNG image of a cytoscape graph | ||
*/ | ||
export async function getPng({ elements }: { elements: ElementDefinition[] }) { | ||
const { page, browser } = await getPage(); | ||
|
||
// read the file from "./dist/index.html" | ||
const indexHtml = join(__dirname, "dist/index.html"); | ||
const html = readFileSync(indexHtml, "utf8"); | ||
|
||
// set the page content | ||
await page.setContent(html); | ||
|
||
// execute code in the browser | ||
await page.evaluate((elements) => { | ||
console.log(window.cy); | ||
// set elements | ||
window.cy.json({ elements }); | ||
window.cy.layout({ name: "grid" }).run(); | ||
|
||
// const themeEditor = getThemeEditor(doc); | ||
// const { layout, style: themeStyle } = toTheme(themeEditor); | ||
// const { style } = preprocessStyle( | ||
// customCssOnly ? customCss : [themeStyle, customCss].join("\n") | ||
// ); | ||
// window.cy | ||
// .layout({ | ||
// ...layout, | ||
// // @ts-ignore | ||
// fit: true, | ||
// padding: 20, | ||
// }) | ||
// .run(); | ||
|
||
// json stringify the elements, and write them to a fixed position | ||
// div on the page so we can read them out in the next step | ||
const elementsDiv = document.createElement("div"); | ||
elementsDiv.id = "elements"; | ||
elementsDiv.style.position = "fixed"; | ||
elementsDiv.style.top = "0"; | ||
elementsDiv.style.left = "0"; | ||
elementsDiv.textContent = JSON.stringify(elements); | ||
document.body.appendChild(elementsDiv); | ||
}, elements); | ||
|
||
const screenshot = await page.screenshot({ encoding: "base64" }); | ||
|
||
await browser.close(); | ||
|
||
return screenshot; | ||
} | ||
export { getPng } from "./src/getPng"; |
Oops, something went wrong.