Skip to content

Commit 7f575b5

Browse files
leandroBorgesFerreiraLeandro Ferreira
andauthored
Fixing crash of directed for graph (#450)
* Fixing crash * Update ForceDirectedGraph.kt --------- Co-authored-by: Leandro Ferreira <[email protected]>
1 parent 60a8410 commit 7f575b5

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

application/core/forcegraph/src/commonMain/kotlin/io/writeopia/forcegraph/ForceDirectedGraph.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ fun BoxWithConstraintsScope.ForceDirectedGraph(
151151
drawText(
152152
textMeasurer,
153153
text = " ${node.label} ",
154-
topLeft = Offset(node.x - 30, node.y + 20),
154+
topLeft = Offset(
155+
max(min(node.x - 30, maxWidth.value - 50), 0F + 50),
156+
max(min(node.y + 20, maxHeight.value - 50), 0F + 50)
157+
),
155158
style = textStyle
156159
)
157160
}

application/features/documents_graph/src/commonMain/kotlin/io/writeopia/documents/graph/navigation/NavigateDocumentGraph.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.writeopia.documents.graph.navigation
22

3-
import androidx.compose.foundation.background
43
import androidx.compose.foundation.layout.BoxWithConstraints
54
import androidx.compose.foundation.layout.fillMaxSize
65
import androidx.compose.runtime.collectAsState
76
import androidx.compose.runtime.getValue
87
import androidx.compose.ui.Modifier
9-
import androidx.compose.ui.graphics.Color
108
import androidx.navigation.NavController
119
import androidx.navigation.NavGraphBuilder
1210
import androidx.navigation.compose.composable
@@ -33,7 +31,7 @@ fun NavGraphBuilder.documentsGraphNavigation(
3331
val state by viewModel.graphSelectedState.collectAsState()
3432

3533
ForceDirectedGraph(
36-
modifier = Modifier.fillMaxSize().background(Color.LightGray),
34+
modifier = Modifier.fillMaxSize(),
3735
nodes = state.nodes,
3836
links = state.links,
3937
onNodeSelected = viewModel::selectNode

0 commit comments

Comments
 (0)