Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Knowledge Space WP Plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
alg
Knowledge Space WP Plugin
Commits
0ca9dd7d
Commit
0ca9dd7d
authored
2 years ago
by
Matthias Konitzny
Browse files
Options
Downloads
Patches
Plain Diff
Improved typing
parent
11bd8d04
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/display/renderer.tsx
+32
-39
32 additions, 39 deletions
src/display/renderer.tsx
with
32 additions
and
39 deletions
src/display/renderer.tsx
+
32
−
39
View file @
0ca9dd7d
...
...
@@ -10,23 +10,16 @@ import React from "react";
import
PropTypes
,
{
InferType
}
from
"
prop-types
"
;
import
SpriteText
from
"
three-spritetext
"
;
import
{
Object3D
,
Sprite
}
from
"
three
"
;
import
{
Graph
,
Coordinate
,
Link
,
Node
}
from
"
../common/graph/graph
"
;
export
interface
GraphNode
extends
Node
{
x
:
number
;
y
:
number
;
z
:
number
;
vx
:
number
;
vy
:
number
;
vz
:
number
;
fx
:
number
;
fy
:
number
;
fz
:
number
;
import
{
Graph
,
Coordinate
}
from
"
../common/graph/graph
"
;
import
{
Node
}
from
"
../common/graph/node
"
;
import
{
Link
}
from
"
../common/graph/link
"
;
export
interface
VisualGraphNode
extends
Node
{
color
:
string
;
__threeObj
:
THREE
.
Group
;
}
export
interface
GraphLink
extends
Link
{
export
interface
Visual
GraphLink
extends
Link
{
__lineObj
?:
Line2
;
}
...
...
@@ -43,9 +36,9 @@ export class GraphRenderer extends React.PureComponent<
props
:
InferType
<
typeof
GraphRenderer
.
propTypes
>
;
state
:
InferType
<
typeof
GraphRenderer
.
stateTypes
>
;
private
forceGraph
:
React
.
RefObject
<
any
>
;
// using typeof ForceGraph3d produces an error here...
private
highlightedNodes
:
Set
<
GraphNode
>
;
private
highlightedLinks
:
Set
<
GraphLink
>
;
private
hoverNode
:
GraphNode
;
private
highlightedNodes
:
Set
<
Visual
GraphNode
>
;
private
highlightedLinks
:
Set
<
Visual
GraphLink
>
;
private
hoverNode
:
Visual
GraphNode
;
private
node3dObjects
:
Map
<
number
,
THREE
.
Group
>
;
static
propTypes
=
{
...
...
@@ -91,7 +84,7 @@ export class GraphRenderer extends React.PureComponent<
this
.
forceGraph
.
current
.
scene
().
add
(
mesh
);
}
drawNode
(
node
:
GraphNode
):
Object3D
{
drawNode
(
node
:
Visual
GraphNode
):
Object3D
{
const
group
=
new
THREE
.
Group
();
const
text
=
new
SpriteText
(
node
.
name
);
...
...
@@ -167,7 +160,7 @@ export class GraphRenderer extends React.PureComponent<
return
line
;
}
onNodeHover
(
node
:
GraphNode
)
{
onNodeHover
(
node
:
Visual
GraphNode
)
{
// no state change
if
(
(
!
node
&&
!
this
.
highlightedNodes
.
size
)
||
...
...
@@ -175,16 +168,16 @@ export class GraphRenderer extends React.PureComponent<
)
return
;
const
highlightedNodes
=
new
Set
<
GraphNode
>
();
const
highlightedLinks
=
new
Set
<
GraphLink
>
();
const
highlightedNodes
=
new
Set
<
Visual
GraphNode
>
();
const
highlightedLinks
=
new
Set
<
Visual
GraphLink
>
();
if
(
node
)
{
highlightedNodes
.
add
(
node
);
node
.
neighbors
.
forEach
((
neighbor
)
=>
highlightedNodes
.
add
(
neighbor
as
GraphNode
)
highlightedNodes
.
add
(
neighbor
as
Visual
GraphNode
)
);
node
.
links
.
forEach
((
link
)
=>
highlightedLinks
.
add
(
link
as
GraphLink
)
highlightedLinks
.
add
(
link
as
Visual
GraphLink
)
);
}
...
...
@@ -192,22 +185,22 @@ export class GraphRenderer extends React.PureComponent<
this
.
updateHighlight
(
highlightedNodes
,
highlightedLinks
);
}
onLinkHover
(
link
:
GraphLink
)
{
const
highlightedNodes
=
new
Set
<
GraphNode
>
();
const
highlightedLinks
=
new
Set
<
GraphLink
>
();
onLinkHover
(
link
:
Visual
GraphLink
)
{
const
highlightedNodes
=
new
Set
<
Visual
GraphNode
>
();
const
highlightedLinks
=
new
Set
<
Visual
GraphLink
>
();
if
(
link
&&
link
.
__lineObj
)
{
highlightedLinks
.
add
(
link
);
highlightedNodes
.
add
(
link
.
source
as
GraphNode
);
highlightedNodes
.
add
(
link
.
target
as
GraphNode
);
highlightedNodes
.
add
(
link
.
source
as
Visual
GraphNode
);
highlightedNodes
.
add
(
link
.
target
as
Visual
GraphNode
);
}
this
.
updateHighlight
(
highlightedNodes
,
highlightedLinks
);
}
updateHighlight
(
highlightedNodes
:
Set
<
GraphNode
>
,
highlightedLinks
:
Set
<
GraphLink
>
highlightedNodes
:
Set
<
Visual
GraphNode
>
,
highlightedLinks
:
Set
<
Visual
GraphLink
>
)
{
// Update Links
this
.
highlightedLinks
.
forEach
(
...
...
@@ -243,7 +236,7 @@ export class GraphRenderer extends React.PureComponent<
}
}
displayNodeSelection
(
node
:
GraphNode
)
{
displayNodeSelection
(
node
:
Visual
GraphNode
)
{
// Set all nodes to a grayed out state
this
.
node3dObjects
.
forEach
((
nodeObj
)
=>
{
this
.
makeNodeInvisible
(
nodeObj
);
...
...
@@ -262,7 +255,7 @@ export class GraphRenderer extends React.PureComponent<
// Reset for current connections
for
(
const
l
of
node
.
links
)
{
const
lObj
=
l
as
GraphLink
;
const
lObj
=
l
as
Visual
GraphLink
;
lObj
.
__lineObj
.
material
.
opacity
=
1.0
;
}
...
...
@@ -287,7 +280,7 @@ export class GraphRenderer extends React.PureComponent<
circle
.
material
.
opacity
=
1.0
;
}
onNodeClick
(
node
:
GraphNode
)
{
onNodeClick
(
node
:
Visual
GraphNode
)
{
this
.
focusOnNode
(
node
);
if
(
MODE
===
"
default
"
&&
this
.
props
.
onNodeClicked
)
{
this
.
props
.
onNodeClicked
(
node
);
...
...
@@ -295,7 +288,7 @@ export class GraphRenderer extends React.PureComponent<
this
.
displayNodeSelection
(
node
);
}
onNodeDragEnd
(
node
:
GraphNode
,
translate
:
Coordinate
)
{
onNodeDragEnd
(
node
:
Visual
GraphNode
,
translate
:
Coordinate
)
{
// NodeDrag is handled like NodeClick if distance is very short
if
(
Math
.
hypot
(
translate
.
x
,
translate
.
y
,
translate
.
z
)
<
...
...
@@ -305,7 +298,7 @@ export class GraphRenderer extends React.PureComponent<
}
}
focusOnNode
(
node
:
GraphNode
)
{
focusOnNode
(
node
:
Visual
GraphNode
)
{
const
distance
=
400
;
// Aim at node from outside it
const
speed
=
0.5
;
// Camera travel speed through space
const
minTime
=
1000
;
// Minimum transition time
...
...
@@ -369,21 +362,21 @@ export class GraphRenderer extends React.PureComponent<
graphData
=
{
this
.
props
.
graph
}
rendererConfig
=
{
{
antialias
:
true
}
}
// nodeLabel={"hidden"}
nodeThreeObject
=
{
(
node
:
GraphNode
)
=>
this
.
drawNode
(
node
)
}
nodeThreeObject
=
{
(
node
:
Visual
GraphNode
)
=>
this
.
drawNode
(
node
)
}
linkThreeObject
=
{
(
link
:
Link
)
=>
this
.
drawLink
(
link
)
}
onNodeClick
=
{
(
node
:
GraphNode
)
=>
this
.
onNodeClick
(
node
)
}
onNodeClick
=
{
(
node
:
Visual
GraphNode
)
=>
this
.
onNodeClick
(
node
)
}
onBackgroundClick
=
{
()
=>
this
.
deselectNode
()
}
//d3AlphaDecay={0.1}
warmupTicks
=
{
150
}
cooldownTime
=
{
1000
}
// TODO: Do we want the simulation to unfreeze on node drag?
enableNodeDrag
=
{
false
}
onNodeHover
=
{
(
node
:
GraphNode
)
=>
this
.
onNodeHover
(
node
)
}
onLinkHover
=
{
(
link
:
GraphLink
)
=>
this
.
onLinkHover
(
link
)
}
onNodeHover
=
{
(
node
:
Visual
GraphNode
)
=>
this
.
onNodeHover
(
node
)
}
onLinkHover
=
{
(
link
:
Visual
GraphLink
)
=>
this
.
onLinkHover
(
link
)
}
linkPositionUpdate
=
{
(
line
:
Line2
,
coords
:
{
start
:
Coordinate
;
end
:
Coordinate
}
)
=>
this
.
updateLinkPosition
(
line
,
coords
.
start
,
coords
.
end
)
}
onNodeDragEnd
=
{
(
node
:
GraphNode
,
translate
:
Coordinate
)
=>
onNodeDragEnd
=
{
(
node
:
Visual
GraphNode
,
translate
:
Coordinate
)
=>
this
.
onNodeDragEnd
(
node
,
translate
)
}
/>
...
...
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