Skip to content

Commit

Permalink
fix(background): start patterns at 0,0 (#1666)
Browse files Browse the repository at this point in the history
* fix(background): start patterns at 0,0

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

* chore(changeset): add

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

---------

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
  • Loading branch information
bcakmakoglu authored Nov 1, 2024
1 parent a6ec480 commit a48659a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-radios-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/background": patch
---

Start patterns at 0,0
15 changes: 7 additions & 8 deletions packages/background/src/Background.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ const { id: vueFlowId, viewport } = useVueFlow()
const background = computed(() => {
const [gapX, gapY] = Array.isArray(gap) ? gap : [gap, gap]
const scaledGap: [number, number] = [gapX * viewport.value.zoom || 1, gapY * viewport.value.zoom || 1]
const scaledSize = size * viewport.value.zoom
const [offsetX, offsetY]: [number, number] = Array.isArray(offset) ? offset : [offset, offset]
const patternOffset =
variant === BackgroundVariant.Dots
? [scaledSize / offset, scaledSize / offset]
: [scaledGap[0] / offset, scaledGap[1] / offset]
const scaledOffset: [number, number] = [
offsetX * viewport.value.zoom || 1 + scaledGap[0] / 2,
offsetY * viewport.value.zoom || 1 + scaledGap[1] / 2,
]
return {
scaledGap,
offset: patternOffset,
offset: scaledOffset,
size: scaledSize,
}
})
Expand Down Expand Up @@ -79,7 +78,7 @@ export default {
</template>

<template v-else-if="variant === BackgroundVariant.Dots">
<DotPattern :color="patternColor" :radius="background.size / offset" />
<DotPattern :color="patternColor" :radius="background.size / 2" />
</template>

<svg v-if="bgColor" height="100" width="100">
Expand Down
2 changes: 1 addition & 1 deletion packages/background/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export interface BackgroundProps {
/** Background y-coordinate (offset y) */
y?: number
/** Background offset */
offset?: number
offset?: number | [number, number]
}

0 comments on commit a48659a

Please sign in to comment.