From cb9c0846acab2653d30975b71aaa7d29d157b2be Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 1 Feb 2023 20:56:53 +0100 Subject: [PATCH] fix graph viewer for negative ids --- frontend/src/lib/components/flows/utils.ts | 6 ++++++ frontend/src/lib/components/graph/FlowGraph.svelte | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts index 7db5571116..ee2bc934e0 100644 --- a/frontend/src/lib/components/flows/utils.ts +++ b/frontend/src/lib/components/flows/utils.ts @@ -180,6 +180,9 @@ export function emptyFlowModuleState(): FlowModuleState { const aCharCode = 'a'.charCodeAt(0) export function numberToChars(n: number, skipTilde: boolean = false) { + if (n < 0) { + return "-" + numberToChars(-n, skipTilde) + } var b = [n], sp, out, @@ -207,6 +210,9 @@ export function numberToChars(n: number, skipTilde: boolean = false) { } export function charsToNumber(n: string): number { + if (n.charAt(0) == '-') { + return charsToNumber(n.slice(1)) * -1 + } let b = Math.pow(27, n.length - 1) let res = 0 for (let c of n) { diff --git a/frontend/src/lib/components/graph/FlowGraph.svelte b/frontend/src/lib/components/graph/FlowGraph.svelte index 2184a6b67f..1db1f7ab44 100644 --- a/frontend/src/lib/components/graph/FlowGraph.svelte +++ b/frontend/src/lib/components/graph/FlowGraph.svelte @@ -123,7 +123,7 @@ return flowModuleToBranch( module, branches, - ['Default', ...module.value.branches.map((x) => `If ${truncateRev(x.expr, 20)}`)], + ['Default', ...module.value.branches.map((x) => `${truncateRev(x.expr, 20)}`)], parent, insideLoop ) @@ -328,11 +328,11 @@ if (!modules.length) { items.push(createVirtualNode(branchParent, 'Empty branch', edgesLabel[i])) } else { - modules.forEach((module) => { + modules.forEach((module, j) => { const item = getConvertedFlowModule( module, items.length ? items : numberToChars(branch.node.id), - edgesLabel[i], + j == 0 ? edgesLabel[i] : undefined, insideLoop ) item && items.push(item) @@ -434,8 +434,9 @@ edgesLabel?: string, offset?: number ): Node { + const id = -idGenerator.next().value - 1 + (offset ?? 0) return { - id: -idGenerator.next().value - 1 + (offset ?? 0), + id, position: { x: -1, y: -1 }, data: { html: `