jneug / typst-finite

Typst-setting finite automata with CeTZ.
MIT License
50 stars 0 forks source link

Styling just the `Start` arrow #4

Open Quantumplation opened 6 months ago

Quantumplation commented 6 months ago

Is it possible to change the label and/or apply a color to just the Start transition?

For example: image

In the first diagram, I've styled the Active state green, but it also applies to the incoming arrow. And in the second diagram, I would like to style Start and the incoming arrow as green, without styling the state.

jneug commented 6 months ago

Right bow it is only possible to change the direction of the arrow and the text.

I will consider expanding this for a future release.

Quantumplation commented 6 months ago

Awesome, thanks! The library is really solid, I've enjoyed it so far!

How do I change the text? i wasn't able to find it in the documentation, but I might just be blind :sweat_smile:

jneug commented 6 months ago

Have a look at the initial argument for #state on page 14. You will habe to draw the automaton manually with #cetz.canvas.

I think you can also pass a dict to the styles key of #automaton with the name of the initial state like this:

styles: (
  "q0": (
    initial: "Start here"
  )
)
jneug commented 6 months ago

Seemed like an easy enough issue, so I added a styling option for initial states in 0.3.1.

You can now do this:

#automaton(
  (
    "Active": ("Done": "Cancel", "Active": ""),
    "Done": ()
  ),
  layout: layout.linear.with(spacing: 3),
  style: (
    "transition": (curve: .5),
    "Active-Active": (curve: 1),
    "Active": (
      stroke: green,
      initial: (
        stroke: black
      )
    )
  )
)

#automaton(
  (
    "Locked": ("Unlockable": "StartTimer"),
    "Unlockable": ("Unlocked": "CancelTimer"),
    "Unlocked": ()
  ),
  layout: layout.linear.with(spacing: 3),
  style: (
    "transition": (curve: .5),
    "Locked": (
      initial: (
        stroke: green
      )
    )
  )
)

You need to get the version from this repository for now, since it is not yet in the package repository.