@@ -24,63 +24,57 @@ function visualizeAlignment(alignedTraces){
2424 const stats = getAlignmentDecorations ( alignedTraces )
2525
2626 //set the violation color
27- /**
28- * A high level API will be provided: see https://github.com/process-analytics/bpmn-visualization-R/issues/13
29- */
30- let mxGraph = globals . bpmnVisualization . graph
31- let activityCurrentStyle = null
32- let activityCell = null
33-
34- //first reset fill and font color
27+ const graph = globals . bpmnVisualization . graph
28+
29+ // first reset fill and font color
3530 // and remove overlays if existing
36- let activities = globals . bpmnVisualization . bpmnElementsRegistry . getElementsByKinds ( ShapeBpmnElementKind . TASK )
37- let activityCells = activities . map ( elt => mxGraph . getModel ( ) . getCell ( elt . bpmnSemantic . id ) )
38- mxGraph . getModel ( ) . beginUpdate ( )
31+ const activities = globals . bpmnVisualization . bpmnElementsRegistry . getElementsByKinds ( ShapeBpmnElementKind . TASK )
32+ const activityCells = activities . map ( elt => graph . getModel ( ) . getCell ( elt . bpmnSemantic . id ) )
33+
34+ graph . getModel ( ) . beginUpdate ( )
3935 try {
40- mxgraph . mxUtils . setCellStyles ( mxGraph . getModel ( ) , activityCells , "fillColor" , "none" )
41- mxgraph . mxUtils . setCellStyles ( mxGraph . getModel ( ) , activityCells , "fontColor" , "none" )
36+ mxgraph . mxUtils . setCellStyles ( graph . getModel ( ) , activityCells , mxgraph . mxConstants . STYLE_FILLCOLOR , "none" )
37+ mxgraph . mxUtils . setCellStyles ( graph . getModel ( ) , activityCells , mxgraph . mxConstants . STYLE_FONTCOLOR , "none" )
4238 } finally {
43- mxGraph . getModel ( ) . endUpdate ( ) ;
39+ graph . getModel ( ) . endUpdate ( ) ;
4440 }
4541
4642 //remove overlays
4743 activities . forEach ( act => globals . bpmnVisualization . bpmnElementsRegistry . removeAllOverlays ( act . bpmnSemantic . id ) )
4844
4945
5046 //set violation color
51- for ( const [ activityName , violationRatio ] of Object . entries ( stats . normalizedStats ) ) {
52- const activityElement = getBpmnActivityElementbyName ( activityName )
53- if ( activityElement ) {
54- activityCell = mxGraph . getModel ( ) . getCell ( activityElement . bpmnSemantic . id )
55- activityCurrentStyle = mxGraph . getModel ( ) . getStyle ( activityCell )
56- mxGraph . getModel ( ) . beginUpdate ( )
57- try {
58- let style = mxgraph . mxUtils . setStyle ( activityCurrentStyle , "fillColor" , myViolationScale ( violationRatio * 100 ) )
59- mxGraph . getModel ( ) . setStyle ( activityCell , style ) ;
60- activityCurrentStyle = mxGraph . getModel ( ) . getStyle ( activityCell )
61- //different way of setting the style
62- //mxGraph.setCellStyles("fillColor", "red", [activityCell]);
63-
47+ graph . getModel ( ) . beginUpdate ( )
48+ try {
49+ for ( const [ activityName , violationRatio ] of Object . entries ( stats . normalizedStats ) ) {
50+ const activityElement = getBpmnActivityElementbyName ( activityName )
51+ if ( activityElement ) {
52+ const activityCell = graph . getModel ( ) . getCell ( activityElement . bpmnSemantic . id )
53+ let style = graph . getModel ( ) . getStyle ( activityCell )
54+ style = mxgraph . mxUtils . setStyle ( style , mxgraph . mxConstants . STYLE_FILLCOLOR , myViolationScale ( violationRatio * 100 ) )
6455 //set label to white when the activity fillColor is above the scale average
65- if ( violationRatio > 0.5 ) {
66- style = mxgraph . mxUtils . setStyle ( activityCurrentStyle , 'fontColor' , 'white' )
67- mxGraph . getModel ( ) . setStyle ( activityCell , style ) ;
56+ if ( violationRatio > 0.5 ) {
57+ style = mxgraph . mxUtils . setStyle ( style , mxgraph . mxConstants . STYLE_FONTCOLOR , 'white' )
6858 }
69- } finally {
70- mxGraph . getModel ( ) . endUpdate ( ) ;
59+ graph . getModel ( ) . setStyle ( activityCell , style ) ;
60+
61+ //add overlay
62+ globals . bpmnVisualization . bpmnElementsRegistry . addOverlays (
63+ activityElement . bpmnSemantic . id ,
64+ [
65+ getDeviationOverlay ( stats . aggStats [ activityName ] . modelMove ,
66+ violationRatio ,
67+ myViolationScale ( violationRatio * 100 ) ) ,
68+ getSynchronousOverlay ( stats . aggStats [ activityName ] . syncMove )
69+ ] )
7170 }
72- //add overlay
73- globals . bpmnVisualization . bpmnElementsRegistry . addOverlays (
74- activityElement . bpmnSemantic . id ,
75- [
76- getDeviationOverlay ( stats . aggStats [ activityName ] . modelMove ,
77- violationRatio ,
78- myViolationScale ( violationRatio * 100 ) ) ,
79- getSynchronousOverlay ( stats . aggStats [ activityName ] . syncMove )
80- ] )
8171 }
82-
72+ // Allow to save the style in a new state, in particular keep the rounded activity
73+ graph . refresh ( ) ;
74+ } finally {
75+ graph . getModel ( ) . endUpdate ( ) ;
8376 }
77+
8478 //add legend
8579 colorLegend ( {
8680 colorScale : myViolationScale ,
@@ -97,17 +91,16 @@ function visualizeAlignment(alignedTraces){
9791 */
9892function getAlignmentDecorations ( alignments ) {
9993 //initialize the aggregated statistics for each activity
100- let aggStats = globals . bpmnActivityElements . map ( function ( elt ) {
101- let result = new Object ( )
94+ const aggStats = globals . bpmnActivityElements . map ( elt => {
95+ let result = { }
10296 result [ elt . bpmnSemantic . name ] = { syncMove : 0 , modelMove : 0 }
10397 return result
10498 } )
105-
106- //convert the list aggStats to one object whose keys are the activity names
107- aggStats = aggStats . reduce ( function ( obj , item ) {
108- const key = Object . keys ( item ) [ 0 ]
109- obj [ key ] = item [ key ] ;
110- return obj ;
99+ //convert the list aggStats to one object whose keys are the activity names
100+ . reduce ( ( obj , item ) => {
101+ const key = Object . keys ( item ) [ 0 ]
102+ obj [ key ] = item [ key ] ;
103+ return obj ;
111104 } , { } ) ;
112105
113106 //extract the alignments
0 commit comments