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
5eae1cf2
Commit
5eae1cf2
authored
2 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Basic add node on background click
parent
98a6689d
No related branches found
No related tags found
1 merge request
!2
Implemented editor in the react framework
Pipeline
#56704
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/editor/js/components/editor.tsx
+39
-8
39 additions, 8 deletions
src/editor/js/components/editor.tsx
with
39 additions
and
8 deletions
src/editor/js/components/editor.tsx
+
39
−
8
View file @
5eae1cf2
...
...
@@ -17,10 +17,15 @@ type stateTypes = {
selectedNode
:
Node
;
keys
:
{
[
name
:
string
]:
boolean
};
};
type
clickPosition
=
{
graph
:
{
x
:
number
;
y
:
number
};
window
:
{
x
:
number
;
y
:
number
};
};
export
class
Editor
extends
React
.
PureComponent
<
propTypes
,
stateTypes
>
{
private
defaultWarmupTicks
=
100
;
private
warmupTicks
=
100
;
private
renderer
:
any
;
constructor
(
props
:
propTypes
)
{
super
(
props
);
...
...
@@ -35,6 +40,10 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
this
.
isHighlighted
=
this
.
isHighlighted
.
bind
(
this
);
this
.
handleNodeCanvasObject
=
this
.
handleNodeCanvasObject
.
bind
(
this
);
this
.
handleLinkCanvasObject
=
this
.
handleLinkCanvasObject
.
bind
(
this
);
this
.
handleBackgroundClick
=
this
.
handleBackgroundClick
.
bind
(
this
);
this
.
extractPositions
=
this
.
extractPositions
.
bind
(
this
);
this
.
renderer
=
React
.
createRef
();
// Set as new state
this
.
state
=
{
...
...
@@ -133,6 +142,24 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
});
}
/**
* Handler for background click event on force graph. Adds new node by default.
* @param event Click event.
*/
private
handleBackgroundClick
(
event
:
any
,
position
:
clickPosition
)
{
const
newNode
=
new
Node
();
newNode
.
label
=
"
Unnamed
"
;
(
newNode
as
any
).
fx
=
position
.
graph
.
x
;
(
newNode
as
any
).
fy
=
position
.
graph
.
y
;
(
newNode
as
any
).
x
=
position
.
graph
.
x
;
(
newNode
as
any
).
y
=
position
.
graph
.
y
;
(
newNode
as
any
).
vx
=
0
;
(
newNode
as
any
).
vy
=
0
;
newNode
.
add
(
this
.
state
.
graph
);
}
/**
* Propagates the changed state of the graph.
*/
...
...
@@ -174,15 +201,12 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
* @param event The corresponding click event.
* @returns Coordinates in graph and coordinates in browser window.
*/
private
extractPositions
(
event
:
any
):
{
// graph: { x: number; y: number };
window
:
{
x
:
number
;
y
:
number
};
}
{
private
extractPositions
(
event
:
any
):
clickPosition
{
return
{
//
graph: this.
state.
renderer.screen2GraphCoords(
//
event.layerX,
//
event.layerY
//
),
graph
:
this
.
renderer
.
current
.
screen2GraphCoords
(
event
.
layerX
,
event
.
layerY
),
window
:
{
x
:
event
.
clientX
,
y
:
event
.
clientY
},
};
}
...
...
@@ -318,6 +342,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
</
div
>
{
this
.
state
.
graph
?
(
<
ReactForceGraph2d
ref
=
{
this
.
renderer
}
graphData
=
{
this
.
state
.
graph
.
data
}
onNodeClick
=
{
this
.
handleNodeClick
}
autoPauseRedraw
=
{
false
}
...
...
@@ -328,6 +353,12 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
nodeCanvasObjectMode
=
{
"
after
"
}
linkCanvasObject
=
{
this
.
handleLinkCanvasObject
}
linkCanvasObjectMode
=
{
"
replace
"
}
onBackgroundClick
=
{
(
event
)
=>
this
.
handleBackgroundClick
(
event
,
this
.
extractPositions
(
event
)
)
}
/>
)
:
undefined
}
</
div
>
...
...
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