import 'package:flutter/material.dart'; import '../layout/layout_models.dart'; import '../routing/route_models.dart'; /// Centralized graph spacing, not component dimensions. Rank separation follows /// actual native label measurements at any text scale. GraphLayoutConfig graphCanvasLayoutConfig(Iterable labels) { final widest = labels.fold( 0, (width, label) => label.width > width ? label.width : width, ); final routing = graphCanvasRoutingConfig(); return GraphLayoutConfig( columnGap: widest + 2 * (routing.nodeClearance + routing.labelGap) + 24, rowGap: 24, padding: 24, ); } RoutingConfig graphCanvasRoutingConfig() => RoutingConfig( nodeClearance: 12, laneSpacing: 28, corridorSpacing: 20, portSpacing: 12, labelGap: 6, boundsPadding: 12, ); /// The native theme roles one definition graph canvas needs. /// /// No palette, font family or size is defined here: every value comes from the /// ambient Material theme, so light/dark and text scaling follow the host /// exactly. Edge labels and diagnostics are metadata, so they use the host's /// secondary-label role rather than the node's own label style. class GraphCanvasStyle { const GraphCanvasStyle({ required this.labelStyle, required this.messageStyle, required this.edgeColor, required this.edgeWidth, }); factory GraphCanvasStyle.of(BuildContext context) { final theme = Theme.of(context); final secondary = theme.colorScheme.onSurfaceVariant; return GraphCanvasStyle( labelStyle: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith( color: secondary, ), messageStyle: (theme.textTheme.bodySmall ?? const TextStyle()).copyWith( color: secondary, ), edgeColor: theme.colorScheme.outline, edgeWidth: theme.dividerTheme.thickness ?? 1, ); } /// Style of one routed outcome label. final TextStyle labelStyle; /// Style of the empty-state and skipped-edge messages. final TextStyle messageStyle; /// Native outline/separator color for the routed edges. final Color edgeColor; /// Native hairline thickness for the routed edges and their arrows. final double edgeWidth; }