Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
cbea6938
Commit
cbea6938
authored
5 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Nodes are now in correct places for desktop.
parent
402e46b0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
App/RobobinApp/Views/CentreGraph.xaml.cs
+42
-6
42 additions, 6 deletions
App/RobobinApp/Views/CentreGraph.xaml.cs
with
42 additions
and
6 deletions
App/RobobinApp/Views/CentreGraph.xaml.cs
+
42
−
6
View file @
cbea6938
...
@@ -69,31 +69,66 @@ namespace RobobinApp.Views
...
@@ -69,31 +69,66 @@ namespace RobobinApp.Views
private
void
DrawNodes
(
ICanvas
canvas
,
float
nodeRadius
,
Node
highlightedNode
)
private
void
DrawNodes
(
ICanvas
canvas
,
float
nodeRadius
,
Node
highlightedNode
)
{
{
// Calculate offsets to center the nodes
float
canvasCenterX
=
storedDirtyRect
.
Width
*
4.5f
/
7
;
float
canvasCenterY
=
storedDirtyRect
.
Height
/
2
;
// Calculate the center of the graph based on node coordinates
float
graphCenterX
=
(
_graph
.
Nodes
.
Min
(
node
=>
node
.
X
)
+
_graph
.
Nodes
.
Max
(
node
=>
node
.
X
))
/
2
;
float
graphCenterY
=
(
_graph
.
Nodes
.
Min
(
node
=>
node
.
Y
)
+
_graph
.
Nodes
.
Max
(
node
=>
node
.
Y
))
/
2
;
// Offset to center the graph
float
offsetX
=
canvasCenterX
-
graphCenterX
;
float
offsetY
=
canvasCenterY
-
graphCenterY
;
foreach
(
var
node
in
_graph
.
Nodes
)
foreach
(
var
node
in
_graph
.
Nodes
)
{
{
float
x
=
node
.
X
;
// Use the original X-coordinate
// Apply centering offsets
float
y
=
node
.
Y
;
// Use the original Y-coordinate
float
centeredX
=
node
.
X
+
offsetX
;
float
centeredY
=
node
.
Y
+
offsetY
;
// Set fill color based on whether the node is highlighted
// Set fill color based on whether the node is highlighted
canvas
.
FillColor
=
(
highlightedNode
==
node
)
?
HighlightedNodeColor
:
DefaultNodeColor
;
canvas
.
FillColor
=
(
highlightedNode
==
node
)
?
HighlightedNodeColor
:
DefaultNodeColor
;
// Draw the node as a circle
// Draw the node as a circle
canvas
.
FillCircle
(
x
,
y
,
nodeRadius
);
canvas
.
FillCircle
(
centeredX
,
centeredY
,
nodeRadius
);
// Optionally, draw node name or other details
// Optionally, draw node name or other details
canvas
.
FontColor
=
Colors
.
White
;
canvas
.
FontColor
=
Colors
.
Black
;
canvas
.
DrawString
(
node
.
Name
,
x
+
nodeRadius
+
2
,
y
-
nodeRadius
,
HorizontalAlignment
.
Left
);
canvas
.
DrawString
(
node
.
Name
,
centeredX
+
nodeRadius
+
2
,
centeredY
-
nodeRadius
,
HorizontalAlignment
.
Left
);
}
}
}
}
public
Node
FindNearestNode
(
float
tapPointX
,
float
tapPointY
)
public
Node
FindNearestNode
(
float
tapPointX
,
float
tapPointY
)
{
{
// Calculate offsets to center the nodes
float
canvasCenterX
=
storedDirtyRect
.
Width
*
4.5f
/
7
;
float
canvasCenterY
=
storedDirtyRect
.
Height
/
2
;
// Calculate the center of the graph based on node coordinates
float
graphCenterX
=
(
_graph
.
Nodes
.
Min
(
node
=>
node
.
X
)
+
_graph
.
Nodes
.
Max
(
node
=>
node
.
X
))
/
2
;
float
graphCenterY
=
(
_graph
.
Nodes
.
Min
(
node
=>
node
.
Y
)
+
_graph
.
Nodes
.
Max
(
node
=>
node
.
Y
))
/
2
;
// Offset to center the graph
float
offsetX
=
canvasCenterX
-
graphCenterX
;
float
offsetY
=
canvasCenterY
-
graphCenterY
;
float
minDistance
=
float
.
MaxValue
;
float
minDistance
=
float
.
MaxValue
;
Node
nearestNode
=
null
;
Node
nearestNode
=
null
;
foreach
(
var
node
in
_graph
.
Nodes
)
foreach
(
var
node
in
_graph
.
Nodes
)
{
{
float
distance
=
(
float
)
Math
.
Sqrt
(
Math
.
Pow
(
node
.
X
-
tapPointX
,
2
)
+
Math
.
Pow
(
node
.
Y
-
tapPointY
,
2
));
// Apply centering offsets to node positions
float
centeredX
=
node
.
X
+
offsetX
;
float
centeredY
=
node
.
Y
+
offsetY
;
// Calculate the distance between the tapped point and the centered node position
float
distance
=
(
float
)
Math
.
Sqrt
(
Math
.
Pow
(
centeredX
-
tapPointX
,
2
)
+
Math
.
Pow
(
centeredY
-
tapPointY
,
2
)
);
if
(
distance
<
minDistance
)
if
(
distance
<
minDistance
)
{
{
minDistance
=
distance
;
minDistance
=
distance
;
...
@@ -103,5 +138,6 @@ namespace RobobinApp.Views
...
@@ -103,5 +138,6 @@ namespace RobobinApp.Views
return
nearestNode
;
return
nearestNode
;
}
}
}
}
}
}
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