Replies: 2 comments 1 reply
-
Victor only takes your Ruby DSL and converts it element-by-element to SVG. The library does not aim to amend the SVG functionality, just to let you write it with code. |
Beta Was this translation helpful? Give feedback.
-
thanks. drawing by order was not so easy to do in my case (I'm making a very complicated astrology chart). I was confused about where exactly to do the custom sorting, as there are no easy hooks. Does this look like the right idea? module Victor
class SVGBase
alias_method :original_tag, :tag
def tag(name, value = nil, attributes = {}, &block)
if value.is_a?(Hash)
attributes = value
value = nil
end
attributes[:z] = attributes[:z].to_i if attributes.key?(:z)
original_tag(name, value, attributes, &block)
end
alias_method :original_build, :build
def build(&block)
original_build(&block)
sort_by_z_index
end
private
def sort_by_z_index
# ...
end
end
end UPDATE: alternatively, I just searched discovered there is the #use element, which will just duplicate the stuff I want on top. I think that will be simpler! https://www.geeksforgeeks.org/how-to-use-z-index-in-svg-elements/ |
Beta Was this translation helpful? Give feedback.
-
I'd love to be able to have the equivalent of z-index, by using a :z attribute on elements.
Browsers don't support this natively, but the same effect could be done by sorting elements by :z attribute before rendering to string. I took a stab at this with a monkeypatch but was unsuccessful, as the sorting was not as simple as I'd imagined, due to nesting. A possible alternative is parsing the endpoint with Nokogiri, and sorting in that domain before rendering to string.
PS thanks for this cool library, it's really handy!
Beta Was this translation helpful? Give feedback.
All reactions