1
+ /* eslint-disable max-params */
1
2
/* eslint-disable max-lines */
2
3
/* eslint-disable no-use-before-define */
3
4
/* eslint-disable complexity */
@@ -29,8 +30,6 @@ import {
29
30
stateNote ,
30
31
} from "./utl.mjs" ;
31
32
32
- let gRenderedTransitions : Set < number > = new Set ( ) ;
33
-
34
33
function initial ( pState : IStateNormalized , pIndent : string ) : string {
35
34
const lActiveAttribute = pState . active ? " penwidth=3.0" : "" ;
36
35
@@ -94,6 +93,7 @@ function compositeRegular(
94
93
pIndent : string ,
95
94
pOptions : IRenderOptions ,
96
95
pModel : StateMachineModel ,
96
+ pRenderedTransitions : Set < number > ,
97
97
) : string {
98
98
// eslint-disable-next-line no-nested-ternary
99
99
const lPenWidth = pState . isParallelArea
@@ -121,7 +121,7 @@ ${pIndent} class="${pState.class}" label= <
121
121
${ lLabelTag }
122
122
${ pIndent } > style=${ lStyle } penwidth=${ lPenWidth } ${ pState . colorAttribute } ${ pState . fontColorAttribute }
123
123
${ pIndent } "${ pState . name } " [shape=point style=invis margin=0 width=0 height=0 fixedsize=true]
124
- ${ states ( pState ?. statemachine ?. states ?? [ ] , `${ pIndent } ` , pOptions , pModel ) }
124
+ ${ states ( pState ?. statemachine ?. states ?? [ ] , `${ pIndent } ` , pOptions , pModel , pRenderedTransitions ) }
125
125
${ pIndent } }${ pState . noteText } `;
126
126
}
127
127
@@ -130,9 +130,16 @@ function regular(
130
130
pIndent : string ,
131
131
pOptions : IRenderOptions ,
132
132
pModel : StateMachineModel ,
133
+ pRenderedTransitions : Set < number > ,
133
134
) : string {
134
135
if ( pState . statemachine ) {
135
- return compositeRegular ( pState , pIndent , pOptions , pModel ) ;
136
+ return compositeRegular (
137
+ pState ,
138
+ pIndent ,
139
+ pOptions ,
140
+ pModel ,
141
+ pRenderedTransitions ,
142
+ ) ;
136
143
}
137
144
return atomicRegular ( pState , pIndent ) ;
138
145
}
@@ -240,14 +247,15 @@ function state(
240
247
pIndent : string ,
241
248
pOptions : IRenderOptions ,
242
249
pModel : StateMachineModel ,
250
+ pRenderedTransitions : Set < number > ,
243
251
) : string {
244
252
const lState = normalizeState ( pState , pOptions , pIndent ) ;
245
253
const lCandidateTransitions = pModel . findTransitionsToSiblings (
246
254
pState . name ,
247
- gRenderedTransitions ,
255
+ pRenderedTransitions ,
248
256
) ;
249
257
lCandidateTransitions . forEach ( ( pTransition ) => {
250
- gRenderedTransitions . add ( pTransition . id ) ;
258
+ pRenderedTransitions . add ( pTransition . id ) ;
251
259
} ) ;
252
260
const lTransitions = transitions (
253
261
lCandidateTransitions ,
@@ -263,6 +271,7 @@ function state(
263
271
pIndent ,
264
272
pOptions ,
265
273
pModel ,
274
+ pRenderedTransitions ,
266
275
) +
267
276
lTransitions +
268
277
"\n"
@@ -274,9 +283,12 @@ function states(
274
283
pIndent : string ,
275
284
pOptions : IRenderOptions ,
276
285
pModel : StateMachineModel ,
286
+ pRenderedTransitions : Set < number > ,
277
287
) : string {
278
288
return pStates
279
- . map ( ( pState ) => state ( pState , pIndent , pOptions , pModel ) )
289
+ . map ( ( pState ) =>
290
+ state ( pState , pIndent , pOptions , pModel , pRenderedTransitions ) ,
291
+ )
280
292
. join ( "" ) ;
281
293
}
282
294
@@ -381,8 +393,14 @@ export default function renderDot(
381
393
const lNodeAttributes = buildNodeAttributes ( pOptions . dotNodeAttrs || [ ] ) ;
382
394
const lEdgeAttributes = buildEdgeAttributes ( pOptions . dotEdgeAttrs || [ ] ) ;
383
395
const lModel = new StateMachineModel ( pStateMachine ) ;
384
- gRenderedTransitions = new Set ( ) ;
385
- const lStates = states ( pStateMachine . states , pIndent , pOptions , lModel ) ;
396
+ const lRenderedTransitions : Set < number > = new Set ( ) ;
397
+ const lStates = states (
398
+ pStateMachine . states ,
399
+ pIndent ,
400
+ pOptions ,
401
+ lModel ,
402
+ lRenderedTransitions ,
403
+ ) ;
386
404
// ideally, we render transitions together with the states. However, in graphviz
387
405
// that only renders as we want to if we if the transition is _within_ the state.
388
406
// In this guy 'a' is rendered within cluster_b, though
@@ -412,14 +430,13 @@ export default function renderDot(
412
430
// 2. Render all other transitions separately (below)
413
431
const lRemainingTransitions = transitions (
414
432
lModel . flattenedTransitions . filter (
415
- ( pTransition ) => ! gRenderedTransitions . has ( pTransition . id ) ,
433
+ ( pTransition ) => ! lRenderedTransitions . has ( pTransition . id ) ,
416
434
) ,
417
435
pIndent ,
418
436
pOptions ,
419
437
lModel ,
420
438
) ;
421
439
422
- gRenderedTransitions = new Set ( ) ;
423
440
return `digraph "state transitions" {
424
441
${ lGraphAttributes }
425
442
node [${ lNodeAttributes } ]
0 commit comments