edemaine / svgtiler

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

Combining mappings #83

Closed edemaine closed 2 years ago

edemaine commented 2 years ago

Currently, symbols defined by a later mapping file override symbols defined in earlier mapping files. I think this behavior is reasonable and intuitive as a default, but #33 makes me wonder about alternative approaches for overlays/underlays. For example:

export combine =  # add rectangle underlay to x/o symbols
  x: <rect z-index="-10" fill="black"/>
  o: <rect z-index="-10" fill="gray"/>
export combine =  # add checkerboard underlay to all symbols
  -> <rect z-index="-10" fill={if @i + @j % 2 == 0 then "gray" else "black"}/>

To implement this, we could have a separate CombineMapping class, and Mappings would check all CombineMappings (and treat them like added <symbol>s at the end), but use the current behavior for regular Mappings. I wonder if the provided context should also specify the "main" <symbol> (in particular its width and height) for these mappings.

Alternatively, we could define combination to be the default behavior....


With #33 complete, we could combine two known mappings by wrapping them in an array. Perhaps we need an svgtiler.require to load the mapping defined by another file (.txt or .js or whatever) as a Mapping, and then someone wanting to combine could wrap them in an array. For example:

export default [
  svgtiler.require './topLayer.txt'
  svgtiler.require './bottomLayer.coffee'
]
edemaine commented 2 years ago

With the addition of svgtiler.require, combining two existing mapping files in sequence (as in command line) or parallel (as in this issue) is now easy: