A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(app): auto color links by node type
dextmorgn939008713d41
diff --git a/flowsint-app/src/components/sketches/details-panel/neighbors.tsx b/flowsint-app/src/components/sketches/details-panel/neighbors.tsxindex e4a04b94..af02f3c8 100644--- a/flowsint-app/src/components/sketches/details-panel/neighbors.tsx+++ b/flowsint-app/src/components/sketches/details-panel/neighbors.tsx@@ -30,9 +30,9 @@ const NeighborsGraph = memo(<ForceGraphViewernodes={neighborsData.nds}edges={neighborsData.rls}- onNodeClick={() => { }}- onNodeRightClick={() => { }}- onBackgroundClick={() => { }}+ onNodeClick={() => {}}+ onNodeRightClick={() => {}}+ onBackgroundClick={() => {}}showLabels={true}showIcons={true}backgroundColor="transparent"@@ -40,6 +40,7 @@ const NeighborsGraph = memo(allowForces={true}autoZoomOnNode={false}showMinimap={false}+ showMinimalControls={true}/></>)}diff --git a/flowsint-app/src/components/sketches/graph/background/background-patterns.tsx b/flowsint-app/src/components/sketches/graph/background/background-patterns.tsxnew file mode 100644index 00000000..c2619188--- /dev/null+++ b/flowsint-app/src/components/sketches/graph/background/background-patterns.tsx@@ -0,0 +1,61 @@+import { memo } from 'react'+import { BackgroundVariant } from './background-types'++interface DotPatternProps {+ radius: number+ className?: string+ centerX?: number+ centerY?: number+}++export const DotPattern = memo(+ ({ radius, className, centerX = 0, centerY = 0 }: DotPatternProps) => {+ return <circle cx={centerX} cy={centerY} r={radius} className={className} fill="currentColor" />+ }+)++DotPattern.displayName = 'DotPattern'++interface LinePatternProps {+ dimensions: [number, number]+ lineWidth: number+ variant: BackgroundVariant+ className?: string+}++export const LinePattern = memo(+ ({ dimensions, lineWidth, variant, className }: LinePatternProps) => {+ const [width, height] = dimensions++ if (variant === BackgroundVariant.Lines) {+ return (+ <path+ className={className}+ stroke="currentColor"+ strokeWidth={lineWidth}+ d={`M${width / 2} 0 V${height} M0 ${height / 2} H${width}`}+ />+ )+ }++ // Cross variant+ return (+ <>+ <path+ className={className}+ stroke="currentColor"+ strokeWidth={lineWidth}+ d={`M${width / 2} 0 V${height}`}+ />+ <path+ className={className}+ stroke="currentColor"+ strokeWidth={lineWidth}+ d={`M0 ${height / 2} H${width}`}+ />+ </>+ )+ }+)++LinePattern.displayName = 'LinePattern'diff --git a/flowsint-app/src/components/sketches/graph/background/background-types.tsx b/flowsint-app/src/components/sketches/graph/background/background-types.tsxnew file mode 100644index 00000000..5ab31ee0--- /dev/null+++ b/flowsint-app/src/components/sketches/graph/background/background-types.tsx@@ -0,0 +1,38 @@+import { CSSProperties } from 'react'++export enum BackgroundVariant {+ Dots = 'dots',+ Lines = 'lines',+ Cross = 'cross'+}++export interface BackgroundProps {+ /** Unique identifier for the background pattern */+ id?: string+ /** The visual style of the background */+ variant?: BackgroundVariant+ /** Spacing between pattern elements (can be [x, y] or single number) */+ gap?: number | [number, number]+ /** Size of dots or line thickness */+ size?: number+ /** Line width for line/cross variants */+ lineWidth?: number+ /** Offset of the pattern (can be [x, y] or single number) */+ offset?: number | [number, number]+ /** Color of the pattern */+ color?: string+ /** Background color */+ bgColor?: string+ /** Custom styles */+ style?: CSSProperties+ /** Custom class name for the container */+ className?: string+ /** Custom class name for the pattern */+ patternClassName?: string+ /** Reference to the graph for viewport tracking */+ graphRef: React.RefObject<any>+ /** Canvas width */+ canvasWidth: number+ /** Canvas height */+ canvasHeight: number+}diff --git a/flowsint-app/src/components/sketches/graph/background/index.tsx b/flowsint-app/src/components/sketches/graph/background/index.tsxnew file mode 100644index 00000000..d60eba38--- /dev/null+++ b/flowsint-app/src/components/sketches/graph/background/index.tsx@@ -0,0 +1,209 @@+import { CSSProperties, memo, useRef, useState, useEffect } from 'react'+import { DotPattern, LinePattern } from './background-patterns'+import { type BackgroundProps, BackgroundVariant } from './background-types'+import { CONSTANTS } from '../utils/constants'+import { cn } from '@/lib/utils'++const defaultSize = {+ [BackgroundVariant.Dots]: 1,+ [BackgroundVariant.Lines]: 1,+ [BackgroundVariant.Cross]: 6+}++function BackgroundComponent({+ id,+ variant = BackgroundVariant.Dots,+ gap = 20,+ size,+ lineWidth = 1,+ offset = 0,+ color = 'rgba(128, 128, 128, 0.3)',+ bgColor = 'transparent',+ style,+ className,+ patternClassName,+ graphRef,+ canvasWidth,+ canvasHeight+}: BackgroundProps) {+ const svgRef = useRef<SVGSVGElement>(null)+ const patternRef = useRef<SVGPatternElement>(null)+ const dotGroupRef = useRef<SVGGElement>(null)+ const rafRef = useRef<number | null>(null)+ const lastTransformRef = useRef<{ x: number; y: number; zoom: number } | null>(null)+ const [isVisible, setIsVisible] = useState(true)++ const patternSize = size || defaultSize[variant]+ const isDots = variant === BackgroundVariant.Dots+ const isCross = variant === BackgroundVariant.Cross+ const gapXY: [number, number] = Array.isArray(gap) ? gap : [gap, gap]+ const offsetXY: [number, number] = Array.isArray(offset) ? offset : [offset, offset]++ const patternId = `pattern-${id || 'default'}-${variant}`++ // Update transform based on graph viewport changes+ useEffect(() => {+ const updateTransform = () => {+ if (!graphRef.current || !patternRef.current) return false++ try {+ // Get zoom level+ const zoom = graphRef.current.zoom?.() || 1++ // Get center position in world coordinates+ let centerX = 0+ let centerY = 0++ if (typeof graphRef.current.centerAt === 'function') {+ const center = graphRef.current.centerAt()+ centerX = center?.x ?? 0+ centerY = center?.y ?? 0+ }++ // Convert world coordinates to screen offset+ const screenX = canvasWidth / 2 - centerX * zoom+ const screenY = canvasHeight / 2 - centerY * zoom++ // Check visibility based on zoom threshold (same as labels)+ const shouldBeVisible = zoom > CONSTANTS.ZOOM_NODE_DETAIL_THRESHOLD+ if (shouldBeVisible !== isVisible) {+ setIsVisible(shouldBeVisible)+ }++ // Only update pattern if visible+ if (!shouldBeVisible) return false++ const last = lastTransformRef.current+ if (!last) {+ lastTransformRef.current = { x: screenX, y: screenY, zoom }+ // Update pattern attributes directly without re-render+ updatePatternAttributes(screenX, screenY, zoom)+ return true+ }++ // Check if transform changed significantly+ const zoomChanged = Math.abs(zoom - last.zoom) > 0.0001+ const posChanged = Math.abs(screenX - last.x) > 0.5 || Math.abs(screenY - last.y) > 0.5++ if (zoomChanged || posChanged) {+ lastTransformRef.current = { x: screenX, y: screenY, zoom }+ // Update pattern attributes directly without re-render+ updatePatternAttributes(screenX, screenY, zoom)+ return true+ }++ return false+ } catch {+ return false+ }+ }++ // Direct DOM manipulation to avoid re-renders+ const updatePatternAttributes = (screenX: number, screenY: number, zoom: number) => {+ if (!patternRef.current) return++ const scaledGap: [number, number] = [gapXY[0] * zoom, gapXY[1] * zoom]+ const scaledSize = patternSize * zoom+ const patternDimensions: [number, number] = isCross ? [scaledSize, scaledSize] : scaledGap+ const scaledOffset: [number, number] = [+ offsetXY[0] * zoom || 1 + patternDimensions[0] / 2,+ offsetXY[1] * zoom || 1 + patternDimensions[1] / 2+ ]++ // Update pattern attributes directly+ patternRef.current.setAttribute('x', String(screenX % scaledGap[0]))+ patternRef.current.setAttribute('y', String(screenY % scaledGap[1]))+ patternRef.current.setAttribute('width', String(scaledGap[0]))+ patternRef.current.setAttribute('height', String(scaledGap[1]))+ patternRef.current.setAttribute(+ 'patternTransform',+ `translate(-${scaledOffset[0]},-${scaledOffset[1]})`+ )++ // Update dot/line size if needed+ if (isDots && dotGroupRef.current) {+ const dotElement = dotGroupRef.current.querySelector('circle')+ if (dotElement) {+ dotElement.setAttribute('r', String(scaledSize / 2))+ dotElement.setAttribute('cx', String(scaledGap[0] / 2))+ dotElement.setAttribute('cy', String(scaledGap[1] / 2))+ }+ }+ }++ // Initial transform+ updateTransform()++ // Use requestAnimationFrame for smooth synchronization+ // Only triggers re-render when transform actually changes+ const animate = () => {+ updateTransform()+ rafRef.current = requestAnimationFrame(animate)+ }++ rafRef.current = requestAnimationFrame(animate)++ return () => {+ if (rafRef.current) {+ cancelAnimationFrame(rafRef.current)+ }+ }+ }, [graphRef, canvasWidth, canvasHeight, isVisible])++ return (+ <svg+ className={cn('absolute inset-0 pointer-events-none', className)}+ style={+ {+ ...style,+ width: canvasWidth,+ height: canvasHeight,+ '--bg-color': bgColor,+ '--pattern-color': color,+ // Hide with CSS instead of unmounting to keep useEffect running+ opacity: isVisible ? 1 : 0,+ visibility: isVisible ? 'visible' : 'hidden'+ } as CSSProperties+ }+ ref={svgRef}+ data-background-variant={variant}+ >+ <defs>+ <pattern+ ref={patternRef}+ id={patternId}+ x="0"+ y="0"+ width={gapXY[0]}+ height={gapXY[1]}+ patternUnits="userSpaceOnUse"+ patternTransform="translate(0,0)"+ >+ {isDots ? (+ <g ref={dotGroupRef} style={{ color }}>+ <DotPattern+ radius={patternSize / 2}+ centerX={gapXY[0] / 2}+ centerY={gapXY[1] / 2}+ className={patternClassName}+ />+ </g>+ ) : (+ <LinePattern+ dimensions={[gapXY[0], gapXY[1]]}+ lineWidth={lineWidth}+ variant={variant}+ className={patternClassName}+ />+ )}+ </pattern>+ </defs>+ <rect x="0" y="0" width="100%" height="100%" fill={bgColor} />+ <rect x="0" y="0" width="100%" height="100%" fill={`url(#${patternId})`} style={{ color }} />+ </svg>+ )+}++BackgroundComponent.displayName = 'Background'++export const Background = memo(BackgroundComponent)diff --git a/flowsint-app/src/components/sketches/graph/edge/link-renderer.ts b/flowsint-app/src/components/sketches/graph/edge/link-renderer.tsindex d385d7e7..f687b8b0 100644--- a/flowsint-app/src/components/sketches/graph/edge/link-renderer.ts+++ b/flowsint-app/src/components/sketches/graph/edge/link-renderer.ts@@ -11,10 +11,16 @@ interface LinkRenderParams {highlightNodes: Set<string>selectedEdges: any[]currentEdge: any+ autoColorLinksByNodeType?: boolean}// Helper to check if a node position is in viewport-const isPositionInViewport = (x: number, y: number, ctx: CanvasRenderingContext2D, margin: number = 80): boolean => {+const isPositionInViewport = (+ x: number,+ y: number,+ ctx: CanvasRenderingContext2D,+ margin: number = 80+): boolean => {const transform = ctx.getTransform()const canvasWidth = ctx.canvas.widthconst canvasHeight = ctx.canvas.height@@ -33,7 +39,11 @@ const isPositionInViewport = (x: number, y: number, ctx: CanvasRenderingContext2}// Helper to check if edge is in viewport (at least one endpoint or edge crosses viewport)-const isEdgeInViewport = (link: any, ctx: CanvasRenderingContext2D, margin: number = 80): boolean => {+const isEdgeInViewport = (+ link: any,+ ctx: CanvasRenderingContext2D,+ margin: number = 80+): boolean => {const { source: start, target: end } = linkif (typeof start !== 'object' || typeof end !== 'object') return false@@ -76,7 +86,8 @@ export const renderLink = ({highlightLinks,highlightNodes,selectedEdges,- currentEdge+ currentEdge,+ autoColorLinksByNodeType}: LinkRenderParams) => {if (globalScale < CONSTANTS.ZOOM_EDGE_DETAIL_THRESHOLD) return@@ -98,6 +109,10 @@ export const renderLink = ({? linkWidthBase: linkWidthBase * CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER+ const targetNodeColor = autoColorLinksByNodeType+ ? end.nodeColor || GRAPH_COLORS.LINK_DEFAULT+ : GRAPH_COLORS.LINK_DEFAULT+let strokeStyle: stringlet lineWidth: numberlet fillStyle: string@@ -107,8 +122,8 @@ export const renderLink = ({fillStyle = 'rgba(59, 130, 246, 0.95)'lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 2.3)} else if (isSelected) {- strokeStyle = 'rgba(255, 115, 0, 0.9)'- fillStyle = 'rgba(255, 115, 0, 0.9)'+ strokeStyle = autoColorLinksByNodeType ? targetNodeColor : GRAPH_COLORS.LINK_HIGHLIGHTED+ fillStyle = autoColorLinksByNodeType ? targetNodeColor : GRAPH_COLORS.LINK_HIGHLIGHTEDlineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 2.5)} else if (isHighlighted) {strokeStyle = GRAPH_COLORS.LINK_HIGHLIGHTED@@ -119,19 +134,30 @@ export const renderLink = ({fillStyle = GRAPH_COLORS.LINK_DIMMEDlineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 5)} else {- strokeStyle = GRAPH_COLORS.LINK_DEFAULT- fillStyle = GRAPH_COLORS.LINK_DEFAULT+ strokeStyle = autoColorLinksByNodeType ? targetNodeColor : GRAPH_COLORS.LINK_DEFAULT+ fillStyle = autoColorLinksByNodeType ? targetNodeColor : GRAPH_COLORS.LINK_DEFAULTlineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 5)}// Calculate node radii to stop links at node edges// Uses the shared calculateNodeSize function to ensure consistency with node-renderer- const startRadius = calculateNodeSize(start, forceSettings, shouldRenderDetails, CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER)- const endRadius = calculateNodeSize(end, forceSettings, shouldRenderDetails, CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER)+ const startRadius = calculateNodeSize(+ start,+ forceSettings,+ shouldRenderDetails,+ CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER+ )+ const endRadius = calculateNodeSize(+ end,+ forceSettings,+ shouldRenderDetails,+ CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER+ )const arrowLengthSetting = forceSettings?.linkDirectionalArrowLength?.value- const arrowLength =- shouldRenderDetails ? arrowLengthSetting : arrowLengthSetting * CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER+ const arrowLength = shouldRenderDetails+ ? arrowLengthSetting+ : arrowLengthSetting * CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER// Draw connection lineconst curvature: number = link.curvature || 0@@ -199,7 +225,12 @@ export const renderLink = ({const tan = bezierTangent(0.99)const tanLen = Math.hypot(tan.x, tan.y) || 1// Use the same calculation as above to ensure consistency- const targetNodeSize = calculateNodeSize(end, forceSettings, shouldRenderDetails, CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER)+ const targetNodeSize = calculateNodeSize(+ end,+ forceSettings,+ shouldRenderDetails,+ CONSTANTS.ZOOMED_OUT_SIZE_MULTIPLIER+ )arrowX = end.x - (tan.x / tanLen) * targetNodeSizearrowY = end.y - (tan.y / tanLen) * targetNodeSize}@@ -270,9 +301,7 @@ export const renderLink = ({}ctx.fill()- ctx.strokeStyle = theme === 'light'- ? 'rgba(0, 0, 0, 0.1)'- : 'rgba(255, 255, 255, 0.1)'+ ctx.strokeStyle = theme === 'light' ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)'ctx.lineWidth = 0.1ctx.stroke()@@ -284,7 +313,8 @@ export const renderLink = ({// Calculate vertical center manually using font metricsconst labelMetrics = ctx.measureText(link.label)- const labelTextY = labelMetrics.actualBoundingBoxAscent * 0.5 - labelMetrics.actualBoundingBoxDescent * 0.5+ const labelTextY =+ labelMetrics.actualBoundingBoxAscent * 0.5 - labelMetrics.actualBoundingBoxDescent * 0.5ctx.fillText(link.label, 0, labelTextY)ctx.restore()diff --git a/flowsint-app/src/components/sketches/graph/index.tsx b/flowsint-app/src/components/sketches/graph/index.tsxindex 96592259..6bf38f24 100644--- a/flowsint-app/src/components/sketches/graph/index.tsx+++ b/flowsint-app/src/components/sketches/graph/index.tsx@@ -23,6 +23,10 @@ import { GraphTooltip } from './components/graph-tooltip'import { GraphLoadingOverlay } from './components/graph-loading-overlay'import { GraphSelectorOverlay } from './components/graph-selector-overlay'import MinimapCanvas from './components/minimap'+import { Background } from './background'+import { BackgroundVariant } from './background/background-types'+import { Maximize } from 'lucide-react'+import { Button } from '@/components/ui/button'const GraphViewer: React.FC<GraphViewerProps> = ({nodes,@@ -43,6 +47,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({sketchId,allowForces = false,autoZoomOnNode = true,+ showMinimalControls = false,showMinimap}) => {const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })@@ -57,9 +62,16 @@ const GraphViewer: React.FC<GraphViewerProps> = ({const customIcons = useNodesDisplaySettings((s) => s.customIcons)const setActions = useGraphControls((s) => s.setActions)const setCurrentLayoutType = useGraphControls((s) => s.setCurrentLayoutType)+ const autoColorLinksByNodeType = useGraphSettingsStore((s) =>+ s.getSettingValue('general', 'autoColorLinksByNodeType')+ )const autoZoomOnCurrentNode = useGraphSettingsStore((s) =>s.getSettingValue('general', 'autoZoomOnCurrentNode'))+ const showBackgroundSetting = useGraphSettingsStore((s) =>+ s.getSettingValue('general', 'showBackground')+ )+const showMinimapSetting = useGraphSettingsStore((s) =>s.getSettingValue('general', 'showMinimap'))@@ -241,6 +253,12 @@ const GraphViewer: React.FC<GraphViewerProps> = ({}}, [])+ const handleZoomToFitLocal = useCallback(() => {+ if (typeof graphRef.current.zoomToFit === 'function') {+ graphRef.current.zoomToFit(400)+ }+ }, [])+const exportToPNG = useCallback(async () => {if (!graphRef.current) {throw new Error('Graph ref not available')@@ -342,10 +360,11 @@ const GraphViewer: React.FC<GraphViewerProps> = ({highlightLinks,highlightNodes,selectedEdges,- currentEdge+ currentEdge,+ autoColorLinksByNodeType})},- [forceSettings, theme, highlightLinks, highlightNodes, selectedEdges, currentEdge]+ [forceSettings, theme, highlightLinks, highlightNodes, selectedEdges, currentEdge, autoColorLinksByNodeType])if (!nodes.length) {@@ -376,6 +395,20 @@ const GraphViewer: React.FC<GraphViewerProps> = ({}}><GraphTooltip tooltip={tooltip} />+ {showBackgroundSetting && containerSize.width > 0 && containerSize.height > 0 && (+ <Background+ key={`background-${instanceId || 'main'}`}+ id={instanceId || 'main'}+ variant={BackgroundVariant.Dots}+ gap={4}+ size={0.25}+ color="rgba(128, 128, 128, 0.47)"+ bgColor="transparent"+ graphRef={graphRef}+ canvasWidth={containerSize.width}+ canvasHeight={containerSize.height}+ />+ )}<ForceGraph2Dref={graphRef}width={containerSize.width}@@ -426,6 +459,19 @@ const GraphViewer: React.FC<GraphViewerProps> = ({canvasHeight={containerSize.height}/>)}+ {showMinimalControls && (+ <div className="absolute top-1 right-1">+ <Button+ onClick={handleZoomToFitLocal}+ variant={'ghost'}+ size={'icon'}+ className="h-6 w-6"+ >+ <Maximize className="h-3.5 w-3.5 opacity-70" />+ </Button>+ </div>+ )}+ ·<GraphLoadingOverlay isVisible={isRegeneratingLayout} /></div>)diff --git a/flowsint-app/src/components/sketches/graph/utils/types.ts b/flowsint-app/src/components/sketches/graph/utils/types.tsindex 8f94fdfc..cde32434 100644--- a/flowsint-app/src/components/sketches/graph/utils/types.ts+++ b/flowsint-app/src/components/sketches/graph/utils/types.ts@@ -19,6 +19,7 @@ export interface GraphViewerProps {sketchId?: stringallowForces?: booleanautoZoomOnNode?: boolean+ showMinimalControls?: booleanshowMinimap?: boolean}diff --git a/flowsint-app/src/components/sketches/settings/icon-picker/trigger.tsx b/flowsint-app/src/components/sketches/settings/icon-picker/trigger.tsxindex 656f58f5..383dd4d3 100644--- a/flowsint-app/src/components/sketches/settings/icon-picker/trigger.tsx+++ b/flowsint-app/src/components/sketches/settings/icon-picker/trigger.tsx@@ -8,8 +8,13 @@ type NodeIconTriggerProps = {export const NodeIconTrigger = ({ type, onClick }: NodeIconTriggerProps) => {const Icon = useIcon(type)return (- <Button onClick={onClick} variant={'ghost'} size={'icon'}>- <Icon size={16} />+ <Button+ className="cursor-pointer hover:bg-muted"+ onClick={onClick}+ variant={'ghost'}+ size={'icon'}+ >+ <Icon size={24} /></Button>)}diff --git a/flowsint-app/src/stores/graph-settings-store.ts b/flowsint-app/src/stores/graph-settings-store.tsindex 6372207f..20eb9273 100644--- a/flowsint-app/src/stores/graph-settings-store.ts+++ b/flowsint-app/src/stores/graph-settings-store.ts@@ -22,6 +22,18 @@ const DEFAULT_SETTINGS = {type: 'boolean',value: true,description: 'Display the minimap overview of the graph.'+ },+ showBackground: {+ name: 'Show Background',+ type: 'boolean',+ value: true,+ description: 'Display the dotted background pattern on the graph.'+ },+ autoColorLinksByNodeType: {+ name: 'Auto Color Links by Node Type',+ type: 'boolean',+ value: true,+ description: 'Automatically color links based on their target node type.'}},graph: {@@ -383,7 +395,7 @@ type GraphGeneralSettingsStore = {}// Storage version - increment this whenever you make breaking changes to DEFAULT_SETTINGS-const STORAGE_VERSION = 4+const STORAGE_VERSION = 5export const useGraphSettingsStore = create<GraphGeneralSettingsStore>()(persist(