cetz icon indicating copy to clipboard operation
cetz copied to clipboard

Improve dashed arrows

Open dscso opened this issue 2 years ago • 4 comments

maybe provide a simpler way to create dashed arrows than like that

line((0, 0), (0, 1), stroke: (thickness: .5pt, dash: "dashed"), mark: (end: ">", fill: black, stroke:black))

image Intuitive way generates this:

line((0, 0), (0, 1), stroke: (thickness: .5pt, dash: "dashed"), mark: (end: ">"))

image

dscso avatar Dec 11 '23 10:12 dscso

This is working as intended. Any style that is auto copies the value of its nearest parent (or at least should in 0.1.2, definitely in 0.2). In this case the mark's stroke is auto so it copies the line's dashed stroke.

If you're using dashed lines a lot you can use set-style:

set-style(mark: (fill: black, stroke: black))

or store the dictionary and use the spreading operator .. to unpack it into the elements you want with the style.

fenjalien avatar Dec 11 '23 15:12 fenjalien

Mark could have a default style like (paint: auto, dash: "solid", ...), which would disable inheriting the dash pattern by default.

johannes-wolf avatar Dec 11 '23 23:12 johannes-wolf

I also see why it is implemented as it is @fenjalien, I just noticed that this might be a hustle when drawing images with the library as I did. I used the spreading operator to do something like that:

#let double_arrow = (mark : (end: ">", start: ">"))
#let single_arrow = (mark : (end: ">"))
#let dashed_arrow = (stroke: (dash: "dashed", thickness: .5pt), mark: (stroke: black, end: ">"))
...

and then

line("manager.west", "tcp.east", ..dashed_arrow, name: "manager_tcp")

and I thought this might be a bit verbose and would create problems if I wanted to use a dashed double arrow... Therefore I'd prefere the solution of @johannes-wolf I think this would fix the issue. Is there a simpler way to do this?

dscso avatar Dec 12 '23 10:12 dscso

There is a style bug in 0.1.2, but something like set-style(mark: (stroke: (dash: "solid", paint: auto))) should work. The problem on 0.1.2 is, that the paint won't get inherited. If you are using the same color for all your marks it should work though.

#canvas(length: 1cm, {
  import draw: *

  set-style(line: (mark: (stroke: (dash: "solid", paint: black))))
  line((0,0), (5,0), mark: (end: ">"), stroke: (dash: "dotted"))
})

If you are using 0.2.0 the example above should work fine, even if you change the line color.

johannes-wolf avatar Dec 12 '23 15:12 johannes-wolf

I think this is solved as we can't reproduce this in 0.2.2, we also don't remember what the problem was or when we fixed it :)

fenjalien avatar Aug 07 '24 18:08 fenjalien