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
ff909d7f
Commit
ff909d7f
authored
2 years ago
by
Matthias Konitzny
Browse files
Options
Downloads
Patches
Plain Diff
Improved typing
parent
ce8279a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/display/renderer.tsx
+0
-1
0 additions, 1 deletion
src/display/renderer.tsx
src/editor/graph.ts
+20
-14
20 additions, 14 deletions
src/editor/graph.ts
with
20 additions
and
15 deletions
src/display/renderer.tsx
+
0
−
1
View file @
ff909d7f
...
...
@@ -15,7 +15,6 @@ import { Node } from "../common/graph/node";
import
{
Link
}
from
"
../common/graph/link
"
;
export
interface
VisualGraphNode
extends
Node
{
color
:
string
;
__threeObj
:
THREE
.
Group
;
}
...
...
This diff is collapsed.
Click to expand it.
src/editor/graph.ts
+
20
−
14
View file @
ff909d7f
import
{
Link
}
from
"
../common/graph/link
"
;
import
{
NodeType
}
from
"
../common/graph/nodetype
"
;
import
{
Node
,
NodeData
}
from
"
../common/graph/node
"
;
import
{
Node
,
NodeData
,
SimNodeData
}
from
"
../common/graph/node
"
;
import
*
as
Common
from
"
../common/graph/graph
"
;
import
{
History
}
from
"
../common/history
"
;
import
{
GraphContent
,
SimGraphData
}
from
"
../common/graph/graph
"
;
...
...
@@ -60,12 +60,22 @@ export class DynamicGraph extends Common.Graph {
return
objectGroup
;
}
public
createNode
(
data
?:
NodeData
):
Node
{
public
createNode
(
data
?:
NodeData
|
SimNodeData
,
x
?:
number
,
y
?:
number
,
vx
?:
number
,
vy
?:
number
):
Node
{
if
(
data
==
undefined
)
{
data
=
{
id
:
0
,
name
:
"
Undefined
"
,
type
:
this
.
objectGroups
[
0
].
name
,
// TODO: Change to id
x
:
x
,
y
:
y
,
vx
:
vx
,
vy
:
vy
,
};
}
return
super
.
createNode
(
data
);
...
...
@@ -120,30 +130,26 @@ export class DynamicGraph extends Common.Graph {
}
/**
* Goes over all nodes and finds the closest node based on distance, that is not the given reference node.
* @param referenceNode Reference node to get closest other node to.
* Goes over all nodes and finds the closest node based on distance.
* @returns Closest node and distance. Undefined, if no closest node can be found.
*/
public
getClosestNeighbor
(
referenceNode
:
Node
):
{
public
getClosestNode
(
x
:
number
,
y
:
number
,
exclude
?:
Node
):
{
node
:
Node
;
distance
:
number
;
}
{
if
(
referenceNode
==
undefined
||
this
.
nodes
.
length
<
2
)
{
return
undefined
;
}
// Iterate over all nodes, keep the one with the shortest distance
let
closestDistance
=
Number
.
MAX_VALUE
;
let
closestNode
:
Node
=
undefined
;
this
.
nodes
.
forEach
((
node
)
=>
{
if
(
node
.
equals
(
referenceNo
de
))
{
if
(
node
.
equals
(
exclu
de
))
{
return
;
// Don't compare to itself
}
const
currentDistance
=
Math
.
hypot
(
referenceNode
.
x
-
node
.
x
,
referenceNode
.
y
-
node
.
y
);
const
currentDistance
=
Math
.
hypot
(
x
-
node
.
x
,
y
-
node
.
y
);
if
(
closestDistance
>
currentDistance
)
{
closestDistance
=
currentDistance
;
...
...
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