diff --git a/src/additional-components/Background/index.tsx b/src/additional-components/Background/index.tsx index 86a24a09..685446e6 100644 --- a/src/additional-components/Background/index.tsx +++ b/src/additional-components/Background/index.tsx @@ -21,8 +21,6 @@ const defaultColors = { const Background = memo( ({ variant = BackgroundVariant.Dots, gap = 24, size = 0.5, color, style, className }: BackgroundProps) => { - const width = useStoreState((s) => s.width); - const height = useStoreState((s) => s.height); const [x, y, scale] = useStoreState((s) => s.transform); const bgClasses = cc(['react-flow__background', className]); @@ -32,15 +30,22 @@ const Background = memo( const yOffset = y % scaledGap; const isLines = variant === BackgroundVariant.Lines; const path = isLines - ? createGridLinesPath(width, height, xOffset, yOffset, scaledGap) - : createGridDotsPath(width, height, xOffset, yOffset, scaledGap, size); + ? createGridLinesPath(xOffset, yOffset, scaledGap) + : createGridDotsPath(xOffset, yOffset, scaledGap, size); const fill = isLines ? 'none' : bgColor; const stroke = isLines ? bgColor : 'none'; + const bg = ``; + return ( - - - +
); } ); diff --git a/src/additional-components/Background/style.css b/src/additional-components/Background/style.css index b96234b9..9343180d 100644 --- a/src/additional-components/Background/style.css +++ b/src/additional-components/Background/style.css @@ -2,4 +2,6 @@ position: absolute; top: 0; left: 0; + width: 100%; + height: 100%; } \ No newline at end of file diff --git a/src/additional-components/Background/utils.ts b/src/additional-components/Background/utils.ts index cf938870..c9b33e3a 100644 --- a/src/additional-components/Background/utils.ts +++ b/src/additional-components/Background/utils.ts @@ -1,37 +1,13 @@ -export const createGridLinesPath = ( - width: number, - height: number, - xOffset: number, - yOffset: number, - gap: number -): string => { - const lineCountX = Math.ceil(width / gap) + 1; - const lineCountY = Math.ceil(height / gap) + 1; +export const createGridLinesPath = (xOffset: number, yOffset: number, scaledGap: number): string => { + const x = xOffset < 0 ? scaledGap + xOffset : xOffset; + const y = yOffset < 0 ? scaledGap + yOffset : yOffset; - const xValues = Array.from({ length: lineCountX }, (_, i) => `M${i * gap + xOffset} 0 V${height}`); - const yValues = Array.from({ length: lineCountY }, (_, i) => `M0 ${i * gap + yOffset} H${width}`); - - return [...xValues, ...yValues].join(' '); + return `M${x} 0 V${scaledGap} M0 ${y} H${scaledGap}`; }; -export const createGridDotsPath = ( - width: number, - height: number, - xOffset: number, - yOffset: number, - gap: number, - size: number -): string => { - const lineCountX = Math.ceil(width / gap) + 1; - const lineCountY = Math.ceil(height / gap) + 1; +export const createGridDotsPath = (xOffset: number, yOffset: number, scaledGap: number, size: number): string => { + const x = xOffset < 0 ? scaledGap + xOffset : xOffset; + const y = yOffset < 0 ? scaledGap + yOffset : yOffset; - const values = Array.from({ length: lineCountX }, (_, col) => { - const x = col * gap + xOffset; - return Array.from({ length: lineCountY }, (_, row) => { - const y = row * gap + yOffset; - return `M${x} ${y - size} l${size} ${size} l${-size} ${size} l${-size} ${-size}z`; - }).join(' '); - }); - - return values.join(' '); + return `M${x} ${y - size} l${size} ${size} l${-size} ${size} l${-size} ${-size}z`; };