Skip to content

Commit

Permalink
Fix template shapes & colors; Fix shape menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-gordon committed May 23, 2024
1 parent e30a074 commit e441065
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
6 changes: 4 additions & 2 deletions app/src/components/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function getGraphUpdater({

try {
const themeEditor = getThemeEditor(doc);
const { layout, style: themeStyle } = toTheme(themeEditor);
const { layout, style: themeStyle, postStyle } = toTheme(themeEditor);

// Eventually, this will become cytoscape again...
const customCss = (doc.meta.cytoscapeStyle as string) ?? "";
Expand All @@ -315,7 +315,9 @@ function getGraphUpdater({
const customCssOnly = (doc.meta?.customCssOnly as boolean) ?? false;

const { style } = preprocessStyle(
customCssOnly ? customCss : [themeStyle, customCss].join("\n")
customCssOnly
? customCss
: [themeStyle, customCss, postStyle].join("\n")
);

elements = getElements(doc.text);
Expand Down
1 change: 1 addition & 0 deletions app/src/components/GraphContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function DynamicClassesMenu({
{Object.entries(dynamicClasses).map(([name, options]) => (
<Submenu
key={name}
// className="max-h-[200px] overflow-y-auto"
label={
<span className="text-sm capitalize">
{name.replace(/-/g, " ")}
Expand Down
4 changes: 4 additions & 0 deletions app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,7 @@ body.dark .pricing-highlights {
.plan-button[aria-current="true"] {
transform: scale(1) translateZ(0);
}

.react-contexify .react-contexify__submenu {
@apply max-h-[300px] overflow-y-auto;
}
3 changes: 2 additions & 1 deletion app/src/lib/preprocessStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export function getStyleStringFromMeta(meta: any) {
if (customCssOnly) {
return cytoscapeStyle;
} else {
return `${toTheme(themeEditor).style}\n${cytoscapeStyle}`;
const theme = toTheme(themeEditor);
return `${theme.style}\n${cytoscapeStyle}\n${theme.postStyle}`;
}
}
2 changes: 1 addition & 1 deletion app/src/lib/templates/flowchart-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export const theme: FFTheme = {
};

export const cytoscapeStyle =
"$color: #1a1a1a;\n$red: #ed6e49;\n$orange: #f4a261;\n$yellow: #f5c844;\n$green: #11ac9a;\n$blue: #4351d1;\n$pink: #f5c3c2;\n$grey: #f2eded;\n\n:childless {\n font-weight: 500;\n}\n\n/** Start */\n:childless[in_degree < 1][out_degree > 0] {\n border-width: 0;\n shape: roundrectangle;\n background-color: $color;\n color: white;\n}\n\n/** Terminal */\n:childless[out_degree < 1][in_degree > 0] {\n border-width: 0;\n shape: roundrectangle;\n background-color: $color;\n color: white;\n}\n\n/** Branching */\n:childless[in_degree > 0][in_degree < 2][out_degree > 1] {\n shape: diamond;\n background-color: $red;\n color: white;\n height: $width;\n border-width: 0;\n text-margin-y: 2;\n}\n\n/** Merging **/\n:childless[in_degree > 1][out_degree > 0][out_degree < 2] {\n}\n\n:childless.color_red {\n background-color: $red;\n color: white;\n}\n:childless.color_orange {\n background-color: $orange;\n color: white;\n}\n:childless.color_yellow {\n background-color: $yellow;\n}\n:childless.color_green {\n background-color: $green;\n color: white;\n}\n:childless.color_blue {\n background-color: $blue;\n color: white;\n}\n:childless.color_pink {\n background-color: $pink;\n color: $color;\n}\n:childless.color_grey {\n background-color: $grey;\n}\n\n:parent.color_white {\n background-color: white;\n}\n:parent.color_grey {\n background-color: $grey;\n}\n";
"$color: #1a1a1a;\n$red: #ed6e49;\n$orange: #f4a261;\n$yellow: #f5c844;\n$green: #11ac9a;\n$blue: #4351d1;\n$pink: #f5c3c2;\n$grey: #f2eded;\n\n:childless {\n font-weight: 500;\n}\n\n/** Start */\n:childless[in_degree < 1][out_degree > 0] {\n border-width: 0;\n shape: roundrectangle;\n background-color: $color;\n color: white;\n}\n\n/** Terminal */\n:childless[out_degree < 1][in_degree > 0] {\n border-width: 0;\n shape: roundrectangle;\n background-color: $color;\n color: white;\n}\n\n/** Branching */\n:childless[in_degree > 0][in_degree < 2][out_degree > 1] {\n shape: diamond;\n background-color: $red;\n color: white;\n height: $width;\n border-width: 0;\n text-margin-y: 2;\n}\n\n/** Merging **/\n:childless[in_degree > 1][out_degree > 0][out_degree < 2] {\n}\n\n:childless.color_red {\n background-color: $red;\n color: white;\n}\n:childless.color_orange {\n background-color: $orange;\n color: white;\n}\n:childless.color_yellow {\n background-color: $yellow;\n}\n:childless.color_green {\n background-color: $green;\n color: white;\n}\n:childless.color_blue {\n background-color: $blue;\n color: white;\n}\n:childless.color_pink {\n background-color: $pink;\n color: $color;\n}\n:childless.color_grey {\n background-color: $grey;\n color: $color;\n}\n\n:parent.color_white {\n background-color: white;\n}\n:parent.color_grey {\n background-color: $grey;\n}\n";
16 changes: 8 additions & 8 deletions app/src/lib/templates/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ export const templates: {
promptType: "flowchart",
accentClasses: ["color_blue", "color_green"],
},
{
key: "mindmap",
img: "template19.png",
bgColor: "#FFFFFF",
title: () => `Mind Map`,
promptType: "knowledge",
accentClasses: ["size_lg", "color_blue", "color_green", "color_orange"],
},
{
key: "org-chart",
img: "template17.png",
Expand All @@ -49,6 +41,14 @@ export const templates: {
promptType: "flowchart",
accentClasses: ["color_blue", "color_green", "color_purple"],
},
{
key: "mindmap",
img: "template19.png",
bgColor: "#FFFFFF",
title: () => `Mind Map`,
promptType: "knowledge",
accentClasses: ["size_lg", "color_blue", "color_green", "color_orange"],
},
{
key: "knowledge-graph",
img: "template20.png",
Expand Down
25 changes: 21 additions & 4 deletions app/src/lib/toTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function toTheme(theme: FFTheme) {
}
}

const elementStyles: cytoscape.StylesheetCSS[] = [
const preStyles: cytoscape.StylesheetCSS[] = [
{
selector: ":childless",
css: node as any,
Expand Down Expand Up @@ -169,10 +169,25 @@ export function toTheme(theme: FFTheme) {
"active-bg-opacity": 0,
},
},
];
const postStyles: cytoscape.StylesheetCSS[] = [
...edgeStyleClasses,
...childlessShapeClasses,
...createSmartChildlessBorderClasses(theme.borderWidth || theme.edgeWidth),
...createSmartShapeClasses(width),
// for width and height in the form [w=100][h=100]
{
selector: ":childless[w]",
css: {
width: "data(width)",
},
},
{
selector: ":childless[h]",
css: {
height: "data(height)",
},
},
];

const variables = [
Expand All @@ -182,17 +197,19 @@ export function toTheme(theme: FFTheme) {
`$background: ${theme.background};`,
].join("\n");

const style = [variables, styleToString(elementStyles)];
const preStyle = [variables, styleToString(preStyles)];
const postStyle = styleToString(postStyles);

// Add font style
let knownFont = fonts.find((f) => f.name === theme.fontFamily);
if (knownFont) {
style.unshift(knownFont.importSnippet);
preStyle.unshift(knownFont.importSnippet);
}

return {
layout,
style: style.join("\n"),
style: preStyle.join("\n"),
postStyle,
};
}

Expand Down

0 comments on commit e441065

Please sign in to comment.