0

The Figure is made of multiple figures (all SVGFigure). I want the parent figure to have a button that change its state so it is rendered simplified (hiding most sub-figures and connectors)

What's the best way to achieve this?

Zerzio
  • 237
  • 3
  • 11
  • I don't know if important for the answer but I'm refactoring code by using VectorFigure in place of SVGFigure. – Zerzio Jul 15 '12 at 09:28

1 Answers1

0

I am not 100% sure if this is what you are looking for, but in my interpretation of the question:

I think you could add classnames to the figures that should not display in a certain state. With for example this pseudo HTML:

<input id="toggleButton" type="button">Toggle</input>
<svg>
    <shape1 class="complexOnly">
    <shape2 class="complexOnly">
    <shape3>
</svg>

And with the following JavaScript, appending an eventlistener for the button to toggle the state:

document.getElementById( "toggleButton" ).addEventListener("click", toggleSVGstate, false );
function toggleSVGstate() {
    this.classList.toggle( "simpleState" );
}

And with the CSS, that only applies to a certain state:

#toggleButton.simpleState>.complexOnly {
    display: none; /* Or visibility: hidden */
}

This means that the elements with the complexOnly class only show when the toggleButton is not in the simple-state (they hide in simple state). Note that the classList.toggle() is not fully crossbrowser, but you could find a crossbrowser one, as I'm simply offering the way to go/think.

EricG
  • 3,788
  • 1
  • 23
  • 34
  • Thanks for the trick. Now that I'm using a VectorFigure I should have a look into RaphaelJS for something similar. However I believe I would have more control by implementing the 'repaint' method with a flag on the object. – Zerzio Jul 15 '12 at 17:27