@@ -2,50 +2,45 @@ import { useMemo } from 'react';
22
33import type { BehaviorMapItem } from './BehaviorMap' ;
44
5- export const useMermaidCode = ( data : BehaviorMapItem ) : string => {
6- const generateMermaidCode = ( root : BehaviorMapItem ) : string => {
7- const lines : string [ ] = [ ] ;
8-
9- lines . push ( 'graph LR' ) ;
10-
11- lines . push ( `classDef baseNode fill:#fff,stroke:none,stroke-width:0px,rx:5,ry:5,font-size:14px` ) ;
12-
13- const traverse = ( node : BehaviorMapItem , parentId ?: string ) => {
14- const safeId = `node_${ node . id . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' ) } ` ;
15- let labelText = node . label . replace ( / " / g, "'" ) ;
16-
17- if ( ! parentId ) {
18- lines . push ( `style ${ safeId } font-size:16px` ) ;
19- labelText = `**${ labelText } **` ;
20- } else if ( node . targetType === 'mvp' ) {
21- const blueDot = `<span style="display:inline-block;width:8px;height:8px;background-color:rgb(22, 119, 255);border-radius:50%;margin-right:8px;vertical-align:middle;"></span>` ;
22- labelText = `${ blueDot } ${ labelText } ` ;
23- } else if ( node . targetType === 'extension' ) {
24- const grayDot = `<span style="display:inline-block;width:8px;height:8px;background-color:rgb(160, 160, 160);border-radius:50%;margin-right:8px;vertical-align:middle;"></span>` ;
25- labelText = `${ grayDot } ${ labelText } ` ;
26- }
27- lines . push ( `${ safeId } ["${ labelText } "]:::baseNode` ) ;
28-
29- if ( node . link ) {
30- lines . push ( `click ${ safeId } "#${ node . link } "` ) ;
31- }
32-
33- if ( parentId ) {
34- lines . push ( `${ parentId } --> ${ safeId } ` ) ;
35- }
36-
37- if ( node . children && node . children . length > 0 ) {
38- node . children . forEach ( ( child ) => traverse ( child , safeId ) ) ;
39- }
40- } ;
41-
42- traverse ( root ) ;
43- return lines . join ( '\n' ) ;
5+ const generateMermaidCode = ( root : BehaviorMapItem ) => {
6+ const lines : string [ ] = [ ] ;
7+
8+ lines . push ( 'graph LR' ) ;
9+
10+ lines . push ( `classDef baseNode fill:#fff,stroke:none,stroke-width:0px,rx:5,ry:5,font-size:14px` ) ;
11+
12+ const traverse = ( node : BehaviorMapItem , parentId ?: string ) => {
13+ const safeId = `node_${ node . id . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' ) } ` ;
14+ let labelText = node . label . replace ( / " / g, "'" ) ;
15+
16+ if ( ! parentId ) {
17+ lines . push ( `style ${ safeId } font-size:16px` ) ;
18+ labelText = `**${ labelText } **` ;
19+ } else if ( node . targetType === 'mvp' ) {
20+ const blueDot = `<span style="display:inline-block;width:8px;height:8px;background-color:rgb(22, 119, 255);border-radius:50%;margin-inline-end:8px;vertical-align:middle;"></span>` ;
21+ labelText = `${ blueDot } ${ labelText } ` ;
22+ } else if ( node . targetType === 'extension' ) {
23+ const grayDot = `<span style="display:inline-block;width:8px;height:8px;background-color:rgb(160, 160, 160);border-radius:50%;margin-inline-end:8px;vertical-align:middle;"></span>` ;
24+ labelText = `${ grayDot } ${ labelText } ` ;
25+ }
26+ lines . push ( `${ safeId } ["${ labelText } "]:::baseNode` ) ;
27+
28+ if ( node . link ) {
29+ lines . push ( `click ${ safeId } "#${ node . link } "` ) ;
30+ }
31+
32+ if ( parentId ) {
33+ lines . push ( `${ parentId } --> ${ safeId } ` ) ;
34+ }
35+
36+ if ( node . children && node . children . length > 0 ) {
37+ node . children . forEach ( ( child ) => traverse ( child , safeId ) ) ;
38+ }
4439 } ;
40+ traverse ( root ) ;
41+ return lines . join ( '\n' ) ;
42+ } ;
4543
46- const mermaidCode = useMemo ( ( ) => {
47- return generateMermaidCode ( data ) ;
48- } , [ data ] ) ;
49-
50- return mermaidCode ;
44+ export const useMermaidCode = ( data : BehaviorMapItem ) => {
45+ return useMemo ( ( ) => generateMermaidCode ( data ) , [ data ] ) ;
5146} ;
0 commit comments