Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit ec232a4

Browse files
Web 0.14.23: verschachtelte Verzweigungen kompakter, Spalten füllen die Verzweigung (#250)
Zweiarmige Verzweigung macht beide Spalten nur gleich breit, wenn keine Spalte eine weitere Verzweigung/Fallauswahl enthält; sonst verdoppelte sich die Breite je Ebene (Lektion 10 Schritt 2, Getränkeautomat). Lektionsvorschau verkleinert breite Diagramme höchstens auf 60 % und scrollt dann seitlich. Claude-Session: https://claude.ai/code/session_01Ugz28U6UTNEkKmTMxnAW3k Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8ba1d66 commit ec232a4

15 files changed

Lines changed: 1438 additions & 1381 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is loosely inspired by Keep a Changelog.
88

99
### Changed
1010

11+
- **Web 0.14.23, compact nested branches:** a two-way branch keeps both columns the same width only when neither column contains another branch or switch. Before, each nesting level doubled the width, so the drinks machine in lesson 10 step 2 (three nested branches) was about 3000 px wide and unreadable in the lesson and in the editor; now it is about half as wide, and 20 other lesson diagrams (e.g. VisuBot solutions, L17 ticket) get narrower too. Columns of a branch or switch inside a loop or another branch now always fill the box; before, the header could stay wider than its columns, so the if in lesson 14 step 3 looked like a loop (37 lesson diagrams affected). Wide diagrams in the lesson text no longer shrink below 60 % of their size; they scroll sideways instead.
1112
- **Web 0.14.22, text case names in quotation marks:** in lesson 10 the traffic light structure chart now uses the case names `"rot"`, `"gelb"`, `"grün"` (en `"red"` …, pt `"vermelho"` …) and the calculator solution `"+"`, `"-"`, `"*"`, so it is clear they are texts and the generated Java (`case "rot" ->`) is valid. Lesson text, hint and quiz say so (de/en/pt). The simulation still accepts case names without quotes.
1213
- **Web 0.14.21, array output like in Java:** `System.out.println(zahlen)` now prints a reference such as `[I@1e3779b1` in Simulation and Programmieren, as real Java does (`[D@`, `[Z@`, `[Ljava.lang.String;@`, `[[I@`; the same array keeps its id). `Arrays.toString(…)` and `Arrays.deepToString(…)` show the content; `Arrays` needs `import java.util.Arrays;` like javac, and the Java export adds it. The variable table still shows the content. Lesson 15 „Jetzt in Java“ explains reference and `Arrays.toString` (de/en/pt).
1314
- **Web 0.14.18, upper and lower case, exercises „Warum läuft das nicht?“:** lesson 4 gets the new step „Groß- und Kleinschreibung“ (case-sensitive: `zahl`, `Zahl` and `ZAHL` are three names) with a structure chart exercise (`zahl` and `Zahl` both declared, `ZAHL` used), a Kompetenz item and a quiz question; glossary entry case-sensitive. Lessons 4–17 and 19 each get a Java exercise „Warum läuft das nicht?“: the start code doesn't run (misspelled variable such as `Alter`/`Grenze`/`properson`, variable used before it is created or never created, `system.out`, `.Length`, `charat`), the student reads the error message, fixes it and clicks Check (de/en/pt). The Code area now reports wrong case in Java words (`system.out.println`, `System.Out`, `Println`, `math.sqrt`, `text.Length()`, `name.charat(0)`) with the right spelling, blocks Run like javac and offers the 💡 fix; the simulation says „Unbekannte Variable: Zahl. Java unterscheidet Groß- und Kleinschreibung: Meintest du zahl?“ when the name exists in another case (all 21 languages).

‎web/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visustruct-web",
33
"private": true,
4-
"version": "0.14.22",
4+
"version": "0.14.23",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

‎web/src/core/layout.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ export class LayoutEngine {
163163

164164
private stretchMultiwayNodeToWidth(node: LayoutNode, newWidth: number): LayoutNode {
165165
const n = copy(node)
166-
const oldW = n.frame.width
167-
if (!(oldW > 0) || n.caseColumnFrames.length === 0) return n
166+
if (n.caseColumnFrames.length === 0) return n
167+
// Alte Breite aus den Spalten, nicht aus `frame.width`: Aufrufer setzen `frame.width` oft schon
168+
// vorher auf die neue Breite. Sonst wäre scale = 1 und die Spalten blieben schmaler als der Kopf.
169+
const oldW = n.caseColumnFrames.reduce((s, c) => s + c.width, 0)
170+
if (!(oldW > 0)) return n
168171
const scale = newWidth / oldW
169172
n.frame.width = newWidth
170173
let xCursor = n.frame.x
@@ -413,8 +416,15 @@ export class LayoutEngine {
413416
totalW += colW
414417
})
415418

416-
// Zweiarmige Verzweigung: beide Spalten gleich breit.
417-
if (e.type === ElementType.verzweigung && colCount === 2 && columnFrames.length === 2) {
419+
// Zweiarmige Verzweigung: beide Spalten gleich breit. Nicht, wenn eine Spalte selbst eine
420+
// Verzweigung oder Fallauswahl enthält: Sonst verdoppelt sich die Breite mit jeder Ebene
421+
// (verschachtelte else-Ketten werden unlesbar breit).
422+
if (
423+
e.type === ElementType.verzweigung &&
424+
colCount === 2 &&
425+
columnFrames.length === 2 &&
426+
!cases.some((c) => containsMultiway(c.elements))
427+
) {
418428
const target = Math.max(columnFrames[0].width, columnFrames[1].width)
419429
const xLeft = x
420430
const xRight = x + target
@@ -480,6 +490,16 @@ export class LayoutEngine {
480490
}
481491
}
482492

493+
/** Steckt irgendwo (auch in Schleifen) eine Verzweigung oder Fallauswahl? */
494+
function containsMultiway(elements: VSElement[]): boolean {
495+
return elements.some(
496+
(el) =>
497+
isMultiType(el.type) ||
498+
containsMultiway(el.loopBody ?? []) ||
499+
(el.cases ?? []).some((c) => containsMultiway(c.elements)),
500+
)
501+
}
502+
483503
function shiftDescendantsY(node: LayoutNode, delta: number): LayoutNode {
484504
if (Math.abs(delta) <= 0.0001) return node
485505
const n = copy(node)

‎web/src/ui/app.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,11 @@ export class App {
13141314
if (!image) return undefined
13151315
// Kleine Diagramme nicht über ihre natürliche Größe hinaus vergrößern.
13161316
const width = image.svg.getAttribute('width')
1317-
if (width) image.svg.style.maxWidth = `${width}px`
1317+
if (width) {
1318+
image.svg.style.maxWidth = `${width}px`
1319+
// Breite Diagramme nicht bis zur Unlesbarkeit verkleinern: lieber seitlich scrollen.
1320+
image.svg.style.minWidth = `${Math.round(Number(width) * 0.6)}px`
1321+
}
13181322
image.svg.removeAttribute('width')
13191323
image.svg.removeAttribute('height')
13201324
return image.svg

‎web/src/ui/styles.css‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,8 @@ button.danger-text:not(:disabled) {
21792179
width: 100%;
21802180
border: 1px solid var(--border);
21812181
border-radius: 8px;
2182-
overflow: hidden;
2182+
overflow-x: auto;
2183+
overflow-y: hidden;
21832184
background: #fafafa;
21842185
}
21852186
.learn-preview > svg {

‎web/test/layoutColumns.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect, test } from 'vitest'
2+
import { readdirSync, readFileSync, statSync } from 'node:fs'
3+
import { join } from 'node:path'
4+
import { decodeDocument } from '../src/core/xmlCodec'
5+
import { LayoutEngine, type LayoutNode } from '../src/core/layout'
6+
7+
/** Spalten einer Verzweigung/Fallauswahl müssen die ganze Breite des Kastens füllen
8+
* (sonst bleibt rechts Kopffarbe stehen und das if sieht aus wie eine Schleife, Lektion 14). */
9+
test('Spalten füllen die Verzweigung in allen Lektionsdiagrammen', () => {
10+
const gaps: string[] = []
11+
const check = (n: LayoutNode, file: string) => {
12+
if (n.caseColumnFrames.length) {
13+
const last = n.caseColumnFrames[n.caseColumnFrames.length - 1]
14+
const end = last.x + last.width
15+
if (Math.abs(end - (n.frame.x + n.frame.width)) > 1) gaps.push(`${file}: ${n.element.textLines[0]}`)
16+
}
17+
n.children.forEach((c) => check(c, file))
18+
}
19+
const walk = (dir: string) => {
20+
for (const f of readdirSync(dir)) {
21+
const p = join(dir, f)
22+
if (statSync(p).isDirectory()) walk(p)
23+
else if (p.endsWith('.visustruct')) {
24+
const doc = decodeDocument(readFileSync(p, 'utf8'))
25+
new LayoutEngine().layout(doc).elements.forEach((n) => check(n, p))
26+
}
27+
}
28+
}
29+
walk('lessons/diagramme')
30+
expect(gaps).toEqual([])
31+
})
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1361 additions & 1361 deletions
Large diffs are not rendered by default.

‎website/app/assets/index-1DNiS0o0.css‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)