@nowline/layout 0.8.5 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/axis-columns.d.ts +70 -0
- package/dist/axis-columns.d.ts.map +1 -0
- package/dist/axis-columns.js +104 -0
- package/dist/axis-columns.js.map +1 -0
- package/dist/band-scale.d.ts.map +1 -1
- package/dist/calendar-resolver.d.ts +27 -0
- package/dist/calendar-resolver.d.ts.map +1 -0
- package/dist/calendar-resolver.js +132 -0
- package/dist/calendar-resolver.js.map +1 -0
- package/dist/calendar.d.ts +0 -19
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +4 -44
- package/dist/calendar.js.map +1 -1
- package/dist/canvas-width.d.ts +23 -0
- package/dist/canvas-width.d.ts.map +1 -0
- package/dist/canvas-width.js +26 -0
- package/dist/canvas-width.js.map +1 -0
- package/dist/capacity.d.ts +28 -0
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js +64 -29
- package/dist/capacity.js.map +1 -1
- package/dist/chart-translation.d.ts +22 -0
- package/dist/chart-translation.d.ts.map +1 -0
- package/dist/chart-translation.js +83 -0
- package/dist/chart-translation.js.map +1 -0
- package/dist/container-header-geometry.d.ts +64 -0
- package/dist/container-header-geometry.d.ts.map +1 -0
- package/dist/container-header-geometry.js +89 -0
- package/dist/container-header-geometry.js.map +1 -0
- package/dist/dsl-utils.d.ts +3 -4
- package/dist/dsl-utils.d.ts.map +1 -1
- package/dist/dsl-utils.js +8 -25
- package/dist/dsl-utils.js.map +1 -1
- package/dist/edge-routing.d.ts +69 -78
- package/dist/edge-routing.d.ts.map +1 -1
- package/dist/edge-routing.js +271 -401
- package/dist/edge-routing.js.map +1 -1
- package/dist/frame-tab-geometry.d.ts +24 -14
- package/dist/frame-tab-geometry.d.ts.map +1 -1
- package/dist/frame-tab-geometry.js +69 -23
- package/dist/frame-tab-geometry.js.map +1 -1
- package/dist/header-card-geometry.d.ts +12 -0
- package/dist/header-card-geometry.d.ts.map +1 -1
- package/dist/header-card-geometry.js +14 -2
- package/dist/header-card-geometry.js.map +1 -1
- package/dist/header-logo.d.ts +28 -0
- package/dist/header-logo.d.ts.map +1 -0
- package/dist/header-logo.js +51 -0
- package/dist/header-logo.js.map +1 -0
- package/dist/i18n.d.ts +11 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +11 -1
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +20 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/inline-date-pin-geometry.d.ts +19 -11
- package/dist/inline-date-pin-geometry.d.ts.map +1 -1
- package/dist/inline-date-pin-geometry.js +45 -46
- package/dist/inline-date-pin-geometry.js.map +1 -1
- package/dist/item-bar-geometry.d.ts +192 -4
- package/dist/item-bar-geometry.d.ts.map +1 -1
- package/dist/item-bar-geometry.js +258 -5
- package/dist/item-bar-geometry.js.map +1 -1
- package/dist/item-port-geometry.d.ts +13 -0
- package/dist/item-port-geometry.d.ts.map +1 -0
- package/dist/item-port-geometry.js +63 -0
- package/dist/item-port-geometry.js.map +1 -0
- package/dist/layout-context.d.ts +115 -51
- package/dist/layout-context.d.ts.map +1 -1
- package/dist/layout-context.js +96 -5
- package/dist/layout-context.js.map +1 -1
- package/dist/layout-insights.d.ts.map +1 -1
- package/dist/layout-insights.js +73 -1
- package/dist/layout-insights.js.map +1 -1
- package/dist/layout.d.ts +35 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +18 -1315
- package/dist/layout.js.map +1 -1
- package/dist/nodes/anchor-node.d.ts.map +1 -1
- package/dist/nodes/anchor-node.js +11 -4
- package/dist/nodes/anchor-node.js.map +1 -1
- package/dist/nodes/content-extent.d.ts +24 -0
- package/dist/nodes/content-extent.d.ts.map +1 -0
- package/dist/nodes/content-extent.js +100 -0
- package/dist/nodes/content-extent.js.map +1 -0
- package/dist/nodes/dependency-edges.d.ts +6 -0
- package/dist/nodes/dependency-edges.d.ts.map +1 -0
- package/dist/nodes/dependency-edges.js +148 -0
- package/dist/nodes/dependency-edges.js.map +1 -0
- package/dist/nodes/footnote-node.d.ts +24 -3
- package/dist/nodes/footnote-node.d.ts.map +1 -1
- package/dist/nodes/footnote-node.js +129 -25
- package/dist/nodes/footnote-node.js.map +1 -1
- package/dist/nodes/group-node.d.ts +10 -21
- package/dist/nodes/group-node.d.ts.map +1 -1
- package/dist/nodes/group-node.js +79 -154
- package/dist/nodes/group-node.js.map +1 -1
- package/dist/nodes/header-node.d.ts +56 -0
- package/dist/nodes/header-node.d.ts.map +1 -0
- package/dist/nodes/header-node.js +163 -0
- package/dist/nodes/header-node.js.map +1 -0
- package/dist/nodes/include-node.d.ts +22 -12
- package/dist/nodes/include-node.d.ts.map +1 -1
- package/dist/nodes/include-node.js +95 -62
- package/dist/nodes/include-node.js.map +1 -1
- package/dist/nodes/item-measure.d.ts +135 -0
- package/dist/nodes/item-measure.d.ts.map +1 -0
- package/dist/nodes/item-measure.js +514 -0
- package/dist/nodes/item-measure.js.map +1 -0
- package/dist/nodes/item-node.d.ts +162 -9
- package/dist/nodes/item-node.d.ts.map +1 -1
- package/dist/nodes/item-node.js +256 -69
- package/dist/nodes/item-node.js.map +1 -1
- package/dist/nodes/marker-band.d.ts +118 -0
- package/dist/nodes/marker-band.d.ts.map +1 -0
- package/dist/nodes/marker-band.js +303 -0
- package/dist/nodes/marker-band.js.map +1 -0
- package/dist/nodes/marker-geometry.js +1 -1
- package/dist/nodes/marker-geometry.js.map +1 -1
- package/dist/nodes/milestone-node.d.ts +112 -15
- package/dist/nodes/milestone-node.d.ts.map +1 -1
- package/dist/nodes/milestone-node.js +246 -95
- package/dist/nodes/milestone-node.js.map +1 -1
- package/dist/nodes/nowline-node.d.ts +8 -0
- package/dist/nodes/nowline-node.d.ts.map +1 -0
- package/dist/nodes/nowline-node.js +74 -0
- package/dist/nodes/nowline-node.js.map +1 -0
- package/dist/nodes/parallel-node.d.ts +7 -12
- package/dist/nodes/parallel-node.d.ts.map +1 -1
- package/dist/nodes/parallel-node.js +66 -32
- package/dist/nodes/parallel-node.js.map +1 -1
- package/dist/nodes/region-markers.d.ts +41 -0
- package/dist/nodes/region-markers.d.ts.map +1 -0
- package/dist/nodes/region-markers.js +130 -0
- package/dist/nodes/region-markers.js.map +1 -0
- package/dist/nodes/roadmap-node.d.ts +9 -72
- package/dist/nodes/roadmap-node.d.ts.map +1 -1
- package/dist/nodes/roadmap-node.js +38 -788
- package/dist/nodes/roadmap-node.js.map +1 -1
- package/dist/nodes/row-track.d.ts +33 -0
- package/dist/nodes/row-track.d.ts.map +1 -0
- package/dist/nodes/row-track.js +170 -0
- package/dist/nodes/row-track.js.map +1 -0
- package/dist/nodes/sequence-item.d.ts +25 -0
- package/dist/nodes/sequence-item.d.ts.map +1 -0
- package/dist/nodes/sequence-item.js +396 -0
- package/dist/nodes/sequence-item.js.map +1 -0
- package/dist/nodes/sequence-one.d.ts +5 -0
- package/dist/nodes/sequence-one.d.ts.map +1 -0
- package/dist/nodes/sequence-one.js +26 -0
- package/dist/nodes/sequence-one.js.map +1 -0
- package/dist/nodes/swimlane-node.d.ts +5 -17
- package/dist/nodes/swimlane-node.d.ts.map +1 -1
- package/dist/nodes/swimlane-node.js +62 -147
- package/dist/nodes/swimlane-node.js.map +1 -1
- package/dist/nodes/wave-node.d.ts +52 -0
- package/dist/nodes/wave-node.d.ts.map +1 -0
- package/dist/nodes/wave-node.js +483 -0
- package/dist/nodes/wave-node.js.map +1 -0
- package/dist/non-working-display.d.ts +14 -0
- package/dist/non-working-display.d.ts.map +1 -0
- package/dist/non-working-display.js +28 -0
- package/dist/non-working-display.js.map +1 -0
- package/dist/phases/date-window.d.ts +48 -0
- package/dist/phases/date-window.d.ts.map +1 -0
- package/dist/phases/date-window.js +130 -0
- package/dist/phases/date-window.js.map +1 -0
- package/dist/phases/finalize.d.ts +198 -0
- package/dist/phases/finalize.d.ts.map +1 -0
- package/dist/phases/finalize.js +1058 -0
- package/dist/phases/finalize.js.map +1 -0
- package/dist/phases/measure.d.ts +77 -0
- package/dist/phases/measure.d.ts.map +1 -0
- package/dist/phases/measure.js +222 -0
- package/dist/phases/measure.js.map +1 -0
- package/dist/phases/place.d.ts +28 -0
- package/dist/phases/place.d.ts.map +1 -0
- package/dist/phases/place.js +225 -0
- package/dist/phases/place.js.map +1 -0
- package/dist/renderable.d.ts.map +1 -1
- package/dist/renderable.js +23 -3
- package/dist/renderable.js.map +1 -1
- package/dist/resolve-today.d.ts +11 -1
- package/dist/resolve-today.d.ts.map +1 -1
- package/dist/resolve-today.js +26 -12
- package/dist/resolve-today.js.map +1 -1
- package/dist/row-packer.d.ts +42 -16
- package/dist/row-packer.d.ts.map +1 -1
- package/dist/row-packer.js +51 -78
- package/dist/row-packer.js.map +1 -1
- package/dist/schedule.d.ts +58 -1
- package/dist/schedule.d.ts.map +1 -1
- package/dist/schedule.js +280 -106
- package/dist/schedule.js.map +1 -1
- package/dist/start-rules.d.ts +27 -0
- package/dist/start-rules.d.ts.map +1 -0
- package/dist/start-rules.js +91 -0
- package/dist/start-rules.js.map +1 -0
- package/dist/start-terms.d.ts +23 -0
- package/dist/start-terms.d.ts.map +1 -0
- package/dist/start-terms.js +27 -0
- package/dist/start-terms.js.map +1 -0
- package/dist/status-dot.d.ts +46 -0
- package/dist/status-dot.d.ts.map +1 -0
- package/dist/status-dot.js +78 -0
- package/dist/status-dot.js.map +1 -0
- package/dist/style-resolution.d.ts.map +1 -1
- package/dist/style-resolution.js +23 -43
- package/dist/style-resolution.js.map +1 -1
- package/dist/text-measure.d.ts +28 -0
- package/dist/text-measure.d.ts.map +1 -0
- package/dist/text-measure.js +70 -0
- package/dist/text-measure.js.map +1 -0
- package/dist/themes/contrast.d.ts +4 -0
- package/dist/themes/contrast.d.ts.map +1 -0
- package/dist/themes/contrast.js +32 -0
- package/dist/themes/contrast.js.map +1 -0
- package/dist/themes/dark.d.ts.map +1 -1
- package/dist/themes/dark.js +28 -1
- package/dist/themes/dark.js.map +1 -1
- package/dist/themes/grayscale.d.ts.map +1 -1
- package/dist/themes/grayscale.js +28 -1
- package/dist/themes/grayscale.js.map +1 -1
- package/dist/themes/index.d.ts +4 -11
- package/dist/themes/index.d.ts.map +1 -1
- package/dist/themes/index.js +6 -4
- package/dist/themes/index.js.map +1 -1
- package/dist/themes/light.d.ts.map +1 -1
- package/dist/themes/light.js +28 -1
- package/dist/themes/light.js.map +1 -1
- package/dist/themes/shape.d.ts +31 -0
- package/dist/themes/shape.d.ts.map +1 -1
- package/dist/themes/shared.d.ts +44 -50
- package/dist/themes/shared.d.ts.map +1 -1
- package/dist/themes/shared.js +79 -83
- package/dist/themes/shared.js.map +1 -1
- package/dist/time-scale.d.ts +42 -6
- package/dist/time-scale.d.ts.map +1 -1
- package/dist/time-scale.js +109 -17
- package/dist/time-scale.js.map +1 -1
- package/dist/types.d.ts +528 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/view-preset.d.ts +61 -6
- package/dist/view-preset.d.ts.map +1 -1
- package/dist/view-preset.js +439 -24
- package/dist/view-preset.js.map +1 -1
- package/dist/wave-barrier.d.ts +107 -0
- package/dist/wave-barrier.d.ts.map +1 -0
- package/dist/wave-barrier.js +174 -0
- package/dist/wave-barrier.js.map +1 -0
- package/dist/wave-hatch.d.ts +4 -0
- package/dist/wave-hatch.d.ts.map +1 -0
- package/dist/wave-hatch.js +21 -0
- package/dist/wave-hatch.js.map +1 -0
- package/dist/wave-layout.d.ts +99 -0
- package/dist/wave-layout.d.ts.map +1 -0
- package/dist/wave-layout.js +130 -0
- package/dist/wave-layout.js.map +1 -0
- package/dist/working-calendar.d.ts +128 -4
- package/dist/working-calendar.d.ts.map +1 -1
- package/dist/working-calendar.js +725 -51
- package/dist/working-calendar.js.map +1 -1
- package/dist/working-span.d.ts +11 -0
- package/dist/working-span.d.ts.map +1 -0
- package/dist/working-span.js +18 -0
- package/dist/working-span.js.map +1 -0
- package/package.json +7 -7
- package/src/axis-columns.ts +140 -0
- package/src/calendar-resolver.ts +161 -0
- package/src/calendar.ts +4 -45
- package/src/canvas-width.ts +36 -0
- package/src/capacity.ts +71 -30
- package/src/chart-translation.ts +88 -0
- package/src/container-header-geometry.ts +116 -0
- package/src/dsl-utils.ts +8 -26
- package/src/edge-routing.ts +347 -491
- package/src/frame-tab-geometry.ts +78 -25
- package/src/header-card-geometry.ts +17 -2
- package/src/header-logo.ts +67 -0
- package/src/i18n.ts +22 -1
- package/src/index.ts +97 -12
- package/src/inline-date-pin-geometry.ts +55 -58
- package/src/item-bar-geometry.ts +341 -5
- package/src/item-port-geometry.ts +69 -0
- package/src/layout-context.ts +210 -72
- package/src/layout-insights.ts +109 -2
- package/src/layout.ts +57 -1530
- package/src/nodes/anchor-node.ts +11 -4
- package/src/nodes/content-extent.ts +107 -0
- package/src/nodes/dependency-edges.ts +171 -0
- package/src/nodes/footnote-node.ts +171 -31
- package/src/nodes/group-node.ts +92 -215
- package/src/nodes/header-node.ts +255 -0
- package/src/nodes/include-node.ts +124 -110
- package/src/nodes/item-measure.ts +723 -0
- package/src/nodes/item-node.ts +358 -80
- package/src/nodes/marker-band.ts +406 -0
- package/src/nodes/marker-geometry.ts +1 -1
- package/src/nodes/milestone-node.ts +321 -136
- package/src/nodes/nowline-node.ts +87 -0
- package/src/nodes/parallel-node.ts +69 -39
- package/src/nodes/region-markers.ts +194 -0
- package/src/nodes/roadmap-node.ts +46 -950
- package/src/nodes/row-track.ts +217 -0
- package/src/nodes/sequence-item.ts +433 -0
- package/src/nodes/sequence-one.ts +40 -0
- package/src/nodes/swimlane-node.ts +66 -206
- package/src/nodes/wave-node.ts +609 -0
- package/src/non-working-display.ts +32 -0
- package/src/phases/date-window.ts +191 -0
- package/src/phases/finalize.ts +1303 -0
- package/src/phases/measure.ts +329 -0
- package/src/phases/place.ts +318 -0
- package/src/renderable.ts +23 -3
- package/src/resolve-today.ts +28 -25
- package/src/row-packer.ts +85 -84
- package/src/schedule.ts +362 -114
- package/src/start-rules.ts +113 -0
- package/src/start-terms.ts +38 -0
- package/src/status-dot.ts +81 -0
- package/src/style-resolution.ts +27 -57
- package/src/text-measure.ts +71 -0
- package/src/themes/contrast.ts +34 -0
- package/src/themes/dark.ts +28 -1
- package/src/themes/grayscale.ts +28 -1
- package/src/themes/index.ts +10 -7
- package/src/themes/light.ts +28 -1
- package/src/themes/shape.ts +38 -0
- package/src/themes/shared.ts +85 -93
- package/src/time-scale.ts +117 -19
- package/src/types.ts +529 -20
- package/src/view-preset.ts +520 -27
- package/src/wave-barrier.ts +242 -0
- package/src/wave-hatch.ts +25 -0
- package/src/wave-layout.ts +203 -0
- package/src/working-calendar.ts +875 -57
- package/src/working-span.ts +19 -0
package/src/edge-routing.ts
CHANGED
|
@@ -1,550 +1,406 @@
|
|
|
1
|
-
//
|
|
2
|
-
// `routeEdge` shipped in m2g with one that:
|
|
1
|
+
// Date-port dependency router (specs/true-width-layout.md §3.4).
|
|
3
2
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// thinner stroke) when no clean channel exists in the source-target
|
|
13
|
-
// gap.
|
|
3
|
+
// An arrow runs on the dates. It leaves the middle of its source's last
|
|
4
|
+
// day through the source's bottom edge (top edge when the target is
|
|
5
|
+
// above), drops into a gap between rows, runs horizontally in that gap to
|
|
6
|
+
// the middle of the target's first day, and turns into the target's top
|
|
7
|
+
// edge (bottom edge when the source is below), arrowhead first. Day
|
|
8
|
+
// centres, never date lines: in a chain the successor starts exactly on
|
|
9
|
+
// its predecessor's end date, so a leg on the date line would run down the
|
|
10
|
+
// successor's edge.
|
|
14
11
|
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// the
|
|
18
|
-
//
|
|
19
|
-
//
|
|
12
|
+
// Legs pass behind bars and cross them at right angles. The horizontal leg
|
|
13
|
+
// sits in a gap no bar, spilled caption or container header reaches into
|
|
14
|
+
// (between the source and the target, over the leg's x-range); among the
|
|
15
|
+
// gaps, the router takes the one whose vertical legs keep clear of every
|
|
16
|
+
// bar edge, then the one whose vertical legs cross the fewest bars, then
|
|
17
|
+
// the one nearest the source. Arrows sharing a gap take offset lanes
|
|
18
|
+
// `CHANNEL_LANE_PX` apart; arrows landing in the same day column share one
|
|
19
|
+
// lane, so they merge into one trunk over their target (§8 O1).
|
|
20
|
+
//
|
|
21
|
+
// Two shapes need no gap: a target on its source's row (a dotted leg at
|
|
22
|
+
// the row's midline, or no arrow when it starts where the source ends),
|
|
23
|
+
// and a marker source (`dependency-edges.ts`). Everything here is pure
|
|
24
|
+
// geometry on numbers the caller reads off the final model.
|
|
25
|
+
|
|
26
|
+
import type { BoundingBox, Point } from './types.js';
|
|
27
|
+
|
|
28
|
+
/** Spacing between the lanes of one gap (§3.4 "Channels"). */
|
|
29
|
+
export const CHANNEL_LANE_PX = 2.5;
|
|
30
|
+
|
|
31
|
+
/** A vertical leg keeps more than this from a bar's left or right edge over its height (§6). */
|
|
32
|
+
export const EDGE_CLEARANCE_PX = 1;
|
|
33
|
+
|
|
34
|
+
/** Full arrowhead width (and the length along the leg is `ARROW_HEAD_LENGTH_PX`). */
|
|
35
|
+
export const ARROW_HEAD_WIDTH_PX = 7;
|
|
36
|
+
|
|
37
|
+
/** Length of a full arrowhead along its leg. */
|
|
38
|
+
export const ARROW_HEAD_LENGTH_PX = 5;
|
|
39
|
+
|
|
40
|
+
/** The narrowest arrowhead; a target narrower than this gets a dot of this diameter (§8 O6). */
|
|
41
|
+
export const ARROW_HEAD_MIN_PX = 3;
|
|
42
|
+
|
|
43
|
+
/** Two x's (or y's) closer than this are the same date line. */
|
|
44
|
+
const SAME_PX = 0.01;
|
|
45
|
+
|
|
46
|
+
/** A gap must be at least this tall to carry a leg. */
|
|
47
|
+
const MIN_GAP_PX = 2;
|
|
48
|
+
|
|
49
|
+
/** Clearance kept between a horizontal leg and anything it must not touch. */
|
|
50
|
+
const BLOCK_MARGIN_PX = 1;
|
|
51
|
+
|
|
52
|
+
/** One end of a dependency arrow: an item bar or a group / parallel. */
|
|
53
|
+
export interface ArrowEnd {
|
|
54
|
+
/** The entity's dates in x (an item's bar is drawn inside them, a seam in from each). */
|
|
55
|
+
startX: number;
|
|
56
|
+
endX: number;
|
|
57
|
+
/** Painted left edge and width (the bar, or the container's box). */
|
|
58
|
+
paintedX: number;
|
|
59
|
+
paintedWidth: number;
|
|
60
|
+
/** Painted top and bottom (a container's box runs from its header to its body's bottom). */
|
|
61
|
+
top: number;
|
|
62
|
+
bottom: number;
|
|
63
|
+
/** An item's row midline (`box.y + bandwidth / 2`); undefined for a container. */
|
|
64
|
+
rowY?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Where a horizontal leg leaves this item on its own row: the row
|
|
67
|
+
* midline, or the progress strip's centre when its caption spills, so
|
|
68
|
+
* the leg runs under the caption. Undefined for a container.
|
|
69
|
+
*/
|
|
70
|
+
exitY?: number;
|
|
71
|
+
}
|
|
20
72
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from './types.js';
|
|
73
|
+
export interface DependencyRouteRequest {
|
|
74
|
+
fromId: string;
|
|
75
|
+
toId: string;
|
|
76
|
+
source: ArrowEnd;
|
|
77
|
+
target: ArrowEnd;
|
|
78
|
+
}
|
|
28
79
|
|
|
29
|
-
/** A
|
|
30
|
-
|
|
31
|
-
* `BRACKET_NUDGE_PX` of one of these lines are shifted away. Brackets
|
|
32
|
-
* are NOT obstacles — they're aesthetic preferences, not collisions. */
|
|
33
|
-
export interface BracketLine {
|
|
80
|
+
/** A vertical stroke a vertical leg must keep clear of. */
|
|
81
|
+
export interface VerticalEdge {
|
|
34
82
|
x: number;
|
|
35
|
-
|
|
36
|
-
|
|
83
|
+
top: number;
|
|
84
|
+
bottom: number;
|
|
37
85
|
}
|
|
38
86
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* router entirely — the cut line is the visible stem, the path is
|
|
49
|
-
* always a short horizontal stub. Set true to bypass routing. */
|
|
50
|
-
isMarkerSource: boolean;
|
|
87
|
+
export interface RouteObstacles {
|
|
88
|
+
/**
|
|
89
|
+
* What a horizontal leg must stay out of: every bar with its spilled
|
|
90
|
+
* caption and decorations, every container header band, and every lane
|
|
91
|
+
* or region edge (zero-height boxes).
|
|
92
|
+
*/
|
|
93
|
+
blocks: BoundingBox[];
|
|
94
|
+
/** The left and right edges of every bar and drawn container, over its height. */
|
|
95
|
+
edges: VerticalEdge[];
|
|
51
96
|
}
|
|
52
97
|
|
|
53
|
-
export interface
|
|
98
|
+
export interface RoutedDependency {
|
|
54
99
|
fromId: string;
|
|
55
100
|
toId: string;
|
|
101
|
+
/** First = source port, last = target port (the arrowhead's tip). */
|
|
56
102
|
waypoints: Point[];
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
103
|
+
/** The target waits: its horizontal leg is dotted, its length the slack. */
|
|
104
|
+
slack: boolean;
|
|
105
|
+
headWidth: number;
|
|
106
|
+
head: 'arrow' | 'dot';
|
|
61
107
|
}
|
|
62
108
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export const BRACKET_NUDGE_PX = 4;
|
|
68
|
-
|
|
69
|
-
/** Minimum horizontal source stub (px) — distance from the source's
|
|
70
|
-
* exit point to the vertical-leg elbow. Below this, the source-side
|
|
71
|
-
* arrow body collapses into the bar's right edge with no visible
|
|
72
|
-
* horizontal segment. Treated as a hard constraint when picking
|
|
73
|
-
* the channel X for left-to-right edges. */
|
|
74
|
-
export const MIN_SOURCE_STUB_PX = 6;
|
|
75
|
-
|
|
76
|
-
/** Minimum horizontal target stub (px) — distance from the vertical-leg
|
|
77
|
-
* elbow to the target's left edge. Below this, the arrowhead has no
|
|
78
|
-
* horizontal lead-in: the leg appears to plunge directly into the bar
|
|
79
|
-
* without a visible target-side stub. Treated as a hard constraint
|
|
80
|
-
* when picking the channel X for left-to-right edges; conflicts with
|
|
81
|
-
* obstacle / bracket clearance trigger the under-bar fallback. */
|
|
82
|
-
export const MIN_TARGET_STUB_PX = 6;
|
|
109
|
+
/** Where an arrow leaves `end`: the middle of its last day, or its middle when shorter than a day. */
|
|
110
|
+
export function sourcePortX(end: ArrowEnd, pixelsPerDay: number): number {
|
|
111
|
+
return end.endX - Math.min(pixelsPerDay / 2, (end.endX - end.startX) / 2);
|
|
112
|
+
}
|
|
83
113
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
/** Where an arrow lands on `end`: the middle of its first day, or its middle when shorter than a day. */
|
|
115
|
+
export function targetPortX(end: ArrowEnd, pixelsPerDay: number): number {
|
|
116
|
+
return end.startX + Math.min(pixelsPerDay / 2, (end.endX - end.startX) / 2);
|
|
117
|
+
}
|
|
88
118
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
/** Arrowhead for a leg landing across a target `width` wide (§8 O6). */
|
|
120
|
+
export function arrowHead(width: number): { headWidth: number; head: 'arrow' | 'dot' } {
|
|
121
|
+
if (width < ARROW_HEAD_MIN_PX) return { headWidth: ARROW_HEAD_MIN_PX, head: 'dot' };
|
|
122
|
+
return { headWidth: Math.min(ARROW_HEAD_WIDTH_PX, width), head: 'arrow' };
|
|
123
|
+
}
|
|
92
124
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* elbow corner; the renderer's `roundedOrthogonalPath` rounds the
|
|
96
|
-
* corners. Left-to-right edges use the per-side `MIN_*_STUB_PX`
|
|
97
|
-
* constants instead — they provide tighter, asymmetric control over
|
|
98
|
-
* the source vs target sides. */
|
|
99
|
-
const STUB_OUT_PX = 10;
|
|
125
|
+
const within = (y: number, lo: number, hi: number): boolean =>
|
|
126
|
+
y >= lo - SAME_PX && y <= hi + SAME_PX;
|
|
100
127
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
brackets: BracketLine[];
|
|
128
|
+
/**
|
|
129
|
+
* True when the target sits on its source's row: each one's row midline
|
|
130
|
+
* crosses the other (a container source, which has no row, only needs the
|
|
131
|
+
* target's midline to cross it).
|
|
132
|
+
*/
|
|
133
|
+
function onSameRow(s: ArrowEnd, t: ArrowEnd): boolean {
|
|
134
|
+
if (t.rowY === undefined || !within(t.rowY, s.top, s.bottom)) return false;
|
|
135
|
+
return s.rowY === undefined || within(s.rowY, t.top, t.bottom);
|
|
110
136
|
}
|
|
111
137
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
/** The free stretches of `(lo, hi)` no block over `[xLo, xHi]` reaches into. */
|
|
139
|
+
function freeGaps(
|
|
140
|
+
blocks: BoundingBox[],
|
|
141
|
+
xLo: number,
|
|
142
|
+
xHi: number,
|
|
143
|
+
lo: number,
|
|
144
|
+
hi: number,
|
|
145
|
+
): Array<[number, number]> {
|
|
146
|
+
const covered: Array<[number, number]> = [];
|
|
147
|
+
for (const b of blocks) {
|
|
148
|
+
if (b.x >= xHi + BLOCK_MARGIN_PX || b.x + b.width <= xLo - BLOCK_MARGIN_PX) continue;
|
|
149
|
+
const top = b.y - BLOCK_MARGIN_PX;
|
|
150
|
+
const bottom = b.y + b.height + BLOCK_MARGIN_PX;
|
|
151
|
+
if (bottom <= lo || top >= hi) continue;
|
|
152
|
+
covered.push([Math.max(lo, top), Math.min(hi, bottom)]);
|
|
119
153
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const bar of this.items) {
|
|
127
|
-
if (x <= bar.x || x >= bar.x + bar.width) continue;
|
|
128
|
-
if (bar.y + bar.height <= lo || bar.y >= hi) continue;
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
154
|
+
covered.sort((a, b) => a[0] - b[0]);
|
|
155
|
+
const gaps: Array<[number, number]> = [];
|
|
156
|
+
let y = lo;
|
|
157
|
+
for (const [top, bottom] of covered) {
|
|
158
|
+
if (top - y >= MIN_GAP_PX) gaps.push([y, top]);
|
|
159
|
+
y = Math.max(y, bottom);
|
|
132
160
|
}
|
|
161
|
+
if (hi - y >= MIN_GAP_PX) gaps.push([y, hi]);
|
|
162
|
+
return gaps;
|
|
163
|
+
}
|
|
133
164
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (b.yBottom <= lo || b.yTop >= hi) continue;
|
|
144
|
-
out.push(b);
|
|
145
|
-
}
|
|
146
|
-
return out;
|
|
165
|
+
/** Bar or container edges a vertical leg at `x` over `(y0, y1)` runs within the clearance of. */
|
|
166
|
+
function grazes(edges: VerticalEdge[], x: number, y0: number, y1: number): number {
|
|
167
|
+
const lo = Math.min(y0, y1);
|
|
168
|
+
const hi = Math.max(y0, y1);
|
|
169
|
+
let n = 0;
|
|
170
|
+
for (const e of edges) {
|
|
171
|
+
if (Math.abs(e.x - x) > EDGE_CLEARANCE_PX) continue;
|
|
172
|
+
if (e.bottom <= lo || e.top >= hi) continue;
|
|
173
|
+
n++;
|
|
147
174
|
}
|
|
175
|
+
return n;
|
|
148
176
|
}
|
|
149
177
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
export function collectRoutingObstacles(
|
|
160
|
-
swimlanes: PositionedSwimlane[],
|
|
161
|
-
includes: PositionedIncludeRegion[],
|
|
162
|
-
): ChannelGridInput {
|
|
163
|
-
const itemBars: BoundingBox[] = [];
|
|
164
|
-
const brackets: BracketLine[] = [];
|
|
165
|
-
|
|
166
|
-
const visitChild = (child: PositionedTrackChild): void => {
|
|
167
|
-
if (child.kind === 'item') {
|
|
168
|
-
itemBars.push(child.box);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (child.kind === 'parallel') {
|
|
172
|
-
// Parallel `bracket:solid|dashed` paints `[ ]` strokes at
|
|
173
|
-
// the box's left/right edges with 12 px vertical padding
|
|
174
|
-
// (matches `renderParallel`). The bracket has THREE
|
|
175
|
-
// strokes per side — a vertical bar at the box edge, plus
|
|
176
|
-
// top/bottom horizontal "feet" extending 4 px inward
|
|
177
|
-
// toward the parallel's center. We model the verticals as
|
|
178
|
-
// full-height bracket lines AND emit thin-Y-band entries
|
|
179
|
-
// at the foot tips so the clearance nudge sees the foot
|
|
180
|
-
// extent (otherwise an elbow nudged just past the
|
|
181
|
-
// vertical at +4 px would land squarely on the inward
|
|
182
|
-
// foot tip — see issue #2 in the channel-routing handoff).
|
|
183
|
-
if (child.style.bracket === 'solid' || child.style.bracket === 'dashed') {
|
|
184
|
-
const padding = 12;
|
|
185
|
-
const stub = 4;
|
|
186
|
-
const yTop = child.box.y - padding;
|
|
187
|
-
const yBottom = child.box.y + child.box.height + padding;
|
|
188
|
-
const lx = child.box.x;
|
|
189
|
-
const rx = child.box.x + child.box.width;
|
|
190
|
-
brackets.push({ x: lx, yTop, yBottom });
|
|
191
|
-
brackets.push({ x: rx, yTop, yBottom });
|
|
192
|
-
// Foot tips: tiny Y bands centered on each foot row
|
|
193
|
-
// so the entries only fire when the elbow's Y span
|
|
194
|
-
// actually crosses the foot line.
|
|
195
|
-
brackets.push({ x: lx + stub, yTop: yTop - 1, yBottom: yTop + 1 });
|
|
196
|
-
brackets.push({ x: lx + stub, yTop: yBottom - 1, yBottom: yBottom + 1 });
|
|
197
|
-
brackets.push({ x: rx - stub, yTop: yTop - 1, yBottom: yTop + 1 });
|
|
198
|
-
brackets.push({ x: rx - stub, yTop: yBottom - 1, yBottom: yBottom + 1 });
|
|
199
|
-
}
|
|
200
|
-
for (const sub of child.children) visitChild(sub);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (child.kind === 'group') {
|
|
204
|
-
// Bracket-style groups (no fill) paint a left-side `[`
|
|
205
|
-
// glyph along `box.x`. Filled-style groups have no bracket
|
|
206
|
-
// — the chiclet is the visual instead.
|
|
207
|
-
const isFilled = child.style.bg !== 'none' && child.style.bg !== '#ffffff';
|
|
208
|
-
if (!isFilled && child.style.bracket && child.style.bracket !== 'none') {
|
|
209
|
-
brackets.push({
|
|
210
|
-
x: child.box.x,
|
|
211
|
-
yTop: child.box.y,
|
|
212
|
-
yBottom: child.box.y + child.box.height,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
for (const sub of child.children) visitChild(sub);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const visitSwimlane = (lane: PositionedSwimlane): void => {
|
|
221
|
-
for (const child of lane.children) visitChild(child);
|
|
222
|
-
for (const nested of lane.nested) visitSwimlane(nested);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
for (const lane of swimlanes) visitSwimlane(lane);
|
|
226
|
-
for (const region of includes) {
|
|
227
|
-
for (const lane of region.nestedSwimlanes) visitSwimlane(lane);
|
|
178
|
+
/** Blocks a vertical leg at `x` over `(y0, y1)` passes behind. */
|
|
179
|
+
function crossings(blocks: BoundingBox[], x: number, y0: number, y1: number): number {
|
|
180
|
+
const lo = Math.min(y0, y1);
|
|
181
|
+
const hi = Math.max(y0, y1);
|
|
182
|
+
let n = 0;
|
|
183
|
+
for (const b of blocks) {
|
|
184
|
+
if (b.height <= 0 || x <= b.x || x >= b.x + b.width) continue;
|
|
185
|
+
if (b.y + b.height <= lo || b.y >= hi) continue;
|
|
186
|
+
n++;
|
|
228
187
|
}
|
|
229
|
-
|
|
230
|
-
return { itemBars, brackets };
|
|
188
|
+
return n;
|
|
231
189
|
}
|
|
232
190
|
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
191
|
+
/** An arrow that needs a gap, before its lane is chosen. */
|
|
192
|
+
interface Pending {
|
|
193
|
+
index: number;
|
|
194
|
+
req: DependencyRouteRequest;
|
|
195
|
+
from: Point;
|
|
196
|
+
to: Point;
|
|
197
|
+
/** +1 when the leg runs down from the source, -1 when up. */
|
|
198
|
+
dir: 1 | -1;
|
|
199
|
+
gap: [number, number];
|
|
200
|
+
centre: number;
|
|
201
|
+
xLo: number;
|
|
202
|
+
xHi: number;
|
|
203
|
+
/** Arrows landing in one day column share a lane (O1). */
|
|
204
|
+
bundle: string;
|
|
205
|
+
}
|
|
242
206
|
|
|
243
207
|
/**
|
|
244
|
-
* Pick
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* renderer emits a straight line.
|
|
208
|
+
* Pick the gap for an arrow from `from` (on the source's edge) to `to` (on
|
|
209
|
+
* the target's edge): clear of every bar edge first, then fewest bars
|
|
210
|
+
* crossed, then nearest the source. With no free gap at all, the leg runs
|
|
211
|
+
* just past the source and passes behind whatever is there.
|
|
249
212
|
*/
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
// Gutter narrower than the combined min stubs — give up
|
|
272
|
-
// and honor the target-stub line so the arrowhead still
|
|
273
|
-
// has its visible lead-in. Source stub absorbs the loss.
|
|
274
|
-
return {
|
|
275
|
-
x: to.x - MIN_TARGET_STUB_PX,
|
|
276
|
-
underBar: true,
|
|
277
|
-
range: null,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
const range: StubRange = { minX, maxX };
|
|
281
|
-
// Try the natural gutter midpoint, clamped into the range.
|
|
282
|
-
const naturalMid = (from.x + to.x) / 2;
|
|
283
|
-
const mid = Math.max(minX, Math.min(maxX, naturalMid));
|
|
284
|
-
if (!grid.hasObstacle(mid, yMin, yMax)) {
|
|
285
|
-
return { x: mid, underBar: false, range };
|
|
286
|
-
}
|
|
287
|
-
// Walk inside the satisfiable range looking for a clear strip.
|
|
288
|
-
const span = maxX - minX;
|
|
289
|
-
for (let step = 1; step <= span; step++) {
|
|
290
|
-
const left = mid - step;
|
|
291
|
-
if (left >= minX && !grid.hasObstacle(left, yMin, yMax)) {
|
|
292
|
-
return { x: left, underBar: false, range };
|
|
293
|
-
}
|
|
294
|
-
const right = mid + step;
|
|
295
|
-
if (right <= maxX && !grid.hasObstacle(right, yMin, yMax)) {
|
|
296
|
-
return { x: right, underBar: false, range };
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return { x: mid, underBar: true, range };
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Right-to-left edge: source ends past target's left edge. Try a
|
|
303
|
-
// channel just right of source first; then walk leftward across
|
|
304
|
-
// the source/target span looking for any clear vertical strip.
|
|
305
|
-
const probes = [from.x + STUB_OUT_PX, to.x - STUB_OUT_PX];
|
|
306
|
-
for (const probe of probes) {
|
|
307
|
-
if (probe > 0 && !grid.hasObstacle(probe, yMin, yMax)) {
|
|
308
|
-
return { x: probe, underBar: false, range: null };
|
|
309
|
-
}
|
|
213
|
+
function pickGap(
|
|
214
|
+
from: Point,
|
|
215
|
+
to: Point,
|
|
216
|
+
dir: 1 | -1,
|
|
217
|
+
obstacles: RouteObstacles,
|
|
218
|
+
): { gap: [number, number]; centre: number } {
|
|
219
|
+
const xLo = Math.min(from.x, to.x);
|
|
220
|
+
const xHi = Math.max(from.x, to.x);
|
|
221
|
+
const lo = Math.min(from.y, to.y);
|
|
222
|
+
const hi = Math.max(from.y, to.y);
|
|
223
|
+
let best: { gap: [number, number]; centre: number; key: number[] } | null = null;
|
|
224
|
+
for (const gap of freeGaps(obstacles.blocks, xLo, xHi, lo, hi)) {
|
|
225
|
+
const centre = (gap[0] + gap[1]) / 2;
|
|
226
|
+
const key = [
|
|
227
|
+
grazes(obstacles.edges, from.x, from.y, centre) +
|
|
228
|
+
grazes(obstacles.edges, to.x, centre, to.y),
|
|
229
|
+
crossings(obstacles.blocks, from.x, from.y, centre) +
|
|
230
|
+
crossings(obstacles.blocks, to.x, centre, to.y),
|
|
231
|
+
Math.abs(centre - from.y),
|
|
232
|
+
];
|
|
233
|
+
if (!best || lessThan(key, best.key)) best = { gap, centre, key };
|
|
310
234
|
}
|
|
311
|
-
|
|
312
|
-
|
|
235
|
+
if (best) return { gap: best.gap, centre: best.centre };
|
|
236
|
+
const reach = Math.min(4, (hi - lo) / 2);
|
|
237
|
+
const centre = from.y + dir * reach;
|
|
238
|
+
return { gap: [lo, hi], centre };
|
|
313
239
|
}
|
|
314
240
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
* preferring the direction that stays inside the satisfiable stub
|
|
319
|
-
* range. When neither direction fits — or the candidate position is
|
|
320
|
-
* still within nudge distance of another bracket — returns the input
|
|
321
|
-
* X clamped to the range and signals `forceUnderBar` so the leg paints
|
|
322
|
-
* BEHIND the bars and bracket strokes (z-order: bracket renders after
|
|
323
|
-
* under-bar edges, so the bracket cleanly covers the colliding
|
|
324
|
-
* portion).
|
|
325
|
-
*/
|
|
326
|
-
function nudgeAwayFromBrackets(
|
|
327
|
-
x: number,
|
|
328
|
-
range: StubRange,
|
|
329
|
-
req: EdgeRouteRequest,
|
|
330
|
-
grid: ChannelGrid,
|
|
331
|
-
): { x: number; forceUnderBar: boolean } {
|
|
332
|
-
const yMin = Math.min(req.from.y, req.to.y);
|
|
333
|
-
const yMax = Math.max(req.from.y, req.to.y);
|
|
334
|
-
const near = grid.bracketsNear(x, yMin, yMax, BRACKET_NUDGE_PX);
|
|
335
|
-
if (near.length === 0) return { x, forceUnderBar: false };
|
|
336
|
-
|
|
337
|
-
// Find the closest bracket — that's the one driving the nudge.
|
|
338
|
-
let closest = near[0];
|
|
339
|
-
let closestDist = Math.abs(near[0].x - x);
|
|
340
|
-
for (let i = 1; i < near.length; i++) {
|
|
341
|
-
const d = Math.abs(near[i].x - x);
|
|
342
|
-
if (d < closestDist) {
|
|
343
|
-
closest = near[i];
|
|
344
|
-
closestDist = d;
|
|
345
|
-
}
|
|
241
|
+
function lessThan(a: number[], b: number[]): boolean {
|
|
242
|
+
for (let i = 0; i < a.length; i++) {
|
|
243
|
+
if (a[i] !== b[i]) return a[i] < b[i];
|
|
346
244
|
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
347
247
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// trip the rejection — and so a SECOND bracket exactly at the
|
|
354
|
-
// nudge distance is also accepted as "just clear enough".
|
|
355
|
-
const candidates = [closest.x + BRACKET_NUDGE_PX, closest.x - BRACKET_NUDGE_PX];
|
|
356
|
-
const recheckRadius = BRACKET_NUDGE_PX - 0.01;
|
|
357
|
-
for (const candidate of candidates) {
|
|
358
|
-
if (range && (candidate < range.minX || candidate > range.maxX)) continue;
|
|
359
|
-
// Clamp right-to-left candidates to the natural gap so they
|
|
360
|
-
// don't escape past either endpoint (range is null on that path).
|
|
361
|
-
const clamped = range
|
|
362
|
-
? candidate
|
|
363
|
-
: Math.max(
|
|
364
|
-
Math.min(req.from.x, req.to.x) + 1,
|
|
365
|
-
Math.min(Math.max(req.from.x, req.to.x) - 1, candidate),
|
|
366
|
-
);
|
|
367
|
-
const stillNear = grid.bracketsNear(clamped, yMin, yMax, recheckRadius);
|
|
368
|
-
if (stillNear.length === 0) {
|
|
369
|
-
return { x: clamped, forceUnderBar: false };
|
|
370
|
-
}
|
|
248
|
+
/** Lane offsets to try, the first one toward the source (so the arrowhead keeps its leg). */
|
|
249
|
+
function laneOffsets(dir: 1 | -1, halfHeight: number): number[] {
|
|
250
|
+
const out = [0];
|
|
251
|
+
for (let k = 1; k * CHANNEL_LANE_PX <= halfHeight + SAME_PX; k++) {
|
|
252
|
+
out.push(-dir * k * CHANNEL_LANE_PX, dir * k * CHANNEL_LANE_PX);
|
|
371
253
|
}
|
|
372
|
-
|
|
373
|
-
// No nudge fits. Keep the channel at its current X (clamped into
|
|
374
|
-
// the range) and force under-bar so item bars + bracket strokes
|
|
375
|
-
// mask the colliding portion of the leg.
|
|
376
|
-
const fallback = range ? Math.min(Math.max(x, range.minX), range.maxX) : x;
|
|
377
|
-
return { x: fallback, forceUnderBar: true };
|
|
254
|
+
return out;
|
|
378
255
|
}
|
|
379
256
|
|
|
380
257
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* collapse back to the centerline (rare; visual stacking accepted).
|
|
258
|
+
* Give each gap-routed arrow its lane: an arrow whose day column already
|
|
259
|
+
* has a lane in this gap joins it; otherwise the first offset no other
|
|
260
|
+
* horizontal leg over the same x's sits on, or, when the gap is full, the
|
|
261
|
+
* least crowded one.
|
|
386
262
|
*/
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const sortedGroup = [...group].sort((a, b) => {
|
|
418
|
-
const aMin = Math.min(a.req.from.y, a.req.to.y);
|
|
419
|
-
const bMin = Math.min(b.req.from.y, b.req.to.y);
|
|
420
|
-
if (Math.abs(aMin - bMin) > 0.5) return aMin - bMin;
|
|
421
|
-
return a.orderIndex - b.orderIndex;
|
|
422
|
-
});
|
|
423
|
-
// Track per-slot maxY assigned so far.
|
|
424
|
-
const slotMaxY: number[] = [];
|
|
425
|
-
for (const entry of sortedGroup) {
|
|
426
|
-
const eMin = Math.min(entry.req.from.y, entry.req.to.y);
|
|
427
|
-
const eMax = Math.max(entry.req.from.y, entry.req.to.y);
|
|
428
|
-
let assigned = -1;
|
|
429
|
-
for (let s = 0; s < slotMaxY.length; s++) {
|
|
430
|
-
if (slotMaxY[s] <= eMin) {
|
|
431
|
-
assigned = s;
|
|
432
|
-
slotMaxY[s] = eMax;
|
|
433
|
-
break;
|
|
263
|
+
function assignLanes(pending: Pending[]): Map<number, number> {
|
|
264
|
+
const placed: Array<{ y: number; xLo: number; xHi: number; bundle: string }> = [];
|
|
265
|
+
const out = new Map<number, number>();
|
|
266
|
+
const order = [...pending].sort(
|
|
267
|
+
(a, b) => a.centre - b.centre || a.xLo - b.xLo || a.index - b.index,
|
|
268
|
+
);
|
|
269
|
+
for (const p of order) {
|
|
270
|
+
const [lo, hi] = p.gap;
|
|
271
|
+
const mate = placed.find(
|
|
272
|
+
(q) => q.bundle === p.bundle && q.y >= lo - SAME_PX && q.y <= hi + SAME_PX,
|
|
273
|
+
);
|
|
274
|
+
let y = p.centre;
|
|
275
|
+
if (mate) {
|
|
276
|
+
y = mate.y;
|
|
277
|
+
} else {
|
|
278
|
+
// The gap already keeps `BLOCK_MARGIN_PX` from its neighbours.
|
|
279
|
+
const offsets = laneOffsets(p.dir, (hi - lo) / 2);
|
|
280
|
+
let bestConflicts = Number.POSITIVE_INFINITY;
|
|
281
|
+
for (const off of offsets) {
|
|
282
|
+
const cy = p.centre + off;
|
|
283
|
+
const conflicts = placed.filter(
|
|
284
|
+
(q) =>
|
|
285
|
+
q.bundle !== p.bundle &&
|
|
286
|
+
Math.abs(q.y - cy) < CHANNEL_LANE_PX - SAME_PX &&
|
|
287
|
+
q.xLo < p.xHi + BLOCK_MARGIN_PX &&
|
|
288
|
+
q.xHi > p.xLo - BLOCK_MARGIN_PX,
|
|
289
|
+
).length;
|
|
290
|
+
if (conflicts < bestConflicts) {
|
|
291
|
+
bestConflicts = conflicts;
|
|
292
|
+
y = cy;
|
|
434
293
|
}
|
|
294
|
+
if (conflicts === 0) break;
|
|
435
295
|
}
|
|
436
|
-
if (assigned === -1) {
|
|
437
|
-
assigned = slotMaxY.length;
|
|
438
|
-
slotMaxY.push(eMax);
|
|
439
|
-
}
|
|
440
|
-
slotsByOrderIndex.set(entry.orderIndex, assigned);
|
|
441
296
|
}
|
|
442
|
-
|
|
297
|
+
placed.push({ y, xLo: p.xLo, xHi: p.xHi, bundle: p.bundle });
|
|
298
|
+
out.set(p.index, y);
|
|
443
299
|
}
|
|
444
|
-
return
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** Convert a slot index to its signed offset around the channel
|
|
448
|
-
* centerline. Slots 0/1/2/... become 0, +SLOT, -SLOT, +2*SLOT,
|
|
449
|
-
* -2*SLOT... so the FIRST edge sits on the centerline (no shift)
|
|
450
|
-
* and additional edges fan out alternately. Past 2 ± slots, slots
|
|
451
|
-
* collapse back to the centerline (visual stacking accepted). */
|
|
452
|
-
function slotOffset(slot: number): number {
|
|
453
|
-
if (slot === 0) return 0;
|
|
454
|
-
if (slot > 4) return 0; // collapse beyond ±2 slots
|
|
455
|
-
const half = Math.ceil(slot / 2);
|
|
456
|
-
const sign = slot % 2 === 1 ? 1 : -1;
|
|
457
|
-
return sign * half * SLOT_SPACING_PX;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Marker → item stub. Source X sits on the marker's vertical cut
|
|
462
|
-
* line; the stub is a short horizontal segment to the target's left
|
|
463
|
-
* visual edge at the target's row mid-Y. No channel selection, no
|
|
464
|
-
* obstacle check — the cut line is the stem.
|
|
465
|
-
*/
|
|
466
|
-
function routeMarkerStub(req: EdgeRouteRequest): EdgeRouteResult {
|
|
467
|
-
// When the cut line sits AT or PAST the target's left edge (item
|
|
468
|
-
// hugs the anchor's date column), nudge the source 1 px back so
|
|
469
|
-
// routeEdge produces a non-degenerate path with a visible
|
|
470
|
-
// arrowhead.
|
|
471
|
-
const from = req.from.x >= req.to.x ? { x: req.to.x - 1, y: req.from.y } : req.from;
|
|
472
|
-
return {
|
|
473
|
-
fromId: req.fromId,
|
|
474
|
-
toId: req.toId,
|
|
475
|
-
waypoints: [from, req.to],
|
|
476
|
-
underBar: false,
|
|
477
|
-
};
|
|
300
|
+
return out;
|
|
478
301
|
}
|
|
479
302
|
|
|
480
303
|
/**
|
|
481
|
-
* Route every dependency
|
|
482
|
-
*
|
|
483
|
-
*
|
|
304
|
+
* Route every item dependency of one chart (the host, or one isolated
|
|
305
|
+
* region) in a batch, so arrows sharing a gap can take lanes. Returns one
|
|
306
|
+
* entry per request; `null` where position already says it (a target on
|
|
307
|
+
* its source's row that starts where the source ends).
|
|
484
308
|
*/
|
|
485
|
-
export function
|
|
486
|
-
requests:
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
309
|
+
export function routeDependencies(
|
|
310
|
+
requests: DependencyRouteRequest[],
|
|
311
|
+
obstacles: RouteObstacles,
|
|
312
|
+
pixelsPerDay: number,
|
|
313
|
+
): Array<RoutedDependency | null> {
|
|
314
|
+
const out: Array<RoutedDependency | null> = new Array(requests.length).fill(null);
|
|
315
|
+
const pending: Pending[] = [];
|
|
316
|
+
requests.forEach((req, index) => {
|
|
317
|
+
const { source: s, target: t } = req;
|
|
318
|
+
const slack = t.startX - s.endX > SAME_PX;
|
|
319
|
+
if (onSameRow(s, t) && t.startX >= s.endX - SAME_PX) {
|
|
320
|
+
if (!slack) return;
|
|
321
|
+
// A dotted leg along the row, from the source's end date to the
|
|
322
|
+
// target's painted start.
|
|
323
|
+
const y =
|
|
324
|
+
s.exitY !== undefined && within(s.exitY, t.top, t.bottom) ? s.exitY : (t.rowY ?? 0);
|
|
325
|
+
out[index] = {
|
|
326
|
+
fromId: req.fromId,
|
|
327
|
+
toId: req.toId,
|
|
328
|
+
waypoints: [
|
|
329
|
+
{ x: s.endX, y },
|
|
330
|
+
{ x: t.paintedX, y },
|
|
331
|
+
],
|
|
332
|
+
slack: true,
|
|
333
|
+
...arrowHead(t.bottom - t.top),
|
|
334
|
+
};
|
|
335
|
+
return;
|
|
502
336
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
337
|
+
const px = sourcePortX(s, pixelsPerDay);
|
|
338
|
+
const tx = targetPortX(t, pixelsPerDay);
|
|
339
|
+
let from: Point;
|
|
340
|
+
let to: Point;
|
|
341
|
+
let dir: 1 | -1;
|
|
342
|
+
if (t.top >= s.bottom - SAME_PX) {
|
|
343
|
+
dir = 1;
|
|
344
|
+
from = { x: px, y: s.bottom };
|
|
345
|
+
to = { x: tx, y: t.top };
|
|
346
|
+
} else if (t.bottom <= s.top + SAME_PX) {
|
|
347
|
+
dir = -1;
|
|
348
|
+
from = { x: px, y: s.top };
|
|
349
|
+
to = { x: tx, y: t.bottom };
|
|
350
|
+
} else {
|
|
351
|
+
// Overlapping but not on one row (a target that starts before
|
|
352
|
+
// its source ends): leave the source's bottom, run below both,
|
|
353
|
+
// come up into the target's bottom.
|
|
354
|
+
const below = Math.max(s.bottom, t.bottom) + 4;
|
|
355
|
+
out[index] = {
|
|
507
356
|
fromId: req.fromId,
|
|
508
357
|
toId: req.toId,
|
|
509
|
-
waypoints: [
|
|
510
|
-
|
|
358
|
+
waypoints: [
|
|
359
|
+
{ x: px, y: s.bottom },
|
|
360
|
+
{ x: px, y: below },
|
|
361
|
+
{ x: tx, y: below },
|
|
362
|
+
{ x: tx, y: t.bottom },
|
|
363
|
+
],
|
|
364
|
+
slack,
|
|
365
|
+
...arrowHead(t.paintedWidth),
|
|
511
366
|
};
|
|
512
|
-
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (Math.abs(px - tx) < SAME_PX) {
|
|
370
|
+
out[index] = {
|
|
371
|
+
fromId: req.fromId,
|
|
372
|
+
toId: req.toId,
|
|
373
|
+
waypoints: [from, to],
|
|
374
|
+
slack,
|
|
375
|
+
...arrowHead(t.paintedWidth),
|
|
376
|
+
};
|
|
377
|
+
return;
|
|
513
378
|
}
|
|
514
|
-
const {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
range,
|
|
379
|
+
const { gap, centre } = pickGap(from, to, dir, obstacles);
|
|
380
|
+
pending.push({
|
|
381
|
+
index,
|
|
518
382
|
req,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
383
|
+
from,
|
|
384
|
+
to,
|
|
385
|
+
dir,
|
|
386
|
+
gap,
|
|
387
|
+
centre,
|
|
388
|
+
xLo: Math.min(px, tx),
|
|
389
|
+
xHi: Math.max(px, tx),
|
|
390
|
+
bundle: `${Math.round(tx * 100)}:${dir}`,
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
const lanes = assignLanes(pending);
|
|
394
|
+
for (const p of pending) {
|
|
395
|
+
const y = lanes.get(p.index) ?? p.centre;
|
|
396
|
+
const slack = p.req.target.startX - p.req.source.endX > SAME_PX;
|
|
397
|
+
out[p.index] = {
|
|
398
|
+
fromId: p.req.fromId,
|
|
399
|
+
toId: p.req.toId,
|
|
400
|
+
waypoints: [p.from, { x: p.from.x, y }, { x: p.to.x, y }, p.to],
|
|
401
|
+
slack,
|
|
402
|
+
...arrowHead(p.req.target.paintedWidth),
|
|
534
403
|
};
|
|
535
404
|
}
|
|
536
|
-
|
|
537
|
-
return results;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Build the orthogonal polyline through a chosen vertical channel.
|
|
542
|
-
* Source-out-stub → vertical leg → target-in-stub. Same-row edges
|
|
543
|
-
* collapse to two points (handled by the caller's same-row skip).
|
|
544
|
-
*/
|
|
545
|
-
function buildOrthogonalPath(from: Point, to: Point, slotX: number): Point[] {
|
|
546
|
-
if (Math.abs(from.y - to.y) < 0.5) {
|
|
547
|
-
return [from, to];
|
|
548
|
-
}
|
|
549
|
-
return [from, { x: slotX, y: from.y }, { x: slotX, y: to.y }, to];
|
|
405
|
+
return out;
|
|
550
406
|
}
|