2

Sometimes it is very tiresome to sort keys alphabetically, especially in larger tables, which grow over time.

Let's look at this diagram: enter image description here

@startuml
!define Table(name,desc) class name as "desc" << (T,white) >>
!define primary_key(x) <b><color:b8861b><&key></color> x</b>
!define column(x) <color:black><&media-record></color> x

Table(testTable, "demoTable") {
column(zzz)
column(aaaa)
column(gggg)
}
@enduml

Is there any option for PlantUML that would sort my column entries based on their names? I want to display the diagram as if I'd have written it as enter image description here

@startuml
!define Table(name,desc) class name as "desc" << (T,white) >>
!define primary_key(x) <b><color:b8861b><&key></color> x</b>
!define column(x) <color:black><&media-record></color> x

Table(testTable, "demoTable") {
column(aaaa)
column(gggg)
column(zzz)
}
@enduml

Is it possible with built-in tools, or do you have any idea how to accomplish this?

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
SomeUser
  • 23
  • 4
  • Thanks, @qwerty_so for the edit, totally missed the direct inclusion :). – SomeUser Dec 08 '21 at 22:20
  • It might be that you had no privilege for placing pictures. Comes early but not at once... – qwerty_so Dec 08 '21 at 23:02
  • 1
    As for your scripts: I don't use PlantUML but I would probably write a litte Python script to do the sorting. Doesn't look like the syntax is overly complicated. And if you have simple constraints for the edit it could be done even without a parser. – qwerty_so Dec 08 '21 at 23:04
  • Yeah, a Python script would be nice. But we use PlantUML embedded in Markdown (GitLab Wiki), so it would be handy, if I didn't need to do it by hand or "offline script" – SomeUser Jan 12 '22 at 19:42

1 Answers1

1

You could suggest the feature to the PlantUML Q&A Forum.

In the mean time, why not use an !include and sort the items in your operating system. Here's a sample:

@startuml
!define Table(name,desc) class name as "desc" << (T,white) >>
!define primary_key(x) <b><color:b8861b><&key></color> x</b>
!define column(x) <color:black><&media-record></color> x

Table(testTable, "demoTable") {
!include items.include
}

Table(testTableSorted, "demoTable(sorted)") {
!include sorted_items.include
}
@enduml

enter image description here

You could always keep the file sorted, or sort a copy of it:

sort items.include > sorted_items.include
Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111