Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback when starting a new drawing #79

Closed
edemaine opened this issue Aug 1, 2022 · 1 comment
Closed

Callback when starting a new drawing #79

edemaine opened this issue Aug 1, 2022 · 1 comment

Comments

@edemaine
Copy link
Owner

edemaine commented Aug 1, 2022

It would be useful to be able to specify a callback function that gets called when starting on a new drawing file. For example:

state = null  # global variable
export onNewDrawing = -> state = []  # new proposal
export default -> ...sometimes modify state to carry data to future cells...

This could also be used as a way to (manually) implement symbol aliases (#68) within a drawing file.

Note that an alternative/workaround right now is to add data to the Context object. This is shared within each drawing but no more.

Another application: preprocessing the drawing. This is arguably a better time to modify a drawing than #69. Maybe even allow returning some global content to draw like #81? But maybe makes more sense to do such global drawing after the layout.

# Example 1: compute
export beforeDrawing = (drawing) ->
  for row, i in drawing.keys
    for char, j in row
      # do some computation / walking through the drawing
      # to detect things that will be used later
  # maybe return content to draw?

# Example 2: configuration in first row of drawing
export beforeDrawing = (drawing) ->
  firstRow = drawing.keys.shift() # remove first row from drawing!
  # set some settings based on firstRow

For symmetry with #81, could maybe be called beforeDrawing.

Could even modify keys to be non-strings (e.g. objects), as this happens after coercion to String.

@edemaine
Copy link
Owner Author

I ended up implementing this as an API call svgtiler.beforeRender, so you can add multiple callbacks if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant