Skip to content

Commit

Permalink
feat: #comment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Oct 1, 2024
1 parent d0ac9ec commit bfb3a6e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Node,
Edge,
Connection,
ConnectionLineType,
ConnectionLineComponent,
} from '@xyflow/react'
import '@xyflow/react/dist/style.css'
import './reactflow-dark.css'
Expand All @@ -32,6 +34,39 @@ const nodeTypes = {
customNode: CustomNode,
}

const CustomConnectionLine: ConnectionLineComponent = ({
fromX,
fromY,
toX,
toY,
connectionLineStyle,
}: {
fromX: number
fromY: number
toX: number
toY: number
connectionLineStyle?: React.CSSProperties
}) => {
// Calculate midpoint
const midX = (fromX + toX) / 2
const midY = (fromY + toY) / 2

// Create a curved path
const path = `M${fromX},${fromY} Q${midX},${fromY} ${midX},${midY} T${toX},${toY}`

return (
<g>
<path
fill="none"
stroke={connectionLineStyle?.stroke || '#999'}
strokeWidth={connectionLineStyle?.strokeWidth || 2}
className="animated"
d={path}
/>
</g>
)
}

function AudioDeviceArrangerApp() {
const {
devices,
Expand Down Expand Up @@ -212,6 +247,8 @@ function AudioDeviceArrangerApp() {
fitView
fitViewOptions={{ padding: 0.2, minZoom: 0.5, maxZoom: 2 }}
className={isDarkMode ? 'dark-flow' : ''}
connectionLineType={ConnectionLineType.SmoothStep}
connectionLineComponent={CustomConnectionLine}
>
<Controls className={isDarkMode ? 'dark-controls' : ''} />
<MiniMap className={isDarkMode ? 'dark-minimap' : ''} />
Expand Down
35 changes: 35 additions & 0 deletions src/components/CustomConnectionLine.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import {
ConnectionLineComponentProps,
getBezierPath,
Position,
} from '@xyflow/react'

const CustomConnectionLine: React.FC<ConnectionLineComponentProps> = ({
fromX,
fromY,
toX,
toY,
connectionLineStyle,
}) => {
const [edgePath] = getBezierPath({
sourceX: fromX,
sourceY: fromY,
sourcePosition: 'bottom' as Position,
targetX: toX,
targetY: toY,
targetPosition: 'top' as Position,
})

return (
<path
fill="none"
stroke={connectionLineStyle?.stroke || '#999'}
strokeWidth={connectionLineStyle?.strokeWidth || 2}
className="animated"
d={edgePath}
/>
)
}

export default CustomConnectionLine

0 comments on commit bfb3a6e

Please sign in to comment.