cancel
Showing results for 
Search instead for 
Did you mean: 

How to Name Sequence Flow and make them visible on generated diagram

smadhu
Champ in-the-making
Champ in-the-making
Hi,

         Iam stuck. I need help in naming SequenceFlows. When I use Eclipse Designer Iam able to name Sequence Flows and Also see them in the diagram inside the IDE.

But now the problem is, I have written a small program to generate BPM diagram using Activiti. It works perfectly, but in the generated diagram Iam unable to see the below set sequenceFlow name ( refer below to flow.setName()).  I also tried generating the corresponding BPMN
XML, Iam able to see the name inside the XML. But this is not visible in the generated PNG.  Can anybody help me out in this.

SequenceFlow flow = new SequenceFlow();
flow.setSourceRef(from);
flow.setTargetRef(to);
flow.setName("X > 10");
11 REPLIES 11

frederikherema1
Star Contributor
Star Contributor
That feature is currently not supported in the DiagramGenerator. However, I saw a pull-request passing by related to this: https://github.com/Activiti/Activiti/pull/331

smadhu
Champ in-the-making
Champ in-the-making
Hi,
       I downloaded 5.16 based on your suggestion and tried the above code example

             (flow.setName("x > 10"));

it still does not gets displayed in generated png diagram. Not sure if this feature has been enabled. Can u suggest me how to get this done, is there any alternative.

thanks in advance

frederikherema1
Star Contributor
Star Contributor
If you look at the https://github.com/Activiti/Activiti/pull/331 comments and state, it's clear that this is not included in the 5.16 release.

ruckenhof
Champ in-the-making
Champ in-the-making
Hi Sudarshan! I've encountered the same problem and I've found that small changes in the sourcecode of activiti-image-generator-5.16.jar will do the trick. Recompile it in Eclipse or contact me: the.measurer@gmail.com.

In org.activiti.image.impl.DefaultProcessDiagramCanvas.java:
1) find method "public void drawLabel(String text, GraphicInfo graphicInfo, boolean centered)"
2) str 1105: replace "int textY = (int) (graphicInfo.getY() + graphicInfo.getHeight());" with "int textY = (int) graphicInfo.getY();"
3) str 1119: replace "double tY = graphicInfo.getY();" with "double tY = graphicInfo.getX();"

In org.activiti.image.impl.DefaultProcessDiagramGenerator.java:
1) find method "protected void drawActivity( …args here )"
2) str 566: comment the line "GraphicInfo lineCenter = getLineCenter(graphicInfoList);"
3) str 567: replace "processDiagramCanvas.drawLabel(sequenceFlow.getName(), lineCenter, false);" with "processDiagramCanvas.drawLabel(sequenceFlow.getName(), labelGraphicInfo, false);"

That should fix horizontal and vertical alignment of your labels. Hope this will help you!

shar
Champ in-the-making
Champ in-the-making
Yes. It works. Thank you very much.
Probably needs to be done to fix initProcessDiagramCanvas. Labels at the bottom boundary of the diagram are cut off.
I still do not understand where I need to fix it.

ruckenhof
Champ in-the-making
Champ in-the-making
Glad to help! You're right about initProcessDiagramCanvas, its logic doesn't take existence of labels into account, so they're cut off when they are too far beyond other elements.

Modify it like that:
1) add initialization of label's GraphicInfo after line 727:
"GraphicInfo labelGraphicInfo = bpmnModel.getLabelGraphicInfo(sequenceFlow.getId());"
2) add the next snippet immediately after, before the declaration of graphicInfoList and appropriate for-loop:
          if (labelGraphicInfo.getX() + labelGraphicInfo.getWidth() > maxX) {
            maxX = labelGraphicInfo.getX() + labelGraphicInfo.getWidth();
          }
          if (labelGraphicInfo.getX() < minX) {
            minX = labelGraphicInfo.getX();
          }
          if (labelGraphicInfo.getY() + labelGraphicInfo.getHeight() > maxY) {
            maxY = labelGraphicInfo.getY() + labelGraphicInfo.getHeight();
          }
          if (labelGraphicInfo.getY() < minY) {
            minY = labelGraphicInfo.getY();
          }

It should push the boundaries of canvas if necessary.

shar
Champ in-the-making
Champ in-the-making
Thank you again. Now everything looks fine.
It is only necessary to insert the check
if (labelGraphicInfo! = null) {
before the snippet.
Like this

if(labelGraphicInfo != null){
if (labelGraphicInfo.getX() + labelGraphicInfo.getWidth() > maxX) {
maxX = labelGraphicInfo.getX() + labelGraphicInfo.getWidth();
}
if (labelGraphicInfo.getX() < minX) {
minX = labelGraphicInfo.getX();
}
if (labelGraphicInfo.getY() + labelGraphicInfo.getHeight() > maxY) {
maxY = labelGraphicInfo.getY() + labelGraphicInfo.getHeight();
}
if (labelGraphicInfo.getY() < minY) {
minY = labelGraphicInfo.getY();
}
}

shar
Champ in-the-making
Champ in-the-making
I wonder when these changes will appear in the standard version. Only 5.17? In October?

smadhu
Champ in-the-making
Champ in-the-making
Hi Ruckenhof ,

         Thanks for your response, really appreciate your help. I tried as you have mentioned above. But still the label does not gets displayed in the diagram. I have attached my class, the modified files (as you have mentioned above),  I'm not sure what's happening, Can you please me out.

thanks