alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
535 stars 56 forks source link

Support stroke-dasharray #130

Closed edemaine closed 1 year ago

edemaine commented 1 year ago

I'd like to be able to render Segments/Rays/Lines with dashed or dotted patterns. Adding a strokeDashArray option in svg's attrs argument to optionally add a stroke-dasharray would be really easy.

alexbol99 commented 1 year ago

Actually we have this option if we can add css to our page. Look at this notebook: https://observablehq.com/@alexbol99/inversion-in-a-circle That is why I added support only for basic attributes.

edemaine commented 1 year ago

Ah, good point; we could use className. I'd personally still prefer to have direct attribute access so it's easy to configure without CSS and programmatically for each element. (For example, what if every segment wanted a different dash array? Admittedly I don't have a use case for this. 😅) I guess there's a question of where to draw the line (no pun intended), but e.g. stroke-dashoffset has applications with stroke-dasharray, and doesn't make sense with CSS.

An alternative approach would be to just pass all unrecognized properties of attrs on as attributes. Then every attribute is supported. We could still support e.g. strokeWidth and className for backward compatibility, but it would then be possible to use stroke-width and class as alternatives. And the added code would be generic so pretty minimal I think.

Let me know if you'd accept a PR in either direction, and I can work on it.

alexbol99 commented 1 year ago

Support any attribute in svg() attribute parameter objects released in version v1.3.7 See https://observablehq.com/d/76f6be5777ed58a2 for example

alexbol99 commented 1 year ago

Released in version 1.3.7, issue closed