diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a624d..ead1eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,19 @@ document versions they bring in. ### Added +- The map shows its two halves, Plan & Deliver and Operate & Control, as shaded bands + (`zones` in `map.json`, checked by `scripts/check.js`), named in the legend, in each + station's spoken name and in its frame subtitle, and labelled as a study aid. +- Clicking a stretch of the map where several connections run together selects all of them + (`#A-B,C-D`): the frame lists each one's description and flows, and the map highlights and + animates each. +- `scripts/check.js` prints layout metrics for each edition's map (crossing points, + shared segments by kind, close parallels); `--layout` lists each one with its grid + coordinates. +- `drawFirst` in `map.json` names transfers to draw before the others, so the others break + where they cross them. +- A grid overlay for maintainers, off by default: `SHOW_GRID` in `src/map.js` or `?grid` in + the address. - Initial process map of FitSM 3.0: FitSM-0 Overview and vocabulary v3.0.1, FitSM-1 Requirements v3.0.1, FitSM-2 Process activities and implementation v3.0.2, FitSM-3 Role model v3.0.1 (all ITEMO e.V., CC BY 4.0). 14 processes, 17 general and 65 process @@ -35,3 +48,15 @@ document versions they bring in. to screen readers; the legend's transfer sample takes its colour from the content. - Checks for alias format, `map.grid` fields and role `tasks`; `scripts/check.js` works from any working directory; unit tests for the map geometry and selection rules. + +### Changed + +- The Reporting and improvement line is orange (`#e06000`, was `#bf360c`) so it can be told + apart from the red Operations line. +- A new map layout: CRM and SLM swap places so the Agreements row is straight and the + Assurance line forks below SLM; transfers leaving CHM, ISRM and CONFM run together as + trunks and branch off; the Reporting line runs below the Assurance fork on row 14; no + transfer runs along a coloured line. Crossing points on the map fall from 51 to 13 and + close parallels from 28 to 5. +- Route bends are drawn as curves, so a branch leaves a trunk smoothly; a curve next to a + crossing is tightened, down to a sharp corner, so the crossing's gap fits. diff --git a/README.md b/README.md index 8de5e74..b396b13 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,15 @@ says about it, with a reference to the FitSM document and section for every item | --- | --- | | A process (station) | Its objective, requirements (FitSM-1), roles, databases and records, activities, interfaces, and inputs/outputs exchanged with parties outside the processes | | A connection | FitSM's description of the interface and the inputs and outputs exchanged in each direction | +| A stretch where several connections run together | All of those connections, each with its description and flows, and each highlighted on the map | | A role | Its tasks (FitSM-3), split into tasks specific to the process and tasks common to every role of that kind | | An activity | Its procedure, as the ordered steps from FitSM-2 | | A database or record | Its FitSM-0 definition and the processes that use it | | **General requirements** (header) | FitSM-1's general requirements GR1–GR7 | Any view can be opened directly by link, for example `…/fitsm-process-map/#ISRM` for a -process, `#ISRM-PM` for an interface or `#GR` for the general requirements. +process, `#ISRM-PM` for an interface, `#CHM-ISRM,CONFM-ISRM` for several interfaces or `#GR` +for the general requirements. The coloured lines group related processes as a study aid. They are not part of FitSM, and the page says so wherever they appear. Everything else on the page is FitSM's own text, with @@ -77,6 +79,7 @@ Then open http://localhost:8765. No build step and no dependencies are needed. | `content/editions.json` | Which FitSM editions are present and which one the page shows | | `content/fitsm-3.0/` | The FitSM 3.0 content: eight JSON files (see below) | | `scripts/check.js` | Consistency and contrast checks, run in CI | +| `scripts/layout.js` | Layout metrics for the map (crossings, overlaps, close parallels), used by `check.js` | | `tests/` | Unit tests (`node --test`) and fixtures for the check script | Each edition directory holds `edition.json` (documents, versions, licence), `processes.json`, @@ -98,6 +101,20 @@ file could not be read. A line whose processes are not all connected through tha warning and does not fail the run. Options: `--content ` checks one edition directory; `--editions ` names a different editions file; `--quiet` prints findings only. +For each edition the script also prints a layout line, for example: + +```text +layout fitsm-3.0/map.json: 15 crossing points (34 crossings between pairs), 40 shared segments (37 transfer merges, 3 within a line, 0 mixed), 7 close parallels +``` + +*Crossing points* are the places on the map where lines cross; a trunk of several +connections crossing a line is one crossing point but one crossing per pair. *Shared +segments* are stretches where two connections lie on top of each other: transfers merged +into a trunk, two connections of the same line, or a mixed pair (such as a transfer over a +coloured line), which is usually worth avoiding. *Close parallels* are parallel stretches at +most one grid unit apart. The line is for information only and never fails the run. Add `--layout` to list each one with its grid +coordinates, which helps when re-routing connections in `map.json`. + ```bash node --test ``` @@ -139,6 +156,22 @@ Edit `lines` in `map.json` only. Membership, names, colours and label sides are change; the checks verify that every process is on a line, that colours pass contrast, and warn when a line's stations are not connected through interfaces. +### Choosing which line breaks at a crossing + +Where two connections cross, the one drawn later breaks with a short gap. Coloured lines are +drawn first; transfers follow in the order of `interfaces.json`. To keep a transfer unbroken +where it crosses other transfers, list its id under `drawFirst` in `map.json`; listed +transfers are drawn before all other transfers, in the listed order. + +### Changing the halves + +The map is split into two halves, Plan & Deliver and Operate & Control, drawn as shaded bands +behind the lines. They are defined under `zones` in `map.json`: each has a name, a fill +colour, the grid rows it covers (`top` and `bottom`), the corner its name sits in (`label`: +`nw`, `ne`, `sw` or `se`) and its stations. The checks verify that +every listed station sits inside its band, that no station is in two halves, that bands do +not overlap, and that line colours keep 3:1 contrast against each fill. + ## CI/CD | Workflow | Trigger | What it does | diff --git a/content/fitsm-3.0/map.json b/content/fitsm-3.0/map.json index cdf4559..d2dfa43 100644 --- a/content/fitsm-3.0/map.json +++ b/content/fitsm-3.0/map.json @@ -1,5 +1,5 @@ { - "note": "The lines group related processes as a study aid. They are not part of FitSM.", + "note": "The lines and the two halves group related processes as a study aid. They are not part of FitSM.", "background": "#ffffff", "transfer": { "colour": "#8a8a8a", @@ -14,6 +14,26 @@ "y": 2 } }, + "zones": [ + { + "id": "plan-deliver", + "name": "Plan & Deliver", + "fill": "#eef3f9", + "top": 0, + "bottom": 13, + "label": "nw", + "stations": ["SPM", "SLM", "CRM", "SUPPM", "SRM", "SACM", "CAPM", "ISM"] + }, + { + "id": "operate-control", + "name": "Operate & Control", + "fill": "#f7f3ea", + "top": 13, + "bottom": 26, + "label": "sw", + "stations": ["ISRM", "PM", "CSI", "CONFM", "CHM", "RDM"] + } + ], "lines": [ { "id": "agreements", @@ -59,7 +79,7 @@ { "id": "reporting", "name": "Reporting and improvement", - "colour": "#bf360c", + "colour": "#e06000", "stations": [ "CSI", "SRM" @@ -73,19 +93,19 @@ "label": "n" }, "SLM": { - "x": 12, + "x": 20, "y": 4, "label": "n" }, "CRM": { - "x": 20, + "x": 12, "y": 4, "label": "n" }, "SUPPM": { "x": 28, "y": 4, - "label": "n" + "label":"e" }, "SRM": { "x": 4, @@ -95,7 +115,7 @@ "SACM": { "x": 12, "y": 10, - "label": "e" + "label": "n" }, "CAPM": { "x": 20, @@ -120,12 +140,12 @@ "CSI": { "x": 34, "y": 16, - "label": "s" + "label": "e" }, "CONFM": { "x": 12, "y": 22, - "label": "s" + "label": "w" }, "CHM": { "x": 20, @@ -135,53 +155,53 @@ "RDM": { "x": 28, "y": 22, - "label": "s" + "label": "e" } }, + "drawFirst": ["CONFM-ISRM", "CONFM-PM"], "routes": { - "SACM-SLM": [], - "SLM-SPM": [], + "SACM-SLM": [ + [16, 10], + [20, 6] + ], + "SLM-SPM": [ + [18, 2], + [6, 2] + ], "CRM-SLM": [], "SACM-SRM": [], "ISRM-PM": [], "CHM-CONFM": [], "CHM-RDM": [], - "CAPM-CHM": [ - [26, 16] - ], - "CRM-SPM": [ - [18, 6], - [6, 6] - ], - "SLM-SUPPM": [ - [15, 7], - [25, 7] - ], + "CAPM-CHM": [], + "CRM-SPM": [], + "SLM-SUPPM": [], "CAPM-SRM": [ [18, 12], - [6, 12] + [12, 12], + [10, 10] ], "CONFM-RDM": [ - [14, 20], - [26, 20] + [14, 24], + [26, 24] ], "CHM-CRM": [ - [20, 16], - [26, 10] + [20, 12] ], "SPM-SUPPM": [ [2, 4], - [2, 1], - [24, 1], - [27, 4] + [2, 0], + [28, 0] ], "CSI-SRM": [ [31, 16], - [23, 8], - [6, 8] + [29, 14], + [6, 14], + [4, 12] ], "ISRM-RDM": [ - [11, 19], + [8, 18], + [9, 19], [28, 19] ], "CHM-SPM": [ @@ -190,66 +210,68 @@ [0, 8] ], "ISM-SLM": [ - [28, 9], - [24, 5], - [11, 5] + [24, 10], + [20, 6] ], "CRM-SRM": [ - [20, 6], - [15, 11], - [4, 11] + [12, 5], + [11, 6], + [7, 6], + [4, 9] ], "CRM-CSI": [ - [26, 4], - [32, 10], - [32, 14] + [20, 12], + [20, 15], + [22, 17], + [33, 17] ], "CHM-CSI": [ - [21, 22], - [28, 15], - [34, 15] + [20, 17], + [33, 17] ], "ISRM-SPM": [ - [8, 13], - [4, 9] + [8, 8] ], "ISRM-SLM": [ - [4, 12] + [8, 8], + [10, 6], + [18, 6] ], "CHM-SACM": [ - [19, 21], - [19, 15], - [12, 15] + [20, 17], + [19, 16], + [18, 16] ], "CHM-ISM": [ - [21, 21], - [21, 17] + [20, 17], + [25, 17], + [26, 16], + [26, 12] ], "CHM-ISRM": [ - [19, 22], - [16, 25], - [8, 25] + [19, 21], + [9, 21], + [8, 20] ], "SLM-SRM": [ - [11, 5], - [6, 5], - [3, 8], - [3, 9] - ], - "CAPM-SLM": [ - [17, 10], - [12, 5] + [18, 6], + [7, 6], + [4, 9] ], + "CAPM-SLM": [], "CONFM-ISRM": [ - [7, 17] + [12, 20], + [11, 19], + [9, 19], + [8, 18] ], "CONFM-PM": [ - [12, 20] + [12, 18], + [14, 18] ], "CHM-PM": [ - [21, 21], - [18, 18], - [18, 16] + [20, 17], + [19, 16] ] } } diff --git a/index.html b/index.html index b0453f1..d23a7f5 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@

FitSM Process Map

diff --git a/scripts/check.js b/scripts/check.js index 7517e07..6749b2b 100644 --- a/scripts/check.js +++ b/scripts/check.js @@ -7,7 +7,7 @@ * Consistency and contrast checks over the content store. * Contract: specs/001-fitsm-process-map/contracts/check-cli.md * - * node scripts/check.js [--content ] [--editions ] [--quiet] + * node scripts/check.js [--content ] [--editions ] [--quiet] [--layout] * * Exit 0: no errors. Exit 1: errors. Exit 2: could not run (missing or invalid files). * Uses Node built-ins only. @@ -17,6 +17,7 @@ import { readFileSync, existsSync, readdirSync } from "node:fs"; import { resolve, join, basename, dirname } from "node:path"; import { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; +import { layoutMetrics } from "./layout.js"; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const FILES = ["edition", "processes", "requirements", "roles", "activities", "records", "interfaces", "map"]; @@ -34,15 +35,17 @@ const PATTERNS = { /* ---------- CLI ---------- */ const args = process.argv.slice(2); -const opts = { content: null, editions: "content/editions.json", quiet: false }; +const opts = { content: null, editions: "content/editions.json", quiet: false, layout: false }; for (let i = 0; i < args.length; i++) { if (args[i] === "--content") opts.content = args[++i]; else if (args[i] === "--editions") opts.editions = args[++i]; else if (args[i] === "--quiet") opts.quiet = true; + else if (args[i] === "--layout") opts.layout = true; else fail(2, `Unknown option ${args[i]}`); } const findings = []; +const layoutLines = []; // map readability metrics, printed on stdout before the summary let itemsChecked = 0; function report(level, edition, file, item, message) { @@ -87,6 +90,7 @@ checkScripts(); const errors = findings.filter((f) => f.level === "error").length; const warnings = findings.length - errors; for (const f of findings) console.error(f.line); +if (!opts.quiet) for (const line of layoutLines) console.log(line); if (!opts.quiet) console.log(`${errors} errors, ${warnings} warnings, ${itemsChecked} items checked across ${editions.length} edition(s)`); process.exit(errors ? 1 : 0); @@ -288,7 +292,7 @@ function checkEdition({ id: ed, dir }) { } // 10. Map - const { grid, stations, routes, lines, transfer, background } = d.map; + const { grid, stations, routes, lines, transfer, background, zones = [] } = d.map; const positive = (n) => Number.isInteger(n) && n > 0; const gridOk = positive(grid.unit) && positive(grid.cols) && positive(grid.rows); if (!gridOk) err("map", "grid", "unit, cols and rows must be positive integers"); @@ -373,12 +377,68 @@ function checkEdition({ id: ed, dir }) { } itemsChecked++; } + // Transfers to draw first (optional): interface ids, each once. + const drawFirst = d.map.drawFirst ?? []; + if (!Array.isArray(drawFirst)) err("map", "drawFirst", "must be an array of interface ids"); + else for (const [k, id] of drawFirst.entries()) { + if (!interfaceIds.has(id)) err("map", "drawFirst", `"${id}" is not an interface`); + else if (drawFirst.indexOf(id) !== k) err("map", "drawFirst", `"${id}" is listed twice`); + } + + // 13. Halves (optional): bands of whole rows, each station in at most one, placed inside it. + const zoneIds = new Set(); + const zoneOf = new Map(); + if (!Array.isArray(zones)) err("map", "zones", "must be an array"); + for (const zone of Array.isArray(zones) ? zones : []) { + const item = `zones.${zone.id || "?"}`; + if (!PATTERNS.slug.test(zone.id || "")) err("map", item, "id must be a slug"); + if (zoneIds.has(zone.id)) err("map", item, "duplicate zone id"); + zoneIds.add(zone.id); + if (!zone.name) err("map", item, "missing name"); + if (!PATTERNS.colour.test(zone.fill || "")) err("map", item, `fill "${zone.fill}" is not #rrggbb`); + if (!["nw", "ne", "sw", "se"].includes(zone.label)) err("map", item, `label "${zone.label}" is not nw, ne, sw or se`); + const rowsOk = Number.isInteger(zone.top) && Number.isInteger(zone.bottom) && zone.top >= 0 && zone.top < zone.bottom && (!gridOk || zone.bottom <= grid.rows); + if (!rowsOk) err("map", item, "top and bottom must be integer rows with 0 <= top < bottom <= rows"); + for (const other of zones) { + if (other === zone || !rowsOk) continue; + if (zone.top < other.bottom && other.top < zone.bottom && zone.id < other.id) err("map", item, `overlaps zone "${other.id}"`); + } + for (const s of Array.isArray(zone.stations) ? zone.stations : []) { + if (!codes.has(s)) err("map", item, `process "${s}" does not exist`); + if (zoneOf.has(s)) err("map", item, `station ${s} is also in zone "${zoneOf.get(s)}"`); + zoneOf.set(s, zone.id); + const pos = stations[s]; + if (pos && rowsOk && !(pos.y > zone.top && pos.y < zone.bottom)) err("map", item, `station ${s} at row ${pos.y} is not inside rows ${zone.top}-${zone.bottom}`); + } + if (!Array.isArray(zone.stations)) err("map", item, "stations must be an array"); + } itemsChecked += d.processes.length; + // 14. Layout metrics (informational): how often routes cross, overlap or run close together. + const metrics = layoutMetrics(d.map); + const at = (p) => `(${p.join(",")})`; + const kinds = { merge: 0, line: 0, mixed: 0 }; + for (const s of metrics.shared) kinds[s.kind]++; + layoutLines.push(`layout ${ed}/map.json: ${metrics.crossingPoints} crossing points (${metrics.crossings.length} crossings between pairs), ` + + `${metrics.shared.length} shared segments (${kinds.merge} transfer merges, ${kinds.line} within a line, ${kinds.mixed} mixed), ` + + `${metrics.close.length} close parallels`); + if (opts.layout) { + for (const c of metrics.crossings) layoutLines.push(` crossing ${c.a} x ${c.b} at ${at(c.at)}`); + for (const s of metrics.shared) layoutLines.push(` shared ${s.a} = ${s.b} from ${at(s.from)} to ${at(s.to)} (${s.kind})`); + for (const c of metrics.close) layoutLines.push(` close ${c.a} ~ ${c.b} from ${at(c.from)} to ${at(c.to)}, ${c.distance} apart`); + } + + // Line and transfer colours sit on the background and on every zone fill. function checkContrast(item, colour) { - if (!PATTERNS.colour.test(background || "")) return; - const ratio = contrast(colour, background); - if (ratio < 3) err("map", item, `colour ${colour} has contrast ${ratio.toFixed(1)}:1 against background (needs 3:1)`); + if (PATTERNS.colour.test(background || "")) { + const ratio = contrast(colour, background); + if (ratio < 3) err("map", item, `colour ${colour} has contrast ${ratio.toFixed(1)}:1 against background (needs 3:1)`); + } + for (const zone of Array.isArray(zones) ? zones : []) { + if (!PATTERNS.colour.test(zone.fill || "")) continue; + const ratio = contrast(colour, zone.fill); + if (ratio < 3) err("map", item, `colour ${colour} has contrast ${ratio.toFixed(1)}:1 against zone "${zone.id}" (needs 3:1)`); + } } } @@ -388,7 +448,7 @@ function checkScripts() { // Resolved from this script's location, so the check works from any working directory. const files = []; if (existsSync(join(ROOT, "src"))) for (const f of readdirSync(join(ROOT, "src"))) if (f.endsWith(".js")) files.push(join("src", f)); - files.push(join("scripts", "check.js")); + files.push(join("scripts", "check.js"), join("scripts", "layout.js")); for (const file of files) { if (!existsSync(join(ROOT, file))) continue; try { diff --git a/scripts/layout.js b/scripts/layout.js new file mode 100644 index 0000000..a3db613 --- /dev/null +++ b/scripts/layout.js @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: 2026 PNED G.I.E. +// +// SPDX-License-Identifier: CC-BY-4.0 + +/* + * Readability metrics for the map layout, in grid units. Used by check.js; pure, no I/O. + * + * Each interface's route is a polyline from its first station through its waypoints to its + * second station. For every pair of routes it finds: + * - crossings: distinct points where the two routes meet, other than a station both end at; + * - shared segments: stretches where the two routes lie on top of each other, of kind + * "merge" (two transfers running as one trunk), "line" (two connections of the same + * line) or "mixed" (any other pair, such as a transfer over a line); + * - close parallels: parallel stretches at most CLOSE grid units apart. + * `crossingPoints` counts the distinct points among the crossings: a trunk of several routes + * crossing a line is one crossing point on the map but one crossing per route. + */ + +const CLOSE = 1; +const EPS = 1e-9; + +const round = (v) => Math.round(v * 1000) / 1000; +const pointKey = (p) => `${round(p[0])},${round(p[1])}`; + +/* Compares segment p-q with segment r-s and records what it finds in `out`. */ +function compareSegments(p, q, r, s, out) { + const d = (q[0] - p[0]) * (s[1] - r[1]) - (q[1] - p[1]) * (s[0] - r[0]); + if (Math.abs(d) > EPS) { + const t = ((r[0] - p[0]) * (s[1] - r[1]) - (r[1] - p[1]) * (s[0] - r[0])) / d; + const u = ((r[0] - p[0]) * (q[1] - p[1]) - (r[1] - p[1]) * (q[0] - p[0])) / d; + if (t >= -EPS && t <= 1 + EPS && u >= -EPS && u <= 1 + EPS) out.points.push([p[0] + t * (q[0] - p[0]), p[1] + t * (q[1] - p[1])]); + return; + } + // Parallel: how far apart, and how long they run side by side. + const len = Math.hypot(q[0] - p[0], q[1] - p[1]); + const dir = [(q[0] - p[0]) / len, (q[1] - p[1]) / len]; + const dist = Math.abs(dir[0] * (r[1] - p[1]) - dir[1] * (r[0] - p[0])); + const along = (v) => (v[0] - p[0]) * dir[0] + (v[1] - p[1]) * dir[1]; + const lo = Math.max(0, Math.min(along(r), along(s))); + const hi = Math.min(len, Math.max(along(r), along(s))); + const from = [p[0] + dir[0] * lo, p[1] + dir[1] * lo]; + const to = [p[0] + dir[0] * hi, p[1] + dir[1] * hi]; + if (dist < EPS) { + if (hi - lo > EPS) out.shared.push({ from, to }); + else if (hi - lo > -EPS) out.points.push(from); // collinear, touching end to end + } else if (dist <= CLOSE + EPS && hi - lo > EPS) { + out.close.push({ from, to, distance: round(dist) }); + } +} + +/* Metrics for a map.json object. Routes whose stations are missing are skipped. */ +export function layoutMetrics(map) { + const routes = []; + for (const [id, waypoints] of Object.entries(map.routes || {})) { + const ends = id.split("-"); + const [a, b] = ends.map((code) => map.stations[code]); + if (!a || !b || !Array.isArray(waypoints)) continue; + // The first line with both ends on it, as on the page; null for a transfer. + const line = (map.lines || []).find((l) => l.stations.includes(ends[0]) && l.stations.includes(ends[1])); + routes.push({ id, ends, line: line ? line.id : null, points: [[a.x, a.y], ...waypoints, [b.x, b.y]] }); + } + const kind = (A, B) => (!A.line && !B.line ? "merge" : A.line === B.line ? "line" : "mixed"); + const crossings = [], shared = [], close = []; + for (let i = 0; i < routes.length; i++) { + for (let j = i + 1; j < routes.length; j++) { + const A = routes[i], B = routes[j]; + const out = { points: [], shared: [], close: [] }; + for (let k = 1; k < A.points.length; k++) { + for (let l = 1; l < B.points.length; l++) compareSegments(A.points[k - 1], A.points[k], B.points[l - 1], B.points[l], out); + } + // Two routes leaving the same station meet there by design; that is not a crossing. + const station = new Set(A.ends.filter((c) => B.ends.includes(c)).map((c) => pointKey([map.stations[c].x, map.stations[c].y]))); + const onShared = (key) => out.shared.some(({ from, to }) => [from, to].some((p) => pointKey(p) === key)); + for (const key of new Set(out.points.map(pointKey))) { + if (!station.has(key) && !onShared(key)) crossings.push({ a: A.id, b: B.id, at: key.split(",").map(Number) }); + } + for (const s of out.shared) shared.push({ a: A.id, b: B.id, kind: kind(A, B), from: s.from.map(round), to: s.to.map(round) }); + for (const c of out.close) close.push({ a: A.id, b: B.id, from: c.from.map(round), to: c.to.map(round), distance: c.distance }); + } + } + const crossingPoints = new Set(crossings.map((c) => c.at.join(","))).size; + return { crossings, crossingPoints, shared, close }; +} diff --git a/specs/001-fitsm-process-map/contracts/check-cli.md b/specs/001-fitsm-process-map/contracts/check-cli.md index 86c433f..d304246 100644 --- a/specs/001-fitsm-process-map/contracts/check-cli.md +++ b/specs/001-fitsm-process-map/contracts/check-cli.md @@ -7,14 +7,15 @@ of constitution VI and the test for FR-027 and SC-006. Revised for edition direc ## Invocation ```bash -node scripts/check.js [--content ] [--quiet] +node scripts/check.js [--content ] [--editions ] [--quiet] [--layout] ``` | Option | Default | Meaning | |---|---|---| | `--content ` | none | Check one edition directory (the eight files) instead of reading an editions file | | `--editions ` | `content/editions.json`, relative to the current working directory | The editions file to read; every listed edition is checked. Edition `path`s inside it resolve relative to the file's own directory. Ignored when `--content` is given | -| `--quiet` | off | Print errors and warnings only; suppress the summary line | +| `--quiet` | off | Print errors and warnings only; suppress the layout and summary lines | +| `--layout` | off | After each edition's layout line, list every crossing, shared segment and close parallel with its grid coordinates | No dependencies beyond `node:fs`, `node:path` and `node:child_process` (for `node --check`). Requires Node 22 or later. @@ -29,14 +30,25 @@ Requires Node 22 or later. ## Output format -One line per finding on stderr (errors and warnings), summary on stdout: +One line per finding on stderr (errors and warnings); on stdout, one layout line per edition +and then the summary: ```text error /: : warning /: : +layout /map.json: crossing points ( crossings between pairs), shared segments ( transfer merges, within a line, mixed),

close parallels errors, warnings, items checked across edition(s) ``` +With `--layout`, each layout line is followed by one indented line per item, in grid +coordinates: + +```text + crossing SACM-SLM x CRM-SPM at (12,6) + shared SACM-SLM = CAPM-SLM from (20,6) to (20,4) (line) + close CONFM-RDM ~ ISRM-RDM from (14,20) to (26,20), 1 apart +``` + With `--content

`, `` is the directory's base name. Examples: @@ -89,8 +101,20 @@ than stopping at the first. transfer colour ≥ 3:1 against `background`. 12. **Line connectivity** (warning): members of each line reachable from each other through same-line connections. -13. **Scripts parse** (once, not per edition): `node --check` on every file in `src/` and on - `scripts/check.js`. + `map.drawFirst`, if present, is an array of interface ids, each listed once. +13. **Halves** (`map.zones`, optional): ids are unique slugs; each has a name, a `#rrggbb` + fill, integer rows `0 <= top < bottom <= rows` and a `label` corner `nw`, `ne`, `sw` or + `se`; bands do not overlap; each listed station exists, is in one half only and sits + strictly inside its rows. Line and transfer colours are also ≥ 3:1 against every fill. +14. **Layout metrics** (informational, never an error or warning; `scripts/layout.js`): for + every pair of routes, in grid units: *crossings*, the distinct points where they meet + other than a station both end at; *shared segments*, stretches where they lie on top of + each other, classed as *transfer merges* (two transfers on one trunk), *within a line* + (two connections of the same line) or *mixed* (any other pair, such as a transfer over a + line); *close parallels*, parallel stretches at most 1 grid unit apart. *Crossing points* + counts the distinct points among all crossings, so a trunk crossing a line counts once. +15. **Scripts parse** (once, not per edition): `node --check` on every file in `src/` and on + `scripts/check.js` and `scripts/layout.js`. ## Tests diff --git a/specs/001-fitsm-process-map/contracts/content-files.md b/specs/001-fitsm-process-map/contracts/content-files.md index 4ba4165..84a3d2e 100644 --- a/specs/001-fitsm-process-map/contracts/content-files.md +++ b/specs/001-fitsm-process-map/contracts/content-files.md @@ -35,7 +35,7 @@ parallel, from the same origin: | `activities.json` | array of Activity | Activities with procedure steps | | `records.json` | array of Record | Records with FitSM-0 definitions and derived usage | | `interfaces.json` | array of Interface | One per connected process pair (descriptions and/or flows) | -| `map.json` | object | Lines with name-label sides, station grid positions, route waypoints, styles | +| `map.json` | object | Halves (`zones`, optional), lines with name-label sides, station grid positions, route waypoints (routes may share stretches), transfers to draw first (`drawFirst`, optional), styles | If `editions.json` or any edition file fails to load or parse, the page shows a single error message in the frame naming the file (`Could not load content//`), and draws @@ -85,6 +85,15 @@ Edit `map.json.lines` only. Membership, names, colours and label sides are free checks verify that every process is on a line, that colours pass contrast, and warn when a line's stations are not connected through interfaces. Nothing in `src/` needs to change. +## Routing connections (map layout) + +Edit `map.json.routes` (and, to choose which transfer breaks at a crossing, `drawFirst`). +Transfers leaving the same station may share waypoints and run as one trunk, and connections +of one line may share a stretch; a transfer should not run along a line's connection. Run +`node scripts/check.js --layout` and compare the layout line before and after: fewer crossing +points and close parallels and no *mixed* shared segments is better. Open the page with +`?grid` to see the grid coordinates. Nothing in `src/` needs to change. + ## What the page does with interpretation and fixed sentences | Field or case | How the page shows it | @@ -94,4 +103,5 @@ line's stations are not connected through interfaces. Nothing in `src/` needs to | `interfaces[].descriptions` empty | Fixed sentence in place of the description: "FitSM-2 lists these inputs and outputs but gives no interface description." | | `processes[].externalFlows` non-empty | Section "Inputs from and outputs to outside the processes" with direction, party, item, source | | `interfaces[].note`, any `note` | Box "Not part of FitSM" | -| `map.json.lines` | Legend entries (name and colour) under the heading "Lines are a study aid, not part of FitSM", and `map.json.note` | +| `map.json.zones` | Shaded bands on the map with their names; legend entries under the heading "Halves and lines are a study aid, not part of FitSM"; the half named in the station's spoken name and frame subtitle | +| `map.json.lines` | Legend entries (name and colour) under the heading "Halves and lines are a study aid, not part of FitSM", and `map.json.note` | diff --git a/specs/001-fitsm-process-map/contracts/url-hash.md b/specs/001-fitsm-process-map/contracts/url-hash.md index 85dd0f8..01da042 100644 --- a/specs/001-fitsm-process-map/contracts/url-hash.md +++ b/specs/001-fitsm-process-map/contracts/url-hash.md @@ -8,10 +8,11 @@ resolve after a content update (FR-022, FR-023, edge case "renamed process"). ```text hash = "" | "#" selection -selection = process | general | interface | role | activity | record +selection = process | general | interface | interfaces | role | activity | record process = CODE ; "#ISRM" general = "GR" ; "#GR" general requirements interface = CODE "-" CODE ; "#ISRM-PM" alphabetical order is canonical +interfaces = interface 1*("," interface) ; "#CHM-ISRM,CONFM-ISRM" sorted, no duplicates role = "role/" ROLE_ID ; "#role/ISRM.manager" activity = "activity/" ACTIVITY_ID ; "#activity/ISRM.A1" record = "record/" RECORD_ID ; "#record/incident-record" @@ -31,6 +32,7 @@ Matching is case-sensitive except for `CODE`, which is upper-cased before lookup | `#` where code is in some process's `aliases` | Redirect: hash replaced with the current code (no history entry), then as above | | `#A-B` where `A-B` is an interface id | Interface view; connection highlighted | | `#B-A` (wrong order) | Redirect to `#A-B` (no history entry) | +| `#A-B,C-D,…` where every pair is an interface | Several-connections view: each connection's description and flows, each with a link to its own view; all of them highlighted, each with its flow markers. Unsorted, reversed, aliased or repeated pairs redirect to the sorted canonical list; a list that reduces to one interface redirects to `#A-B`; one unknown pair makes the whole address not found | | `#role/`, `#activity/`, `#record/` that exists | That view; the owning process's station highlighted (records: no highlight) | | anything else | Not-found view: "No item called ``" and the list of the 14 process codes as links (FR-024); nothing highlighted | @@ -44,12 +46,16 @@ Matching is case-sensitive except for `CODE`, which is upper-cased before lookup belongs to this page (`app.js` tags every entry with its depth in `history.state`). At the page's first entry: role or activity → its process; interface or record → `#` (nothing). - The hash is read once on load (User Story 1, scenario 4) and on every `hashchange`. +- A pointer click on a connection where other connections are drawn along the same stretch + goes to the several-connections address for all of them (`app.js`, using + `connectionsAt` in `map.js`); a keyboard Enter on a connection, which has no position, + goes to that connection alone. ## Router API (`src/router.js`, pure) ```js -parse(hash: string): { kind: "none"|"process"|"general"|"interface"|"role"|"activity"|"record"|"unknown", id?: string, raw: string } -format(kind: string, id?: string): string // inverse of parse; returns "#..." or "" +parse(hash: string): { kind: "none"|"process"|"general"|"interface"|"interfaces"|"role"|"activity"|"record"|"unknown", id?: string, ids?: string[], raw: string } +format(kind: string, id?: string | string[]): string // inverse of parse; returns "#..." or "" (ids for "interfaces") canonical(parsed, model): { hash: string, redirect: boolean } // applies alias and order rules ``` diff --git a/specs/001-fitsm-process-map/data-model.md b/specs/001-fitsm-process-map/data-model.md index f7e823d..a58f793 100644 --- a/specs/001-fitsm-process-map/data-model.md +++ b/specs/001-fitsm-process-map/data-model.md @@ -206,6 +206,19 @@ Study aid, not FitSM content (FR-003). Rules: every process appears in at least one line (error); when two connected processes share several lines, the first line in file order colours the connection. +### Half (`map.json` `zones`) + +Study aid, not FitSM content (FR-036). Optional. + +| Field | Type | Rule | +|---|---|---| +| `id` | string | slug; unique | +| `name` | string | Shown on the map, in the legend and in the frame | +| `fill` | string | `#rrggbb`; every line colour and the transfer colour keep contrast ≥ 3:1 against it | +| `top`, `bottom` | integer | Grid rows the band covers, `0 <= top < bottom <= rows`; bands do not overlap; a band at the grid's edge extends into the margin | +| `label` | enum | Corner for the name: `nw`, `ne`, `sw` or `se` | +| `stations` | string[] | Process codes in this half; each exists, is in one half only and sits strictly inside the rows | + ### Map layout (`map.json`) ```json @@ -227,6 +240,12 @@ several lines, the first line in file order colours the connection. | `routes` | One entry per interface id; waypoints are grid points; empty array = straight segment; each consecutive pair must be horizontal, vertical or 45° | | `transfer` | Style for cross-line connections: `colour` (contrast ≥ 3:1) and `width` in px, thinner than line strokes; drawn solid | | `grid.margin` | Optional `{ x, y }` in grid cells added around the grid for edge labels (default 2 and 1) | +| `zones` | Optional; the halves (see Half) | +| `drawFirst` | Optional array of interface ids, each once: transfers drawn before the other transfers, so that those yield where they cross them (FR-003) | + +Routes MAY share stretches: transfers with transfers (a trunk) and connections of one line +with each other. A transfer sharing a stretch with a line's connection, or two lines sharing a +stretch, is reported by the checks as a *mixed* shared segment (FR-037). ## Derived values (computed by `content.js` / `graph.js`, never stored) diff --git a/specs/001-fitsm-process-map/plan.md b/specs/001-fitsm-process-map/plan.md index 720a9b9..bdb3224 100644 --- a/specs/001-fitsm-process-map/plan.md +++ b/specs/001-fitsm-process-map/plan.md @@ -140,9 +140,11 @@ content/ ├── interfaces.json # One entry per connected process pair: descriptions + flows └── map.json # Lines (study aid), station grid positions, route waypoints scripts/ -└── check.js # Consistency and contrast checks (contracts/check-cli.md) +├── check.js # Consistency and contrast checks (contracts/check-cli.md) +└── layout.js # Pure: layout metrics for map.json (crossings, shared segments, + # close parallels), reported by check.js tests/ -├── content.test.js, graph.test.js, router.test.js, check.test.js +├── content.test.js, graph.test.js, router.test.js, check.test.js, map.test.js, layout.test.js └── fixtures/ # valid/ and broken// content directories for check.test.js .github/ ├── workflows/test.yml, main.yml, release.yml # rewritten from the existing files diff --git a/specs/001-fitsm-process-map/quickstart.md b/specs/001-fitsm-process-map/quickstart.md index 4ad657f..19304b2 100644 --- a/specs/001-fitsm-process-map/quickstart.md +++ b/specs/001-fitsm-process-map/quickstart.md @@ -87,6 +87,11 @@ Each scenario maps to a spec acceptance scenario (US = user story). Tick each wh - [ ] 2.4 In the interface frame, click the **PM** name. The PM process frame opens. - [ ] 2.5 Type `#PM-ISRM` in the address bar. It redirects to `#ISRM-PM` and the browser back button does not return to `#PM-ISRM`. +- [ ] 2.6 Click the grey trunk just above **CHM**, where several transfers run together. The + frame says how many connections run there and lists each with its description, flows + and a link to its own view; the map highlights all of them, each with its markers. The + address lists them, for example `#CAPM-CHM,CHM-CRM,…`. Tab to one of those connections + and press Enter instead: only that connection opens. ### US3: Roles and activities @@ -133,7 +138,9 @@ Each scenario maps to a spec acceptance scenario (US = user story). Tick each wh stations → legend → frame; every focusable element shows a visible focus ring; Enter opens it. - [ ] E4 A cross-line connection is a thin solid grey stroke; where connections cross, one - stops short of the other with a tick at each end and resumes beyond it; a same-line + stops short of the other with a tick at each end and resumes beyond it; where a grey + connection leaves a shared trunk it curves away with no gap; no grey stroke runs along + a coloured one; the two halves are shaded with their names; a same-line connection has the line's colour; no line names appear on the map itself; the legend names every line and says it is a study aid. diff --git a/specs/001-fitsm-process-map/research.md b/specs/001-fitsm-process-map/research.md index 8dbcd9e..1f60460 100644 --- a/specs/001-fitsm-process-map/research.md +++ b/specs/001-fitsm-process-map/research.md @@ -50,7 +50,10 @@ shows it when opened. Line names are not drawn on the map: the legend beside the frame's wording identify lines (FR-006). Stations and connections are SVG `` elements. Each connection has a wide transparent stroke under the visible one as a hit area. The SVG uses `viewBox` and scales to its container; under 900 px the container -scrolls horizontally. +scrolls horizontally. Bends are drawn as quadratic curves (radius 36 px), shrunk where the +segments are short or a crossing's gap needs the room. The optional halves (`zones`) are +shaded bands drawn first; an optional grid overlay (`SHOW_GRID` in `map.js`, or `?grid`) is +drawn over them for maintainers. **Rationale**: SVG is resolution-independent, styleable with CSS and accessible through native links. Generating it from data keeps the layout editable without touching code (FR-025). @@ -156,9 +159,18 @@ plain links. heading is announced exactly once. `document.title` follows the selection. - Lines are told apart by name: the legend (name + swatch + "study aid") and the frame's wording; nothing on the map relies on reading a line's name. The transfer style is a thinner solid grey stroke, so width - differs as well as colour. Connections never share a segment; at crossings the later-drawn - connection yields: it stops short of the other with a short perpendicular tick at each end - and resumes beyond it, so the crossing line stays unbroken. + differs as well as colour. Transfers may share a stretch (a trunk) and connections of one line + may share a stretch; at crossings the later-drawn connection yields: it stops short of the + other with a short perpendicular tick at each end and resumes beyond it, so the crossing line + stays unbroken. Lines are drawn first, then the transfers named in `map.drawFirst`, then the + rest. A bend where a route joins or leaves a stretch it shares is a junction, not a crossing: + no gap. On a shared stretch a route does not yield to a crossing that an earlier route on the + same stretch already made yield, so a trunk is broken at most once per crossing. +- A pointer click on a connection looks up every route running along the same stretch at the + click point (parallel and within half a unit; a line merely crossing there does not count). + Several give the address `#A-B,C-D`: the frame lists each connection and the map highlights + and animates each. A keyboard Enter (`event.detail === 0`) has no position and opens the + focused connection alone. - `check.js` computes WCAG 2.1 contrast: each line colour and the transfer colour against the map background ≥ 3:1; label text ≥ 4.5:1. - Focus is visible on every link (`:focus-visible` outline, 3 px, ≥ 3:1 against white). diff --git a/specs/001-fitsm-process-map/spec.md b/specs/001-fitsm-process-map/spec.md index c19a119..123d422 100644 --- a/specs/001-fitsm-process-map/spec.md +++ b/specs/001-fitsm-process-map/spec.md @@ -49,6 +49,25 @@ "transfer"); the map has a short spoken description; a new selection is announced when the frame updates; the legend is readable text. +### Session 2026-10-22 (map layout) + +- Q: May two connections be drawn along the same stretch of the map? → A: Transfers may run + together as a shared trunk and branch off where their routes part, like tracks at a junction; + two connections of the same line may also share a stretch. A transfer never runs along a + coloured line, and two lines of different colours never share a stretch. +- Q: What does a click on a stretch shared by several connections open? → A: All of them: the + frame lists each connection's description and flows with a link to its own view, and the map + highlights and animates each. A keyboard selection, which has no position, opens the focused + connection alone. +- Q: How are bends drawn? → A: As curves, so that a branch peels off a trunk smoothly instead of + meeting it at a corner that looks like half a crossing. A curve next to a crossing is made + tighter, down to a sharp corner, so the crossing's gap always fits. +- Q: Which connection breaks where two cross? → A: The one drawn later. Lines are drawn before + transfers; the map content may name transfers to draw first, so that the others break where + they cross them. +- Q: Should the map show FitSM's split into Plan & Deliver and Operate & Control? → A: Yes, as + two shaded halves with their names, labelled as a study aid like the lines. + ## User Scenarios & Testing *(mandatory)* ### User Story 1 - Explore a process from the map (Priority: P1) @@ -114,6 +133,9 @@ cites the source. visitor opens the connection, **Then** each direction is shown separately and clearly. 4. **Given** a relationship is shown in the frame, **When** the visitor clicks either process name in the frame, **Then** that process's detail opens (User Story 1). +5. **Given** several transfers run together along a stretch of the map, **When** the visitor + clicks that stretch, **Then** the frame lists every connection running there, each with its + description and flows and a link to its own view, and the map highlights all of them. --- @@ -208,7 +230,10 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence - A process has interfaces with many other processes. The map must still be readable, which means: no station label overlaps another label or a stroke; no segment passes through a station it does not end at; parallel segments between the same two stations do not overlap. - Routes may bend, and a station shared by several lines is drawn as an interchange. + Routes may bend, and a station shared by several lines is drawn as an interchange. Transfers + leaving a busy station may run together as a trunk and branch off later (FR-003). +- Several connections run along the same stretch. A click there selects all of them (FR-005); + each can still be opened on its own from the frame or with the keyboard. - Two processes have interfaces in both directions. The connection is one clickable element, and the frame separates the two directions. - Two connected processes are on different lines. The connection is drawn once, in the neutral @@ -276,10 +301,16 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence "Control"), with a name and a colour. A connection between two processes on the same line is drawn once in that line's colour. A connection between processes on different lines is drawn once in a neutral "transfer" style: a solid grey stroke thinner than the line strokes, - so that it differs from every line in width as well as colour. No interface is drawn twice, - and no two connections share a segment; where one connection crosses another, one of them - yields: it stops short of the other with a short perpendicular tick at each end and resumes - beyond it, so each can be followed through the crossing. Every process MUST belong to at least one line and + so that it differs from every line in width as well as colour. No interface is drawn twice. + Transfers MAY run together along a shared stretch (a trunk) and branch off where their routes + part, and connections of the same line MAY share a stretch; a transfer MUST NOT run along a + line's connection, and connections of two different lines MUST NOT share a stretch. Where a + connection joins or leaves a shared stretch it curves smoothly, with no gap. Where one + connection crosses another, the one drawn later yields: it stops short of the other with a + short perpendicular tick at each end and resumes beyond it, so each can be followed through + the crossing. Lines are drawn before transfers; the map content MAY name transfers to draw + before the other transfers. Bends are drawn as curves, tightened (down to a sharp corner) where + a crossing's gap needs the room. Every process MUST belong to at least one line and MAY belong to several. When two connected processes share more than one line, the line listed first in the content wins. A line is never drawn as a separate track between members that FitSM does not connect (FR-002). The grouping is not part of FitSM: it MUST be labelled @@ -295,7 +326,11 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence shows a soft halo in its own colour behind it, and the selection is marked as current for assistive technology. Highlighting MUST NOT rely on colour alone. Clicking the selected station or connection again MUST - deselect it and return the map to the state with nothing selected (FR-035). While a role or activity is shown, its owning process's station stays + deselect it and return the map to the state with nothing selected (FR-035). A pointer click + on a stretch where several connections run together MUST select all of them: the frame lists + each with its description and flows and a link to its own view, and each is highlighted and + animated on the map; the selection has its own address (`#A-B,C-D`). A keyboard selection + opens the focused connection alone. While a role or activity is shown, its owning process's station stays highlighted; while a record, the general requirements, the not-found view or nothing is shown, no station is highlighted. - **FR-006**: Lines MUST be distinguishable without relying on colour alone. A legend next to @@ -415,7 +450,8 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence - **FR-027**: Automated checks MUST verify that every reference between items resolves, that every process has at least an objective, requirements, roles and activities, that every connection joins two known processes and has a drawable route, that every process belongs - to at least one line, and that every item has a source reference. All of these are errors + to at least one line, that every process listed in a half (FR-036) sits inside it, and that + every item has a source reference. All of these are errors and fail the checks with a message that names the offending item. One finding is a warning that does not fail the checks: a line whose member processes are not all connected to each other through that line's own connections. @@ -456,6 +492,18 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence - **FR-035**: When nothing is selected (the address has no item), the frame MUST show an intro view: what the map shows, how to use it (click a station or a connection; use the keyboard), and the edition line. No station is highlighted. +- **FR-036**: The map MUST show its two halves, Plan & Deliver and Operate & Control, as shaded + bands behind the lines, each with its name. Each process belongs to at most one half, which + the legend, the station's spoken name and the process view's subtitle name in words. The + halves are a study aid like the lines (FR-003): labelled as not part of FitSM, and defined in + the map content so a maintainer can change them without touching behaviour. +- **FR-037**: The automated checks MUST report, for information only, how readable the map + layout is: the crossing points on the map, the stretches where connections share a segment + (split into transfer merges, stretches within one line, and mixed pairs), and the parallel + stretches at most one grid cell apart. These never fail the checks. +- **FR-038**: For maintainers, the map MAY draw the grid that stations and bends sit on, with + row and column numbers. It is off unless switched on in the page code or by adding `?grid` + to the address. ### Key Entities @@ -496,6 +544,8 @@ to fitsm.eu. Open the repository and find the licence file and per-file licence lines are neutral. When members share more than one line, the line listed first applies. The grouping is a study aid, not part of FitSM, and is labelled as interpretation wherever it is shown. +- **Half**: Plan & Deliver or Operate & Control: a band of the map with a name and the + processes in it. A study aid like the lines, labelled as such. - **Source reference**: The FitSM document, version and section (or identifier) an item comes from. Attached to every content item. diff --git a/src/app.js b/src/app.js index fdffe8a..d70cb13 100644 --- a/src/app.js +++ b/src/app.js @@ -11,7 +11,7 @@ import { loadContent } from "./content.js"; import { parse, canonical, format } from "./router.js"; -import { renderMap, setSelected } from "./map.js"; +import { renderMap, setSelected, connectionsAt } from "./map.js"; import { render } from "./panel.js"; const SITE_TITLE = "FitSM Process Map"; @@ -49,13 +49,25 @@ async function start() { renderLegend(state.model); renderFooter(state.model); window.addEventListener("hashchange", route); - // Clicking the selected station or connection again deselects it. + // A pointer click on a connection selects every connection drawn along that stretch + // (a keyboard Enter has no position and selects the focused one). Clicking the current + // selection again deselects it. dom.map.addEventListener("click", (event) => { const link = event.target.closest("a[data-hash]"); - if (!link || link.dataset.hash !== state.current) return; + if (!link) return; + let target = link.dataset.hash; + if (event.detail > 0 && link.closest(".connections")) { + const ids = connectionsAt(dom.map, target.slice(1), event.clientX, event.clientY); + if (ids.length > 1) target = format("interfaces", ids); + } + if (target === link.dataset.hash && target !== state.current) return; // the link's own navigation event.preventDefault(); - history.pushState({ depth: state.depth + 1 }, "", location.pathname + location.search); - route(); + if (target === state.current) { + history.pushState({ depth: state.depth + 1 }, "", location.pathname + location.search); + route(); + } else { + location.hash = target; + } }); route(); } @@ -105,6 +117,12 @@ function route() { title = `${a} ↔ ${b} – ${SITE_TITLE}`; break; } + case "interfaces": { + render("interfaces", result.ids.map((id) => model.interfaces.get(id)), ctx); + setSelected(dom.map, result.hash); + title = `${result.ids.length} connections – ${SITE_TITLE}`; + break; + } case "role": { const role = model.roles.get(result.id); render("role", role, ctx); @@ -164,6 +182,14 @@ function goBack() { } function renderLegend(model) { + const zones = (model.map.zones || []).map((zone) => { + const li = document.createElement("li"); + const swatch = document.createElement("span"); + swatch.className = "swatch swatch-zone"; + swatch.style.background = zone.fill; + li.append(swatch, document.createTextNode(`${zone.name} half`)); + return li; + }); const items = model.map.lines.map((line) => { const li = document.createElement("li"); const swatch = document.createElement("span"); @@ -177,7 +203,7 @@ function renderLegend(model) { swatch.className = "swatch swatch-transfer"; swatch.style.background = model.map.transfer.colour; transfer.append(swatch, document.createTextNode("Thin grey: transfer between lines")); - dom.legend.replaceChildren(...items, transfer); + dom.legend.replaceChildren(...zones, ...items, transfer); } function renderFooter(model) { diff --git a/src/graph.js b/src/graph.js index 0dd322c..80d0b80 100644 --- a/src/graph.js +++ b/src/graph.js @@ -5,7 +5,7 @@ /* * Line and label helpers for the map (research R3, R8, R10). * - * Model fields used: `model.map` (map.json), `model.processes` (Map by code, + * Model fields used: `model.map` (map.json, `zones` optional), `model.processes` (Map by code, * each with `name`), `model.interfaces` (Map by id, each with `processes: [a, b]`). * Pure: no DOM access. */ @@ -15,6 +15,11 @@ export function stationLines(code, model) { return model.map.lines.filter((line) => line.stations.includes(code)); } +/* The half of the map (map.zones) the station is in, or null. */ +export function stationZone(code, model) { + return (model.map.zones || []).find((zone) => zone.stations.includes(code)) || null; +} + export function isInterchange(code, model) { return stationLines(code, model).length >= 2; } @@ -41,12 +46,15 @@ function lineNames(lines) { return `${names.join(", ")} and ${last} lines`; } -/* Spoken name of a station: "Incident and service request management, ISRM, on the Operations line". */ +/* Spoken name of a station: + * "Incident and service request management, ISRM, in Operate & Control, on the Operations line". */ export function stationLabel(code, model) { const process = model.processes.get(code); const lines = stationLines(code, model); + const zone = stationZone(code, model); + const half = zone ? `, in ${zone.name}` : ""; const where = lines.length ? `, on the ${lineNames(lines)}` : ""; - return `${process.name}, ${code}${where}`; + return `${process.name}, ${code}${half}${where}`; } /* Spoken name of a connection: "Interface between and , Operations line". */ diff --git a/src/map.js b/src/map.js index 87a8bd6..468dc61 100644 --- a/src/map.js +++ b/src/map.js @@ -18,7 +18,11 @@ const STATION_RADIUS = 11; const RING_STEP = 5; const GAP_HALF = 7; // half the length of the gap a yielding line leaves at a crossing const TICK = 4; // half the length of the perpendicular tick at each end of the gap +const CORNER_RADIUS = 36; // radius of the curve drawn at a route's bend, so a branch peels off smoothly const DEFAULT_MARGIN = { x: 2, y: 1 }; +// Layout aid: draw the grid that stations and route bends sit on, with row and column +// numbers in the margins. Off by default; also switched on by adding ?grid to the address. +const SHOW_GRID = false; function el(name, attrs = {}, children = []) { const node = document.createElementNS(SVG_NS, name); @@ -46,6 +50,15 @@ function unitVector(p, q) { return [(q[0] - p[0]) / len, (q[1] - p[1]) / len]; } +function pointEquals(p, q) { + return Math.abs(p[0] - q[0]) < 1e-6 && Math.abs(p[1] - q[1]) < 1e-6; +} + +/* True when two unit vectors point along the same line (either way). */ +function parallel(u, v) { + return Math.abs(u[0] * v[1] - u[1] * v[0]) < 1e-6; +} + /* Parameter (0..1, exclusive) of point v along segment p-q when v lies strictly inside it, else null. */ function alongSegment(v, p, q) { const cross = (q[0] - p[0]) * (v[1] - p[1]) - (q[1] - p[1]) * (v[0] - p[0]); @@ -68,24 +81,35 @@ export function intersection(p1, p2, p3, p4) { /* Path data for a polyline that yields at every crossing with `others` (arrays of points): * the line stops short of the crossing line, with a short tick at each end drawn parallel * to the crossing line, and resumes on the other side. The crossing line itself stays - * unbroken. At shallow angles the gap widens so the ticks still clear the crossing line. */ -export function yieldingPath(points, others) { + * unbroken. At shallow angles the gap widens so the ticks still clear the crossing line. + * Bends are drawn as curves of the given radius (smaller where the segments are short), so a + * route leaving a shared trunk curves away from it instead of meeting it at a corner. */ +export function yieldingPath(points, others, radius = CORNER_RADIUS) { let d = `M${points[0][0]} ${points[0][1]}`; // A bend sitting exactly on a line is a crossing that `intersection` never reports (it is // an end point of a segment on one side), so vertices are tested separately, both ways: // this route's own bends against the other lines, and the other lines' bends against - // this route's segments. - const vertexHit = (v) => { + // this route's segments. Where the two run along the same stretch on one side of the bend, + // the bend is a junction (one route branching off a shared trunk), not a crossing. + const vertexHit = (i) => { + const v = points[i]; + const own = [unitVector(points[i - 1], v), unitVector(v, points[i + 1])]; for (const other of others) { for (let k = 1; k < other.length; k++) { - if (alongSegment(v, other[k - 1], other[k]) !== null) return unitVector(other[k - 1], other[k]); + if (alongSegment(v, other[k - 1], other[k]) === null) continue; + const odir = unitVector(other[k - 1], other[k]); + if (!own.some((u) => parallel(u, odir))) return odir; } } return null; }; + const last = points.length - 1; + const hits = points.map((_, i) => (i > 0 && i < last ? vertexHit(i) : null)); const tick = ([x, y], [tx, ty]) => ` M${x + tx * TICK} ${y + ty * TICK} L${x - tx * TICK} ${y - ty * TICK}`; - let resume = null; // direction of the line the previous segment stopped short of at its end vertex - for (let i = 1; i < points.length; i++) { + + // First pass: every crossing on every segment, as { t, odir, half }. + const segments = [null]; + for (let i = 1; i <= last; i++) { const a = points[i - 1], b = points[i]; const len = Math.hypot(b[0] - a[0], b[1] - a[1]); const dir = unitVector(a, b); @@ -93,35 +117,62 @@ export function yieldingPath(points, others) { const sin = Math.abs(dir[0] * odir[1] - dir[1] * odir[0]); return Math.min(GAP_HALF / Math.max(sin, 0.5), 2 * GAP_HALF); }; - // Gaps around a vertex on another line: the end of this segment, the start of the next. - // A segment too short for both becomes one gap, with its ticks at the middle. - const endHit = i < points.length - 1 ? vertexHit(b) : null; - let lo = resume ? halfFor(resume) : 0; - let hi = len - (endHit ? halfFor(endHit) : 0); - const squeezed = lo >= hi; - if (squeezed) lo = hi = len / 2; - if (resume) { - const start = [a[0] + dir[0] * lo, a[1] + dir[1] * lo]; - d += tick(start, resume) + ` M${start[0]} ${start[1]}`; - resume = null; - } - const gaps = []; - const consider = (t, odir) => { - const half = halfFor(odir); - if (t * len > lo + half + TICK && t * len < hi - half - TICK) gaps.push({ t, odir, half }); + // On a stretch shared with an earlier line, a crossing that already yielded to that line + // shows its gap there; yielding again would break both lines. + const shown = (t, ci) => { + const x = [a[0] + dir[0] * t * len, a[1] + dir[1] * t * len]; + return others.slice(0, ci).some((line) => line.some((p, k) => k > 0 && parallel(unitVector(line[k - 1], p), dir) && + (alongSegment(x, line[k - 1], p) !== null || pointEquals(x, p) || pointEquals(x, line[k - 1])) && + Math.abs((p[0] - a[0]) * dir[1] - (p[1] - a[1]) * dir[0]) < 1e-6)); }; - for (const other of others) { + const crossings = []; + const add = (t, odir) => crossings.push({ t, odir, half: halfFor(odir) }); + for (const [ci, other] of others.entries()) { for (let k = 1; k < other.length; k++) { const p = other[k - 1], q = other[k]; const hit = intersection(a, b, p, q); - if (hit) consider(hit.t, unitVector(p, q)); + if (hit && !shown(hit.t, ci)) add(hit.t, unitVector(p, q)); // The other line's bend lying on this segment; the tick follows its incoming side. + // A bend where the other line joins or leaves this segment is a junction: no gap. if (k < other.length - 1) { const t = alongSegment(q, a, b); - if (t !== null) consider(t, unitVector(p, q)); + const joins = parallel(unitVector(p, q), dir) || parallel(unitVector(q, other[k + 1]), dir); + if (t !== null && !joins && !shown(t, ci)) add(t, unitVector(p, q)); } } } + segments.push({ a, b, len, dir, halfFor, crossings }); + } + + // How far before and after each bend the curve starts and ends: 0 for a bend on another + // line, and never so far that it leaves no room for the gap of a crossing next to it (the + // bend turns sharp if it has to). + const corners = points.map((v, i) => { + if (i === 0 || i === last || hits[i]) return 0; + const into = segments[i], out = segments[i + 1]; + const turn = Math.acos(Math.max(-1, Math.min(1, into.dir[0] * out.dir[0] + into.dir[1] * out.dir[1]))); + let size = Math.min(radius * Math.tan(turn / 2), into.len / 2, out.len / 2); + for (const g of into.crossings) size = Math.min(size, into.len - g.t * into.len - g.half - TICK - 0.5); + for (const g of out.crossings) size = Math.min(size, g.t * out.len - g.half - TICK - 0.5); + return Math.max(0, Math.round(size * 1e6) / 1e6); + }); + + let resume = null; // direction of the line the previous segment stopped short of at its end vertex + for (let i = 1; i <= last; i++) { + const { a, b, len, dir, halfFor, crossings } = segments[i]; + // Gaps around a vertex on another line: the end of this segment, the start of the next. + // A segment too short for both becomes one gap, with its ticks at the middle. + const endHit = hits[i]; + let lo = resume ? halfFor(resume) : corners[i - 1]; + let hi = len - (endHit ? halfFor(endHit) : corners[i]); + const squeezed = lo >= hi; + if (squeezed) lo = hi = len / 2; + if (resume) { + const start = [a[0] + dir[0] * lo, a[1] + dir[1] * lo]; + d += tick(start, resume) + ` M${start[0]} ${start[1]}`; + resume = null; + } + const gaps = crossings.filter((g) => g.t * len > lo + g.half + TICK && g.t * len < hi - g.half - TICK); gaps.sort((p, q) => p.t - q.t); // Gaps that are too close to draw separately are merged into one longer gap; each end // keeps the tick direction of the crossing line it stops at. @@ -146,6 +197,10 @@ export function yieldingPath(points, others) { if (!squeezed) d += ` L${stop[0]} ${stop[1]}`; d += tick(stop, endHit); resume = endHit; + } else if (corners[i] > 0) { + const stop = [a[0] + dir[0] * hi, a[1] + dir[1] * hi]; + const next = unitVector(b, points[i + 1]); + d += ` L${stop[0]} ${stop[1]} Q${b[0]} ${b[1]} ${b[0] + next[0] * corners[i]} ${b[1] + next[1] * corners[i]}`; } else { d += ` L${b[0]} ${b[1]}`; } @@ -179,17 +234,41 @@ export function renderMap(container, model) { el("rect", { width, height, fill: map.background }), ); + // Halves of the map, drawn as shaded bands across the full width with their name in the + // corner given by the zone's `label`. A band touching the top or bottom of the grid runs + // into the margin. + const zones = el("g", { class: "zones", "aria-hidden": "true" }); + for (const zone of map.zones || []) { + const top = zone.top <= 0 ? 0 : point(0, zone.top)[1]; + const bottom = zone.bottom >= map.grid.rows ? height : point(0, zone.bottom)[1]; + zones.append( + el("rect", { class: "zone", x: 0, y: top, width, height: bottom - top, fill: zone.fill }), + el("text", { + class: "zone-label", + x: zone.label.endsWith("w") ? 12 : width - 12, + y: zone.label.startsWith("n") ? top + 22 : bottom - 12, + "text-anchor": zone.label.endsWith("w") ? "start" : "end", + }, [document.createTextNode(zone.name)]), + ); + } + svg.append(zones); + if (SHOW_GRID || new URLSearchParams(location.search).has("grid")) svg.append(gridOverlay(map.grid, point)); + // Connections: coloured (line) connections first, transfers on top so their hops read. + // A connection drawn later yields where it crosses one drawn earlier; map.drawFirst lists + // transfers to draw before the others, so that the others yield to them. const connections = el("g", { class: "connections" }); const drawn = []; - const ordered = [...model.interfaces.values()].sort((a, b) => Number(!!connectionLine(b.id, model)) - Number(!!connectionLine(a.id, model))); + const first = map.drawFirst || []; + const rank = (iface) => (connectionLine(iface.id, model) ? -1 : first.includes(iface.id) ? first.indexOf(iface.id) : first.length); + const ordered = [...model.interfaces.values()].sort((a, b) => rank(a) - rank(b)); for (const iface of ordered) { const [a, b] = iface.processes; const route = map.routes[iface.id]; if (!map.stations[a] || !map.stations[b] || !route) continue; const points = [point(map.stations[a].x, map.stations[a].y), ...route.map(([x, y]) => point(x, y)), point(map.stations[b].x, map.stations[b].y)]; const d = yieldingPath(points, drawn); - const hit = points.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x} ${y}`).join(" "); + const hit = yieldingPath(points, []); drawn.push(points); rendered.routes.set(iface.id, points); const line = connectionLine(iface.id, model); @@ -247,20 +326,82 @@ export function renderMap(container, model) { return svg; } +/* Thin lines through every grid point, a little stronger every fifth, numbered every second + * point along the top and left margins. */ +function gridOverlay(grid, point) { + const group = el("g", { class: "grid-overlay", "aria-hidden": "true" }); + const line = (x1, y1, x2, y2, major) => group.append(el("line", { x1, y1, x2, y2, class: major ? "grid-line grid-line-major" : "grid-line" })); + const label = (x, y, text, anchor) => group.append(el("text", { x, y, class: "grid-label", "text-anchor": anchor }, [document.createTextNode(text)])); + for (let gx = 0; gx <= grid.cols; gx++) { + const [x, top] = point(gx, 0), [, bottom] = point(gx, grid.rows); + line(x, top, x, bottom, gx % 5 === 0); + if (gx % 2 === 0) label(x, top - 6, gx, "middle"); + } + for (let gy = 0; gy <= grid.rows; gy++) { + const [left, y] = point(0, gy), [right] = point(grid.cols, gy); + line(left, y, right, y, gy % 5 === 0); + if (gy % 2 === 0) label(left - 6, y + 3, gy, "end"); + } + return group; +} + /* Pure classification of one map element (`own`, "#CODE" or "#A-B") against the selected - * hash (null for none): `selected` when they match; `related` for a connection touching the - * selected station, or a station at either end of the selected connection. Far-end stations - * of a selected station are added by setSelected once the connections are known. */ + * hash (null for none; "#A-B,C-D" for several connections): `selected` when it is one of + * the selected items; `related` for a connection touching the selected station, or a + * station at either end of a selected connection. Far-end stations of a selected station + * are added by setSelected once the connections are known. */ export function selectionState(hash, own) { if (hash === null || hash === undefined) return { selected: false, related: false }; - if (own === hash) return { selected: true, related: false }; - const selectedCodes = hash.slice(1).split("-"); + const items = hash.slice(1).split(","); + if (items.includes(own.slice(1))) return { selected: true, related: false }; const codes = own.slice(1).split("-"); - const touches = codes.some((c) => selectedCodes.includes(c)); - const related = touches && (codes.length === 2 ? selectedCodes.length === 1 : selectedCodes.length === 2); + const related = items.some((item) => { + const selectedCodes = item.split("-"); + const touches = codes.some((c) => selectedCodes.includes(c)); + return touches && (codes.length === 2 ? selectedCodes.length === 1 : selectedCodes.length === 2); + }); return { selected: false, related }; } +/* ---------- connections under a point ---------- */ + +/* Closest point to `p` on the polyline `points`, with the direction of that segment. */ +function closestOnPolyline(p, points) { + let best = null; + for (let k = 1; k < points.length; k++) { + const a = points[k - 1], b = points[k]; + const l2 = (b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2; + const t = Math.max(0, Math.min(1, ((p[0] - a[0]) * (b[0] - a[0]) + (p[1] - a[1]) * (b[1] - a[1])) / l2)); + const q = [a[0] + t * (b[0] - a[0]), a[1] + t * (b[1] - a[1])]; + const dist = Math.hypot(p[0] - q[0], p[1] - q[1]); + if (!best || dist < best.dist) best = { point: q, dist, dir: unitVector(a, b) }; + } + return best; +} + +/* Ids of every route running along the clicked route `id` at `p` (map coordinates): the + * point on `id` nearest `p`, and every route that passes through that point in the same + * direction. A route merely crossing there is not included. Sorted; `id` alone when it + * shares nothing there. */ +export function connectionsThrough(routes, id, p) { + const own = closestOnPolyline(p, routes.get(id)); + const ids = []; + for (const [other, points] of routes) { + const near = closestOnPolyline(own.point, points); + if (other === id || (near.dist < 0.5 && parallel(near.dir, own.dir))) ids.push(other); + } + return ids.sort(); +} + +/* The connection ids under a click on connection `id` at client coordinates (x, y). */ +export function connectionsAt(container, id, x, y) { + const svg = container.querySelector("svg"); + const ctm = svg?.getScreenCTM(); + if (!ctm || !rendered.routes.has(id)) return [id]; + const p = new DOMPoint(x, y).matrixTransform(ctm.inverse()); + return connectionsThrough(rendered.routes, id, [p.x, p.y]); +} + /* Highlights the station or connection whose hash matches; null clears all. Nothing gets * heavier: the selected element and what it connects to keep full strength while everything * else fades (FR-005). A selected station also shows a soft halo. */ @@ -276,7 +417,7 @@ export function setSelected(container, hash) { else link.removeAttribute("aria-current"); } // Stations at the far end of a selected station's connections stay at full strength too. - if (hash && selectedCodes.size === 1) { + if (hash && selectedCodes.size === 1 && !hash.includes(",")) { const [code] = selectedCodes; for (const conn of container.querySelectorAll(".connections a[data-hash]")) { const ends = conn.dataset.hash.slice(1).split("-"); @@ -294,26 +435,30 @@ export function setSelected(container, hash) { const DOTS_PER_DIRECTION = 3; const DOT_SPEED = 70; // px per second -/* While a connection is selected, small markers travel along it in the direction of each +/* While connections are selected, small markers travel along each in the direction of each * flow FitSM-2 lists (both ways when flows exist in both directions). Removed on deselect, * and never shown when the visitor prefers reduced motion. */ function animateFlows(svg, hash) { svg.querySelector(".flow-animation")?.remove(); - const { model, routes } = rendered; + const { model } = rendered; if (!model || !hash) return; - const id = hash.slice(1); + if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; + const group = el("g", { class: "flow-animation", "aria-hidden": "true" }); + for (const id of hash.slice(1).split(",")) addFlows(group, id); + if (group.childNodes.length) svg.append(group); +} + +function addFlows(group, id) { + const { model, routes } = rendered; const iface = model.interfaces.get(id); const points = routes.get(id); if (!iface || !points) return; - if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; - const line = connectionLine(id, model); const colour = line ? line.colour : model.map.transfer.colour; - const group = el("g", { class: "flow-animation", "aria-hidden": "true" }); const [a] = iface.processes; for (const from of iface.directions.keys()) { const oriented = from === a ? points : [...points].reverse(); - const d = oriented.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x} ${y}`).join(" "); + const d = yieldingPath(oriented, []); const pathId = `flow-${id}-${from}`; group.append(el("path", { id: pathId, d, fill: "none", stroke: "none" })); const length = oriented.slice(1).reduce((sum, p, i) => sum + Math.hypot(p[0] - oriented[i][0], p[1] - oriented[i][1]), 0); @@ -325,5 +470,4 @@ function animateFlows(svg, hash) { group.append(el("circle", { class: "flow-dot", r: 4, stroke: colour }, [motion])); } } - svg.append(group); } diff --git a/src/panel.js b/src/panel.js index 83690f5..62686e7 100644 --- a/src/panel.js +++ b/src/panel.js @@ -8,7 +8,7 @@ * specs/…/contracts/content-files.md. */ -import { connectionLabel, stationLines } from "./graph.js"; +import { connectionLabel, stationLines, stationZone } from "./graph.js"; export const LABELS = { interpretation: "Not part of FitSM", @@ -66,8 +66,8 @@ function heading(text) { return h("h2", { id: "panel-title", tabindex: "-1", text }); } -function section(title, children) { - return [h("h3", { text: title }), ...children]; +function section(title, children, tag = "h3") { + return [h(tag, { text: title }), ...children]; } function link(hash, text) { @@ -90,6 +90,44 @@ function editionLine(model) { return `${model.edition.standard} ${model.edition.edition}: ${docs.join("; ")}.`; } +/* What FitSM says about one interface: its description and the flows in each direction. + * `tag` is the heading level of its sections. */ +function interfaceDetails(iface, model, tag) { + const [a, b] = iface.processes; + const out = []; + if (iface.descriptions.length > 1) out.push(interpretation(` ${LABELS.multipleDescriptions}`)); + if (iface.descriptions.length) { + out.push(...section("Interface description", [h("ul", {}, iface.descriptions.map((d) => quoted(d.text, d.source, model)))], tag)); + } else if (!iface.flows.length) { + out.push(h("p", { class: "fixed-sentence", text: LABELS.noDescription })); + } + + for (const [from, to] of [[a, b], [b, a]]) { + const flows = iface.directions.get(from) || []; + if (!flows.length) continue; + // The same row often appears under both processes' tables. Identical wording is shown + // once with every source; different wording is shown in full with the FR-020 note. + const byText = new Map(); + for (const f of flows) { + if (!byText.has(f.item)) byText.set(f.item, []); + byText.get(f.item).push(f); + } + const listedBy = new Set(flows.map((f) => f.listedBy).filter(Boolean)); + const children = []; + if (listedBy.size > 1 && byText.size > 1) { + children.push(interpretation(` ${LABELS.multipleDescriptions} Listed under ${[...listedBy].join(" and ")}.`)); + } + children.push(h("ul", {}, [...byText.entries()].map(([text, group]) => h("li", {}, [ + h("span", { class: "quote", text }), + ...group.map((f) => sourceLine(f.source, model)), + ])))); + out.push(...section(`${from} → ${to}`, children, tag)); + } + + if (iface.note) out.push(interpretation(` ${iface.note}`)); + return out; +} + /* ---------- views ---------- */ const views = { @@ -106,14 +144,15 @@ const views = { process(process, ctx) { const { model } = ctx; - // Which line(s) the station is on, in words (FR-006): the lines are a study aid. + // Which half and line(s) the station is in, in words (FR-006): both are a study aid. + const zone = stationZone(process.code, model); const lineNames = stationLines(process.code, model).map((l) => l.name); const onLines = lineNames.length === 0 ? "On no line" : lineNames.length === 1 ? `On the ${lineNames[0]} line` : `On the ${lineNames.slice(0, -1).join(", ")} and ${lineNames[lineNames.length - 1]} lines`; const out = [ heading(`${process.name} (${process.code})`), - h("p", { class: "subtitle", text: `${onLines} (study aid, not part of FitSM)` }), + h("p", { class: "subtitle", text: `${zone ? `In ${zone.name}. ` : ""}${onLines} (study aid, not part of FitSM)` }), ...section("Objective", [h("p", { class: "quote", text: process.objective.text }), sourceLine(process.objective.source, model)]), ]; @@ -191,42 +230,30 @@ const views = { interface(iface, ctx) { const { model } = ctx; const [a, b] = iface.processes; - const out = [ + return [ h("h2", { id: "panel-title", tabindex: "-1" }, [processLink(a, model), document.createTextNode(" ↔ "), processLink(b, model)]), h("p", { class: "subtitle", text: capitalise(connectionLabel(iface.id, model)) }), backControl(ctx), + ...interfaceDetails(iface, model, "h3"), ]; + }, - if (iface.descriptions.length > 1) out.push(interpretation(` ${LABELS.multipleDescriptions}`)); - if (iface.descriptions.length) { - out.push(...section("Interface description", [h("ul", {}, iface.descriptions.map((d) => quoted(d.text, d.source, model)))])); - } else if (!iface.flows.length) { - out.push(h("p", { class: "fixed-sentence", text: LABELS.noDescription })); - } - - for (const [from, to] of [[a, b], [b, a]]) { - const flows = iface.directions.get(from) || []; - if (!flows.length) continue; - // The same row often appears under both processes' tables. Identical wording is shown - // once with every source; different wording is shown in full with the FR-020 note. - const byText = new Map(); - for (const f of flows) { - if (!byText.has(f.item)) byText.set(f.item, []); - byText.get(f.item).push(f); - } - const listedBy = new Set(flows.map((f) => f.listedBy).filter(Boolean)); - const children = []; - if (listedBy.size > 1 && byText.size > 1) { - children.push(interpretation(` ${LABELS.multipleDescriptions} Listed under ${[...listedBy].join(" and ")}.`)); - } - children.push(h("ul", {}, [...byText.entries()].map(([text, group]) => h("li", {}, [ - h("span", { class: "quote", text }), - ...group.map((f) => sourceLine(f.source, model)), - ])))); - out.push(...section(`${from} → ${to}`, children)); + // Several connections drawn along the same stretch of the map, clicked together. + interfaces(ifaces, ctx) { + const { model } = ctx; + const out = [ + heading(`${ifaces.length} connections run here`), + h("p", { class: "subtitle", text: "They share this stretch of the map. Each is listed with what FitSM says about it." }), + backControl(ctx), + ]; + for (const iface of ifaces) { + const [a, b] = iface.processes; + out.push( + h("h3", { class: "connection-heading" }, [link(`#${iface.id}`, `${model.processes.get(a).name} ↔ ${model.processes.get(b).name}`)]), + h("p", { class: "subtitle", text: capitalise(connectionLabel(iface.id, model)) }), + ...interfaceDetails(iface, model, "h4"), + ); } - - if (iface.note) out.push(interpretation(` ${iface.note}`)); return out; }, diff --git a/src/router.js b/src/router.js index 3a8ff9c..705a7e9 100644 --- a/src/router.js +++ b/src/router.js @@ -9,6 +9,7 @@ * "#GR" general requirements * "#ISRM" process (code, case-insensitive) * "#ISRM-PM" interface (codes in alphabetical order) + * "#CHM-PM,CHM-SACM" several interfaces at once (ids sorted, comma-separated) * "#role/ISRM.manager" role, "#activity/ISRM.A1" activity, "#record/incident-record" record * * Pure: no DOM access. `canonical` needs the content model for aliases and lookups. @@ -25,6 +26,10 @@ export function parse(hash) { if (prefixed) return { kind: prefixed[1], id: prefixed[2], raw }; const upper = raw.toUpperCase(); if (upper === "GR") return { kind: "general", raw }; + if (upper.includes(",")) { + const ids = upper.split(","); + return ids.every((id) => PAIR.test(id)) ? { kind: "interfaces", ids, raw } : { kind: "unknown", raw }; + } if (PAIR.test(upper)) return { kind: "interface", id: upper, raw }; if (CODE.test(upper)) return { kind: "process", id: upper, raw }; return { kind: "unknown", raw }; @@ -39,6 +44,8 @@ export function format(kind, id) { case "process": case "interface": return `#${id}`; + case "interfaces": + return `#${id.join(",")}`; case "role": case "activity": case "record": @@ -54,6 +61,15 @@ function resolveCode(code, model) { return model.aliases.get(code) || null; } +/* "A-B" with codes or aliases in either order to the interface id, or null. */ +function interfaceId(pair, model) { + const [, a, b] = pair.match(PAIR); + const codes = [resolveCode(a, model), resolveCode(b, model)]; + if (codes.includes(null) || codes[0] === codes[1]) return null; + const id = codes.sort().join("-"); + return model.interfaces.has(id) ? id : null; +} + /* * Applies aliases and ordering rules. Returns { kind, id, hash, redirect }: * `redirect` is true when the address should be replaced by `hash` without a @@ -73,14 +89,19 @@ export function canonical(parsed, model) { return { kind: "process", id: code, hash, redirect: hash !== `#${parsed.raw}` }; } case "interface": { - const [, a, b] = parsed.id.match(PAIR); - const codes = [resolveCode(a, model), resolveCode(b, model)]; - if (codes.includes(null) || codes[0] === codes[1]) return unknown; - const id = codes.sort().join("-"); - if (!model.interfaces.has(id)) return unknown; + const id = interfaceId(parsed.id, model); + if (!id) return unknown; const hash = format("interface", id); return { kind: "interface", id, hash, redirect: hash !== `#${parsed.raw}` }; } + case "interfaces": { + const ids = parsed.ids.map((id) => interfaceId(id, model)); + if (ids.includes(null)) return unknown; + const unique = [...new Set(ids)].sort(); + if (unique.length === 1) return { kind: "interface", id: unique[0], hash: format("interface", unique[0]), redirect: true }; + const hash = format("interfaces", unique); + return { kind: "interfaces", ids: unique, hash, redirect: hash !== `#${parsed.raw}` }; + } case "role": case "activity": case "record": { diff --git a/styles.css b/styles.css index 48b809a..3644494 100644 --- a/styles.css +++ b/styles.css @@ -92,6 +92,18 @@ a { color: var(--link); } .station-disc { fill: var(--paper); stroke-width: var(--station-stroke); } .station-ring { fill: none; } +/* Layout aid (SHOW_GRID in src/map.js, or ?grid in the address). */ +.grid-line { stroke: #9a9aa8; stroke-width: 1; } +.grid-line-major { stroke: #5f5f6e; stroke-width: 1.5; } +.grid-label { font-size: 9px; fill: var(--ink-muted); } +/* Names of the map's halves, set small and muted so they read as background. */ +.zone-label { + font-size: 13px; + font-weight: 700; + letter-spacing: 0.08em; + text-transform: uppercase; + fill: var(--ink-muted); +} /* Station codes get a white halo so they stay legible where a connection runs close by. */ .station-label { font-size: 15px; @@ -134,6 +146,7 @@ a { color: var(--link); } .legend li { display: flex; align-items: center; gap: 0.4rem; } .swatch { display: inline-block; width: 1.4rem; height: 0.4rem; border-radius: 2px; } .swatch-transfer { height: 0.25rem; } /* colour comes from map.json's transfer.colour */ +.swatch-zone { height: 0.9rem; border: 1px solid var(--rule); } /* colour comes from map.json's zone fill */ /* Detail frame */ .panel { padding: 0 0.25rem 1rem; } diff --git a/tests/check.test.js b/tests/check.test.js index 8b91ff6..17c379c 100644 --- a/tests/check.test.js +++ b/tests/check.test.js @@ -48,8 +48,18 @@ const cases = { "bad-grid": "error bad-grid/map.json: grid: unit, cols and rows must be positive integers", "role-without-tasks": "error role-without-tasks/roles.json: AA.manager: tasks must be an array (may be empty)", "bad-waypoint": "error bad-waypoint/map.json: routes.AA-BB: waypoint 0 is not a grid point [x, y] within the grid", + "bad-draw-first": 'error bad-draw-first/map.json: drawFirst: "AA-ZZ" is not an interface', + "zone-misplaced": "error zone-misplaced/map.json: zones.top: station HH at row 4 is not inside rows 0-3", }; +test("the layout metrics are printed before the summary, and listed with --layout", () => { + const r = run("--content", "tests/fixtures/valid"); + assert.match(r.out, /^layout valid\/map\.json: 0 crossing points \(0 crossings between pairs\), 0 shared segments \(0 transfer merges, 0 within a line, 0 mixed\), 0 close parallels$/m); + const real = run("--layout"); + assert.match(real.out, /^ crossing [A-Z]+-[A-Z]+ x [A-Z]+-[A-Z]+ at \(\d+,\d+\)$/m); + assert.equal(run("--quiet").out, ""); +}); + test("the syntax check does not depend on the working directory", () => { const args = [script, "--content", join(root, "tests", "fixtures", "valid")]; const fromRoot = spawnSync(process.execPath, args, { cwd: root, encoding: "utf8" }); diff --git a/tests/fixtures/broken/bad-draw-first/activities.json b/tests/fixtures/broken/bad-draw-first/activities.json new file mode 100644 index 0000000..fb0a001 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/activities.json @@ -0,0 +1,408 @@ +[ + { + "id": "AA.S", + "process": "AA", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "AA.A1", + "process": "AA", + "phase": "execution", + "name": "Do AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "BB.S", + "process": "BB", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "BB.A1", + "process": "BB", + "phase": "execution", + "name": "Do BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "CC.S", + "process": "CC", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "CC.A1", + "process": "CC", + "phase": "execution", + "name": "Do CC", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "DD.S", + "process": "DD", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "DD.A1", + "process": "DD", + "phase": "execution", + "name": "Do DD", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "EE.S", + "process": "EE", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "EE.A1", + "process": "EE", + "phase": "execution", + "name": "Do EE", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "FF.S", + "process": "FF", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "FF.A1", + "process": "FF", + "phase": "execution", + "name": "Do FF", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "GG.S", + "process": "GG", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "GG.A1", + "process": "GG", + "phase": "execution", + "name": "Do GG", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "HH.S", + "process": "HH", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "HH.A1", + "process": "HH", + "phase": "execution", + "name": "Do HH", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "II.S", + "process": "II", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "II.A1", + "process": "II", + "phase": "execution", + "name": "Do II", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "JJ.S", + "process": "JJ", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "JJ.A1", + "process": "JJ", + "phase": "execution", + "name": "Do JJ", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "KK.S", + "process": "KK", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "KK.A1", + "process": "KK", + "phase": "execution", + "name": "Do KK", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "LL.S", + "process": "LL", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "LL.A1", + "process": "LL", + "phase": "execution", + "name": "Do LL", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "MM.S", + "process": "MM", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "MM.A1", + "process": "MM", + "phase": "execution", + "name": "Do MM", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "NN.S", + "process": "NN", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "NN.A1", + "process": "NN", + "phase": "execution", + "name": "Do NN", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + } +] diff --git a/tests/fixtures/broken/bad-draw-first/edition.json b/tests/fixtures/broken/bad-draw-first/edition.json new file mode 100644 index 0000000..193123e --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/edition.json @@ -0,0 +1,32 @@ +{ + "standard": "FitSM", + "edition": "9.9", + "documents": { + "FitSM-0": { + "title": "FitSM-0: Vocabulary", + "version": "9.9", + "url": "https://example.test/0" + }, + "FitSM-1": { + "title": "FitSM-1: Requirements", + "version": "9.9", + "url": "https://example.test/1" + }, + "FitSM-2": { + "title": "FitSM-2: Activities", + "version": "9.9", + "url": "https://example.test/2" + }, + "FitSM-3": { + "title": "FitSM-3: Roles", + "version": "9.9", + "url": "https://example.test/3" + } + }, + "downloads": "https://example.test/downloads", + "licence": { + "name": "CC BY 4.0", + "url": "https://creativecommons.org/licenses/by/4.0/" + }, + "attribution": "ITEMO e.V." +} diff --git a/tests/fixtures/broken/bad-draw-first/interfaces.json b/tests/fixtures/broken/bad-draw-first/interfaces.json new file mode 100644 index 0000000..b4faf7d --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/interfaces.json @@ -0,0 +1,64 @@ +[ + { + "id": "AA-BB", + "processes": [ + "AA", + "BB" + ], + "descriptions": [ + { + "text": "AA and BB work together", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "flows": [ + { + "from": "AA", + "to": "BB", + "item": "Records", + "listedBy": "AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + { + "from": "BB", + "to": "AA", + "item": "Reports", + "listedBy": "BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "id": "BB-CC", + "processes": [ + "BB", + "CC" + ], + "descriptions": [], + "flows": [ + { + "from": "BB", + "to": "CC", + "item": "Flows only", + "listedBy": "BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + } +] diff --git a/tests/fixtures/broken/bad-draw-first/map.json b/tests/fixtures/broken/bad-draw-first/map.json new file mode 100644 index 0000000..d2274e1 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/map.json @@ -0,0 +1,126 @@ +{ + "note": "Study aid", + "background": "#ffffff", + "transfer": { + "colour": "#6b6b6b", + "width": 4 + }, + "grid": { + "unit": 60, + "cols": 14, + "rows": 6 + }, + "zones": [ + { "id": "top", "name": "Top", "fill": "#eef3f9", "top": 0, "bottom": 3, "label": "nw", "stations": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"] }, + { "id": "bottom", "name": "Bottom", "fill": "#f7f3ea", "top": 3, "bottom": 6, "label": "sw", "stations": ["HH", "II", "JJ", "KK", "LL", "MM", "NN"] } + ], + "lines": [ + { + "id": "one", + "name": "One", + "colour": "#1565c0", + "stations": [ + "AA", + "BB" + ], + "labelSide": "n" + }, + { + "id": "two", + "name": "Two", + "colour": "#c62828", + "stations": [ + "CC", + "DD", + "EE", + "FF", + "GG", + "HH", + "II", + "JJ", + "KK", + "LL", + "MM", + "NN" + ], + "labelSide": "n" + } + ], + "stations": { + "AA": { + "x": 1, + "y": 1, + "label": "s" + }, + "BB": { + "x": 3, + "y": 1, + "label": "s" + }, + "CC": { + "x": 5, + "y": 1, + "label": "s" + }, + "DD": { + "x": 7, + "y": 1, + "label": "s" + }, + "EE": { + "x": 9, + "y": 1, + "label": "s" + }, + "FF": { + "x": 11, + "y": 1, + "label": "s" + }, + "GG": { + "x": 13, + "y": 1, + "label": "s" + }, + "HH": { + "x": 1, + "y": 4, + "label": "s" + }, + "II": { + "x": 3, + "y": 4, + "label": "s" + }, + "JJ": { + "x": 5, + "y": 4, + "label": "s" + }, + "KK": { + "x": 7, + "y": 4, + "label": "s" + }, + "LL": { + "x": 9, + "y": 4, + "label": "s" + }, + "MM": { + "x": 11, + "y": 4, + "label": "s" + }, + "NN": { + "x": 13, + "y": 4, + "label": "s" + } + }, + "drawFirst": ["AA-BB", "AA-ZZ"], + "routes": { + "AA-BB": [], + "BB-CC": [] + } +} diff --git a/tests/fixtures/broken/bad-draw-first/processes.json b/tests/fixtures/broken/bad-draw-first/processes.json new file mode 100644 index 0000000..3082c67 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/processes.json @@ -0,0 +1,489 @@ +[ + { + "code": "AA", + "name": "Process AA", + "requirements": "PR1", + "objective": { + "text": "Objective of AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [ + { + "direction": "in", + "party": "Customers", + "item": "Requests", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "code": "BB", + "name": "Process BB", + "requirements": "PR2", + "objective": { + "text": "Objective of BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "CC", + "name": "Process CC", + "requirements": "PR3", + "objective": { + "text": "Objective of CC", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "DD", + "name": "Process DD", + "requirements": "PR4", + "objective": { + "text": "Objective of DD", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "EE", + "name": "Process EE", + "requirements": "PR5", + "objective": { + "text": "Objective of EE", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "FF", + "name": "Process FF", + "requirements": "PR6", + "objective": { + "text": "Objective of FF", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "GG", + "name": "Process GG", + "requirements": "PR7", + "objective": { + "text": "Objective of GG", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "HH", + "name": "Process HH", + "requirements": "PR8", + "objective": { + "text": "Objective of HH", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "II", + "name": "Process II", + "requirements": "PR9", + "objective": { + "text": "Objective of II", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "JJ", + "name": "Process JJ", + "requirements": "PR10", + "objective": { + "text": "Objective of JJ", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "KK", + "name": "Process KK", + "requirements": "PR11", + "objective": { + "text": "Objective of KK", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "LL", + "name": "Process LL", + "requirements": "PR12", + "objective": { + "text": "Objective of LL", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "MM", + "name": "Process MM", + "requirements": "PR13", + "objective": { + "text": "Objective of MM", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "NN", + "name": "Process NN", + "requirements": "PR14", + "objective": { + "text": "Objective of NN", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + } +] diff --git a/tests/fixtures/broken/bad-draw-first/records.json b/tests/fixtures/broken/bad-draw-first/records.json new file mode 100644 index 0000000..48394e7 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/records.json @@ -0,0 +1,60 @@ +[ + { + "id": "record", + "name": "Record", + "definition": { + "text": "Documentation of an event", + "source": { + "doc": "FitSM-0", + "section": "6.1", + "page": 2 + } + }, + "usedBy": [ + { + "process": "AA", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + { + "process": "BB", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "id": "report", + "name": "Report", + "definition": { + "text": "A structured record", + "source": { + "doc": "FitSM-0", + "section": "6.1", + "page": 2 + } + }, + "usedBy": [ + { + "process": "CC", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + } +] diff --git a/tests/fixtures/broken/bad-draw-first/requirements.json b/tests/fixtures/broken/bad-draw-first/requirements.json new file mode 100644 index 0000000..2d4c958 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/requirements.json @@ -0,0 +1,426 @@ +{ + "general": [ + { + "id": "GR1", + "name": "General 1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR1.1", + "text": "Requirement GR1.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR2", + "name": "General 2", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR2.1", + "text": "Requirement GR2.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR3", + "name": "General 3", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR3.1", + "text": "Requirement GR3.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR4", + "name": "General 4", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR4.1", + "text": "Requirement GR4.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR5", + "name": "General 5", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR5.1", + "text": "Requirement GR5.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR6", + "name": "General 6", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR6.1", + "text": "Requirement GR6.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR7", + "name": "General 7", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR7.1", + "text": "Requirement GR7.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + } + ], + "process": [ + { + "id": "PR1", + "process": "AA", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR1.1", + "text": "Requirement PR1.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR2", + "process": "BB", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR2.1", + "text": "Requirement PR2.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR3", + "process": "CC", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR3.1", + "text": "Requirement PR3.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR4", + "process": "DD", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR4.1", + "text": "Requirement PR4.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR5", + "process": "EE", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR5.1", + "text": "Requirement PR5.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR6", + "process": "FF", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR6.1", + "text": "Requirement PR6.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR7", + "process": "GG", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR7.1", + "text": "Requirement PR7.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR8", + "process": "HH", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR8.1", + "text": "Requirement PR8.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR9", + "process": "II", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR9.1", + "text": "Requirement PR9.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR10", + "process": "JJ", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR10.1", + "text": "Requirement PR10.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR11", + "process": "KK", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR11.1", + "text": "Requirement PR11.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR12", + "process": "LL", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR12.1", + "text": "Requirement PR12.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR13", + "process": "MM", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR13.1", + "text": "Requirement PR13.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR14", + "process": "NN", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR14.1", + "text": "Requirement PR14.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + } + ] +} diff --git a/tests/fixtures/broken/bad-draw-first/roles.json b/tests/fixtures/broken/bad-draw-first/roles.json new file mode 100644 index 0000000..456ab32 --- /dev/null +++ b/tests/fixtures/broken/bad-draw-first/roles.json @@ -0,0 +1,730 @@ +{ + "generic": { + "owner": { + "name": "Generic owner", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of owner" + ] + }, + "manager": { + "name": "Generic manager", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of manager" + ] + }, + "case-owner": { + "name": "Generic case-owner", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of case-owner" + ] + }, + "staff": { + "name": "Generic staff", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of staff" + ] + } + }, + "roles": [ + { + "id": "AA.owner", + "process": "AA", + "kind": "owner", + "name": "Process owner AA", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "AA.manager", + "process": "AA", + "kind": "manager", + "name": "Process manager AA", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "AA.staff", + "process": "AA", + "kind": "staff", + "name": "Staff AA", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "AA.case-owner", + "process": "AA", + "kind": "case-owner", + "name": "Case owner: Thing owner", + "count": "1 per thing", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Own the thing", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "BB.owner", + "process": "BB", + "kind": "owner", + "name": "Process owner BB", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "BB.manager", + "process": "BB", + "kind": "manager", + "name": "Process manager BB", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "BB.staff", + "process": "BB", + "kind": "staff", + "name": "Staff BB", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "CC.owner", + "process": "CC", + "kind": "owner", + "name": "Process owner CC", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "CC.manager", + "process": "CC", + "kind": "manager", + "name": "Process manager CC", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "CC.staff", + "process": "CC", + "kind": "staff", + "name": "Staff CC", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "DD.owner", + "process": "DD", + "kind": "owner", + "name": "Process owner DD", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "DD.manager", + "process": "DD", + "kind": "manager", + "name": "Process manager DD", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "DD.staff", + "process": "DD", + "kind": "staff", + "name": "Staff DD", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "EE.owner", + "process": "EE", + "kind": "owner", + "name": "Process owner EE", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "EE.manager", + "process": "EE", + "kind": "manager", + "name": "Process manager EE", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "EE.staff", + "process": "EE", + "kind": "staff", + "name": "Staff EE", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "FF.owner", + "process": "FF", + "kind": "owner", + "name": "Process owner FF", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "FF.manager", + "process": "FF", + "kind": "manager", + "name": "Process manager FF", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "FF.staff", + "process": "FF", + "kind": "staff", + "name": "Staff FF", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "GG.owner", + "process": "GG", + "kind": "owner", + "name": "Process owner GG", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "GG.manager", + "process": "GG", + "kind": "manager", + "name": "Process manager GG", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "GG.staff", + "process": "GG", + "kind": "staff", + "name": "Staff GG", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "HH.owner", + "process": "HH", + "kind": "owner", + "name": "Process owner HH", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "HH.manager", + "process": "HH", + "kind": "manager", + "name": "Process manager HH", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "HH.staff", + "process": "HH", + "kind": "staff", + "name": "Staff HH", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "II.owner", + "process": "II", + "kind": "owner", + "name": "Process owner II", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "II.manager", + "process": "II", + "kind": "manager", + "name": "Process manager II", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "II.staff", + "process": "II", + "kind": "staff", + "name": "Staff II", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "JJ.owner", + "process": "JJ", + "kind": "owner", + "name": "Process owner JJ", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "JJ.manager", + "process": "JJ", + "kind": "manager", + "name": "Process manager JJ", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "JJ.staff", + "process": "JJ", + "kind": "staff", + "name": "Staff JJ", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "KK.owner", + "process": "KK", + "kind": "owner", + "name": "Process owner KK", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "KK.manager", + "process": "KK", + "kind": "manager", + "name": "Process manager KK", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "KK.staff", + "process": "KK", + "kind": "staff", + "name": "Staff KK", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "LL.owner", + "process": "LL", + "kind": "owner", + "name": "Process owner LL", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "LL.manager", + "process": "LL", + "kind": "manager", + "name": "Process manager LL", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "LL.staff", + "process": "LL", + "kind": "staff", + "name": "Staff LL", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "MM.owner", + "process": "MM", + "kind": "owner", + "name": "Process owner MM", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "MM.manager", + "process": "MM", + "kind": "manager", + "name": "Process manager MM", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "MM.staff", + "process": "MM", + "kind": "staff", + "name": "Staff MM", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "NN.owner", + "process": "NN", + "kind": "owner", + "name": "Process owner NN", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "NN.manager", + "process": "NN", + "kind": "manager", + "name": "Process manager NN", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "NN.staff", + "process": "NN", + "kind": "staff", + "name": "Staff NN", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + } + ] +} diff --git a/tests/fixtures/broken/zone-misplaced/activities.json b/tests/fixtures/broken/zone-misplaced/activities.json new file mode 100644 index 0000000..fb0a001 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/activities.json @@ -0,0 +1,408 @@ +[ + { + "id": "AA.S", + "process": "AA", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "AA.A1", + "process": "AA", + "phase": "execution", + "name": "Do AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "BB.S", + "process": "BB", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "BB.A1", + "process": "BB", + "phase": "execution", + "name": "Do BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "CC.S", + "process": "CC", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "CC.A1", + "process": "CC", + "phase": "execution", + "name": "Do CC", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "DD.S", + "process": "DD", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "DD.A1", + "process": "DD", + "phase": "execution", + "name": "Do DD", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "EE.S", + "process": "EE", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "EE.A1", + "process": "EE", + "phase": "execution", + "name": "Do EE", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "FF.S", + "process": "FF", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "FF.A1", + "process": "FF", + "phase": "execution", + "name": "Do FF", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "GG.S", + "process": "GG", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "GG.A1", + "process": "GG", + "phase": "execution", + "name": "Do GG", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "HH.S", + "process": "HH", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "HH.A1", + "process": "HH", + "phase": "execution", + "name": "Do HH", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "II.S", + "process": "II", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "II.A1", + "process": "II", + "phase": "execution", + "name": "Do II", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "JJ.S", + "process": "JJ", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "JJ.A1", + "process": "JJ", + "phase": "execution", + "name": "Do JJ", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "KK.S", + "process": "KK", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "KK.A1", + "process": "KK", + "phase": "execution", + "name": "Do KK", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "LL.S", + "process": "LL", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "LL.A1", + "process": "LL", + "phase": "execution", + "name": "Do LL", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "MM.S", + "process": "MM", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "MM.A1", + "process": "MM", + "phase": "execution", + "name": "Do MM", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + }, + { + "id": "NN.S", + "process": "NN", + "phase": "setup", + "name": "Initial process setup", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Set it up" + ] + }, + { + "id": "NN.A1", + "process": "NN", + "phase": "execution", + "name": "Do NN", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + }, + "procedure": [ + "Step one", + "Step two" + ] + } +] diff --git a/tests/fixtures/broken/zone-misplaced/edition.json b/tests/fixtures/broken/zone-misplaced/edition.json new file mode 100644 index 0000000..193123e --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/edition.json @@ -0,0 +1,32 @@ +{ + "standard": "FitSM", + "edition": "9.9", + "documents": { + "FitSM-0": { + "title": "FitSM-0: Vocabulary", + "version": "9.9", + "url": "https://example.test/0" + }, + "FitSM-1": { + "title": "FitSM-1: Requirements", + "version": "9.9", + "url": "https://example.test/1" + }, + "FitSM-2": { + "title": "FitSM-2: Activities", + "version": "9.9", + "url": "https://example.test/2" + }, + "FitSM-3": { + "title": "FitSM-3: Roles", + "version": "9.9", + "url": "https://example.test/3" + } + }, + "downloads": "https://example.test/downloads", + "licence": { + "name": "CC BY 4.0", + "url": "https://creativecommons.org/licenses/by/4.0/" + }, + "attribution": "ITEMO e.V." +} diff --git a/tests/fixtures/broken/zone-misplaced/interfaces.json b/tests/fixtures/broken/zone-misplaced/interfaces.json new file mode 100644 index 0000000..b4faf7d --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/interfaces.json @@ -0,0 +1,64 @@ +[ + { + "id": "AA-BB", + "processes": [ + "AA", + "BB" + ], + "descriptions": [ + { + "text": "AA and BB work together", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "flows": [ + { + "from": "AA", + "to": "BB", + "item": "Records", + "listedBy": "AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + { + "from": "BB", + "to": "AA", + "item": "Reports", + "listedBy": "BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "id": "BB-CC", + "processes": [ + "BB", + "CC" + ], + "descriptions": [], + "flows": [ + { + "from": "BB", + "to": "CC", + "item": "Flows only", + "listedBy": "BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + } +] diff --git a/tests/fixtures/broken/zone-misplaced/map.json b/tests/fixtures/broken/zone-misplaced/map.json new file mode 100644 index 0000000..22f7db3 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/map.json @@ -0,0 +1,125 @@ +{ + "note": "Study aid", + "background": "#ffffff", + "transfer": { + "colour": "#6b6b6b", + "width": 4 + }, + "grid": { + "unit": 60, + "cols": 14, + "rows": 6 + }, + "zones": [ + { "id": "top", "name": "Top", "fill": "#eef3f9", "top": 0, "bottom": 3, "label": "nw", "stations": ["AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH"] }, + { "id": "bottom", "name": "Bottom", "fill": "#f7f3ea", "top": 3, "bottom": 6, "label": "sw", "stations": ["II", "JJ", "KK", "LL", "MM", "NN"] } + ], + "lines": [ + { + "id": "one", + "name": "One", + "colour": "#1565c0", + "stations": [ + "AA", + "BB" + ], + "labelSide": "n" + }, + { + "id": "two", + "name": "Two", + "colour": "#c62828", + "stations": [ + "CC", + "DD", + "EE", + "FF", + "GG", + "HH", + "II", + "JJ", + "KK", + "LL", + "MM", + "NN" + ], + "labelSide": "n" + } + ], + "stations": { + "AA": { + "x": 1, + "y": 1, + "label": "s" + }, + "BB": { + "x": 3, + "y": 1, + "label": "s" + }, + "CC": { + "x": 5, + "y": 1, + "label": "s" + }, + "DD": { + "x": 7, + "y": 1, + "label": "s" + }, + "EE": { + "x": 9, + "y": 1, + "label": "s" + }, + "FF": { + "x": 11, + "y": 1, + "label": "s" + }, + "GG": { + "x": 13, + "y": 1, + "label": "s" + }, + "HH": { + "x": 1, + "y": 4, + "label": "s" + }, + "II": { + "x": 3, + "y": 4, + "label": "s" + }, + "JJ": { + "x": 5, + "y": 4, + "label": "s" + }, + "KK": { + "x": 7, + "y": 4, + "label": "s" + }, + "LL": { + "x": 9, + "y": 4, + "label": "s" + }, + "MM": { + "x": 11, + "y": 4, + "label": "s" + }, + "NN": { + "x": 13, + "y": 4, + "label": "s" + } + }, + "routes": { + "AA-BB": [], + "BB-CC": [] + } +} diff --git a/tests/fixtures/broken/zone-misplaced/processes.json b/tests/fixtures/broken/zone-misplaced/processes.json new file mode 100644 index 0000000..3082c67 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/processes.json @@ -0,0 +1,489 @@ +[ + { + "code": "AA", + "name": "Process AA", + "requirements": "PR1", + "objective": { + "text": "Objective of AA", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [ + { + "direction": "in", + "party": "Customers", + "item": "Requests", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "code": "BB", + "name": "Process BB", + "requirements": "PR2", + "objective": { + "text": "Objective of BB", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "CC", + "name": "Process CC", + "requirements": "PR3", + "objective": { + "text": "Objective of CC", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "DD", + "name": "Process DD", + "requirements": "PR4", + "objective": { + "text": "Objective of DD", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "EE", + "name": "Process EE", + "requirements": "PR5", + "objective": { + "text": "Objective of EE", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "FF", + "name": "Process FF", + "requirements": "PR6", + "objective": { + "text": "Objective of FF", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "GG", + "name": "Process GG", + "requirements": "PR7", + "objective": { + "text": "Objective of GG", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "HH", + "name": "Process HH", + "requirements": "PR8", + "objective": { + "text": "Objective of HH", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "II", + "name": "Process II", + "requirements": "PR9", + "objective": { + "text": "Objective of II", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "JJ", + "name": "Process JJ", + "requirements": "PR10", + "objective": { + "text": "Objective of JJ", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "KK", + "name": "Process KK", + "requirements": "PR11", + "objective": { + "text": "Objective of KK", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "LL", + "name": "Process LL", + "requirements": "PR12", + "objective": { + "text": "Objective of LL", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "MM", + "name": "Process MM", + "requirements": "PR13", + "objective": { + "text": "Objective of MM", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + }, + { + "code": "NN", + "name": "Process NN", + "requirements": "PR14", + "objective": { + "text": "Objective of NN", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + "inputs": [ + { + "text": "An input", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "outputs": [ + { + "text": "A record", + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ], + "externalFlows": [] + } +] diff --git a/tests/fixtures/broken/zone-misplaced/records.json b/tests/fixtures/broken/zone-misplaced/records.json new file mode 100644 index 0000000..48394e7 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/records.json @@ -0,0 +1,60 @@ +[ + { + "id": "record", + "name": "Record", + "definition": { + "text": "Documentation of an event", + "source": { + "doc": "FitSM-0", + "section": "6.1", + "page": 2 + } + }, + "usedBy": [ + { + "process": "AA", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + }, + { + "process": "BB", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + }, + { + "id": "report", + "name": "Report", + "definition": { + "text": "A structured record", + "source": { + "doc": "FitSM-0", + "section": "6.1", + "page": 2 + } + }, + "usedBy": [ + { + "process": "CC", + "basis": "output", + "derived": true, + "source": { + "doc": "FitSM-2", + "section": "4.1", + "page": 5 + } + } + ] + } +] diff --git a/tests/fixtures/broken/zone-misplaced/requirements.json b/tests/fixtures/broken/zone-misplaced/requirements.json new file mode 100644 index 0000000..2d4c958 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/requirements.json @@ -0,0 +1,426 @@ +{ + "general": [ + { + "id": "GR1", + "name": "General 1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR1.1", + "text": "Requirement GR1.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR2", + "name": "General 2", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR2.1", + "text": "Requirement GR2.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR3", + "name": "General 3", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR3.1", + "text": "Requirement GR3.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR4", + "name": "General 4", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR4.1", + "text": "Requirement GR4.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR5", + "name": "General 5", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR5.1", + "text": "Requirement GR5.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR6", + "name": "General 6", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR6.1", + "text": "Requirement GR6.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "GR7", + "name": "General 7", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "GR7.1", + "text": "Requirement GR7.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + } + ], + "process": [ + { + "id": "PR1", + "process": "AA", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR1.1", + "text": "Requirement PR1.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR2", + "process": "BB", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR2.1", + "text": "Requirement PR2.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR3", + "process": "CC", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR3.1", + "text": "Requirement PR3.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR4", + "process": "DD", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR4.1", + "text": "Requirement PR4.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR5", + "process": "EE", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR5.1", + "text": "Requirement PR5.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR6", + "process": "FF", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR6.1", + "text": "Requirement PR6.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR7", + "process": "GG", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR7.1", + "text": "Requirement PR7.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR8", + "process": "HH", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR8.1", + "text": "Requirement PR8.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR9", + "process": "II", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR9.1", + "text": "Requirement PR9.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR10", + "process": "JJ", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR10.1", + "text": "Requirement PR10.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR11", + "process": "KK", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR11.1", + "text": "Requirement PR11.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR12", + "process": "LL", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR12.1", + "text": "Requirement PR12.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR13", + "process": "MM", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR13.1", + "text": "Requirement PR13.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + }, + { + "id": "PR14", + "process": "NN", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + }, + "items": [ + { + "id": "PR14.1", + "text": "Requirement PR14.1", + "source": { + "doc": "FitSM-1", + "section": "PR1", + "page": 3 + } + } + ] + } + ] +} diff --git a/tests/fixtures/broken/zone-misplaced/roles.json b/tests/fixtures/broken/zone-misplaced/roles.json new file mode 100644 index 0000000..456ab32 --- /dev/null +++ b/tests/fixtures/broken/zone-misplaced/roles.json @@ -0,0 +1,730 @@ +{ + "generic": { + "owner": { + "name": "Generic owner", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of owner" + ] + }, + "manager": { + "name": "Generic manager", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of manager" + ] + }, + "case-owner": { + "name": "Generic case-owner", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of case-owner" + ] + }, + "staff": { + "name": "Generic staff", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + "Generic task of staff" + ] + } + }, + "roles": [ + { + "id": "AA.owner", + "process": "AA", + "kind": "owner", + "name": "Process owner AA", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "AA.manager", + "process": "AA", + "kind": "manager", + "name": "Process manager AA", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "AA.staff", + "process": "AA", + "kind": "staff", + "name": "Staff AA", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "AA.case-owner", + "process": "AA", + "kind": "case-owner", + "name": "Case owner: Thing owner", + "count": "1 per thing", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Own the thing", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "BB.owner", + "process": "BB", + "kind": "owner", + "name": "Process owner BB", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "BB.manager", + "process": "BB", + "kind": "manager", + "name": "Process manager BB", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "BB.staff", + "process": "BB", + "kind": "staff", + "name": "Staff BB", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "CC.owner", + "process": "CC", + "kind": "owner", + "name": "Process owner CC", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "CC.manager", + "process": "CC", + "kind": "manager", + "name": "Process manager CC", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "CC.staff", + "process": "CC", + "kind": "staff", + "name": "Staff CC", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "DD.owner", + "process": "DD", + "kind": "owner", + "name": "Process owner DD", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "DD.manager", + "process": "DD", + "kind": "manager", + "name": "Process manager DD", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "DD.staff", + "process": "DD", + "kind": "staff", + "name": "Staff DD", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "EE.owner", + "process": "EE", + "kind": "owner", + "name": "Process owner EE", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "EE.manager", + "process": "EE", + "kind": "manager", + "name": "Process manager EE", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "EE.staff", + "process": "EE", + "kind": "staff", + "name": "Staff EE", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "FF.owner", + "process": "FF", + "kind": "owner", + "name": "Process owner FF", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "FF.manager", + "process": "FF", + "kind": "manager", + "name": "Process manager FF", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "FF.staff", + "process": "FF", + "kind": "staff", + "name": "Staff FF", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "GG.owner", + "process": "GG", + "kind": "owner", + "name": "Process owner GG", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "GG.manager", + "process": "GG", + "kind": "manager", + "name": "Process manager GG", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "GG.staff", + "process": "GG", + "kind": "staff", + "name": "Staff GG", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "HH.owner", + "process": "HH", + "kind": "owner", + "name": "Process owner HH", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "HH.manager", + "process": "HH", + "kind": "manager", + "name": "Process manager HH", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "HH.staff", + "process": "HH", + "kind": "staff", + "name": "Staff HH", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "II.owner", + "process": "II", + "kind": "owner", + "name": "Process owner II", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "II.manager", + "process": "II", + "kind": "manager", + "name": "Process manager II", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "II.staff", + "process": "II", + "kind": "staff", + "name": "Staff II", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "JJ.owner", + "process": "JJ", + "kind": "owner", + "name": "Process owner JJ", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "JJ.manager", + "process": "JJ", + "kind": "manager", + "name": "Process manager JJ", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "JJ.staff", + "process": "JJ", + "kind": "staff", + "name": "Staff JJ", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "KK.owner", + "process": "KK", + "kind": "owner", + "name": "Process owner KK", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "KK.manager", + "process": "KK", + "kind": "manager", + "name": "Process manager KK", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "KK.staff", + "process": "KK", + "kind": "staff", + "name": "Staff KK", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "LL.owner", + "process": "LL", + "kind": "owner", + "name": "Process owner LL", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "LL.manager", + "process": "LL", + "kind": "manager", + "name": "Process manager LL", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "LL.staff", + "process": "LL", + "kind": "staff", + "name": "Staff LL", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "MM.owner", + "process": "MM", + "kind": "owner", + "name": "Process owner MM", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "MM.manager", + "process": "MM", + "kind": "manager", + "name": "Process manager MM", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "MM.staff", + "process": "MM", + "kind": "staff", + "name": "Staff MM", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "NN.owner", + "process": "NN", + "kind": "owner", + "name": "Process owner NN", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + }, + { + "id": "NN.manager", + "process": "NN", + "kind": "manager", + "name": "Process manager NN", + "count": "1 in total", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [ + { + "text": "Specific task", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + } + } + ] + }, + { + "id": "NN.staff", + "process": "NN", + "kind": "staff", + "name": "Staff NN", + "source": { + "doc": "FitSM-3", + "section": "6.1", + "page": 4 + }, + "tasks": [] + } + ] +} diff --git a/tests/fixtures/valid/map.json b/tests/fixtures/valid/map.json index 8d1acef..1784c4f 100644 --- a/tests/fixtures/valid/map.json +++ b/tests/fixtures/valid/map.json @@ -10,6 +10,10 @@ "cols": 14, "rows": 6 }, + "zones": [ + { "id": "top", "name": "Top", "fill": "#eef3f9", "top": 0, "bottom": 3, "label": "nw", "stations": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"] }, + { "id": "bottom", "name": "Bottom", "fill": "#f7f3ea", "top": 3, "bottom": 6, "label": "sw", "stations": ["HH", "II", "JJ", "KK", "LL", "MM", "NN"] } + ], "lines": [ { "id": "one", diff --git a/tests/graph.test.js b/tests/graph.test.js index 81f859a..4158b92 100644 --- a/tests/graph.test.js +++ b/tests/graph.test.js @@ -6,7 +6,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { stationLines, isInterchange, connectionLine, connectionLabel, - stationLabel, interfaceLabel, + stationLabel, interfaceLabel, stationZone, } from "../src/graph.js"; const model = { @@ -57,3 +57,11 @@ test("labels name lines in words", () => { assert.equal(stationLabel("PM", model), "Problem management, PM, on the Operations, Control and Everything lines"); assert.equal(interfaceLabel("ISRM-PM", model), "Interface between Incident and service request management and Problem management, Operations line"); }); + +test("a station in a half names it in its label", () => { + const zoned = { ...model, map: { ...model.map, zones: [{ id: "oc", name: "Operate & Control", stations: ["CHM"] }] } }; + assert.equal(stationZone("CHM", zoned).id, "oc"); + assert.equal(stationZone("PM", zoned), null); + assert.equal(stationZone("CHM", model), null); + assert.equal(stationLabel("CHM", zoned), "Change management, CHM, in Operate & Control, on the Control and Everything lines"); +}); diff --git a/tests/layout.test.js b/tests/layout.test.js new file mode 100644 index 0000000..19e4cf0 --- /dev/null +++ b/tests/layout.test.js @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2026 PNED G.I.E. +// +// SPDX-License-Identifier: CC-BY-4.0 + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { layoutMetrics } from "../scripts/layout.js"; + +const at = (x, y) => ({ x, y, label: "s" }); + +test("two routes crossing in an X count as one crossing", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 0), BB: at(4, 4), CC: at(0, 4), DD: at(4, 0) }, + routes: { "AA-BB": [], "CC-DD": [] }, + }); + assert.deepEqual(m.crossings, [{ a: "AA-BB", b: "CC-DD", at: [2, 2] }]); + assert.equal(m.crossingPoints, 1); + assert.equal(m.shared.length, 0); + assert.equal(m.close.length, 0); +}); + +test("routes meeting at a station they share do not cross", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 0), BB: at(2, 0), CC: at(4, 0), DD: at(2, 2) }, + routes: { "AA-BB": [], "BB-CC": [], "BB-DD": [] }, + }); + assert.deepEqual(m, { crossings: [], crossingPoints: 0, shared: [], close: [] }); +}); + +test("a bend lying on another route counts as a crossing", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 2), BB: at(4, 2), CC: at(1, 0), DD: at(3, 0) }, + routes: { "AA-BB": [], "CC-DD": [[2, 2]] }, + }); + assert.deepEqual(m.crossings, [{ a: "AA-BB", b: "CC-DD", at: [2, 2] }]); +}); + +test("routes leaving a station along the same stretch share a segment", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 0), BB: at(0, 4), CC: at(3, 4) }, + routes: { "AA-BB": [], "AA-CC": [[0, 1], [3, 4]] }, + }); + assert.deepEqual(m.shared, [{ a: "AA-BB", b: "AA-CC", kind: "merge", from: [0, 0], to: [0, 1] }]); + assert.equal(m.crossings.length, 0); +}); + +test("parallel routes one unit apart are close; two units apart are not", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 0), BB: at(4, 0), CC: at(1, 1), DD: at(6, 1), EE: at(0, 3), FF: at(4, 3) }, + routes: { "AA-BB": [], "CC-DD": [], "EE-FF": [] }, + }); + assert.deepEqual(m.close, [{ a: "AA-BB", b: "CC-DD", from: [1, 0], to: [4, 0], distance: 1 }]); +}); + +test("shared segments are classed as transfer merges, within a line, or mixed", () => { + const stations = { AA: at(0, 0), BB: at(0, 4), CC: at(3, 4), DD: at(-3, 4) }; + const routes = { "AA-BB": [], "AA-CC": [[0, 1], [3, 4]], "AA-DD": [[0, 1], [-3, 4]] }; + const kinds = (lines) => layoutMetrics({ stations, routes, lines }).shared.map((s) => `${s.a}=${s.b}:${s.kind}`); + assert.deepEqual(kinds([]), ["AA-BB=AA-CC:merge", "AA-BB=AA-DD:merge", "AA-CC=AA-DD:merge"]); + const oneLine = [{ id: "one", stations: ["AA", "BB", "CC"] }]; + assert.deepEqual(kinds(oneLine), ["AA-BB=AA-CC:line", "AA-BB=AA-DD:mixed", "AA-CC=AA-DD:mixed"]); +}); + +test("crossing points count a trunk crossing a line once", () => { + const m = layoutMetrics({ + stations: { AA: at(0, 0), BB: at(4, 0), CC: at(2, -2), DD: at(2, 2), EE: at(4, 2) }, + routes: { "AA-BB": [], "CC-DD": [], "CC-EE": [[2, 2]] }, // CC-DD and CC-EE share x = 2 + }); + assert.equal(m.crossings.length, 2); + assert.equal(m.crossingPoints, 1); +}); diff --git a/tests/map.test.js b/tests/map.test.js index 2ea6499..05fec81 100644 --- a/tests/map.test.js +++ b/tests/map.test.js @@ -4,7 +4,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -import { intersection, yieldingPath, selectionState } from "../src/map.js"; +import { intersection, yieldingPath, selectionState, connectionsThrough } from "../src/map.js"; test("intersection finds crossings strictly inside both segments", () => { const hit = intersection([0, 0], [10, 10], [0, 10], [10, 0]); @@ -40,8 +40,46 @@ test("yieldingPath cuts a gap around a bend that lies on another line", () => { assert.ok(!bend.includes("L50 0"), bend); assert.match(bend, /^M0 0 L43 0 M43 4 L43 -4 M/, "stops 7 px before the bend with a vertical tick"); assert.match(bend, / L100 50$/, "resumes after the bend and reaches the far end"); - // A bend that is not on any other line is drawn through as before. - assert.equal(yieldingPath([[0, 0], [50, 0], [100, 50]], [[[70, -50], [70, 50]]]).startsWith("M0 0 L50 0 "), true); + // A bend that is not on any other line is drawn through as before (sharp with radius 0). + assert.equal(yieldingPath([[0, 0], [50, 0], [100, 50]], [[[70, -50], [70, 50]]], 0).startsWith("M0 0 L50 0 "), true); +}); + +test("yieldingPath draws a bend as a curve, shortened where the segments are short", () => { + // A 90° bend with radius 20: the curve starts 20 px before the corner and ends 20 px after. + assert.equal(yieldingPath([[0, 0], [100, 0], [100, 100]], [], 20), "M0 0 L80 0 Q100 0 100 20 L100 100"); + // Segments of 30 px leave room for at most 15 px on each side of the corner. + assert.equal(yieldingPath([[0, 0], [30, 0], [30, 30]], [], 20), "M0 0 L15 0 Q30 0 30 15 L30 30"); + // A straight run through a vertex is not a bend. + assert.equal(yieldingPath([[0, 0], [50, 0], [100, 0]], [], 20), "M0 0 L50 0 L100 0"); +}); + +test("yieldingPath tightens a curve, down to a sharp corner, to make room for a nearby gap", () => { + // A vertical line crosses 20 px before the bend at (100,0). A full 30 px curve would cover + // the crossing; the gap (7 px each side plus a 4 px tick) leaves room for a 8.5 px curve. + const near = yieldingPath([[0, 0], [100, 0], [100, 100]], [[[80, -50], [80, 50]]], 30); + assert.match(near, /M87 0 L91\.5 0 Q100 0 100 8\.5 /, near); + // Closer still, the bend turns sharp. + const sharp = yieldingPath([[0, 0], [100, 0], [100, 100]], [[[88.5, -50], [88.5, 50]]], 30); + assert.match(sharp, /L100 0 L100 100$/, sharp); +}); + +test("yieldingPath leaves no gap where a route branches off a shared stretch", () => { + const trunk = [[0, 0], [100, 0]]; + // This route runs along the trunk to x = 50, then turns away: a junction, not a crossing. + const branch = yieldingPath([[0, 0], [50, 0], [100, 50]], [trunk], 0); + assert.equal(branch, "M0 0 L50 0 L100 50"); + // The trunk does not yield where the branch leaves it. + assert.equal(yieldingPath(trunk, [[[0, 0], [50, 0], [100, 50]]], 0), "M0 0 L100 0"); +}); + +test("yieldingPath on a shared stretch skips a crossing an earlier line already yielded to", () => { + const cross = [[50, -50], [50, 50]]; + const trunk = [[0, 0], [100, 0]]; + // The crossing line was drawn after the first trunk line, so it already has a gap there; + // a second line on the same stretch stays unbroken too. + assert.equal(yieldingPath(trunk, [trunk, cross]), "M0 0 L100 0"); + // Drawn before the trunk, the crossing line is unbroken, so the trunk yields as usual. + assert.equal(yieldingPath(trunk, [cross, trunk]), "M0 0 L43 0 M43 4 L43 -4 M57 4 L57 -4 M57 0 L100 0"); }); test("yieldingPath cuts a gap where another line's bend lies on this segment", () => { @@ -79,3 +117,24 @@ test("selectionState: a connection is selected", () => { assert.deepEqual(selectionState("#ISRM-PM", "#CHM-PM"), { selected: false, related: false }); assert.deepEqual(selectionState("#ISRM-PM", "#SLM"), { selected: false, related: false }); }); + +test("selectionState: several connections are selected", () => { + const hash = "#CHM-ISRM,CONFM-ISRM"; + assert.deepEqual(selectionState(hash, "#CHM-ISRM"), { selected: true, related: false }); + assert.deepEqual(selectionState(hash, "#CONFM-ISRM"), { selected: true, related: false }); + assert.deepEqual(selectionState(hash, "#CONFM"), { selected: false, related: true }, "an end of one of them"); + assert.deepEqual(selectionState(hash, "#CHM-PM"), { selected: false, related: false }); + assert.deepEqual(selectionState(hash, "#PM"), { selected: false, related: false }); +}); + +test("connectionsThrough finds the routes sharing the clicked stretch, not those crossing it", () => { + const routes = new Map([ + ["AA-BB", [[0, 0], [100, 0]]], + ["AA-CC", [[0, 0], [50, 0], [100, 50]]], // shares the first half, then branches off + ["DD-EE", [[30, -50], [30, 50]]], // crosses at x = 30 + ["FF-GG", [[0, 40], [100, 40]]], // elsewhere + ]); + assert.deepEqual(connectionsThrough(routes, "AA-BB", [30, 3]), ["AA-BB", "AA-CC"], "on the shared stretch, even at a crossing"); + assert.deepEqual(connectionsThrough(routes, "AA-BB", [80, -2]), ["AA-BB"], "past the branch"); + assert.deepEqual(connectionsThrough(routes, "FF-GG", [10, 40]), ["FF-GG"]); +}); diff --git a/tests/router.test.js b/tests/router.test.js index 0231de4..39f2ade 100644 --- a/tests/router.test.js +++ b/tests/router.test.js @@ -9,7 +9,7 @@ import { parse, format, canonical } from "../src/router.js"; const model = { processes: new Map([["ISRM", {}], ["PM", {}], ["CHM", {}]]), aliases: new Map([["INCM", "ISRM"]]), - interfaces: new Map([["ISRM-PM", {}]]), + interfaces: new Map([["ISRM-PM", {}], ["CHM-PM", {}]]), roles: new Map([["ISRM.manager", {}]]), activities: new Map([["ISRM.A1", {}]]), records: new Map([["incident-record", {}]]), @@ -35,9 +35,9 @@ test("parse upper-cases codes typed by hand", () => { }); test("format is the inverse of parse for every valid selection", () => { - for (const hash of ["", "#GR", "#ISRM", "#ISRM-PM", "#role/ISRM.manager", "#activity/ISRM.A1", "#record/incident-record"]) { + for (const hash of ["", "#GR", "#ISRM", "#ISRM-PM", "#CHM-PM,ISRM-PM", "#role/ISRM.manager", "#activity/ISRM.A1", "#record/incident-record"]) { const p = parse(hash); - assert.equal(format(p.kind, p.id), hash); + assert.equal(format(p.kind, p.ids ?? p.id), hash); } }); @@ -63,3 +63,12 @@ test("canonical reports unknown items without redirect", () => { assert.equal(c.redirect, false, hash); } }); + +test("several interfaces: parsed, sorted, de-duplicated, and one alone is a plain interface", () => { + assert.deepEqual(parse("#ISRM-PM,chm-pm"), { kind: "interfaces", ids: ["ISRM-PM", "CHM-PM"], raw: "ISRM-PM,chm-pm" }); + assert.equal(parse("#ISRM-PM,GR").kind, "unknown"); + assert.deepEqual(canonical(parse("#CHM-PM,ISRM-PM"), model), { kind: "interfaces", ids: ["CHM-PM", "ISRM-PM"], hash: "#CHM-PM,ISRM-PM", redirect: false }); + assert.deepEqual(canonical(parse("#PM-INCM,PM-CHM"), model), { kind: "interfaces", ids: ["CHM-PM", "ISRM-PM"], hash: "#CHM-PM,ISRM-PM", redirect: true }); + assert.deepEqual(canonical(parse("#ISRM-PM,PM-ISRM"), model), { kind: "interface", id: "ISRM-PM", hash: "#ISRM-PM", redirect: true }); + assert.equal(canonical(parse("#ISRM-PM,ISRM-CHM"), model).kind, "unknown", "one unknown interface makes the whole address unknown"); +});