mirror of
https://github.com/ParkerTenBroeck/automata.git
synced 2026-06-06 21:24:06 -04:00
fixed npda crash on duplicate states/symbols, reduced font size for edges, fixed incorrect caret color, fixed edge label alignment
This commit is contained in:
parent
13bcab9cd1
commit
47d7482342
5 changed files with 35 additions and 24 deletions
|
|
@ -211,8 +211,9 @@ impl Npda {
|
||||||
State(0)
|
State(0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if states.insert(ident, state).is_some() {
|
if let Some(old) = states.insert(ident, state) {
|
||||||
ctx.emit_error("state redefined", item.1);
|
ctx.emit_error("state redefined", item.1);
|
||||||
|
states.insert(ident, old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,8 +285,9 @@ impl Npda {
|
||||||
Symbol(0)
|
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);
|
ctx.emit_error("stack symbol redefined", item.1);
|
||||||
|
stack_symbols.insert(ident, old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ togglePhysicsBtn.onclick = () => {
|
||||||
const enabled = !togglePhysicsBtn.classList.contains("active");
|
const enabled = !togglePhysicsBtn.classList.contains("active");
|
||||||
setPhysicsButtonUI(enabled);
|
setPhysicsButtonUI(enabled);
|
||||||
network.setOptions({ physics: { enabled } });
|
network.setOptions({ physics: { enabled } });
|
||||||
|
network.setOptions({edges: {smooth: enabled}});
|
||||||
};
|
};
|
||||||
|
|
||||||
setPhysicsButtonUI(togglePhysicsBtn.classList.contains("active"));
|
setPhysicsButtonUI(togglePhysicsBtn.classList.contains("active"));
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { invalidateGraphThemeCache, network } from "./visualizer.ts";
|
import { getGraphTheme, invalidateGraphThemeCache, network } from "./visualizer.ts";
|
||||||
|
|
||||||
function cssVar(name: string, fallback = ""): string {
|
function cssVar(name: string, fallback = ""): string {
|
||||||
return getComputedStyle(document.documentElement)
|
return getComputedStyle(document.documentElement)
|
||||||
|
|
@ -56,16 +56,22 @@ function applyGraphTheme() {
|
||||||
nodes: {
|
nodes: {
|
||||||
font: {
|
font: {
|
||||||
color: cssVar("--graph-node-text"),
|
color: cssVar("--graph-node-text"),
|
||||||
|
bold: {
|
||||||
|
color: cssVar("--fg-1"),
|
||||||
|
mod: ''
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
edges: {
|
edges: {
|
||||||
labelHighlightBold: true,
|
labelHighlightBold: true,
|
||||||
font: {
|
font: {
|
||||||
align: "middle",
|
align: "top",
|
||||||
|
size: getGraphTheme().edge_font_size,
|
||||||
color: cssVar("--fg-0"),
|
color: cssVar("--fg-0"),
|
||||||
strokeColor: cssVar("--bg-0"),
|
strokeColor: cssVar("--bg-0"),
|
||||||
bold: {
|
bold: {
|
||||||
color: cssVar("--fg-1"),
|
color: cssVar("--fg-1"),
|
||||||
|
size: getGraphTheme().edge_font_size,
|
||||||
mod: ''
|
mod: ''
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,13 @@ export function setAutomaton(auto: GraphDef) {
|
||||||
// Populate edges
|
// Populate edges
|
||||||
for (const [k, v] of Object.entries(automaton.transitions)) {
|
for (const [k, v] of Object.entries(automaton.transitions)) {
|
||||||
const to_from = k.split("#");
|
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)) {
|
if (edges.get(k)) {
|
||||||
edges.update({
|
edges.update({
|
||||||
id: k,
|
id: k,
|
||||||
|
font,
|
||||||
from: to_from[0],
|
from: to_from[0],
|
||||||
to: to_from[1],
|
to: to_from[1],
|
||||||
label: v,
|
label: v,
|
||||||
|
|
@ -60,6 +64,7 @@ export function setAutomaton(auto: GraphDef) {
|
||||||
} else {
|
} else {
|
||||||
edges.add({
|
edges.add({
|
||||||
id: k,
|
id: k,
|
||||||
|
font,
|
||||||
from: to_from[0],
|
from: to_from[0],
|
||||||
to: to_from[1],
|
to: to_from[1],
|
||||||
label: v,
|
label: v,
|
||||||
|
|
@ -108,13 +113,14 @@ function createGraph(): vis.Network {
|
||||||
layout: { improvedLayout: true },
|
layout: { improvedLayout: true },
|
||||||
physics: {
|
physics: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
solver: "barnesHut",
|
solver: "forceAtlas2Based",
|
||||||
barnesHut: {
|
// solver: "barnesHut",
|
||||||
gravitationalConstant: -8000,
|
// barnesHut: {
|
||||||
springLength: 120,
|
// gravitationalConstant: -8000,
|
||||||
springConstant: 0.04,
|
// springLength: 120,
|
||||||
},
|
// springConstant: 0.04,
|
||||||
stabilization: { iterations: 200 },
|
// },
|
||||||
|
// stabilization: { iterations: 200 },
|
||||||
},
|
},
|
||||||
interaction: {
|
interaction: {
|
||||||
dragNodes: true,
|
dragNodes: true,
|
||||||
|
|
@ -124,20 +130,14 @@ function createGraph(): vis.Network {
|
||||||
selectConnectedEdges: false,
|
selectConnectedEdges: false,
|
||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
font: { color: "#c9d1d9" },
|
shape: "custom",
|
||||||
color: {
|
size: 18,
|
||||||
background: "#1f6feb",
|
|
||||||
border: "#79c0ff",
|
|
||||||
highlight: { background: "#388bfd", border: "#a5d6ff" },
|
|
||||||
},
|
|
||||||
// // @ts-expect-error bad library
|
// // @ts-expect-error bad library
|
||||||
// chosen: {
|
// chosen: {
|
||||||
// node: chosen_node,
|
// node: chosen_node,
|
||||||
// },
|
// },
|
||||||
shape: "custom",
|
|
||||||
// @ts-expect-error bad library
|
// @ts-expect-error bad library
|
||||||
ctxRenderer: renderNode,
|
ctxRenderer: renderNode,
|
||||||
size: 18,
|
|
||||||
},
|
},
|
||||||
edges: {
|
edges: {
|
||||||
chosen: {
|
chosen: {
|
||||||
|
|
@ -145,10 +145,6 @@ function createGraph(): vis.Network {
|
||||||
// edge: chosen_edge,
|
// edge: chosen_edge,
|
||||||
},
|
},
|
||||||
arrowStrikethrough: false,
|
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",
|
arrows: "to",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -179,6 +175,7 @@ export type GraphTheme = {
|
||||||
current: string;
|
current: string;
|
||||||
edge: string;
|
edge: string;
|
||||||
glow: string;
|
glow: string;
|
||||||
|
edge_font_size: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _graphTheme: GraphTheme | null = null;
|
let _graphTheme: GraphTheme | null = null;
|
||||||
|
|
@ -187,7 +184,7 @@ export function invalidateGraphThemeCache() {
|
||||||
_graphTheme = null;
|
_graphTheme = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGraphTheme(): GraphTheme {
|
export function getGraphTheme(): GraphTheme {
|
||||||
function cssVar(name: string, fallback = ""): string {
|
function cssVar(name: string, fallback = ""): string {
|
||||||
return getComputedStyle(document.documentElement)
|
return getComputedStyle(document.documentElement)
|
||||||
.getPropertyValue(name)
|
.getPropertyValue(name)
|
||||||
|
|
@ -212,6 +209,7 @@ function getGraphTheme(): GraphTheme {
|
||||||
edge: cssVar("--graph-edge", "rgba(201,209,217,0.55)"),
|
edge: cssVar("--graph-edge", "rgba(201,209,217,0.55)"),
|
||||||
|
|
||||||
glow: cssVar("--accent", "#79c0ff"),
|
glow: cssVar("--accent", "#79c0ff"),
|
||||||
|
edge_font_size: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _graphTheme;
|
return _graphTheme;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
color: var(--fg-0);
|
color: var(--fg-0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cm-content{
|
||||||
|
caret-color: var(--fg-0)!important;
|
||||||
|
}
|
||||||
|
|
||||||
.cm-gutters {
|
.cm-gutters {
|
||||||
background: var(--bg-2) !important;
|
background: var(--bg-2) !important;
|
||||||
color: var(--fg-muted);
|
color: var(--fg-muted);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue