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
62306bd5
Commit
62306bd5
authored
2 years ago
by
Matthias Konitzny
Browse files
Options
Downloads
Patches
Plain Diff
Added simple graph data structure
parent
83b91b40
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Master into new editor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/display/graph.ts
+112
-0
112 additions, 0 deletions
src/display/graph.ts
with
112 additions
and
0 deletions
src/display/graph.ts
0 → 100644
+
112
−
0
View file @
62306bd5
import
{
LineMaterial
}
from
"
three-fatline
"
;
export
interface
GraphNode
extends
NodeData
{
x
:
number
;
y
:
number
;
z
:
number
;
vx
:
number
;
vy
:
number
;
vz
:
number
;
fx
:
number
;
fy
:
number
;
fz
:
number
;
color
:
string
;
}
export
interface
GraphLink
extends
LinkData
{
material
?:
LineMaterial
;
}
export
interface
LinkData
{
source
:
NodeData
;
target
:
NodeData
;
type
?:
string
;
}
export
interface
NodeData
{
id
:
string
;
name
:
string
;
description
?:
string
;
type
?:
string
;
video
?:
string
;
neighbors
:
NodeData
[];
links
:
LinkData
[];
}
export
interface
Coordinate
{
x
:
number
;
y
:
number
;
z
:
number
;
}
export
class
Graph
{
public
nodes
:
NodeData
[];
public
links
:
LinkData
[];
private
idToNode
:
Map
<
string
,
NodeData
>
;
constructor
(
nodes
:
NodeData
[],
links
:
LinkData
[])
{
this
.
nodes
=
nodes
;
this
.
links
=
links
;
this
.
idToNode
=
new
Map
<
string
,
NodeData
>
();
nodes
.
forEach
((
node
)
=>
{
this
.
idToNode
.
set
(
node
.
id
,
node
);
});
this
.
updateNodeData
();
}
resetNodeData
()
{
for
(
const
node
of
this
.
nodes
)
{
node
.
neighbors
=
[];
node
.
links
=
[];
}
}
/**
* Updates the graph data structure to contain additional values.
* Creates a 'neighbors' and 'links' array for each node object.
*/
updateNodeData
()
{
this
.
resetNodeData
();
this
.
links
.
forEach
((
link
)
=>
{
const
a
=
link
.
source
;
const
b
=
link
.
target
;
a
.
neighbors
.
push
(
b
);
b
.
neighbors
.
push
(
a
);
a
.
links
.
push
(
link
);
b
.
links
.
push
(
link
);
});
}
node
(
id
:
string
):
NodeData
{
return
this
.
idToNode
.
get
(
id
);
}
/**
* Returns an array containing the different edge types of the graph.
* @returns {*[]}
*/
getLinkClasses
():
string
[]
{
const
linkClasses
:
string
[]
=
[];
this
.
links
.
forEach
((
link
)
=>
linkClasses
.
push
(
link
.
type
));
return
[...
new
Set
(
linkClasses
)].
map
((
c
)
=>
String
(
c
));
}
getNodeClasses
():
string
[]
{
const
nodeClasses
:
string
[]
=
[];
this
.
nodes
.
forEach
((
node
)
=>
nodeClasses
.
push
(
node
.
type
));
return
[...
new
Set
(
nodeClasses
)].
map
((
c
)
=>
String
(
c
));
}
view
(
nodeTypes
:
Map
<
string
,
boolean
>
,
linkTypes
:
Map
<
string
,
boolean
>
):
Graph
{
return
new
Graph
(
this
.
nodes
.
filter
((
l
)
=>
nodeTypes
.
get
(
l
.
type
)),
this
.
links
.
filter
((
l
)
=>
linkTypes
.
get
(
l
.
type
))
);
}
}
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