11import globals from './globals.js' ;
2+ import { mxgraph } from './mxgraph-initializer' ;
23import { violationScale , colorLegend } from './colors.js'
34import { getDeviationOverlay , getSynchronousOverlay } from './overlays.js'
45import { getBpmnActivityElementbyName } from './utils.js' ;
6+ import { ShapeBpmnElementKind } from 'bpmn-visualization' ;
57
68export function getAlignment ( formData ) {
79 console . log ( "Get alignments..." ) ;
@@ -20,20 +22,56 @@ export function getAlignment(formData) {
2022function visualizeAlignment ( alignedTraces ) {
2123 const myViolationScale = violationScale ( 0 , 100 )
2224 console . log ( "alignments received!" ) ;
25+
2326 //compute aggregated statistics of the received alignment
2427 const stats = getAlignmentDecorations ( alignedTraces )
25- //generate colors for stats.normalizedStats
26- console . log ( stats . normalizedStats )
28+
29+ //set the violation color
30+ /**
31+ * A high level API will be provided: see https://github.com/process-analytics/bpmn-visualization-R/issues/13
32+ */
33+ let mxGraph = globals . bpmnVisualization . graph
34+ let activityCurrentStyle = null
35+ let activityCell = null
36+
37+ //first reset fill anf font color
38+ let activities = globals . bpmnVisualization . bpmnElementsRegistry . getElementsByKinds ( ShapeBpmnElementKind . TASK )
39+ let activityCells = activities . map ( elt => mxGraph . getModel ( ) . getCell ( elt . bpmnSemantic . id ) )
40+ mxGraph . getModel ( ) . beginUpdate ( )
41+ try {
42+ mxgraph . mxUtils . setCellStyles ( mxGraph . getModel ( ) , activityCells , "fillColor" , "none" )
43+ mxgraph . mxUtils . setCellStyles ( mxGraph . getModel ( ) , activityCells , "fontColor" , "none" )
44+ } finally {
45+ mxGraph . getModel ( ) . endUpdate ( ) ;
46+ }
47+
48+ //set violation color
2749 for ( const [ activityName , violationValue ] of Object . entries ( stats . normalizedStats ) ) {
28- const activityElement = getBpmnActivityElementbyName ( activityName )
29- //set the violation color
30- //firstChild is the svg rect element of the activity element
50+ const activityElement = getBpmnActivityElementbyName ( activityName )
51+ if ( activityElement ) {
52+ activityCell = mxGraph . getModel ( ) . getCell ( activityElement . bpmnSemantic . id )
53+ activityCurrentStyle = mxGraph . getModel ( ) . getStyle ( activityCell )
54+ mxGraph . getModel ( ) . beginUpdate ( )
55+ try {
56+ let style = mxgraph . mxUtils . setStyle ( activityCurrentStyle , "fillColor" , myViolationScale ( violationValue * 100 ) )
57+ mxGraph . getModel ( ) . setStyle ( activityCell , style ) ;
58+ //different way of setting the style
59+ //mxGraph.setCellStyles("fillColor", "red", [activityCell]);
3160
32- activityElement . htmlElement . firstChild . setAttribute ( "fill" , myViolationScale ( violationValue * 100 ) )
61+ //set label to white when the activity fillColor is above the scale average
62+ if ( violationValue > 0.5 ) {
63+ activityCurrentStyle = mxGraph . getModel ( ) . getStyle ( activityCell )
64+ style = mxgraph . mxUtils . setStyle ( activityCurrentStyle , 'fontColor' , 'white' )
65+ mxGraph . getModel ( ) . setStyle ( activityCell , style ) ;
66+ }
67+ } finally {
68+ mxGraph . getModel ( ) . endUpdate ( ) ;
69+ }
70+ }
3371 //add overlay
3472 globals . bpmnVisualization . bpmnElementsRegistry . addOverlays (
3573 activityElement . bpmnSemantic . id ,
36- [ getDeviationOverlay ( stats . aggStats [ activityName ] . modelMove , myViolationScale ( violationValue * 100 ) ) ,
74+ [ getDeviationOverlay ( stats . aggStats [ activityName ] . modelMove , violationValue , myViolationScale ( violationValue * 100 ) ) ,
3775 getSynchronousOverlay ( stats . aggStats [ activityName ] . syncMove ) ] )
3876 }
3977 //add legend
0 commit comments