edemaine / svgtiler

Tool for drawing diagrams on a grid, combining grids of SVGs into a big SVG figure
MIT License
61 stars 6 forks source link

Metadata support #94

Closed edemaine closed 2 years ago

edemaine commented 2 years ago

SVG supports several metadata tags that can appear at the top level: <title>, <desc>, <metadata>, and I guess <style> and <script>.

svgtiler.afterRender is a decent way to add these:

svgtiler.afterRender -> <desc>Made with SVG Tiler!</desc>
svgtiler.afterRender ({drawing}) -> <title>{drawing.filename}</title>
svgtiler.afterRender (render) -> <style>...some dynamic style depending on render...</style>

However, currently these get wrapped in <svg> which is probably not ideal.

We can instead call svgtiler.def(...).force(), but this will assign them an id.

I also wonder whether it makes sense to add an svgtiler.metadata callback (similar to svgtiler.def) that just takes the tag as an argument, and adds that content without any wrapper or id. It could still be called within svgtiler.afterRender (in which case it gets added directly to the render), or not for static content (like the <desc> above, in which case it gets attached to the mapping). Alternatively, if we restrict to this being called in beforeRender/afterRender/tile (not at top level of mapping), then it could be a method of the render object, e.g., svgtiler.currentRender().add().

Related, I wonder whether a svgtiler.afterRender callback should be calling an svgtiler.overlay() or render.add() function instead of just returning VDOM content for that overlay. This would also allow calling it in svgtiler.beforeRender. (We could also support svgtiler.beforeRender returning VDOM content, but it's a bit annoying in CoffeeScript to make sure you don't accidentally return something... though arguably that's an issue with CoffeeScript, not SVG Tiler.) Then all render modifications would be naturally wrapped in svgtiler.{def,metadata,overlay}.