Conditional Drawing of Box Participants in Sequence Diagram

0 votes
asked Jun 21 in Question / help by kjw

Hi 

I am using parameters to drive conditional drawing of participants in box groups in a sequence diagram - I am running on planttext.com

Sequence Blocks setup as

'===PART 1===
!ifdef PART1

Sequence goes herr

!endif

I was helped in an earlier question with preprocessor functions - DRAW works without fault

!unquoted function DRAW($x) return %set_variable_value($x, 1)

'====DRAW Specific Diagrams by Comment/Uncommenting Line===
'====Only uncomment one line at a Time======================
'DRAW(PART1)
DRAW(PART2)
'DRAW(PART3)
'DRAW(PART4)
'DRAW(PART5)
'DRAW(PARTX)
'DRAW(PARTY)
'DRAW(PART_REF)
'DRAW(PART_TMX)

My new function adds a control participant if the defined variable exists

!unquoted function addService($part, $service, $as)
    !ifdef $part
    '!if %variable_exists($part)
        control "$service" as $as
    !endif
!endfunction

Used as follows

box "AWS " #LightBlue
    participant "mPlatform" as mp
    addService("PART_REF", "RefDat_MS", "rdms")
    participant "PING Access" as pa
end box

box "ApplicationZone Z5 " #LightGrey
    participant "Data Power" as dp_z5
    participant "Ping Federate" as pf_z5
    participant "ESP" as esp
    addService("PART2", "Service Portal", "portal") 
    !ifdef PART10
    participant "Service Portal" as portal
    participant "API Gateway" as apig
    participant "Service" as service
    !endif
end box

In my function

 !ifdef $part does not discriminate between defined parameters and inserts all services

  !if %variable_exists($part)does not insert any services into the box 

Is this a bug or am I missing something ?

Ambition is to have dynamic participants in functional box groups depending on the viewpoint 

1 Answer

0 votes
answered Jun 21 by plantuml (206,820 points)

Thanks for the feedback. It looks like a bug.

However, it seems to works when you remove the unquoted keyword :

@startuml
!function addService($part, $service, $as)
    !if %variable_exists($part)
        control "$service" as $as
    !endif
!endfunction

!define PART_REF

box "AWS" #LightBlue
    participant "mPlatform" as mp
    addService("PART_REF", "RefDat_MS", "rdms")
    participant "PING Access" as pa
end box

box "ApplicationZone Z5 " #LightGrey
    participant "ESP" as esp
    addService("PART2", "Service Portal", "portal")
end box
@enduml

http://www.plantuml.com/plantuml/uml/ROzDImCn48Rl-HNJMC65dWJlNR4MGMNP5OHUbcbsee5yX2HRwhytsNL5g7F9VCoyxvDjJ1ZIQ3HRoT6Af9m578QEmaa9kbdxFDt0EivrpZ1M37Aib8Jh4mQ5HqqzdLLCSLwVvoM4ioau3Novvu2nICmAP0SbMNaMQyPM0qbb2PgwVUlRtIDZHtS6Nhzt7AwUrSTdkjSZJVV5ImdbqIRWfj6Of0jciZ2-RFpz25y4-GPuI_81K__IbI8C9lBgKh5vUjr3BGJ5E6bwP9aKCix2vBrM0WltmMNamnqiZFj0NvUAkwwPb2Z-ZtTRS7uwqBYGK9UEdxCAVlstEHcD_WO0

We are going to investigate this.

commented Jun 25 by kjw

IN addition

!unquoted function DRAW($x) return %set_variable_value($x, 1)

!function addBox($part, $box, $colour)
    '!ifdef $part
    !if %variable_exists($box)
        box "$box" #"$colour"
            participant "xXXX" as xx
        end box
    !endif
!endfunction

DRAW(PART25)

!ifdef PART25
title  TESTING  (Boxes & Participants)  Part25
!endif

addBox("PART25", "New Box", "white")

The function addBox doesn't seem to be outputting the expected Box and Participant

commented Jun 25 by plantuml (206,820 points)

It seems to me that you should write it this way:

@startuml
!unquoted function DRAW($x) return %set_variable_value($x, 1)

!function addBox($part, $box, $colour)
    !if %variable_exists($part)
        box "$box" #$colour
            participant "xXXX" as xx
        end box
    !endif
!endfunction

DRAW(PART25)

!ifdef PART25
title  TESTING  (Boxes & Participants)  Part25
!endif

addBox("PART25", "New Box", "red")
@enduml

http://www.plantuml.com/plantuml/uml/HL1DImCn4BtdLxp6Lhgm5mNlhIZYfPIwuDuatSn2O4rgFZG_tqcphdD8PZBllPcNNOZAn_GvYLMoNyb5qXYJ7Q9n5a-d_VjsdHjuYibRR0B5Zs_bZJfFnCcKYDijxXeXLWjBQVteydPzOU4MwxFBV0vkSiat0XmhCsApo50s8OOAB_qQp88iN8cRcLnxSnIq6Sn5sGYP-xwNK04vBo2okeZKWLoOKPJhRqiXhkQE-rDt_r3MDwEc4RKMqSI9WExvhNizl01RDaG1jpZ-ZmqDhYN3PtqnEvTLHRQG1_e1FvNKavQDs36KV_iN

commented Jun 27 by kjw

This is probably stretching the pre-processor design but are there ways to pass data in as a JSON or other structure array and manipulate it in a loop ? (Excuse the syntax mangling but iI hope the idea has legs)

!unquoted function DRAW($x) return %set_variable_value($x, 1)

!function addComponent($part, $component, $as)
    !if %variable_exists($part)
        participant "$component" as $as
    !endif
!endfunction

!function addBox2($part, $box, $colour, $array)
    !if %variable_exists($part)
        box "$box" #$colour
            !foreach($array[a][])
                addComponent($part, "$array[a,0]" as $array[a,1])
            !endforeach
        end box
    !endif
!endfunction

DRAW(PART25)

!ifdef PART25
title  TESTING  (Boxes & Participants)  Part25
!endif

$array[a,b]="[{XYZ,xyz},{RST, rts},{UVW, uvw}]"

addBox2("PART25", "New Box", "white" ,"$array[][]")


to get

box "New Box" #white
    participant "XYZ" as xyz
    participant "RST" as rst
    participant "UVW" as uvw
end box

commented Jun 27 by plantuml (206,820 points)
Brillant. This is completely crazy, so yes we like the idea :-)

However, there are some specification works before going further.

So we have started a wiki discussion page http://wiki.plantuml.net/site/preprocessing-json

The wiki is completely open so please update the page to add your comments.

The idea is to propose something consistent to other users. When everybody will agree, we'll see how to implement it.

Thanks for your contribution-to-be !
commented Jul 3 by Serge Wenger Work (11,800 points)
Very nice idea
...