@knowvah/dot-engine 1.3.0 → 1.5.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.
@@ -92,7 +92,21 @@ export interface NodeGeometry {
92
92
  * type) still holds calloc-zero coordinates, so it is reported as absent
93
93
  * rather than as a label at the origin.
94
94
  *
95
+ * `sp`/`ep` are the arrow attachment points. When an end carries an arrow the
96
+ * spline is shortened to leave room for it, and the arrow spans from the
97
+ * terminal control point out to this point — so a consumer drawing its own
98
+ * arrowheads reads the tip here instead of extrapolating one. Each is present
99
+ * only when that end actually has an arrow (C `sflag`/`eflag`); with no arrow
100
+ * the field holds the calloc-zero point, which is not geometry.
101
+ *
102
+ * These are the *attachment* points on the node boundary, verbatim from the
103
+ * bezier — with `arrowhead=none` the spline simply ends there. Graphviz's own
104
+ * renderer insets the arrow polygon it draws by a penwidth-dependent amount
105
+ * (measured: ~1.5pt at `penwidth=1`, ~6.2pt at `penwidth=5`), so `ep` is the
106
+ * point to draw an arrow *to*, not a copy of the rendered polygon's tip.
107
+ *
95
108
  * @see lib/common/types.h:ED_spl, ED_label, ED_tail_label, ED_head_label
109
+ * @see lib/common/types.h:bezier (sflag/eflag, sp/ep)
96
110
  */
97
111
  export interface EdgeGeometry {
98
112
  tail: string;
@@ -102,6 +116,22 @@ export interface EdgeGeometry {
102
116
  x: number;
103
117
  y: number;
104
118
  }[];
119
+ /**
120
+ * Arrow attachment point at the tail end, if that end carries an arrow.
121
+ * @see lib/common/types.h:bezier.sp
122
+ */
123
+ sp?: {
124
+ x: number;
125
+ y: number;
126
+ };
127
+ /**
128
+ * Arrow attachment point at the head end, if that end carries an arrow.
129
+ * @see lib/common/types.h:bezier.ep
130
+ */
131
+ ep?: {
132
+ x: number;
133
+ y: number;
134
+ };
105
135
  /** Centre edge label position, if present. @see lib/common/types.h:ED_label */
106
136
  label?: {
107
137
  x: number;
@@ -137,7 +167,15 @@ export interface EdgeGeometry {
137
167
  * `class="cluster"` polygon, so a consumer quantizing to SVG precision gets
138
168
  * byte-conformant geometry.
139
169
  *
170
+ * `label` is the cluster title's placed position and measured size, present
171
+ * only when the cluster declares a label. Unlike the edge port labels, it is
172
+ * *not* gated on the label's `set` flag: C draws a cluster label on existence
173
+ * alone (emit.c:3920 has no `->set` test, unlike emit_edge_label:2891), so an
174
+ * unplaced one still renders at whatever pos it holds. Gating here would hide
175
+ * geometry `render()` acts on.
176
+ *
140
177
  * @see lib/common/types.h:GD_bb (of a cluster subgraph)
178
+ * @see lib/common/types.h:GD_label (textlabel_t.pos / .dimen)
141
179
  */
142
180
  export interface ClusterGeometry {
143
181
  /** Cluster subgraph name (e.g. `cluster6`); encodes nesting. */
@@ -146,6 +184,18 @@ export interface ClusterGeometry {
146
184
  y: number;
147
185
  width: number;
148
186
  height: number;
187
+ /**
188
+ * Cluster label placement, if the cluster has one. `x`/`y` are the **centre**
189
+ * of the label space (matching `EdgeGeometry.label`, not the box corner
190
+ * `x`/`y` above); `width`/`height` are its measured size.
191
+ * @see lib/common/postproc.c:place_graph_label
192
+ */
193
+ label?: {
194
+ x: number;
195
+ y: number;
196
+ width: number;
197
+ height: number;
198
+ };
149
199
  }
150
200
  /**
151
201
  * Plain, JSON-serializable snapshot of the graph's computed geometry.
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/api/geometry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAU/C,+CAA+C;AAC/C,MAAM,MAAM,KAAK,GAAG,IAAI,GAAG,MAAM,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MA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lbl === void 0 || !lbl.set) return void 0;
691
691
  return { x: lbl.pos.x, y: flipY(lbl.pos.y) };
692
692
  }
693
+ function arrowAttachPoints(edge, flipY) {
694
+ const spl = edge.info.spl;
695
+ if (spl === void 0 || spl.size === 0) return {};
696
+ const out = {};
697
+ const first = spl.list[0];
698
+ if (first.sflag !== 0) out.sp = { x: first.sp.x, y: flipY(first.sp.y) };
699
+ const last = spl.list[spl.size - 1];
700
+ if (last.eflag !== 0) out.ep = { x: last.ep.x, y: flipY(last.ep.y) };
701
+ return out;
702
+ }
693
703
  function snapshotEdge(edge, flipY) {
694
704
  const geom = {
695
705
  tail: edge.tail.name,
@@ -704,11 +714,14 @@ function snapshotEdge(edge, flipY) {
704
714
  if (tailLabel !== void 0) geom.tailLabel = tailLabel;
705
715
  const headLabel = placedLabelPos(edge.info.head_label, flipY);
706
716
  if (headLabel !== void 0) geom.headLabel = headLabel;
717
+ const { sp, ep } = arrowAttachPoints(edge, flipY);
718
+ if (sp !== void 0) geom.sp = sp;
719
+ if (ep !== void 0) geom.ep = ep;
707
720
  return geom;
708
721
  }
709
722
  function snapshotCluster(sg, yAxis, flipY) {
710
723
  const bb = sg.info.bb;
711
- return {
724
+ const geom = {
712
725
  name: sg.name,
713
726
  x: bb.ll.x,
714
727
  // 'up' keeps the lower-left y; 'down' flips the upper-right y to the
@@ -717,6 +730,16 @@ function snapshotCluster(sg, yAxis, flipY) {
717
730
  width: bb.ur.x - bb.ll.x,
718
731
  height: bb.ur.y - bb.ll.y
719
732
  };
733
+ const lab = sg.info.label;
734
+ if (lab !== void 0) {
735
+ geom.label = {
736
+ x: lab.pos.x,
737
+ y: flipY(lab.pos.y),
738
+ width: lab.dimen.x,
739
+ height: lab.dimen.y
740
+ };
741
+ }
742
+ return geom;
720
743
  }
721
744
  function collectClusters(sg, yAxis, flipY, out) {
722
745
  for (const c of sg.info.clust ?? []) {