-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
[hiccup-svg] Add pattern to hiccup-svg #332
Comments
I digged a bit more into the tooling of hiccup. Got a hang on vite and building the tools. But I realised it is already possible to use pattern as a generic hiccup that can be transduced:
One thing I observed and which confused me, is the api for creating i.e. a circle.
Hiccup-svg function creates hiccup-svg, which will be converted to hiccup as far as I understood from the code. The reason why I went this way, is the missing parsing of hiccup within The alternative way would be to mix with hiccup-svg, and map each geom
|
Hi @dennemark - do you wanna create a PR for the pattern function above? Would be a useful addition indeed (though I've rarely used SVG patterns myself so far). Thank you! As for the differences between the different hiccup flavors for defining shape elements. The issue with SVG is that all attribute values are being stringified and therefore cause a serious perf hit, esp. for shapes with larger data values, e.g. paths, polygons etc. To avoid that hit and be more flexible in terms of transforming hiccup to other output formats, the geom package is generating hiccup for all supported shapes in the more "raw" (i.e. non-stringified) format also used by the hiccup-canvas package. This allows for much faster & better processing/drawing of shapes using the HTML canvas API. But I also always considered hiccup as a more general intermediate format for encoding any hierarchical data (outside any HTML/SVG specifics) and this is also how you should understand it in this case... The import { asSVG, svgDoc, circle } from "@thi.ng/geom";
asSvg(svgDoc({}, circle(100, { fill: [1,0,0] }))) This does the following: compute view box (optional), doc dimensions (optional), convert colors to CSS, call <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200" viewBox="-100 -100 200 200"><circle fill="#ff0000" cx="0" cy="0" r="100"/></svg> This approach sadly won't work if you're going to use SVG specific additions like patterns, |
Hi,
I haven´t tested it yet, but it should be possible to add patterns to svgs via the attached code.
I hope this convert function makes sense:
The text was updated successfully, but these errors were encountered: