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

Commit b9a9d72

Browse files
authored
fix: keep the tasks rounded when applying the data (#24)
A call to `mxGraph.refresh` was missing. Also limit the number of mxGraph model transactions that are done when applying custom styles.
1 parent f26fdc2 commit b9a9d72

File tree

2 files changed

+68
-92
lines changed

2 files changed

+68
-92
lines changed

frontend/src/conformance.js

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
9892
function 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

frontend/src/discovery.js

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,55 +47,38 @@ function visualizeFrequency(data) {
4747
const myFrequencyScale = frequencyScale(0, max)
4848

4949
//change activity style through mxGraph
50-
/**
51-
* A high level API will be provided: see https://github.com/process-analytics/bpmn-visualization-R/issues/13
52-
*/
53-
let mxGraph = globals.bpmnVisualization.graph
54-
let activityCurrentStyle = null
55-
let activityCell = null
50+
let graph = globals.bpmnVisualization.graph
5651

57-
//iterate over the activites and set their color by calling the frequency color scale function
58-
for (const [activityName, freqValue] of Object.entries(data)) {
59-
const activityElement = getBpmnActivityElementbyName(activityName)
60-
if(activityElement){
61-
activityCell = mxGraph.getModel().getCell(activityElement.bpmnSemantic.id)
62-
//activityCurrentStyle = mxGraph.getCurrentCellStyle(activityCell)
63-
activityCurrentStyle = mxGraph.getModel().getStyle(activityCell)
64-
65-
mxGraph.getModel().beginUpdate()
66-
try {
67-
let style = mxgraph.mxUtils.setStyle(activityCurrentStyle, 'fillColor', myFrequencyScale(freqValue))
68-
mxGraph.getModel().setStyle(activityCell, style);
69-
activityCurrentStyle = mxGraph.getModel().getStyle(activityCell)
70-
//different ways of setting the style
71-
//mxGraph.setCellStyles("fillColor", myFrequencyScale(freqValue), [activityCell]);
72-
//or
73-
//mxGraph.setCellStyles(mxgraph.mxConstants.STYLE_FILLCOLOR, 'red', [activityCell]);
74-
75-
//set label to white when the activity fillColor is above the scale average
76-
if (freqValue > avg){
77-
style = mxgraph.mxUtils.setStyle(activityCurrentStyle, 'fontColor', 'white')
78-
mxGraph.getModel().setStyle(activityCell, style);
79-
//different way of setting the style
80-
//mxGraph.setCellStyles("fontColor", "white", [activityCell]);
52+
try {
53+
//iterate over the activities and set their color by calling the frequency color scale function
54+
for (const [activityName, freqValue] of Object.entries(data)) {
55+
const activityElement = getBpmnActivityElementbyName(activityName)
56+
if (activityElement) {
57+
const activityCell = graph.getModel().getCell(activityElement.bpmnSemantic.id)
58+
let style = graph.getModel().getStyle(activityCell);
59+
style = mxgraph.mxUtils.setStyle(style, mxgraph.mxConstants.STYLE_FILLCOLOR, myFrequencyScale(freqValue))
60+
if (freqValue > avg) {
61+
style = mxgraph.mxUtils.setStyle(style, mxgraph.mxConstants.STYLE_FONTCOLOR, 'white')
8162
}
82-
} finally {
83-
mxGraph.getModel().endUpdate();
84-
}
63+
graph.getModel().setStyle(activityCell, style);
8564

86-
//add frequency overlay
87-
globals.bpmnVisualization.bpmnElementsRegistry.addOverlays(
88-
activityElement.bpmnSemantic.id,
89-
getFrequencyOverlay(freqValue, max,
90-
myFrequencyScale(freqValue)))
91-
}
65+
//add frequency overlay
66+
globals.bpmnVisualization.bpmnElementsRegistry.addOverlays(
67+
activityElement.bpmnSemantic.id,
68+
getFrequencyOverlay(freqValue, max, myFrequencyScale(freqValue)))
69+
}
70+
}
71+
// Allow to save the style in a new state, in particular keep the rounded activity
72+
graph.refresh();
73+
} finally {
74+
graph.getModel().endUpdate();
9275
}
9376

9477
//add legend
9578
colorLegend({
9679
colorScale: myFrequencyScale,
9780
title: "Frequency of execution"
98-
})
99-
81+
})
82+
10083
overlayLegend({rightOverlayLegend : "# executions"})
101-
}
84+
}

0 commit comments

Comments
 (0)