Skip to content

Commit 5bc8df0

Browse files
committed
Gemini review comments
1 parent 0b906a5 commit 5bc8df0

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

app/src/main/java/com/example/cahier/developer/brushgraph/data/GraphDataModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,11 @@ sealed class Port(
395395
) {
396396
abstract val side: PortSide
397397

398-
class Output(nodeId: String, id: String = "output", label: DisplayText? = null) :
398+
companion object {
399+
const val OUTPUT_PORT_ID = "output"
400+
}
401+
402+
class Output(nodeId: String, id: String = OUTPUT_PORT_ID, label: DisplayText? = null) :
399403
Port(nodeId, id, label, isAddPort = false) {
400404
override val side = PortSide.OUTPUT
401405
}

app/src/main/java/com/example/cahier/developer/brushgraph/ui/GraphCameraController.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import com.example.cahier.developer.brushgraph.data.TutorialAnchor
3333
import com.example.cahier.developer.brushgraph.data.TutorialStep
3434
import com.example.cahier.developer.brushgraph.ui.node.NodeRegistry
3535

36+
private const val TUTORIAL_TARGET_Y = 280f
37+
3638
@Composable
3739
fun GraphCameraController(
3840
offset: Offset,
@@ -58,7 +60,7 @@ fun GraphCameraController(
5860
val node = step.getTargetNode(graph)
5961
if (node != null) {
6062
val density = context.resources.displayMetrics.density
61-
val targetY = 280f * density
63+
val targetY = TUTORIAL_TARGET_Y * density
6264
val targetX = maxWidthDp.value * density / 2f
6365

6466
val newOffset = calculateFocusOffset(

app/src/main/java/com/example/cahier/developer/brushgraph/ui/GraphCanvas.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import com.example.cahier.developer.brushgraph.data.GraphEdge
7878
import com.example.cahier.developer.brushgraph.data.GraphNode
7979
import com.example.cahier.developer.brushgraph.data.NodeData
8080
import com.example.cahier.developer.brushgraph.data.Port
81+
import com.example.cahier.developer.brushgraph.data.Port.OUTPUT_PORT_ID
8182
import com.example.cahier.developer.brushgraph.data.PortSide
8283
import kotlin.math.roundToInt
8384

@@ -170,7 +171,7 @@ fun GraphCanvas(
170171
val toNode = currentGraph.nodes.find { it.id == edge.toNodeId }
171172

172173
val start = if (fromNode != null) {
173-
nodeRegistry.getPortPosition(edge.fromNodeId, "output", currentGraph)
174+
nodeRegistry.getPortPosition(edge.fromNodeId, OUTPUT_PORT_ID, currentGraph)
174175
} else Offset.Zero
175176
val end = if (toNode != null) {
176177
nodeRegistry.getPortPosition(edge.toNodeId, edge.toPortId, currentGraph)
@@ -263,7 +264,7 @@ fun GraphCanvas(
263264
val edge = graph.edges.find { it.toNodeId == node.id && it.toPortId == portId && !it.isDisabled }
264265

265266
if (edge != null) {
266-
activeSourcePort = Port.Output(edge.fromNodeId, "output")
267+
activeSourcePort = Port.Output(edge.fromNodeId)
267268
onEdgeDetach(edge)
268269
}
269270
}
@@ -435,7 +436,7 @@ fun EdgeRenderer(
435436
val toNode = graph.nodes.find { it.id == edge.toNodeId }
436437

437438
val start = if (fromNode != null) {
438-
nodeRegistry.getPortPosition(edge.fromNodeId, "output", graph)
439+
nodeRegistry.getPortPosition(edge.fromNodeId, OUTPUT_PORT_ID, graph)
439440
} else Offset.Zero
440441
val end = if (toNode != null) {
441442
nodeRegistry.getPortPosition(edge.toNodeId, edge.toPortId, graph)

app/src/main/java/com/example/cahier/developer/brushgraph/ui/GraphLayout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.example.cahier.developer.brushgraph.data.BrushGraph
2020
import com.example.cahier.developer.brushgraph.data.GraphNode
2121
import com.example.cahier.developer.brushgraph.data.NodeData
2222
import com.example.cahier.developer.brushgraph.data.Port
23-
import java.util.UUID
2423

2524
const val NODE_WIDTH = 300f
2625
const val NODE_PADDING_VERTICAL = 8f
@@ -180,6 +179,7 @@ object GraphLayout {
180179
nodeSubtreeMaxY: MutableMap<String, Float>
181180
): Float {
182181
val node = graph.nodes.find { it.id == nodeId } ?: return desiredY
182+
if (depth > 100) return desiredY // Prevent stack overflow on extremely deep graphs
183183
val data = node.data as? NodeData.Behavior ?: return desiredY
184184

185185
if (assignedNodeIds.contains(nodeId)) {

0 commit comments

Comments
 (0)