Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(app): randomize node colors + remove unused tab component

dextmorgnaa4ebad3748a
diff --git a/flowsint-app/src/components/graphs/graph-viewer.tsx b/flowsint-app/src/components/graphs/graph-viewer.tsx
index 83d1786a..2f3028c0 100644
--- a/flowsint-app/src/components/graphs/graph-viewer.tsx
+++ b/flowsint-app/src/components/graphs/graph-viewer.tsx
@@ -674,7 +674,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
CONSTANTS.MIN_FONT_SIZE,
(CONSTANTS.NODE_FONT_SIZE * (size / 2)) / globalScale + 2
)
- const nodeLabelSetting = forceSettings.nodeLabelFontSize.value ?? 50
+ const nodeLabelSetting = forceSettings?.nodeLabelFontSize?.value ?? 50
const fontSize = baseFontSize * (nodeLabelSetting / 100)
ctx.font = `${fontSize}px Sans-Serif`
@@ -739,26 +739,26 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
(link: any, ctx: CanvasRenderingContext2D, globalScale: number) => {
const { source: start, target: end } = link
if (typeof start !== 'object' || typeof end !== 'object') return
- const shouldUseSimpleRendering =
- nodes.length > CONSTANTS.NODE_COUNT_THRESHOLD || globalScale < 1.5
const linkKey = `${start.id}-${end.id}`
const isHighlighted = highlightLinks.has(linkKey)
const hasAnyHighlight = highlightNodes.size > 0 || highlightLinks.size > 0
+ const linkWidth = forceSettings?.linkWidth?.value ?? 2
+ const nodeSize = forceSettings?.nodeSize?.value ?? 14
let strokeStyle: string
let lineWidth: number
let fillStyle: string
if (isHighlighted) {
strokeStyle = GRAPH_COLORS.LINK_HIGHLIGHTED
fillStyle = GRAPH_COLORS.LINK_HIGHLIGHTED
- lineWidth = CONSTANTS.LINK_WIDTH * (forceSettings.linkWidth.value / 3)
+ lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 3)
} else if (hasAnyHighlight) {
strokeStyle = GRAPH_COLORS.LINK_DIMMED
fillStyle = GRAPH_COLORS.LINK_DIMMED
- lineWidth = CONSTANTS.LINK_WIDTH * (forceSettings.linkWidth.value / 5)
+ lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 5)
} else {
strokeStyle = GRAPH_COLORS.LINK_DEFAULT
fillStyle = GRAPH_COLORS.LINK_DEFAULT
- lineWidth = CONSTANTS.LINK_WIDTH * (forceSettings.linkWidth.value / 5)
+ lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 5)
}
// Draw connection line (use quadratic curve if curvature present)
const curvature: number = link.curvature || 0
@@ -783,9 +783,9 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
ctx.lineWidth = lineWidth
ctx.stroke()
// Draw directional arrow
- const arrowLength = forceSettings.linkDirectionalArrowLength.value
+ const arrowLength = forceSettings?.linkDirectionalArrowLength?.value
if (arrowLength && arrowLength > 0) {
- const arrowRelPos = forceSettings.linkDirectionalArrowRelPos.value || 1
+ const arrowRelPos = forceSettings?.linkDirectionalArrowRelPos?.value || 1
// Helper to get point and tangent along straight/curved link
const bezierPoint = (t: number) => {
if (curvature === 0) {
@@ -814,7 +814,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
const tanLen = Math.hypot(tan.x, tan.y) || 1
const targetNodeSize =
(end.nodeSize || CONSTANTS.NODE_DEFAULT_SIZE) *
- (forceSettings.nodeSize.value / 100 + 0.4)
+ (nodeSize / 100 + 0.4)
arrowX = end.x - (tan.x / tanLen) * targetNodeSize
arrowY = end.y - (tan.y / tanLen) * targetNodeSize
}
@@ -859,7 +859,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
if (textAngle > CONSTANTS.HALF_PI || textAngle < -CONSTANTS.HALF_PI) {
textAngle += textAngle > 0 ? -CONSTANTS.PI : CONSTANTS.PI
}
- const linkLabelSetting = forceSettings.linkLabelFontSize.value ?? 50
+ const linkLabelSetting = forceSettings?.linkLabelFontSize?.value ?? 50
// Measure and draw label with dynamic font size
const linkFontSize = CONSTANTS.LABEL_FONT_SIZE * (linkLabelSetting / 100)
ctx.font = `${linkFontSize}px Sans-Serif`
@@ -1070,7 +1070,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
<>
<div
className="absolute z-20 top-14 flex items-center gap-1 left-3 bg-primary/20 text-primary border border-primary rounded-lg p-1 px-2 shadow-lg text-xs pointer-events-none"
- ><Info className='h-3 w-3 '/> Lasso is active</div>
+ ><Info className='h-3 w-3 ' /> Lasso is active</div>
<Lasso
nodes={graphData.nodes}
graph2ScreenCoords={graph2ScreenCoords}
diff --git a/flowsint-app/src/components/graphs/settings.tsx b/flowsint-app/src/components/graphs/settings.tsx
index 177f426b..e0c4f20e 100644
--- a/flowsint-app/src/components/graphs/settings.tsx
+++ b/flowsint-app/src/components/graphs/settings.tsx
@@ -211,6 +211,7 @@ function NodeColorsSection() {
const storeColors = useNodesDisplaySettings((s) => s.colors)
const setColor = useNodesDisplaySettings((s) => s.setColor)
const resetColors = useNodesDisplaySettings((s) => s.resetColors)
+ const randomizeColors = useNodesDisplaySettings((s) => s.randomizeColors)
// Local state for immediate UI updates
const [localColors, setLocalColors] = useState(storeColors)
@@ -247,6 +248,10 @@ function NodeColorsSection() {
[setColor]
)
+ const handleRandomizeColors = useCallback(() => {
+ randomizeColors()
+ }, [])
+
const handleReset = useCallback(() => {
// Clear all pending timers
debounceTimers.current.forEach((timer) => clearTimeout(timer))
@@ -272,10 +277,13 @@ function NodeColorsSection() {
</p>
</div>
- <div className="border-b pb-4">
- <Button variant="outline" size="sm" onClick={handleReset} className="w-full">
+ <div className="border-b flex items-center gap-2 pb-4">
+ <Button variant="outline" size="sm" onClick={handleReset} className="grow">
Reset to Default Colors
</Button>
+ <Button variant="outline" size="sm" onClick={handleRandomizeColors} className="grow">
+ Randomize
+ </Button>
</div>
<div className="pr-4">
diff --git a/flowsint-app/src/components/tab.tsx b/flowsint-app/src/components/tab.tsx
deleted file mode 100644
index f8ce0af2..00000000
--- a/flowsint-app/src/components/tab.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { TabInfo } from '@/types/tabs'
-import { cn } from '@/utils/cn'
-import { motion, Reorder } from 'framer-motion'
-import { VscClose } from 'react-icons/vsc'
-
-interface Props {
- item: TabInfo
- isSelected: boolean
- showSeparator: boolean
- onClick: () => void
- onRemove: () => void
-}
-
-export const Tab = ({ item, onClick, onRemove, isSelected, showSeparator }: Props) => {
- return (
- <Reorder.Item
- value={item}
- id={item.id}
- initial={{
- opacity: 1,
- y: 30
- }}
- animate={{
- opacity: 1,
- y: 0,
- transition: { duration: 0.1, ease: 'easeInOut' }
- }}
- exit={{ opacity: 0, y: 20, transition: { duration: 0.15 } }}
- whileDrag={{
- transition: { ease: 'easeInOut' }
- }}
- className={cn(
- isSelected
- ? 'selected bg-card text-white border-border border-b-transparent'
- : 'bg-background text-white border-transparent',
- 'titlebar-button min-w-[120px] max-w-[200px]',
- `h-8 pl-4 relative cursor-pointer flex justify-between items-center
- flex-1 overflow-hidden select-none border border-transparent`
- )}
- onPointerDown={onClick}
- >
- <motion.span
- className={cn(
- `text-xs text-center flex-shrink flex-grow leading-[18px] whitespace-nowrap block
- min-w-0 pr-[30px] truncate`,
- isSelected ? 'text-foreground' : 'text-white'
- )}
- layout="position"
- >{`${item.title || 'Flowsint'} ${item.id}`}</motion.span>
- <motion.div
- layout
- className="absolute top-0 bottom-0 right-[0px] flex align-center items-center justify-end
- flex-shrink-0 pr-2"
- >
- <motion.button
- onPointerDown={(event) => {
- event.stopPropagation()
- onRemove()
- }}
- initial={false}
- animate={{
- backgroundColor: 'hsl(var(--transparent))'
- }}
- className="h-full flex items-center"
- >
- <VscClose
- className={cn(
- 'rounded-full transition-all duration-300',
- isSelected ? 'hover:bg-black/20' : 'hover:bg-white/20'
- )}
- />
- </motion.button>
- <div
- className={cn(
- isSelected || !showSeparator ? 'invisible' : 'visible',
- 'bg-white/20 w-[1.5px] h-[15px] ml-2'
- )}
- />
- </motion.div>
- </Reorder.Item>
- )
-}
diff --git a/flowsint-app/src/stores/node-display-settings.ts b/flowsint-app/src/stores/node-display-settings.ts
index 8d4cb9ee..920ac798 100644
--- a/flowsint-app/src/stores/node-display-settings.ts
+++ b/flowsint-app/src/stores/node-display-settings.ts
@@ -56,6 +56,7 @@ export type ItemType =
| 'affiliation'
| 'phrase'
+
export const ITEM_TYPES: ItemType[] = [
'individual',
'phone',
@@ -281,6 +282,39 @@ const DEFAULT_SIZES: Record<ItemType, number> = {
phrase: 10 // Small
}
+const hslToHex = (h: number, s: number, l: number): string => {
+ const s1 = s / 100
+ const l1 = l / 100
+ const c = (1 - Math.abs(2 * l1 - 1)) * s1
+ const hh = h / 60
+ const x = c * (1 - Math.abs((hh % 2) - 1))
+ let r1 = 0, g1 = 0, b1 = 0
+ if (hh >= 0 && hh < 1) { r1 = c; g1 = x; b1 = 0 }
+ else if (hh >= 1 && hh < 2) { r1 = x; g1 = c; b1 = 0 }
+ else if (hh >= 2 && hh < 3) { r1 = 0; g1 = c; b1 = x }
+ else if (hh >= 3 && hh < 4) { r1 = 0; g1 = x; b1 = c }
+ else if (hh >= 4 && hh < 5) { r1 = x; g1 = 0; b1 = c }
+ else { r1 = c; g1 = 0; b1 = x }
+ const m = l1 - c / 2
+ const r = Math.round((r1 + m) * 255)
+ const g = Math.round((g1 + m) * 255)
+ const b = Math.round((b1 + m) * 255)
+ const toHex = (v: number) => v.toString(16).padStart(2, '0')
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`
+}
+
+const randomizeColors = (colors: Record<ItemType, string>): Record<ItemType, string> => {
+ const next: Record<ItemType, string> = { ...colors }
+ ITEM_TYPES.forEach((t) => {
+ // Simple, slightly vibrant but not neon
+ const h = Math.floor(Math.random() * 360)
+ const s = Math.floor(45 + Math.random() * 15) // 45% - 60%
+ const l = Math.floor(65 + Math.random() * 10) // 65% - 75%
+ next[t] = hslToHex(h, s, l)
+ })
+ return next
+}
+
interface NodesDisplaySettingsState {
colors: Record<ItemType, string>
icons: Record<ItemType, string>
@@ -288,6 +322,7 @@ interface NodesDisplaySettingsState {
setColor: (itemType: ItemType, color: string) => void
setIcon: (itemType: ItemType, iconPath: string) => void
resetColors: () => void
+ randomizeColors: () => void
resetIcons: () => void
resetAll: () => void
getIcon: (itemType: ItemType) => string
@@ -316,6 +351,7 @@ export const useNodesDisplaySettings = create<NodesDisplaySettingsState>()(
})),
resetColors: () => set({ colors: { ...DEFAULT_COLORS } }),
resetIcons: () => set({ icons: { ...DEFAULT_ICONS } }),
+ randomizeColors: () => set({ colors: randomizeColors(get().colors) }),
resetAll: () =>
set({
colors: { ...DEFAULT_COLORS },