diff --git a/src/automata/npda.rs b/src/automata/npda.rs index 52af692..6519b32 100644 --- a/src/automata/npda.rs +++ b/src/automata/npda.rs @@ -211,8 +211,9 @@ impl Npda { State(0) } }; - if states.insert(ident, state).is_some() { + if let Some(old) = states.insert(ident, state) { ctx.emit_error("state redefined", item.1); + states.insert(ident, old); } } @@ -284,8 +285,9 @@ impl Npda { Symbol(0) } }; - if stack_symbols.insert(ident, symbol).is_some() { + if let Some(old) = stack_symbols.insert(ident, symbol) { ctx.emit_error("stack symbol redefined", item.1); + stack_symbols.insert(ident, old); } } diff --git a/web/root/src/controls.ts b/web/root/src/controls.ts index c4d2441..58a6f38 100644 --- a/web/root/src/controls.ts +++ b/web/root/src/controls.ts @@ -27,6 +27,7 @@ togglePhysicsBtn.onclick = () => { const enabled = !togglePhysicsBtn.classList.contains("active"); setPhysicsButtonUI(enabled); network.setOptions({ physics: { enabled } }); + network.setOptions({edges: {smooth: enabled}}); }; setPhysicsButtonUI(togglePhysicsBtn.classList.contains("active")); diff --git a/web/root/src/theme.ts b/web/root/src/theme.ts index 1fd5944..88f7625 100644 --- a/web/root/src/theme.ts +++ b/web/root/src/theme.ts @@ -1,4 +1,4 @@ -import { invalidateGraphThemeCache, network } from "./visualizer.ts"; +import { getGraphTheme, invalidateGraphThemeCache, network } from "./visualizer.ts"; function cssVar(name: string, fallback = ""): string { return getComputedStyle(document.documentElement) @@ -56,16 +56,22 @@ function applyGraphTheme() { nodes: { font: { color: cssVar("--graph-node-text"), + bold: { + color: cssVar("--fg-1"), + mod: '' + }, }, }, edges: { labelHighlightBold: true, font: { - align: "middle", + align: "top", + size: getGraphTheme().edge_font_size, color: cssVar("--fg-0"), strokeColor: cssVar("--bg-0"), bold: { color: cssVar("--fg-1"), + size: getGraphTheme().edge_font_size, mod: '' }, }, diff --git a/web/root/src/visualizer.ts b/web/root/src/visualizer.ts index 6fd2e68..0e9712b 100644 --- a/web/root/src/visualizer.ts +++ b/web/root/src/visualizer.ts @@ -50,9 +50,13 @@ export function setAutomaton(auto: GraphDef) { // Populate edges for (const [k, v] of Object.entries(automaton.transitions)) { const to_from = k.split("#"); + const font = { + vadjust: -getGraphTheme().edge_font_size*Math.floor(((v.match(/\n/g) || '').length + 1)/2) + }; if (edges.get(k)) { edges.update({ id: k, + font, from: to_from[0], to: to_from[1], label: v, @@ -60,6 +64,7 @@ export function setAutomaton(auto: GraphDef) { } else { edges.add({ id: k, + font, from: to_from[0], to: to_from[1], label: v, @@ -108,13 +113,14 @@ function createGraph(): vis.Network { layout: { improvedLayout: true }, physics: { enabled: true, - solver: "barnesHut", - barnesHut: { - gravitationalConstant: -8000, - springLength: 120, - springConstant: 0.04, - }, - stabilization: { iterations: 200 }, + solver: "forceAtlas2Based", + // solver: "barnesHut", + // barnesHut: { + // gravitationalConstant: -8000, + // springLength: 120, + // springConstant: 0.04, + // }, + // stabilization: { iterations: 200 }, }, interaction: { dragNodes: true, @@ -124,20 +130,14 @@ function createGraph(): vis.Network { selectConnectedEdges: false, }, nodes: { - font: { color: "#c9d1d9" }, - color: { - background: "#1f6feb", - border: "#79c0ff", - highlight: { background: "#388bfd", border: "#a5d6ff" }, - }, + shape: "custom", + size: 18, // // @ts-expect-error bad library // chosen: { // node: chosen_node, // }, - shape: "custom", // @ts-expect-error bad library ctxRenderer: renderNode, - size: 18, }, edges: { chosen: { @@ -145,10 +145,6 @@ function createGraph(): vis.Network { // edge: chosen_edge, }, arrowStrikethrough: false, - font: { align: "middle", color: "#000000ff" }, - color: { color: "rgba(201,209,217,0.35)", highlight: "#c9d1d9" }, - // @ts-expect-error bad library - smooth: { type: "dynamic" }, arrows: "to", }, }, @@ -179,6 +175,7 @@ export type GraphTheme = { current: string; edge: string; glow: string; + edge_font_size: number, }; let _graphTheme: GraphTheme | null = null; @@ -187,7 +184,7 @@ export function invalidateGraphThemeCache() { _graphTheme = null; } -function getGraphTheme(): GraphTheme { +export function getGraphTheme(): GraphTheme { function cssVar(name: string, fallback = ""): string { return getComputedStyle(document.documentElement) .getPropertyValue(name) @@ -212,6 +209,7 @@ function getGraphTheme(): GraphTheme { edge: cssVar("--graph-edge", "rgba(201,209,217,0.55)"), glow: cssVar("--accent", "#79c0ff"), + edge_font_size: 10, }; return _graphTheme; diff --git a/web/root/style/editor.scss b/web/root/style/editor.scss index ccb0e06..a09ed24 100644 --- a/web/root/style/editor.scss +++ b/web/root/style/editor.scss @@ -18,6 +18,10 @@ color: var(--fg-0); } +.cm-content{ + caret-color: var(--fg-0)!important; +} + .cm-gutters { background: var(--bg-2) !important; color: var(--fg-muted);