Skip to content

Commit 5059956

Browse files
committed
REA-462: Adapt react-yfiles-process-mining to HTML 3.0
1 parent 4044a86 commit 5059956

15 files changed

+168
-157
lines changed

docs/introduction/GettingStarted.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ You can learn how to work with the yFiles npm module in our [Developer’s Guide
3131

3232
Add the yFiles dependency:
3333
```
34-
npm install <yFiles package path>/lib-dev/yfiles-26.0.0+dev.tgz
34+
npm install <yFiles package path>/lib-dev/yfiles-30.0.0+dev.tgz
3535
```
3636

3737
<details>
@@ -43,7 +43,7 @@ You can learn how to work with the yFiles npm module in our [Developer’s Guide
4343
"dependencies": {
4444
"react": "^18.2.0",
4545
"react-dom": "^18.2.0",
46-
"yfiles": "./lib-dev/yfiles-26.0.0.tgz"
46+
"@yfiles/yfiles": "./lib-dev/yfiles-30.0.0.tgz"
4747
}
4848
```
4949
</details>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yworks/react-yfiles-process-mining",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"author": {
55
"name": "yFiles for HTML team @ yWorks GmbH",
66
"email": "[email protected]"
@@ -50,7 +50,7 @@
5050
"peerDependencies": {
5151
"react": "^18.2.0",
5252
"react-dom": "^18.2.0",
53-
"yfiles": "^26.0.0"
53+
"@yfiles/yfiles": ">=30"
5454
},
5555
"devDependencies": {
5656
"@types/react": "^18.2.15",

src/ProcessMining.tsx

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import {
2525
useReactNodeRendering,
2626
withGraphComponent
2727
} from '@yworks/react-yfiles-core'
28-
import { ClickEventArgs, GraphViewerInputMode, ICanvasObject, IEdge, INode } from 'yfiles'
28+
import {
29+
ClickEventArgs,
30+
GraphViewerInputMode,
31+
IEdge,
32+
INode,
33+
IRenderTreeElement
34+
} from '@yfiles/yfiles'
2935
import {
3036
ProcessMiningProvider,
3137
useProcessMiningContext,
@@ -274,14 +280,14 @@ export interface ProcessMiningProps<TEvent extends ActivityEvent, TNeedle> {
274280
* The optional position of the popup. The default is 'north'.
275281
*/
276282
popupPosition?:
277-
| 'east'
278-
| 'north'
279-
| 'north-east'
280-
| 'north-west'
281-
| 'south'
282-
| 'south-east'
283-
| 'south-west'
284-
| 'west'
283+
| 'bottom'
284+
| 'left'
285+
| 'right'
286+
| 'top'
287+
| 'top-right'
288+
| 'top-left'
289+
| 'bottom-right'
290+
| 'bottom-left'
285291
/**
286292
* An optional component used for rendering a custom popup.
287293
*/
@@ -414,7 +420,7 @@ const ProcessMiningCore = withGraphComponent(
414420
}, [])
415421

416422
useEffect(() => {
417-
checkStylesheetLoaded(graphComponent.div, 'react-yfiles-process-mining')
423+
checkStylesheetLoaded(graphComponent.htmlElement, 'react-yfiles-process-mining')
418424
}, [])
419425

420426
useEffect(() => {
@@ -440,7 +446,7 @@ const ProcessMiningCore = withGraphComponent(
440446
}, [transitionStyles])
441447

442448
useEffect(() => {
443-
let heatMapCanvasObject: ICanvasObject | null = null
449+
let heatMapCanvasObject: IRenderTreeElement | null = null
444450

445451
if (showHeatmap) {
446452
// this function provides the heat for a node or edge at a specific time
@@ -455,14 +461,14 @@ const ProcessMiningCore = withGraphComponent(
455461

456462
return () => {
457463
if (heatMapCanvasObject) {
458-
heatMapCanvasObject.remove()
464+
heatMapCanvasObject.renderTree.remove(heatMapCanvasObject)
459465
heatMapCanvasObject = null
460466
}
461467
}
462468
}, [graphComponent, showHeatmap, timestamp])
463469

464470
useEffect(() => {
465-
transitionEventVisualSupport.hideVisual()
471+
transitionEventVisualSupport.hideVisual(graphComponent)
466472
if (showTransitionEvents) {
467473
// add the item visual to be able to render dots for the traversing events
468474
transitionEventVisualSupport.showVisual(graphComponent)
@@ -492,16 +498,17 @@ const ProcessMiningCore = withGraphComponent(
492498
return () => {
493499
// clean up
494500
hoverItemChangedListener &&
495-
(
496-
graphComponent.inputMode as GraphViewerInputMode
497-
).itemHoverInputMode.removeHoveredItemChangedListener(hoverItemChangedListener)
501+
(graphComponent.inputMode as GraphViewerInputMode).itemHoverInputMode.removeEventListener(
502+
'hovered-item-changed',
503+
hoverItemChangedListener
504+
)
498505
}
499506
}, [onItemHover])
500507

501508
useEffect(() => {
502509
let transitionEventsClickedListener: (
503-
inputMode: GraphViewerInputMode,
504-
event: ClickEventArgs
510+
event: ClickEventArgs,
511+
inputMode: GraphViewerInputMode
505512
) => void
506513

507514
if (showTransitionEvents) {
@@ -515,10 +522,12 @@ const ProcessMiningCore = withGraphComponent(
515522
return () => {
516523
// clean up
517524
if (transitionEventsClickedListener) {
518-
;(graphComponent.inputMode as GraphViewerInputMode).removeCanvasClickedListener(
525+
;(graphComponent.inputMode as GraphViewerInputMode).removeEventListener(
526+
'canvas-clicked',
519527
transitionEventsClickedListener
520528
)
521-
;(graphComponent.inputMode as GraphViewerInputMode).removeItemClickedListener(
529+
;(graphComponent.inputMode as GraphViewerInputMode).removeEventListener(
530+
'item-clicked',
522531
transitionEventsClickedListener
523532
)
524533
}
@@ -533,9 +542,11 @@ const ProcessMiningCore = withGraphComponent(
533542
return () => {
534543
// clean up the listeners
535544
currentItemChangedListener &&
536-
graphComponent.removeCurrentItemChangedListener(currentItemChangedListener)
545+
graphComponent.removeEventListener('current-item-changed', currentItemChangedListener)
546+
selectedItemChangedListener &&
547+
graphComponent.selection.removeEventListener('item-added', selectedItemChangedListener)
537548
selectedItemChangedListener &&
538-
graphComponent.selection.removeItemSelectionChangedListener(selectedItemChangedListener)
549+
graphComponent.selection.removeEventListener('item-removed', selectedItemChangedListener)
539550
}
540551
}, [onItemFocus, onItemSelect])
541552

src/ProcessMiningModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GraphComponent } from 'yfiles'
1+
import { GraphComponent } from '@yfiles/yfiles'
22
import { ExportSettings, PrintSettings } from '@yworks/react-yfiles-core'
33
import { ProcessStep, Transition } from './core/process-graph-extraction.ts'
44
import { ActivityEvent, LayoutOptions } from './ProcessMining.tsx'

src/ProcessMiningProvider.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import {
1111
import { ProcessMiningModel, ProcessMiningModelInternal } from './ProcessMiningModel.ts'
1212
import {
1313
GraphComponent,
14-
HierarchicLayout,
15-
HierarchicLayoutData,
16-
HierarchicLayoutEdgeLayoutDescriptor,
17-
HierarchicLayoutEdgeRoutingStyle,
18-
HierarchicLayoutRoutingStyle,
19-
ICommand,
14+
HierarchicalLayout,
15+
HierarchicalLayoutData,
16+
HierarchicalLayoutEdgeDescriptor,
17+
HierarchicalLayoutRoutingStyle,
18+
RoutingStyleDescriptor,
19+
Command,
2020
IGraph,
2121
INode,
2222
MutableRectangle,
23-
NodeHalo
24-
} from 'yfiles'
23+
Insets
24+
} from '@yfiles/yfiles'
2525
import { getProcessStepData, ProcessStep, Transition } from './core/process-graph-extraction.ts'
2626
import { AnimationController } from './animation/AnimationController.ts'
2727
import { ActivityEvent, LayoutOptions } from './ProcessMining.tsx'
@@ -242,32 +242,32 @@ export function createProcessMiningModel<TEvent extends ActivityEvent>(
242242

243243
async applyLayout(layoutOptions = defaultLayoutOptions, morphLayout = false) {
244244
if (_showTransitionEvents && _eventLog) {
245-
_transitionEventVisualSupport.hideVisual()
245+
_transitionEventVisualSupport.hideVisual(graphComponent)
246246
_transitionEventVisualSupport.clearItems()
247247
}
248248

249-
const layout = new HierarchicLayout({
249+
const layout = new HierarchicalLayout({
250250
layoutOrientation: layoutOptions.direction,
251251
minimumLayerDistance: layoutOptions.minimumLayerDistance,
252-
nodeToNodeDistance: layoutOptions.nodeToNodeDistance,
252+
nodeDistance: layoutOptions.nodeToNodeDistance,
253253
nodeToEdgeDistance: layoutOptions.nodeToEdgeDistance,
254-
maximumDuration: layoutOptions.maximumDuration,
254+
stopDuration: layoutOptions.maximumDuration,
255255
automaticEdgeGrouping: layoutOptions.edgeGrouping,
256-
edgeLayoutDescriptor: new HierarchicLayoutEdgeLayoutDescriptor({
257-
routingStyle: new HierarchicLayoutRoutingStyle(
258-
HierarchicLayoutEdgeRoutingStyle.CURVED,
256+
defaultEdgeDescriptor: new HierarchicalLayoutEdgeDescriptor({
257+
routingStyleDescriptor: new RoutingStyleDescriptor(
258+
HierarchicalLayoutRoutingStyle.CURVED,
259259
false
260260
)
261261
})
262262
})
263-
const layoutData = new HierarchicLayoutData({
264-
nodeHalos: () => NodeHalo.create(5)
263+
const layoutData = new HierarchicalLayoutData({
264+
nodeMargins: new Insets(5)
265265
})
266-
await graphComponent.morphLayout({
266+
await graphComponent.applyLayoutAnimated({
267267
layout,
268-
morphDuration: morphLayout ? '1s' : '0s',
268+
animationDuration: morphLayout ? '1s' : '0s',
269269
layoutData,
270-
targetBoundsInsets: 50
270+
targetBoundsPadding: 50
271271
})
272272

273273
if (_showTransitionEvents && _eventLog) {
@@ -291,19 +291,19 @@ export function createProcessMiningModel<TEvent extends ActivityEvent>(
291291
zoomTo,
292292

293293
zoomIn() {
294-
ICommand.INCREASE_ZOOM.execute(null, graphComponent)
294+
graphComponent.executeCommand(Command.INCREASE_ZOOM, null)
295295
},
296296

297297
zoomOut() {
298-
ICommand.DECREASE_ZOOM.execute(null, graphComponent)
298+
graphComponent.executeCommand(Command.DECREASE_ZOOM, null)
299299
},
300300

301301
zoomToOriginal() {
302-
ICommand.ZOOM.execute(1.0, graphComponent)
302+
graphComponent.executeCommand(Command.ZOOM, 1.0)
303303
},
304304

305305
fitContent() {
306-
ICommand.FIT_GRAPH_BOUNDS.execute(null, graphComponent)
306+
graphComponent.executeCommand(Command.FIT_GRAPH_BOUNDS, null)
307307
},
308308

309309
async exportToSvg(exportSettings: ExportSettings) {

src/animation/AnimationController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Animator, GraphComponent } from 'yfiles'
1+
import { Animator, GraphComponent } from '@yfiles/yfiles'
22

33
/**
44
* This controller manages the animation of the heatmap and transition events.
@@ -15,7 +15,7 @@ export class AnimationController {
1515
constructor(public graphComponent: GraphComponent) {
1616
this.running = false
1717
this.animator = new Animator({
18-
canvas: graphComponent,
18+
canvasComponent: graphComponent,
1919
allowUserInteraction: true,
2020
autoInvalidation: true
2121
})

src/core/SingleSelectionHelper.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import {
44
GraphComponent,
55
GraphInputMode,
66
GraphItemTypes,
7-
ICommand,
7+
Command,
88
IModelItem,
9-
KeyboardInputModeBinding
10-
} from 'yfiles'
9+
KeyboardInputModeBinding,
10+
ExecuteCommandArgs,
11+
CanExecuteCommandArgs
12+
} from '@yfiles/yfiles'
1113

1214
// TODO move to core?
1315

14-
type Recognizer = (eventSource: any, evt: EventArgs) => boolean
16+
type Recognizer = (evt: EventArgs, eventSource: any) => boolean
1517

1618
let commandBindings: KeyboardInputModeBinding[] = []
1719

@@ -32,13 +34,13 @@ export function disableSingleSelection(graphComponent: GraphComponent) {
3234
}
3335

3436
// re-activate commands
35-
mode.availableCommands.add(ICommand.TOGGLE_ITEM_SELECTION)
36-
mode.availableCommands.add(ICommand.SELECT_ALL)
37+
mode.availableCommands.add(Command.TOGGLE_ITEM_SELECTION)
38+
mode.availableCommands.add(Command.SELECT_ALL)
3739

38-
mode.navigationInputMode.availableCommands.add(ICommand.EXTEND_SELECTION_LEFT)
39-
mode.navigationInputMode.availableCommands.add(ICommand.EXTEND_SELECTION_UP)
40-
mode.navigationInputMode.availableCommands.add(ICommand.EXTEND_SELECTION_DOWN)
41-
mode.navigationInputMode.availableCommands.add(ICommand.EXTEND_SELECTION_RIGHT)
40+
mode.navigationInputMode.availableCommands.add(Command.EXTEND_SELECTION_LEFT)
41+
mode.navigationInputMode.availableCommands.add(Command.EXTEND_SELECTION_UP)
42+
mode.navigationInputMode.availableCommands.add(Command.EXTEND_SELECTION_DOWN)
43+
mode.navigationInputMode.availableCommands.add(Command.EXTEND_SELECTION_RIGHT)
4244

4345
// remove the previously registered command bindings
4446
for (const binding of commandBindings) {
@@ -61,26 +63,35 @@ export function enableSingleSelection(graphComponent: GraphComponent) {
6163
mode.multiSelectionRecognizer = EventRecognizers.NEVER
6264

6365
// deactivate commands that can lead to multi selection
64-
mode.availableCommands.remove(ICommand.TOGGLE_ITEM_SELECTION)
65-
mode.availableCommands.remove(ICommand.SELECT_ALL)
66+
mode.availableCommands.remove(Command.TOGGLE_ITEM_SELECTION)
67+
mode.availableCommands.remove(Command.SELECT_ALL)
6668

67-
mode.navigationInputMode.availableCommands.remove(ICommand.EXTEND_SELECTION_LEFT)
68-
mode.navigationInputMode.availableCommands.remove(ICommand.EXTEND_SELECTION_UP)
69-
mode.navigationInputMode.availableCommands.remove(ICommand.EXTEND_SELECTION_DOWN)
70-
mode.navigationInputMode.availableCommands.remove(ICommand.EXTEND_SELECTION_RIGHT)
69+
mode.navigationInputMode.availableCommands.remove(Command.EXTEND_SELECTION_LEFT)
70+
mode.navigationInputMode.availableCommands.remove(Command.EXTEND_SELECTION_UP)
71+
mode.navigationInputMode.availableCommands.remove(Command.EXTEND_SELECTION_DOWN)
72+
mode.navigationInputMode.availableCommands.remove(Command.EXTEND_SELECTION_RIGHT)
7173

7274
// add dummy command bindings that do nothing in order to prevent default behavior
73-
commandBindings.push(mode.keyboardInputMode.addCommandBinding(ICommand.EXTEND_SELECTION_LEFT))
74-
commandBindings.push(mode.keyboardInputMode.addCommandBinding(ICommand.EXTEND_SELECTION_UP))
75-
commandBindings.push(mode.keyboardInputMode.addCommandBinding(ICommand.EXTEND_SELECTION_DOWN))
76-
commandBindings.push(mode.keyboardInputMode.addCommandBinding(ICommand.EXTEND_SELECTION_RIGHT))
75+
const dummyExecutedHandler = (_: ExecuteCommandArgs) => {}
76+
commandBindings.push(
77+
mode.keyboardInputMode.addCommandBinding(Command.EXTEND_SELECTION_LEFT, dummyExecutedHandler)
78+
)
79+
commandBindings.push(
80+
mode.keyboardInputMode.addCommandBinding(Command.EXTEND_SELECTION_UP, dummyExecutedHandler)
81+
)
82+
commandBindings.push(
83+
mode.keyboardInputMode.addCommandBinding(Command.EXTEND_SELECTION_DOWN, dummyExecutedHandler)
84+
)
85+
commandBindings.push(
86+
mode.keyboardInputMode.addCommandBinding(Command.EXTEND_SELECTION_RIGHT, dummyExecutedHandler)
87+
)
7788

7889
// add custom binding for toggle item selection
7990
commandBindings.push(
8091
mode.keyboardInputMode.addCommandBinding(
81-
ICommand.TOGGLE_ITEM_SELECTION,
82-
(command, parameter) => toggleItemSelectionExecuted(graphComponent, parameter),
83-
(command, parameter) => toggleItemSelectionCanExecute(graphComponent, parameter)
92+
Command.TOGGLE_ITEM_SELECTION,
93+
(evt: ExecuteCommandArgs) => toggleItemSelectionExecuted(graphComponent, evt.parameter),
94+
(evt: CanExecuteCommandArgs) => toggleItemSelectionCanExecute(graphComponent, evt.parameter)
8495
)
8596
)
8697
// Also clear the selection - even though the setup works when more than one item is selected, it looks a bit
@@ -105,7 +116,7 @@ function toggleItemSelectionCanExecute(graphComponent: GraphComponent, parameter
105116
* @param graphComponent The given graphComponent
106117
* @param parameter The given parameter
107118
*/
108-
function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter: any): boolean {
119+
function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter: any): void {
109120
// get the item
110121
const modelItem = parameter instanceof IModelItem ? parameter : graphComponent.currentItem
111122
const inputMode = graphComponent.inputMode as GraphInputMode
@@ -117,10 +128,10 @@ function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter:
117128
!GraphItemTypes.itemIsOfTypes(inputMode.selectableItems, modelItem) ||
118129
!inputMode.graphSelection
119130
) {
120-
return false
131+
return
121132
}
122133

123-
const isSelected = inputMode.graphSelection.isSelected(modelItem)
134+
const isSelected = inputMode.graphSelection.includes(modelItem)
124135
if (isSelected) {
125136
// the item is selected and needs to be unselected - just clear the selection
126137
inputMode.graphSelection.clear()
@@ -129,5 +140,4 @@ function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter:
129140
inputMode.graphSelection.clear()
130141
inputMode.setSelected(modelItem, true)
131142
}
132-
return true
133143
}

0 commit comments

Comments
 (0)