We help IT Professionals succeed at work.

SVG Logic Statements

SDKCompany
SDKCompany asked
on
This may seem like a silly question, but I can't seem to find anything on it.  Is there a way to perform logic statements in svg coding such as if-then-else or case statements?
Comment
Watch Question

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
Can you explain what you want to do?
SVG is an XML application to represent (express) Vector Graphics.
Interaction is usually achieved using JavaScript.
I would like to understand your usecase to understand what you are really looking for

Author

Commented:
Sure.  The gist of what I am trying to accomplish is that if a user clicks on hotspot 1, show certain elements, if a user clicks on hotspot 2, show other elements , else hide all elements.  I can accomplish this with numerous lines of code using onclick in each situation and hiding some elements while showing others, but I was hoping to be able to condense the code by using a if-then or case statement.  I just am not positive they exist.
Information Architect
Top Expert 2006
Commented:
Nothing of that kind in SVG I am afraid (at least not that I know of)

But it sounds as if you could consider one of two approaches
- group or layer the elements that need to be shown and make an entire layer visible (or not) depending on user click
you can auto generate the SVG from a core SVG file that drives this, so you could even introduce duplicates in the SVG for elements that belong to two layers
- generate the SVG on the fly when the use clicks something. This generatiuon could be initiated by an XSLT.
Then the code is in the XSLT, gathered together, rather than dispersed over some onclick responses

But this is just wild guessing not kowing anything about the real context
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
layer maybe is a bad name for SVG because the only known concept is a "group": <svg:g>
but the concept is teh same.
And if I think about it, actually with a <svg:g> you have your cases