merman-render 0.5.0

Headless layout + SVG renderer for Mermaid (parity-focused; upstream SVG goldens).
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
use merman_core::ParseMetadata;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::sync::Arc;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutMeta {
    pub diagram_type: String,
    pub title: Option<String>,
    pub config: Value,
    pub effective_config: Value,
}

impl LayoutMeta {
    pub fn from_parse_metadata(meta: &ParseMetadata) -> Self {
        Self {
            diagram_type: meta.diagram_type.clone(),
            title: meta.title.clone(),
            config: meta.config.as_value().clone(),
            effective_config: meta.effective_config.as_value().clone(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bounds {
    pub min_x: f64,
    pub min_y: f64,
    pub max_x: f64,
    pub max_y: f64,
}

impl Bounds {
    pub fn from_points(points: impl IntoIterator<Item = (f64, f64)>) -> Option<Self> {
        let mut it = points.into_iter();
        let (x0, y0) = it.next()?;
        let mut b = Self {
            min_x: x0,
            min_y: y0,
            max_x: x0,
            max_y: y0,
        };
        for (x, y) in it {
            b.min_x = b.min_x.min(x);
            b.min_y = b.min_y.min(y);
            b.max_x = b.max_x.max(x);
            b.max_y = b.max_y.max(y);
        }
        Some(b)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutPoint {
    pub x: f64,
    pub y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutLabel {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
}

#[derive(Debug, Clone)]
pub struct ClassNodeRowMetrics {
    pub members: Vec<crate::text::TextMetrics>,
    pub methods: Vec<crate::text::TextMetrics>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutNode {
    pub id: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub is_cluster: bool,
    #[serde(skip)]
    pub label_width: Option<f64>,
    #[serde(skip)]
    pub label_height: Option<f64>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutCluster {
    pub id: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    /// Mermaid cluster "diff" value used during cluster positioning.
    pub diff: f64,
    /// Mermaid cluster "offsetY" value: title bbox height minus half padding.
    pub offset_y: f64,
    pub title: String,
    pub title_label: LayoutLabel,
    pub requested_dir: Option<String>,
    pub effective_dir: String,
    pub padding: f64,
    pub title_margin_top: f64,
    pub title_margin_bottom: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutEdge {
    pub id: String,
    pub from: String,
    pub to: String,
    #[serde(default)]
    pub from_cluster: Option<String>,
    #[serde(default)]
    pub to_cluster: Option<String>,
    pub points: Vec<LayoutPoint>,
    pub label: Option<LayoutLabel>,
    #[serde(default)]
    pub start_label_left: Option<LayoutLabel>,
    #[serde(default)]
    pub start_label_right: Option<LayoutLabel>,
    #[serde(default)]
    pub end_label_left: Option<LayoutLabel>,
    #[serde(default)]
    pub end_label_right: Option<LayoutLabel>,
    /// Optional SVG marker id for marker-start (e.g. ER cardinality markers).
    #[serde(default)]
    pub start_marker: Option<String>,
    /// Optional SVG marker id for marker-end (e.g. ER cardinality markers).
    #[serde(default)]
    pub end_marker: Option<String>,
    /// Optional SVG dash pattern (e.g. identifying vs non-identifying ER relationships).
    #[serde(default)]
    pub stroke_dasharray: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequirementDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArchitectureDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MindmapDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SankeyNodeLayout {
    pub id: String,
    pub index: usize,
    pub depth: usize,
    pub height: usize,
    pub layer: usize,
    pub value: f64,
    pub x0: f64,
    pub x1: f64,
    pub y0: f64,
    pub y1: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SankeyLinkLayout {
    pub index: usize,
    pub source: String,
    pub target: String,
    pub value: f64,
    pub width: f64,
    pub y0: f64,
    pub y1: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SankeyDiagramLayout {
    pub bounds: Option<Bounds>,
    pub width: f64,
    pub height: f64,
    pub node_width: f64,
    pub node_padding: f64,
    pub nodes: Vec<SankeyNodeLayout>,
    pub links: Vec<SankeyLinkLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadarAxisLayout {
    pub label: String,
    pub angle: f64,
    pub line_x2: f64,
    pub line_y2: f64,
    pub label_x: f64,
    pub label_y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadarGraticuleShapeLayout {
    pub kind: String,
    pub r: Option<f64>,
    #[serde(default)]
    pub points: Vec<LayoutPoint>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadarCurveLayout {
    pub label: String,
    pub class_index: i64,
    #[serde(default)]
    pub points: Vec<LayoutPoint>,
    pub path_d: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadarLegendItemLayout {
    pub label: String,
    pub class_index: i64,
    pub x: f64,
    pub y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadarDiagramLayout {
    pub bounds: Option<Bounds>,
    pub svg_width: f64,
    pub svg_height: f64,
    pub center_x: f64,
    pub center_y: f64,
    pub radius: f64,
    pub axis_label_factor: f64,
    pub title_y: f64,
    #[serde(default)]
    pub axes: Vec<RadarAxisLayout>,
    #[serde(default)]
    pub graticules: Vec<RadarGraticuleShapeLayout>,
    #[serde(default)]
    pub curves: Vec<RadarCurveLayout>,
    #[serde(default)]
    pub legend_items: Vec<RadarLegendItemLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TreemapSectionLayout {
    pub name: String,
    pub depth: i64,
    pub value: f64,
    pub x0: f64,
    pub y0: f64,
    pub x1: f64,
    pub y1: f64,
    #[serde(default)]
    pub class_selector: Option<String>,
    #[serde(default)]
    pub css_compiled_styles: Option<Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TreemapLeafLayout {
    pub name: String,
    pub value: f64,
    #[serde(default)]
    pub parent_name: Option<String>,
    pub x0: f64,
    pub y0: f64,
    pub x1: f64,
    pub y1: f64,
    #[serde(default)]
    pub class_selector: Option<String>,
    #[serde(default)]
    pub css_compiled_styles: Option<Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TreemapDiagramLayout {
    pub title_height: f64,
    pub width: f64,
    pub height: f64,
    pub use_max_width: bool,
    pub diagram_padding: f64,
    pub show_values: bool,
    pub value_format: String,
    #[serde(default, rename = "accTitle")]
    pub acc_title: Option<String>,
    #[serde(default, rename = "accDescr")]
    pub acc_descr: Option<String>,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub sections: Vec<TreemapSectionLayout>,
    #[serde(default)]
    pub leaves: Vec<TreemapLeafLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XyChartRectData {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub fill: String,
    #[serde(rename = "strokeFill")]
    pub stroke_fill: String,
    #[serde(rename = "strokeWidth")]
    pub stroke_width: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XyChartTextData {
    pub text: String,
    pub x: f64,
    pub y: f64,
    pub fill: String,
    #[serde(rename = "fontSize")]
    pub font_size: f64,
    #[serde(default)]
    pub rotation: f64,
    #[serde(rename = "verticalPos")]
    pub vertical_pos: String,
    #[serde(rename = "horizontalPos")]
    pub horizontal_pos: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XyChartPathData {
    pub path: String,
    #[serde(default)]
    pub fill: Option<String>,
    #[serde(rename = "strokeFill")]
    pub stroke_fill: String,
    #[serde(rename = "strokeWidth")]
    pub stroke_width: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum XyChartDrawableElem {
    #[serde(rename = "rect")]
    Rect {
        #[serde(rename = "groupTexts")]
        group_texts: Vec<String>,
        data: Vec<XyChartRectData>,
    },
    #[serde(rename = "text")]
    Text {
        #[serde(rename = "groupTexts")]
        group_texts: Vec<String>,
        data: Vec<XyChartTextData>,
    },
    #[serde(rename = "path")]
    Path {
        #[serde(rename = "groupTexts")]
        group_texts: Vec<String>,
        data: Vec<XyChartPathData>,
    },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XyChartDiagramLayout {
    pub width: f64,
    pub height: f64,
    #[serde(rename = "chartOrientation")]
    pub chart_orientation: String,
    #[serde(rename = "showDataLabel")]
    pub show_data_label: bool,
    #[serde(rename = "backgroundColor")]
    pub background_color: String,
    #[serde(rename = "labelData")]
    pub label_data: Vec<String>,
    #[serde(default)]
    pub drawables: Vec<XyChartDrawableElem>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuadrantChartTextData {
    pub text: String,
    pub x: f64,
    pub y: f64,
    pub fill: String,
    #[serde(rename = "fontSize")]
    pub font_size: f64,
    #[serde(default)]
    pub rotation: f64,
    #[serde(rename = "verticalPos")]
    pub vertical_pos: String,
    #[serde(rename = "horizontalPos")]
    pub horizontal_pos: String,
}

pub type QuadrantChartAxisLabelData = QuadrantChartTextData;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuadrantChartQuadrantData {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub fill: String,
    pub text: QuadrantChartTextData,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuadrantChartBorderLineData {
    #[serde(rename = "strokeWidth")]
    pub stroke_width: f64,
    #[serde(rename = "strokeFill")]
    pub stroke_fill: String,
    pub x1: f64,
    pub y1: f64,
    pub x2: f64,
    pub y2: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuadrantChartPointData {
    pub x: f64,
    pub y: f64,
    pub fill: String,
    pub radius: f64,
    #[serde(rename = "strokeColor")]
    pub stroke_color: String,
    #[serde(rename = "strokeWidth")]
    pub stroke_width: String,
    pub text: QuadrantChartTextData,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuadrantChartDiagramLayout {
    pub width: f64,
    pub height: f64,
    #[serde(default)]
    pub title: Option<QuadrantChartTextData>,
    pub quadrants: Vec<QuadrantChartQuadrantData>,
    #[serde(rename = "borderLines")]
    pub border_lines: Vec<QuadrantChartBorderLineData>,
    pub points: Vec<QuadrantChartPointData>,
    #[serde(rename = "axisLabels")]
    pub axis_labels: Vec<QuadrantChartAxisLabelData>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FlowchartV2Layout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub clusters: Vec<LayoutCluster>,
    pub bounds: Option<Bounds>,
    /// Mermaid's DOM insertion order for each extracted root graph (`""` = top-level root).
    #[serde(skip)]
    pub dom_node_order_by_root: std::collections::HashMap<String, Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateDiagramV2Layout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub clusters: Vec<LayoutCluster>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClassDiagramV2Layout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub clusters: Vec<LayoutCluster>,
    pub bounds: Option<Bounds>,
    #[serde(skip)]
    pub class_row_metrics_by_id: FxHashMap<String, Arc<ClassNodeRowMetrics>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SequenceDiagramLayout {
    pub nodes: Vec<LayoutNode>,
    pub edges: Vec<LayoutEdge>,
    pub clusters: Vec<LayoutCluster>,
    pub bounds: Option<Bounds>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InfoDiagramLayout {
    pub bounds: Option<Bounds>,
    pub version: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PacketBlockLayout {
    pub start: i64,
    pub end: i64,
    pub label: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PacketWordLayout {
    pub blocks: Vec<PacketBlockLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PacketDiagramLayout {
    pub bounds: Option<Bounds>,
    pub width: f64,
    pub height: f64,
    pub row_height: f64,
    pub padding_x: f64,
    pub padding_y: f64,
    pub bit_width: f64,
    pub bits_per_row: i64,
    pub show_bits: bool,
    pub words: Vec<PacketWordLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PieSliceLayout {
    pub label: String,
    pub value: f64,
    pub start_angle: f64,
    pub end_angle: f64,
    pub is_full_circle: bool,
    pub percent: i64,
    pub text_x: f64,
    pub text_y: f64,
    pub fill: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PieLegendItemLayout {
    pub label: String,
    pub value: f64,
    pub fill: String,
    pub y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PieDiagramLayout {
    pub bounds: Option<Bounds>,
    pub center_x: f64,
    pub center_y: f64,
    pub radius: f64,
    pub outer_radius: f64,
    pub legend_x: f64,
    pub legend_start_y: f64,
    pub legend_step_y: f64,
    pub slices: Vec<PieSliceLayout>,
    pub legend_items: Vec<PieLegendItemLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineNodeLayout {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    /// Width used for wrapping (excluding padding).
    pub content_width: f64,
    /// Padding used to compute `width` (Mermaid 11.12.2 uses 20).
    pub padding: f64,
    pub section_class: String,
    pub label: String,
    /// Wrapped lines as rendered into `<tspan>` nodes.
    pub label_lines: Vec<String>,
    pub kind: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineLineLayout {
    pub kind: String,
    pub x1: f64,
    pub y1: f64,
    pub x2: f64,
    pub y2: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineTaskLayout {
    pub node: TimelineNodeLayout,
    pub connector: TimelineLineLayout,
    pub events: Vec<TimelineNodeLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineSectionLayout {
    pub node: TimelineNodeLayout,
    pub tasks: Vec<TimelineTaskLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineDiagramLayout {
    pub bounds: Option<Bounds>,
    pub left_margin: f64,
    pub base_x: f64,
    pub base_y: f64,
    /// `svg.node().getBBox().width` computed *before* title/activity line are inserted.
    pub pre_title_box_width: f64,
    pub sections: Vec<TimelineSectionLayout>,
    #[serde(default)]
    pub orphan_tasks: Vec<TimelineTaskLayout>,
    pub activity_line: TimelineLineLayout,
    pub title: Option<String>,
    pub title_x: f64,
    pub title_y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyActorLegendLineLayout {
    pub text: String,
    pub x: f64,
    pub y: f64,
    pub tspan_x: f64,
    pub text_margin: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyActorLegendItemLayout {
    pub actor: String,
    pub pos: i64,
    pub color: String,
    pub circle_cx: f64,
    pub circle_cy: f64,
    pub circle_r: f64,
    pub label_lines: Vec<JourneyActorLegendLineLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum JourneyMouthKind {
    Smile,
    Sad,
    Ambivalent,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyTaskActorCircleLayout {
    pub actor: String,
    pub pos: i64,
    pub color: String,
    pub cx: f64,
    pub cy: f64,
    pub r: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyTaskLayout {
    pub index: i64,
    pub section: String,
    pub task: String,
    pub score: i64,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub fill: String,
    pub num: i64,
    pub people: Vec<String>,
    pub actor_circles: Vec<JourneyTaskActorCircleLayout>,
    pub line_id: String,
    pub line_x1: f64,
    pub line_y1: f64,
    pub line_x2: f64,
    pub line_y2: f64,
    pub face_cx: f64,
    pub face_cy: Option<f64>,
    pub mouth: JourneyMouthKind,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneySectionLayout {
    pub section: String,
    pub num: i64,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub fill: String,
    pub task_count: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyLineLayout {
    pub x1: f64,
    pub y1: f64,
    pub x2: f64,
    pub y2: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JourneyDiagramLayout {
    pub bounds: Option<Bounds>,
    pub left_margin: f64,
    pub max_actor_label_width: f64,
    pub width: f64,
    pub height: f64,
    pub svg_height: f64,
    pub title: Option<String>,
    pub title_x: f64,
    pub title_y: f64,
    pub actor_legend: Vec<JourneyActorLegendItemLayout>,
    pub sections: Vec<JourneySectionLayout>,
    pub tasks: Vec<JourneyTaskLayout>,
    pub activity_line: JourneyLineLayout,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KanbanSectionLayout {
    pub id: String,
    pub label: String,
    pub index: i64,
    pub center_x: f64,
    pub center_y: f64,
    pub width: f64,
    pub rect_y: f64,
    pub rect_height: f64,
    pub rx: f64,
    pub ry: f64,
    pub label_width: f64,
    #[serde(skip)]
    pub label_height: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KanbanItemLayout {
    pub id: String,
    pub label: String,
    pub parent_id: String,
    pub center_x: f64,
    pub center_y: f64,
    pub width: f64,
    pub height: f64,
    pub rx: f64,
    pub ry: f64,
    #[serde(default)]
    pub ticket: Option<String>,
    #[serde(default)]
    pub assigned: Option<String>,
    #[serde(default)]
    pub priority: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KanbanDiagramLayout {
    pub bounds: Option<Bounds>,
    pub section_width: f64,
    pub padding: f64,
    pub max_label_height: f64,
    pub viewbox_padding: f64,
    pub sections: Vec<KanbanSectionLayout>,
    pub items: Vec<KanbanItemLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitGraphBranchLayout {
    pub name: String,
    pub index: i64,
    pub pos: f64,
    pub bbox_width: f64,
    pub bbox_height: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitGraphCommitLayout {
    pub id: String,
    pub message: String,
    pub seq: i64,
    pub commit_type: i64,
    #[serde(default)]
    pub custom_type: Option<i64>,
    #[serde(default)]
    pub custom_id: Option<bool>,
    #[serde(default)]
    pub tags: Vec<String>,
    #[serde(default)]
    pub parents: Vec<String>,
    pub branch: String,
    pub pos: f64,
    pub pos_with_offset: f64,
    pub x: f64,
    pub y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitGraphArrowLayout {
    pub from: String,
    pub to: String,
    pub class_index: i64,
    pub d: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitGraphDiagramLayout {
    pub bounds: Option<Bounds>,
    pub direction: String,
    pub rotate_commit_label: bool,
    pub show_branches: bool,
    pub show_commit_label: bool,
    pub parallel_commits: bool,
    pub diagram_padding: f64,
    pub max_pos: f64,
    pub branches: Vec<GitGraphBranchLayout>,
    pub commits: Vec<GitGraphCommitLayout>,
    pub arrows: Vec<GitGraphArrowLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttAxisTickLayout {
    pub time_ms: i64,
    pub x: f64,
    pub label: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttExcludeRangeLayout {
    pub id: String,
    pub start_ms: i64,
    pub end_ms: i64,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttSectionTitleLayout {
    pub section: String,
    pub index: i64,
    pub x: f64,
    pub y: f64,
    pub dy_em: f64,
    pub lines: Vec<String>,
    pub class: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttRowLayout {
    pub index: i64,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub class: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttTaskLabelLayout {
    pub id: String,
    pub text: String,
    pub font_size: f64,
    pub width: f64,
    pub x: f64,
    pub y: f64,
    pub class: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttTaskBarLayout {
    pub id: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub rx: f64,
    pub ry: f64,
    pub class: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttTaskLayout {
    pub id: String,
    pub task: String,
    pub section: String,
    pub task_type: String,
    pub order: i64,
    pub start_ms: i64,
    pub end_ms: i64,
    #[serde(default)]
    pub render_end_ms: Option<i64>,
    pub milestone: bool,
    pub vert: bool,
    pub bar: GanttTaskBarLayout,
    pub label: GanttTaskLabelLayout,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GanttDiagramLayout {
    pub bounds: Option<Bounds>,
    pub width: f64,
    pub height: f64,
    pub left_padding: f64,
    pub right_padding: f64,
    pub top_padding: f64,
    pub grid_line_start_padding: f64,
    pub bar_height: f64,
    pub bar_gap: f64,
    pub title_top_margin: f64,
    pub font_size: f64,
    pub section_font_size: f64,
    pub number_section_styles: i64,
    pub display_mode: String,
    pub date_format: String,
    pub axis_format: String,
    #[serde(default)]
    pub tick_interval: Option<String>,
    pub top_axis: bool,
    pub today_marker: String,
    pub categories: Vec<String>,
    pub rows: Vec<GanttRowLayout>,
    pub section_titles: Vec<GanttSectionTitleLayout>,
    pub tasks: Vec<GanttTaskLayout>,
    pub excludes: Vec<GanttExcludeRangeLayout>,
    #[serde(default)]
    pub has_excludes_layer: bool,
    pub bottom_ticks: Vec<GanttAxisTickLayout>,
    #[serde(default)]
    pub top_ticks: Vec<GanttAxisTickLayout>,
    pub title: Option<String>,
    pub title_x: f64,
    pub title_y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4TextBlockLayout {
    pub text: String,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub line_count: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4ImageLayout {
    pub width: f64,
    pub height: f64,
    pub y: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4ShapeLayout {
    pub alias: String,
    pub parent_boundary: String,
    pub type_c4_shape: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub margin: f64,
    pub image: C4ImageLayout,
    pub type_block: C4TextBlockLayout,
    pub label: C4TextBlockLayout,
    #[serde(default)]
    pub ty: Option<C4TextBlockLayout>,
    #[serde(default)]
    pub techn: Option<C4TextBlockLayout>,
    #[serde(default)]
    pub descr: Option<C4TextBlockLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4BoundaryLayout {
    pub alias: String,
    pub parent_boundary: String,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub image: C4ImageLayout,
    pub label: C4TextBlockLayout,
    #[serde(default)]
    pub ty: Option<C4TextBlockLayout>,
    #[serde(default)]
    pub descr: Option<C4TextBlockLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4RelLayout {
    pub from: String,
    pub to: String,
    pub rel_type: String,
    pub start_point: LayoutPoint,
    pub end_point: LayoutPoint,
    #[serde(default)]
    pub offset_x: Option<i64>,
    #[serde(default)]
    pub offset_y: Option<i64>,
    pub label: C4TextBlockLayout,
    #[serde(default)]
    pub techn: Option<C4TextBlockLayout>,
    #[serde(default)]
    pub descr: Option<C4TextBlockLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct C4DiagramLayout {
    pub bounds: Option<Bounds>,
    pub width: f64,
    pub height: f64,
    pub viewport_width: f64,
    pub viewport_height: f64,
    pub c4_type: String,
    pub title: Option<String>,
    pub boundaries: Vec<C4BoundaryLayout>,
    pub shapes: Vec<C4ShapeLayout>,
    pub rels: Vec<C4RelLayout>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorDiagramLayout {
    pub viewbox_width: f64,
    pub viewbox_height: f64,
    pub max_width_px: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LayoutDiagram {
    BlockDiagram(Box<BlockDiagramLayout>),
    RequirementDiagram(Box<RequirementDiagramLayout>),
    ArchitectureDiagram(Box<ArchitectureDiagramLayout>),
    MindmapDiagram(Box<MindmapDiagramLayout>),
    SankeyDiagram(Box<SankeyDiagramLayout>),
    RadarDiagram(Box<RadarDiagramLayout>),
    TreemapDiagram(Box<TreemapDiagramLayout>),
    XyChartDiagram(Box<XyChartDiagramLayout>),
    QuadrantChartDiagram(Box<QuadrantChartDiagramLayout>),
    FlowchartV2(Box<FlowchartV2Layout>),
    StateDiagramV2(Box<StateDiagramV2Layout>),
    ClassDiagramV2(Box<ClassDiagramV2Layout>),
    ErDiagram(Box<ErDiagramLayout>),
    SequenceDiagram(Box<SequenceDiagramLayout>),
    InfoDiagram(Box<InfoDiagramLayout>),
    PacketDiagram(Box<PacketDiagramLayout>),
    TimelineDiagram(Box<TimelineDiagramLayout>),
    PieDiagram(Box<PieDiagramLayout>),
    JourneyDiagram(Box<JourneyDiagramLayout>),
    KanbanDiagram(Box<KanbanDiagramLayout>),
    GitGraphDiagram(Box<GitGraphDiagramLayout>),
    GanttDiagram(Box<GanttDiagramLayout>),
    C4Diagram(Box<C4DiagramLayout>),
    ErrorDiagram(Box<ErrorDiagramLayout>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutedDiagram {
    pub meta: LayoutMeta,
    pub semantic: Value,
    pub layout: LayoutDiagram,
}