-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] [refactor] graph web worker 적용 (#133)
- Loading branch information
Showing
7 changed files
with
142 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export { default as useGraph } from './graph/useGraph'; | ||
export { default as useGraphData } from './graph/useGraphData'; | ||
export { default as useGraphEmphasize } from './graph/useGraphEmphasize'; | ||
export { default as useGraphZoom } from './graph/useGraphZoom'; | ||
export { default as useLinkUpdate } from './graph/useLinkUpdate'; | ||
export { default as useNodeUpdate } from './graph/useNodeUpdate'; | ||
export { default as useDebouncedValue } from './useDebouncedValue'; | ||
export { default as useInterval } from './useInterval'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
frontend/src/pages/PaperDetail/workers/forceSimulation.worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as d3 from 'd3'; | ||
import { Link, Node } from '../components/ReferenceGraph'; | ||
|
||
interface DataProps { | ||
data: { | ||
nodes: Node[]; | ||
links: Link[]; | ||
centerX: number; | ||
centerY: number; | ||
}; | ||
} | ||
|
||
self.onmessage = ({ data }: DataProps) => { | ||
const { nodes, links, centerX, centerY } = data; | ||
const simulation = d3 | ||
.forceSimulation(nodes) | ||
.force('charge', d3.forceManyBody().strength(-200).distanceMax(200)) | ||
.force('center', d3.forceCenter(centerX, centerY)) | ||
.force( | ||
'link', | ||
d3.forceLink(links).id((d) => (d as Node).key), | ||
) | ||
.on('tick', () => { | ||
self.postMessage({ type: 'tick', newNodes: nodes, newLinks: links }); | ||
if (simulation.alpha() < simulation.alphaMin()) { | ||
simulation.stop(); | ||
self.postMessage({ type: 'stop' }); | ||
} | ||
}); | ||
}; |