34
34
import java .util .stream .Collectors ;
35
35
import java .util .stream .Stream ;
36
36
37
+ import com .structurizr .export .plantuml .AbstractPlantUMLExporter ;
37
38
import org .springframework .lang .Nullable ;
38
39
import org .springframework .modulith .core .ApplicationModule ;
39
40
import org .springframework .modulith .core .ApplicationModules ;
@@ -553,6 +554,7 @@ private String render(ComponentView view, DiagramOptions options) {
553
554
case C4 :
554
555
555
556
var c4PlantUmlExporter = new C4PlantUMLExporter ();
557
+ addSkinParamsFromOptions (c4PlantUmlExporter , options );
556
558
var diagram = c4PlantUmlExporter .export (view );
557
559
558
560
return diagram .getDefinition ();
@@ -561,12 +563,19 @@ private String render(ComponentView view, DiagramOptions options) {
561
563
default :
562
564
563
565
var plantUmlExporter = new CustomizedPlantUmlExporter ();
566
+ addSkinParamsFromOptions (plantUmlExporter , options );
564
567
plantUmlExporter .addSkinParam ("componentStyle" , "uml1" );
565
568
566
569
return plantUmlExporter .export (view ).getDefinition ();
567
570
}
568
571
}
569
572
573
+ private void addSkinParamsFromOptions (AbstractPlantUMLExporter exporter , DiagramOptions options ) {
574
+ for (var skinParamEntry : options .skinParams .entrySet ()) {
575
+ exporter .addSkinParam (skinParamEntry .getKey (), skinParamEntry .getValue ());
576
+ }
577
+ }
578
+
570
579
private String createPlantUml (DiagramOptions options ) {
571
580
572
581
ComponentView componentView = createComponentView (options );
@@ -667,6 +676,7 @@ public static class DiagramOptions {
667
676
private final Function <ApplicationModule , String > defaultDisplayName ;
668
677
private final DiagramStyle style ;
669
678
private final ElementsWithoutRelationships elementsWithoutRelationships ;
679
+ private final Map <String , String > skinParams ;
670
680
671
681
/**
672
682
* @param dependencyTypes must not be {@literal null}.
@@ -679,13 +689,15 @@ public static class DiagramOptions {
679
689
* @param defaultDisplayName must not be {@literal null}.
680
690
* @param style must not be {@literal null}.
681
691
* @param elementsWithoutRelationships must not be {@literal null}.
692
+ * @param skinParams must not be {@literal null}.
682
693
*/
683
694
DiagramOptions (Set <DependencyType > dependencyTypes , DependencyDepth dependencyDepth ,
684
695
Predicate <ApplicationModule > exclusions , Predicate <Component > componentFilter ,
685
696
Predicate <ApplicationModule > targetOnly , @ Nullable String targetFileName ,
686
697
Function <ApplicationModule , Optional <String >> colorSelector ,
687
698
Function <ApplicationModule , String > defaultDisplayName , DiagramStyle style ,
688
- ElementsWithoutRelationships elementsWithoutRelationships ) {
699
+ ElementsWithoutRelationships elementsWithoutRelationships ,
700
+ Map <String , String > skinParams ) {
689
701
690
702
Assert .notNull (dependencyTypes , "Dependency types must not be null!" );
691
703
Assert .notNull (dependencyDepth , "Dependency depth must not be null!" );
@@ -696,6 +708,7 @@ public static class DiagramOptions {
696
708
Assert .notNull (defaultDisplayName , "Default display name must not be null!" );
697
709
Assert .notNull (style , "DiagramStyle must not be null!" );
698
710
Assert .notNull (elementsWithoutRelationships , "ElementsWithoutRelationships must not be null!" );
711
+ Assert .notNull (skinParams , "SkinParams must not be null!" );
699
712
700
713
this .dependencyTypes = dependencyTypes ;
701
714
this .dependencyDepth = dependencyDepth ;
@@ -707,30 +720,31 @@ public static class DiagramOptions {
707
720
this .defaultDisplayName = defaultDisplayName ;
708
721
this .style = style ;
709
722
this .elementsWithoutRelationships = elementsWithoutRelationships ;
723
+ this .skinParams = skinParams ;
710
724
}
711
725
712
726
/**
713
727
* The {@link DependencyDepth} to define which other modules to be included in the diagram to be created.
714
728
*/
715
729
public DiagramOptions withDependencyDepth (DependencyDepth dependencyDepth ) {
716
730
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
717
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
731
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
718
732
}
719
733
720
734
/**
721
735
* A {@link Predicate} to define the which modules to exclude from the diagram to be created.
722
736
*/
723
737
public DiagramOptions withExclusions (Predicate <ApplicationModule > exclusions ) {
724
738
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
725
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
739
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
726
740
}
727
741
728
742
/**
729
743
* A {@link Predicate} to define which Structurizr {@link Component}s to be included in the diagram to be created.
730
744
*/
731
745
public DiagramOptions withComponentFilter (Predicate <Component > componentFilter ) {
732
746
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
733
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
747
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
734
748
}
735
749
736
750
/**
@@ -740,7 +754,7 @@ public DiagramOptions withComponentFilter(Predicate<Component> componentFilter)
740
754
*/
741
755
public DiagramOptions withTargetOnly (Predicate <ApplicationModule > targetOnly ) {
742
756
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
743
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
757
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
744
758
}
745
759
746
760
/**
@@ -752,15 +766,15 @@ public DiagramOptions withTargetFileName(String targetFileName) {
752
766
Assert .isTrue (targetFileName .contains ("%s" ), () -> INVALID_FILE_NAME_PATTERN .formatted (targetFileName ));
753
767
754
768
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
755
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
769
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
756
770
}
757
771
758
772
/**
759
773
* A callback to return a hex-encoded color per {@link ApplicationModule}.
760
774
*/
761
775
public DiagramOptions withColorSelector (Function <ApplicationModule , Optional <String >> colorSelector ) {
762
776
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
763
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
777
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
764
778
}
765
779
766
780
/**
@@ -769,15 +783,15 @@ public DiagramOptions withColorSelector(Function<ApplicationModule, Optional<Str
769
783
*/
770
784
public DiagramOptions withDefaultDisplayName (Function <ApplicationModule , String > defaultDisplayName ) {
771
785
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
772
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
786
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
773
787
}
774
788
775
789
/**
776
790
* Which style to render the diagram in. Defaults to {@link DiagramStyle#UML}.
777
791
*/
778
792
public DiagramOptions withStyle (DiagramStyle style ) {
779
793
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
780
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
794
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
781
795
}
782
796
783
797
/**
@@ -790,7 +804,18 @@ public DiagramOptions withStyle(DiagramStyle style) {
790
804
*/
791
805
public DiagramOptions withElementsWithoutRelationships (ElementsWithoutRelationships elementsWithoutRelationships ) {
792
806
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
793
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
807
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
808
+ }
809
+
810
+ /**
811
+ * Configuration setting to add arbitrary skin parameters to the created diagrams.
812
+ *
813
+ * Applies to both the UML and C4 {@link DiagramStyle styles}.
814
+ */
815
+ public DiagramOptions withSkinParam (String name , String value ) {
816
+ skinParams .put (name , value );
817
+ return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
818
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
794
819
}
795
820
796
821
/**
@@ -803,7 +828,7 @@ public DiagramOptions withElementsWithoutRelationships(ElementsWithoutRelationsh
803
828
public static DiagramOptions defaults () {
804
829
return new DiagramOptions (ALL_TYPES , DependencyDepth .IMMEDIATE , it -> false , it -> true , it -> false , null ,
805
830
__ -> Optional .empty (), it -> it .getDisplayName (), DiagramStyle .C4 ,
806
- ElementsWithoutRelationships .HIDDEN );
831
+ ElementsWithoutRelationships .HIDDEN , new LinkedHashMap <>() );
807
832
}
808
833
809
834
/**
@@ -820,7 +845,7 @@ public DiagramOptions withDependencyTypes(DependencyType... types) {
820
845
821
846
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
822
847
targetFileName ,
823
- colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
848
+ colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
824
849
}
825
850
826
851
private Optional <String > getTargetFileName () {
0 commit comments