Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bielefeld-CeBiTec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
2024 Competition
Bielefeld-CeBiTec
Commits
8ee05a9a
Commit
8ee05a9a
authored
8 months ago
by
Liliana Sanfilippo
Browse files
Options
Downloads
Patches
Plain Diff
markup mindmap
parent
1ac893cd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#397633
failed
8 months ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/mindmap/mindmap-hooks.tsx
+27
-17
27 additions, 17 deletions
src/components/mindmap/mindmap-hooks.tsx
src/components/mindmap/mindmap.ts
+4
-2
4 additions, 2 deletions
src/components/mindmap/mindmap.ts
with
31 additions
and
19 deletions
src/components/mindmap/mindmap-hooks.tsx
+
27
−
17
View file @
8ee05a9a
import
React
,
{
useState
,
useRef
,
useEffect
}
from
'
react
'
;
import
{
Markmap
}
from
'
markmap-view
'
;
import
{
transformer
}
from
'
./mindmap
'
;
import
'
markmap-toolbar/dist/style.css
'
;
const
initValue
=
`#
markmap
- beautiful
-
useful
-
easy
-
interactive
const
initValue
=
`#
Stakeholders
- Patients
- hi
-
Industry
-
Academia
-
Medical Professionals
`
;
export
default
function
MarkmapHooks
()
{
const
[
value
,
setValue
]
=
useState
(
initValue
);
const
[
value
]
=
useState
(
initValue
);
// Ref for SVG element
const
refSvg
=
useRef
<
SVGSVGElement
>
(
);
const
refSvg
=
useRef
<
SVGSVGElement
>
(
null
);
// Initialize with null
// Ref for markmap object
const
refMm
=
useRef
<
Markmap
>
();
const
refMm
=
useRef
<
Markmap
|
null
>
(
null
);
// Initialize with null
useEffect
(()
=>
{
// Create markmap and save to refMm
if
(
refMm
.
current
)
return
;
if
(
refMm
.
current
||
!
refSvg
.
current
)
return
;
// Add null check
const
mm
=
Markmap
.
create
(
refSvg
.
current
);
refMm
.
current
=
mm
;
// Add double-click event listener to prevent zoom
const
svgElement
=
refSvg
.
current
;
if
(
svgElement
)
{
const
handleDoubleClick
=
(
event
:
MouseEvent
)
=>
{
event
.
preventDefault
();
};
svgElement
.
addEventListener
(
'
dblclick
'
,
handleDoubleClick
);
// Cleanup event listener on unmount
return
()
=>
{
svgElement
.
removeEventListener
(
'
dblclick
'
,
handleDoubleClick
);
};
}
},
[
refSvg
.
current
]);
useEffect
(()
=>
{
...
...
@@ -33,15 +46,12 @@ export default function MarkmapHooks() {
if
(
!
mm
)
return
;
const
{
root
}
=
transformer
.
transform
(
value
);
mm
.
setData
(
root
);
mm
.
fit
();
mm
.
fit
();
},
[
refMm
.
current
,
value
]);
return
(
<
React
.
Fragment
>
<
div
className
=
"flex-1"
>
</
div
>
<
div
className
=
"flex-1"
></
div
>
<
svg
className
=
"flex-1"
ref
=
{
refSvg
}
/>
</
React
.
Fragment
>
);
...
...
This diff is collapsed.
Click to expand it.
src/components/mindmap/mindmap.ts
+
4
−
2
View file @
8ee05a9a
...
...
@@ -3,5 +3,7 @@ import { Transformer } from 'markmap-lib';
export
const
transformer
=
new
Transformer
();
const
{
scripts
,
styles
}
=
transformer
.
getAssets
();
loadCSS
(
styles
);
loadJS
(
scripts
);
// Provide default empty array if styles or scripts are undefined
loadCSS
(
styles
??
[]);
loadJS
(
scripts
??
[]);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment