chartlet 0.23.0

Compile structured data into deterministic, accessible static charts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
//! What both orientations of a diagram share: its spacing, the layered graph, and every text
//! measured and wrapped into the boxes of the steps and the labels of the edges.

use super::{
    BALL, EDGE_LABEL, EDGE_SIZE, GAP, GRID, GROUP_GAP, INITIAL, INTERFACE_GAP, INTERFACE_LINE,
    INTERFACE_PAD, INTERFACE_SIZE, LABEL_SIZE, MARGIN, MAX_NODE, MEMBER_LINE, MEMBER_PAD,
    MEMBER_SIZE, MIN_NODE, NODE_GAP, NODE_LINE, PAD, PASSING_GAP, SUBLABEL_SIZE, TAG_INSET,
    TAG_PAD, TAG_SIZE, TAG_TRACK,
    graph::Graph,
    model::{Diagram, Node, Shape},
    ports::{Across, across_sides, side_room},
    trunks::Trunks,
    up,
};
use crate::{
    diagram::TECH_SIZE,
    diagram::wrap,
    error::ChartWarning,
    layout::{NARROW, count},
    metrics::{MONO_ADVANCE, TextMetrics},
    parts,
    spec::{DiagramSpacing, NumberStyle},
    symbols,
};

/// The spacing of a diagram: roomy on a wide canvas, compact below [`NARROW`] pixels, such as a
/// mobile variant, where steps get narrower and wrap their labels sooner, and the space around
/// and between them shrinks.
#[derive(Debug, Clone, Copy)]
pub(super) struct Spacing {
    pub(super) margin: f64,
    min_node: f64,
    max_node: f64,
    pub(super) node_gap: f64,
    pub(super) passing_gap: f64,
    pub(super) group_gap: f64,
    /// The least distance between two layers, and how much it grows when the canvas leaves room.
    pub(super) layer_gap: f64,
    pub(super) max_stretch: f64,
    edge_label: f64,
    /// Whether the diagram has the editorial look, and whether it shows type tags.
    pub(super) editorial: bool,
    pub(super) tags: bool,
}

impl Spacing {
    /// Whether this is the compact spacing of a narrow canvas.
    pub(super) fn is_compact(&self) -> bool {
        self.margin < MARGIN
    }

    pub(super) fn new(width: u32, profile: DiagramSpacing, look: (bool, bool)) -> Self {
        let (editorial, tags) = look;
        let spacing = if width < NARROW {
            Self {
                margin: 12.0,
                min_node: 64.0,
                max_node: 120.0,
                node_gap: 16.0,
                passing_gap: 8.0,
                group_gap: 20.0,
                layer_gap: GAP,
                max_stretch: MAX_STRETCH,
                edge_label: 96.0,
                editorial,
                tags,
            }
        } else {
            Self {
                margin: MARGIN,
                min_node: MIN_NODE,
                max_node: MAX_NODE,
                node_gap: NODE_GAP,
                passing_gap: PASSING_GAP,
                group_gap: GROUP_GAP,
                layer_gap: GAP,
                max_stretch: MAX_STRETCH,
                edge_label: EDGE_LABEL,
                editorial,
                tags,
            }
        };
        // The editorial look leaves more air, on the 4 px grid.
        let spacing = if editorial && width >= NARROW {
            Self {
                node_gap: 32.0,
                passing_gap: 16.0,
                group_gap: 32.0,
                layer_gap: 32.0,
                ..spacing
            }
        } else {
            spacing
        };
        spacing.scaled(profile)
    }

    /// The gaps between layers and between neighbours in a layer, scaled by `profile`: never the
    /// size of steps or texts, the margins or the distance between two tracks, and a compact gap
    /// never below the gaps of a narrow canvas between steps, or 20 between layers. A compact
    /// diagram keeps its gaps on a canvas that leaves room, instead of spreading its layers over
    /// it.
    fn scaled(self, profile: DiagramSpacing) -> Self {
        let (factor, floor) = match profile {
            DiagramSpacing::Normal => return self,
            DiagramSpacing::Compact => (COMPACT, true),
            DiagramSpacing::Roomy => (ROOMY, false),
        };
        let scale = |gap: f64, least: f64| {
            let gap = up(gap * factor, GRID);
            if floor { gap.max(least) } else { gap }
        };
        Self {
            node_gap: scale(self.node_gap, 16.0),
            passing_gap: scale(self.passing_gap, 8.0),
            group_gap: scale(self.group_gap, 20.0),
            layer_gap: scale(self.layer_gap, 20.0),
            max_stretch: if floor { 1.0 } else { self.max_stretch },
            ..self
        }
    }
}

/// How much the compact and the roomy spacing scale the gaps of a diagram.
const COMPACT: f64 = 0.7;
const ROOMY: f64 = 1.5;

/// Growth of the gaps between layers when the canvas leaves room.
const MAX_STRETCH: f64 = 1.6;

/// What both orientations need: the layered graph, and every text measured and wrapped.
pub(super) struct Model<'a> {
    pub(super) diagram: &'a Diagram,
    pub(super) spacing: Spacing,
    pub(super) ends: Vec<(usize, usize)>,
    pub(super) graph: Graph,
    /// Each step's label on one or two lines, and its box: width and height on the page.
    pub(super) labels: Vec<Vec<String>>,
    /// Each step's sublabel on one or two lines.
    pub(super) sublabels: Vec<Vec<String>>,
    pub(super) sizes: Vec<(f64, f64)>,
    /// Each edge's label on one or two lines, and the widest of them.
    pub(super) edge_labels: Vec<Vec<String>>,
    pub(super) edge_widths: Vec<f64>,
    /// Per edge, the technology its label ends in, set in monospace; only in the editorial look.
    pub(super) edge_tech: Vec<Option<String>>,
    /// The labels of the edges from each step to itself, joined.
    pub(super) loops: Vec<Option<String>>,
    /// The same, on as many lines as the edge labels take.
    pub(super) loop_lines: Vec<Vec<String>>,
    /// How the values of the parts of a step are written.
    pub(super) number_style: NumberStyle,
    /// Per step, the type tag it carries at its top left; always `None` outside the editorial look,
    /// without tags and on a narrow canvas.
    pub(super) tags: Vec<Option<String>>,
    /// The edges drawn on shared trunks.
    pub(super) trunks: Trunks,
    /// Per edge, the side across the flow it leaves its first step on and reaches its last on.
    pub(super) across: Vec<(Option<Across>, Option<Across>)>,
    /// Per step, the room the edges that meet it across the flow take on its low and high side.
    pub(super) side_room: Vec<(f64, f64)>,
    /// Per group, the width its frame needs for its name, which sits in the top left corner.
    pub(super) group_names: Vec<f64>,
}

impl<'a> Model<'a> {
    /// The extra room between an edge label's mask and its line: 4 px in the editorial look, which
    /// makes the visible gap 8 px, and none in the classic look.
    pub(super) fn label_gap(&self) -> f64 {
        if self.spacing.editorial { 4.0 } else { 0.0 }
    }

    pub(super) fn new(
        diagram: &'a Diagram,
        (spacing, number_style): (Spacing, NumberStyle),
        metrics: &impl TextMetrics,
        warnings: &mut Vec<ChartWarning>,
    ) -> Self {
        let ends = diagram.ends();
        let graph = Graph::new(diagram);
        let tags = node_tags(diagram, &spacing);
        let (labels, sublabels, mut sizes) =
            node_boxes(diagram, &spacing, &tags, metrics, warnings);
        // A step's middle lies on the grid when its size is a multiple of twice the grid.
        for (node, size) in diagram.nodes.iter().zip(&mut sizes) {
            if node.shape != Shape::Interface {
                *size = (up(size.0, 2.0 * GRID), up(size.1, 2.0 * GRID));
            }
        }
        let (edge_labels, edge_widths, edge_tech) = edge_labels(
            diagram,
            spacing.edge_label,
            spacing.editorial,
            metrics,
            warnings,
        );
        let loops: Vec<Option<String>> = (0..diagram.nodes.len())
            .map(|node| {
                let labels: Vec<&str> = diagram
                    .edges
                    .iter()
                    .zip(&ends)
                    .filter(|(_, (from, to))| *from == node && *to == node)
                    .map(|(edge, _)| edge.label.as_deref().unwrap_or(""))
                    .collect();
                (!labels.is_empty()).then(|| {
                    labels
                        .into_iter()
                        .filter(|label| !label.is_empty())
                        .collect::<Vec<_>>()
                        .join(", ")
                })
            })
            .collect();
        let loop_lines = loops
            .iter()
            .enumerate()
            .map(|(node, label): (usize, &Option<String>)| {
                let Some(label) = label.as_ref().filter(|label| !label.is_empty()) else {
                    return Vec::new();
                };
                let path = diagram
                    .edges
                    .iter()
                    .find(|edge| edge.from == node && edge.to == node)
                    .map_or("", |edge| edge.label_path.as_str());
                wrap(
                    label,
                    spacing.edge_label,
                    EDGE_SIZE,
                    metrics,
                    warnings,
                    path,
                )
            })
            .collect();
        let across = across_sides(diagram, &graph, warnings);
        let side_room = side_room(diagram.nodes.len(), &graph, &across, spacing.passing_gap);
        let group_names = diagram
            .groups
            .iter()
            .map(|group| up(metrics.width(&group.label, SUBLABEL_SIZE) + 16.0, GRID))
            .collect();
        Self {
            diagram,
            spacing,
            ends,
            graph,
            labels,
            sublabels,
            sizes,
            edge_labels,
            edge_widths,
            edge_tech,
            loops,
            loop_lines,
            number_style,
            tags,
            trunks: Trunks::none(diagram.edges.len()),
            across,
            side_room,
            group_names,
        }
    }
}

/// Each step's label and sublabel on one or two lines, and its box: width and height.
#[allow(clippy::type_complexity, clippy::too_many_lines)]
fn node_boxes(
    diagram: &Diagram,
    spacing: &Spacing,
    tags: &[Option<String>],
    metrics: &impl TextMetrics,
    warnings: &mut Vec<ChartWarning>,
) -> (Vec<Vec<String>>, Vec<Vec<String>>, Vec<(f64, f64)>) {
    let mut labels = Vec::with_capacity(diagram.nodes.len());
    let mut sublabels = Vec::with_capacity(diagram.nodes.len());
    let mut sizes = Vec::with_capacity(diagram.nodes.len());
    for (index, node) in diagram.nodes.iter().enumerate() {
        if node.shape == Shape::Block {
            let block = diagram
                .blocks
                .iter()
                .find(|block| block.node == index)
                .expect("a block node has its block");
            labels.push(Vec::new());
            sublabels.push(Vec::new());
            sizes.push(block.size);
            continue;
        }
        if node.shape == Shape::Initial {
            labels.push(Vec::new());
            sublabels.push(Vec::new());
            sizes.push((INITIAL, INITIAL));
            continue;
        }
        if matches!(node.shape, Shape::Note | Shape::Interface) {
            let (lines, size) = if node.shape == Shape::Note {
                note_box(&node.label, &node.path, spacing, metrics, warnings)
            } else {
                interface_box(node, spacing, metrics, warnings)
            };
            labels.push(lines);
            sublabels.push(Vec::new());
            sizes.push(size);
            continue;
        }
        let (extra_width, extra_height) = match node.shape {
            Shape::Decision => (48.0, 24.0),
            Shape::Io => (20.0, 0.0),
            Shape::Subprocess => (16.0, 0.0),
            Shape::Store => (0.0, 10.0),
            Shape::Final => (8.0, 8.0),
            Shape::Frontend => (0.0, 12.0),
            Shape::Bucket => (16.0, 4.0),
            Shape::Cache => (24.0, 0.0),
            Shape::Shield | Shape::Person => (0.0, 18.0),
            Shape::Node => (8.0, 6.0),
            Shape::Artifact => (8.0, 0.0),
            _ => (0.0, 0.0),
        };
        // Never narrower than the longest word, which cannot wrap.
        let word = node
            .label
            .split(' ')
            .map(|word| metrics.width(word, LABEL_SIZE))
            .fold(0.0, f64::max);
        let room = (spacing.max_node - 2.0 * PAD).max(word);
        let path = format!("{}/label", node.path);
        let lines = wrap(&node.label, room, LABEL_SIZE, metrics, warnings, &path);
        let sublines = node.sublabel.as_ref().map_or_else(Vec::new, |sublabel| {
            let path = format!("{}/sublabel", node.path);
            wrap(sublabel, room, SUBLABEL_SIZE, metrics, warnings, &path)
        });
        let text = lines
            .iter()
            .map(|line| metrics.width(line, LABEL_SIZE))
            .chain(
                sublines
                    .iter()
                    .map(|line| metrics.width(line, SUBLABEL_SIZE)),
            )
            .fold(0.0, f64::max);
        if node.shape == Shape::Class {
            // Members are never wrapped: the box is as wide as its widest line.
            let members = node
                .compartments
                .iter()
                .flatten()
                .map(|line| metrics.width(line, MEMBER_SIZE))
                .fold(0.0, f64::max);
            let width = (text.max(members) + 2.0 * PAD).max(spacing.min_node);
            let height = class_header(lines.len(), sublines.len())
                + class_compartments(&node.compartments).iter().sum::<f64>();
            labels.push(lines);
            sublabels.push(sublines);
            sizes.push((width, height));
            continue;
        }
        let width = (text + 2.0 * PAD)
            .clamp(spacing.min_node, spacing.max_node.max(room + 2.0 * PAD))
            + extra_width;
        // The tag stands on the top edge, and the box is wide enough to hold it with its inset.
        let width = tags[index].as_ref().map_or(width, |tag| {
            width.max(tag_width(tag) + 2.0 * TAG_INSET + extra_width)
        });
        let stripe = if node.has_stripe() { parts::ROOM } else { 0.0 };
        let symbol = if node.symbol.is_some() {
            symbols::ROOM
        } else {
            0.0
        };
        let height = if spacing.editorial { 24.0 } else { 20.0 }
            + NODE_LINE * count(lines.len())
            + 14.0 * count(sublines.len())
            + extra_height
            + stripe
            + symbol;
        labels.push(lines);
        sublabels.push(sublines);
        sizes.push((width, height));
    }
    (labels, sublabels, sizes)
}

/// The type tag of every step: the tag its specification gives, or the one its shape carries,
/// in capitals; none outside the editorial look, with `tags: false` and on a narrow canvas.
fn node_tags(diagram: &Diagram, spacing: &Spacing) -> Vec<Option<String>> {
    let shown = spacing.editorial && spacing.tags && !spacing.is_compact();
    diagram
        .nodes
        .iter()
        .map(|node| {
            let tag = match node.shape {
                Shape::Initial
                | Shape::Interface
                | Shape::Note
                | Shape::Block
                | Shape::Decision => None,
                shape => node
                    .tag
                    .clone()
                    .or_else(|| default_tag(shape).map(str::to_owned)),
            };
            tag.filter(|_| shown).map(|tag| tag.to_uppercase())
        })
        .collect()
}

/// The tag a kind of step carries when its specification names none.
const fn default_tag(shape: Shape) -> Option<&'static str> {
    match shape {
        Shape::Store => Some("DB"),
        Shape::External => Some("EXT"),
        Shape::Queue => Some("QUEUE"),
        Shape::Cache => Some("CACHE"),
        Shape::Bucket => Some("FILES"),
        Shape::Shield => Some("SEC"),
        Shape::Frontend => Some("UI"),
        Shape::Person => Some("USER"),
        Shape::Node => Some("HOST"),
        Shape::Artifact => Some("ARTIFACT"),
        _ => None,
    }
}

/// The width of the tag plate for `tag`: its letters in monospace with their tracking, and the
/// padding on both sides, rounded up to an even number of pixels.
pub(super) fn tag_width(tag: &str) -> f64 {
    // A tag has at most a few characters.
    #[allow(clippy::cast_precision_loss)]
    let letters = tag.chars().count() as f64;
    let width = letters * (MONO_ADVANCE * TAG_SIZE + TAG_TRACK) + 2.0 * TAG_PAD;
    (width / 2.0).ceil() * 2.0
}

/// The name of an interface on one or two lines, and its box in portrait: the ball in the
/// middle, the name on one side and as much room on the other.
fn interface_box(
    node: &Node,
    spacing: &Spacing,
    metrics: &impl TextMetrics,
    warnings: &mut Vec<ChartWarning>,
) -> (Vec<String>, (f64, f64)) {
    let path = format!("{}/label", node.path);
    let lines = wrap(
        &node.label,
        spacing.min_node,
        INTERFACE_SIZE,
        metrics,
        warnings,
        &path,
    );
    let text = lines
        .iter()
        .map(|line| metrics.width(line, INTERFACE_SIZE))
        .fold(0.0, f64::max);
    let size = if spacing.is_compact() {
        // On a narrow canvas the name stands below the ball, on a chip over the stem.
        (
            (text + 2.0 * INTERFACE_PAD).max(2.0 * BALL),
            2.0 * (BALL + INTERFACE_PAD + INTERFACE_LINE * count(lines.len())),
        )
    } else {
        (
            2.0 * (BALL + INTERFACE_GAP + text),
            (2.0 * BALL).max(INTERFACE_LINE * count(lines.len())),
        )
    };
    (lines, size)
}

/// The text of a note, its padding above and below, and the most lines it takes before the rest
/// is shortened.
const NOTE_SIZE: f64 = 12.0;
pub(super) const NOTE_PAD: f64 = 8.0;
const MAX_NOTE_LINES: usize = 10;

/// The lines of a note and its box: width and height.
pub(super) fn note_box(
    text: &str,
    path: &str,
    spacing: &Spacing,
    metrics: &impl TextMetrics,
    warnings: &mut Vec<ChartWarning>,
) -> (Vec<String>, (f64, f64)) {
    let path = format!("{path}/text");
    let lines = note_lines(text, spacing.max_node - 2.0 * PAD, metrics, warnings, &path);
    let text = lines
        .iter()
        .map(|line| metrics.width(line, NOTE_SIZE))
        .fold(0.0, f64::max);
    let width = (text + 2.0 * PAD).max(spacing.min_node / 2.0);
    let height = 2.0 * NOTE_PAD + MEMBER_LINE * count(lines.len());
    (lines, (width, height))
}

/// The text of a note on as many lines of at most `room` as it needs, word by word; past
/// [`MAX_NOTE_LINES`] the last line is shortened, as is a word wider than a line, with a warning.
fn note_lines(
    text: &str,
    room: f64,
    metrics: &impl TextMetrics,
    warnings: &mut Vec<ChartWarning>,
    path: &str,
) -> Vec<String> {
    let mut lines: Vec<String> = Vec::new();
    let mut line = String::new();
    for word in text.split_whitespace() {
        let longer = if line.is_empty() {
            word.to_owned()
        } else {
            format!("{line} {word}")
        };
        if line.is_empty() || metrics.width(&longer, NOTE_SIZE) <= room {
            line = longer;
        } else {
            lines.push(std::mem::replace(&mut line, word.to_owned()));
        }
    }
    lines.push(line);
    if lines.len() > MAX_NOTE_LINES {
        let rest = lines.split_off(MAX_NOTE_LINES - 1).join(" ");
        lines.push(rest);
    }
    lines
        .iter()
        .map(|line| crate::layout::fit_text(line, room, NOTE_SIZE, metrics, warnings, path))
        .collect()
}

/// The height of the top of a class box: its stereotype lines above its name lines.
pub(super) fn class_header(name_lines: usize, stereotype_lines: usize) -> f64 {
    16.0 + NODE_LINE * count(name_lines) + 14.0 * count(stereotype_lines)
}

/// The height of every compartment of a class box below its name; one without lines is left out.
fn class_compartments(compartments: &[Vec<String>]) -> Vec<f64> {
    compartments
        .iter()
        .filter(|lines| !lines.is_empty())
        .map(|lines| 2.0 * MEMBER_PAD + MEMBER_LINE * count(lines.len()))
        .collect()
}

/// Each edge's label on one or two lines with its technology in brackets below, and the widest
/// line of each.
fn edge_labels(
    diagram: &Diagram,
    widest: f64,
    editorial: bool,
    metrics: &impl TextMetrics,
    warnings: &mut Vec<ChartWarning>,
) -> (Vec<Vec<String>>, Vec<f64>, Vec<Option<String>>) {
    let mut edge_labels = Vec::with_capacity(diagram.edges.len());
    let mut edge_widths = Vec::with_capacity(diagram.edges.len());
    let mut edge_tech = Vec::with_capacity(diagram.edges.len());
    for edge in &diagram.edges {
        let mut tech = None;
        let mut lines = edge.label.as_ref().map_or_else(Vec::new, |label| {
            let word = label
                .split(' ')
                .map(|word| metrics.width(word, EDGE_SIZE))
                .fold(0.0, f64::max);
            wrap(
                label,
                widest.max(word),
                EDGE_SIZE,
                metrics,
                warnings,
                &edge.label_path,
            )
        });
        if let Some(technology) = &edge.technology
            && editorial
        {
            // The technology joins the last line of the label after a dot, as long as that fits
            // the width of a label; otherwise it stands on a line of its own. No brackets.
            let room = widest.max(EDGE_LABEL);
            let path = edge.label_path.replace("/label", "/technology");
            let fitted =
                crate::layout::fit_text(technology, room, TECH_SIZE, metrics, warnings, &path);
            match lines.last_mut() {
                Some(last)
                    if metrics.width(&format!("{last} · "), EDGE_SIZE)
                        + metrics.width(&fitted, TECH_SIZE)
                        <= room =>
                {
                    *last = format!("{last} · {fitted}");
                }
                _ => lines.push(fitted.clone()),
            }
            tech = Some(fitted);
        } else if let Some(technology) = &edge.technology {
            // A technology cannot wrap: it may run as wide as a label does on a wide canvas.
            lines.push(crate::layout::fit_text(
                &format!("[{technology}]"),
                widest.max(EDGE_LABEL),
                EDGE_SIZE,
                metrics,
                warnings,
                &edge.label_path.replace("/label", "/technology"),
            ));
        }
        edge_widths.push(
            lines
                .iter()
                .map(|line| crate::diagram::run_width(line, tech.as_deref(), metrics))
                .fold(0.0, f64::max),
        );
        edge_labels.push(lines);
        edge_tech.push(tech);
    }
    (edge_labels, edge_widths, edge_tech)
}