-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.tsx
executable file
路99 lines (93 loc) 路 3.35 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { useEffect, useRef } from 'react'
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
import Layout from '@theme/Layout'
import styles from './index.module.css'
import BrowserOnly from '@docusaurus/BrowserOnly'
import { backlinks } from '@site/src/data/backlinks'
import { UnrealBloomPass } from '@site/src/components/UnrealBloomPass'
import Head from '@docusaurus/Head'
import { useScreenSize } from '@site/src/util/useScreenSize'
import { processBacklinksToGraph } from '@site/src/util/graph'
export const GraphView3d = (props: { width: number; height: number }) => {
if (typeof window === 'undefined') {
return null
}
const gData = processBacklinksToGraph(backlinks, false)
return (
<div className={styles.graphView}>
<BrowserOnly>
{() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ForceGraph3D } = require('react-force-graph')
const FocusGraph = () => {
const fgRef = useRef<unknown>()
useEffect(() => {
const bloomPass = new UnrealBloomPass()
bloomPass.strength = 0.8
bloomPass.radius = 0.8
bloomPass.threshold = 0.25
fgRef.current.postProcessingComposer().addPass(bloomPass)
}, [])
return (
<ForceGraph3D
rendererConfig={{
alpha: true,
antialias: true,
}}
width={props.width}
height={props.height}
ref={fgRef}
graphData={gData}
nodeLabel={`nodeLabel`}
nodeAutoColorBy="group"
nodeVal={(node) => {
return Math.sqrt(node.nodeRelSize)
}}
linkDirectionalParticles={2}
linkDirectionalParticleWidth={2}
linkDirectionalParticleSpeed={0.01}
nodeColor={(node) => {
if (node.id?.length === 10) {
return '#888'
}
return `#${node.id}`
}}
linkColor={() => '#4976ca'}
linkOpacity={0.5}
linkWidth={1}
showNavInfo={false}
onNodeClick={(node) => {
window.location.href = '/r/' + node.id
}}
/>
)
}
return <FocusGraph />
}}
</BrowserOnly>
</div>
)
}
export default function Graph(): JSX.Element {
const [width, height] = useScreenSize()
const { siteConfig } = useDocusaurusContext()
return (
<Layout title="Hippocampal Neuron Graph" description={siteConfig.tagline}>
<Head>
<title>{'Hippocampal Neuron Graph'}</title>
<meta name="description" content={siteConfig.tagline} />
<meta property="og:title" content={'Hippocampal Neuron Graph'} />
<meta property="og:description" content={siteConfig.tagline} />
<meta
property="og:image"
content={`https://og.cho.sh/api/og?title=${encodeURIComponent(
'Hippocampal Neuron Graph'
)}&subheading=${encodeURIComponent(siteConfig.tagline)}`}
/>
</Head>
<main className={styles.mainContainer}>
<GraphView3d width={width} height={height} />
</main>
</Layout>
)
}