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
b167d87f
Commit
b167d87f
authored
2 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Added basic getters
parent
35b7df82
No related branches found
No related tags found
1 merge request
!2
Implemented editor in the react framework
Pipeline
#56379
failed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/editor/js/structures/graph/graph.ts
+45
-19
45 additions, 19 deletions
src/editor/js/structures/graph/graph.ts
with
45 additions
and
19 deletions
src/editor/js/structures/graph/graph.ts
+
45
−
19
View file @
b167d87f
import
ManagedData
from
"
../manageddata
"
;
import
{
Link
}
from
"
./link
"
;
import
{
NodeType
}
from
"
./nodetype
"
;
import
{
Node
}
from
"
./node
"
;
import
{
GLOBAL_PARAMS
}
from
"
../helper/serializableitem
"
;
import
{
Link
}
from
"
./link
"
;
import
{
NodeType
}
from
"
./nodetype
"
;
import
{
Node
}
from
"
./node
"
;
import
{
GLOBAL_PARAMS
}
from
"
../helper/serializableitem
"
;
import
{
GraphElement
}
from
"
./graphelement
"
;
const
GRAPH_PARAMS
=
[...
GLOBAL_PARAMS
];
const
GRAPH_DATA_PARAMS
=
[
"
nodes
"
,
"
links
"
,
"
types
"
];
type
GraphData
=
{
nodes
:
Node
[]
,
links
:
Link
[]
,
types
:
NodeType
[]
};
type
GraphData
=
{
nodes
:
Node
[]
;
links
:
Link
[]
;
types
:
NodeType
[]
};
export
class
Graph
extends
ManagedData
{
public
data
:
GraphData
;
private
nextNodeId
:
number
=
0
;
private
nextLinkId
:
number
=
0
;
private
nextTypeId
:
number
=
0
;
private
nextNodeId
=
0
;
private
nextLinkId
=
0
;
private
nextTypeId
=
0
;
// Callbacks
public
onChangeCallbacks
:
{
(
data
:
any
):
void
;
}
[];
public
onChangeCallbacks
:
{
(
data
:
any
):
void
}[];
constructor
(
data
:
GraphData
)
{
super
(
data
);
...
...
@@ -27,6 +27,30 @@ export class Graph extends ManagedData {
this
.
prepareIds
(
data
);
}
/**
* Intuitive getter for links.
* @returns All links associated with the graph.
*/
public
get
links
():
Link
[]
{
return
this
.
data
.
links
;
}
/**
* Intuitive getter for nodes.
* @returns All nodes associated with the graph.number
*/
public
get
nodes
():
Node
[]
{
return
this
.
data
.
nodes
;
}
/**
* Intuitive getter for node types.
* @returns All node types associated with the graph.
*/
public
get
types
():
NodeType
[]
{
return
this
.
data
.
types
;
}
/**
* Determines the highest, used ids for GraphElements in data for later use.
* @param data Data to analyse.
...
...
@@ -49,7 +73,7 @@ export class Graph extends ManagedData {
* @returns Highest id in list.
*/
private
getHighestId
(
elements
:
GraphElement
[]):
number
{
let
highest
:
number
=
0
;
let
highest
=
0
;
elements
.
forEach
((
element
)
=>
{
if
(
highest
<
element
.
id
)
{
highest
=
element
.
id
;
...
...
@@ -82,7 +106,7 @@ export class Graph extends ManagedData {
protected
storableData
(
data
:
GraphData
):
any
{
let
clean
:
GraphData
;
clean
.
links
=
data
.
links
.
map
((
link
)
=>
link
.
getCleanInstance
());
clean
.
nodes
=
data
.
nodes
.
map
((
node
)
=>
node
.
getCleanInstance
());
clean
.
types
=
data
.
types
.
map
((
type
)
=>
type
.
getCleanInstance
());
...
...
@@ -99,11 +123,11 @@ export class Graph extends ManagedData {
* @param data GraphData object to serialize.
* @returns Serialized data.
*/
private
serializeData
(
data
:
GraphData
)
:
any
{
private
serializeData
(
data
:
GraphData
):
any
{
return
{
...
this
.
serializeProperties
(
GRAPH_PARAMS
),
...
this
.
serializeProperties
(
GRAPH_DATA_PARAMS
,
data
),
}
}
;
}
/**
...
...
@@ -113,7 +137,7 @@ export class Graph extends ManagedData {
*/
public
addNode
(
node
:
Node
)
{
if
(
this
.
data
.
nodes
.
includes
(
node
))
{
return
true
;
// Already exists in graph.
return
true
;
// Already exists in graph.
}
// Update id
...
...
@@ -136,7 +160,7 @@ export class Graph extends ManagedData {
*/
public
deleteNode
(
node
:
Node
):
boolean
{
if
(
!
this
.
data
.
nodes
.
includes
(
node
))
{
return
true
;
// Doesn't even exist in graph to begin with.
return
true
;
// Doesn't even exist in graph to begin with.
}
this
.
data
.
nodes
.
filter
((
n
:
Node
)
=>
n
!==
node
);
...
...
@@ -155,7 +179,9 @@ export class Graph extends ManagedData {
this
.
triggerOnChange
();
// TODO: Use toString implementation of node
this
.
storeCurrentData
(
"
Deleted node [
"
+
node
+
"
] and all connected links
"
);
this
.
storeCurrentData
(
"
Deleted node [
"
+
node
+
"
] and all connected links
"
);
return
true
;
}
...
...
@@ -167,7 +193,7 @@ export class Graph extends ManagedData {
*/
public
addLink
(
link
:
Link
):
boolean
{
if
(
this
.
data
.
links
.
includes
(
link
))
{
return
true
;
// Already exists in graph.
return
true
;
// Already exists in graph.
}
// Updateid
...
...
@@ -190,7 +216,7 @@ export class Graph extends ManagedData {
*/
public
deleteLink
(
link
:
Link
):
boolean
{
if
(
!
this
.
data
.
links
.
includes
(
link
))
{
return
true
;
// Doesn't even exist in graph to begin with.
return
true
;
// Doesn't even exist in graph to begin with.
}
this
.
data
.
links
.
filter
((
l
:
Link
)
=>
l
!==
link
);
...
...
@@ -201,4 +227,4 @@ export class Graph extends ManagedData {
return
true
;
}
}
\ No newline at end of file
}
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