Fix dashes on arrows

This commit is contained in:
Steve Ruiz 2021-10-10 11:55:52 +01:00
parent a9db0dbe23
commit e695cbb07f
2 changed files with 11 additions and 5 deletions

View file

@ -111,7 +111,8 @@ export function getPerfectDashProps(
length: number,
strokeWidth: number,
style: DashStyle,
snap = 1
snap = 1,
outset = true
): {
strokeDasharray: string
strokeDashoffset: string
@ -128,7 +129,7 @@ export function getPerfectDashProps(
} else if (style === DashStyle.Dashed) {
dashLength = strokeWidth * 2
ratio = 1
strokeDashoffset = (dashLength / 2).toString()
strokeDashoffset = outset ? (dashLength / 2).toString() : '0'
} else {
dashLength = strokeWidth / 100
ratio = 100
@ -141,7 +142,10 @@ export function getPerfectDashProps(
dashes = Math.max(dashes, 4)
const gapLength = Math.max(strokeWidth * 2, (length - dashes * dashLength) / dashes)
const gapLength = Math.max(
dashLength,
(length - dashes * dashLength) / (outset ? dashes : dashes - 1)
)
return {
strokeDasharray: [dashLength, gapLength].join(' '),

View file

@ -107,7 +107,8 @@ export const Arrow = new ShapeUtil<ArrowShape, SVGSVGElement, TLDrawMeta>(() =>
arrowDist,
strokeWidth * 1.618,
shape.style.dash,
2
2,
false
)
if (decorations.start) {
@ -158,7 +159,8 @@ export const Arrow = new ShapeUtil<ArrowShape, SVGSVGElement, TLDrawMeta>(() =>
Math.abs(length),
sw,
shape.style.dash,
2
2,
false
)
if (decorations.start) {