Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 43e403d

Browse files
committed
fix the activity and overlay style
1 parent 6a4e084 commit 43e403d

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

frontend/src/conformance.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import globals from './globals.js';
2+
import { mxgraph } from './mxgraph-initializer';
23
import { violationScale, colorLegend } from './colors.js'
34
import { getDeviationOverlay, getSynchronousOverlay } from './overlays.js'
45
import { getBpmnActivityElementbyName } from './utils.js';
6+
import { ShapeBpmnElementKind } from 'bpmn-visualization';
57

68
export function getAlignment(formData) {
79
console.log("Get alignments...");
@@ -20,20 +22,56 @@ export function getAlignment(formData) {
2022
function 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

frontend/src/overlays.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
export function getDeviationOverlay(label, color){
1+
export function getDeviationOverlay(label, violationValue, color){
2+
let fontColor = "none"
3+
if(violationValue > 0.5){
4+
fontColor = "white"
5+
}
6+
else{
7+
fontColor = "black"
8+
}
29
return {
310
position: 'top-right',
411
label: `${label}`,
512
style: {
6-
font: { color: 'black', size: 20 },
7-
fill: { color: color, opacity: 50},
8-
stroke: { color: 'transparent', width: 0}
13+
font: { color: fontColor, size: 20 },
14+
fill: { color: color, opacity: 50},
15+
stroke: { color: 'transparent', width: 0}
916
}
1017
}
1118
}

0 commit comments

Comments
 (0)