Difference between revisions of "Canyon Map/Test"
From B.E.R.T. Wiki
| Line 2: | Line 2: | ||
a test to see if we can get dynamic SVG to execute in a page. | a test to see if we can get dynamic SVG to execute in a page. | ||
| − | Above is a | + | Above is a SVG file reference |
| − | + | ----- | |
| + | here is raw svg of same | ||
<html> | <html> | ||
| − | + | <body> | |
| − | <script> | + | <object> |
| + | <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" onload="Init(evt)"> | ||
| + | <title>Hiding and Showing Elements</title> | ||
| + | |||
| + | <desc> | ||
| + | A demonstration of the differences in approach to hiding an element or group of elements in SVG, using the display, visibility, and opacity style properties. | ||
| + | Written by Doug Schepers [[email protected]], September 2003. | ||
| + | </desc> | ||
| + | |||
| + | <script type="text/ecmascript"><![CDATA[ | ||
| + | var SVGDocument = null; | ||
| + | var SVGRoot = null; | ||
| + | |||
| + | function Init(evt) | ||
| + | { | ||
| + | SVGDocument = evt.target.ownerDocument; | ||
| + | SVGRoot = SVGDocument.documentElement; | ||
| + | |||
| + | } | ||
| + | |||
| + | function ToggleDisplay(evt, targetId) | ||
| + | { | ||
| + | var newTarget = evt.target; | ||
| + | if (targetId) | ||
| + | { | ||
| + | newTarget = SVGDocument.getElementById(targetId); | ||
| + | } | ||
| + | var newValue = newTarget.getAttributeNS(null, 'display') | ||
| − | + | if ('none' != newValue) | |
| − | + | { | |
| − | + | newValue = 'none'; | |
| − | + | } | |
| − | + | else | |
| − | + | { | |
| − | + | newValue = 'inline'; | |
| + | } | ||
| + | newTarget.setAttributeNS(null, 'display', newValue); | ||
| − | + | if (targetId) | |
| − | + | { | |
| − | + | SVGDocument.getElementById(targetId + 'Exception').setAttributeNS(null, 'display', 'inline'); | |
| − | + | } | |
| − | + | } | |
| − | |||
| − | + | function ToggleVisibilty(evt, targetId) | |
| + | { | ||
| + | var newTarget = evt.target; | ||
| + | if (targetId) | ||
| + | { | ||
| + | newTarget = SVGDocument.getElementById(targetId); | ||
| + | } | ||
| + | var newValue = newTarget.getAttributeNS(null, 'visibility') | ||
| − | + | if ('hidden' != newValue) | |
| − | + | { | |
| − | + | newValue = 'hidden'; | |
| − | + | } | |
| − | + | else | |
| + | { | ||
| + | newValue = 'visible'; | ||
| + | } | ||
| + | newTarget.setAttributeNS(null, 'visibility', newValue); | ||
| − | + | if (targetId) | |
| − | + | { | |
| − | + | SVGDocument.getElementById(targetId + 'Exception').setAttributeNS(null, 'visibility', 'visible'); | |
| − | + | } | |
| + | } | ||
| − | + | function ToggleOpacity(evt, targetId) | |
| + | { | ||
| + | var newTarget = evt.target; | ||
| + | if (targetId) | ||
| + | { | ||
| + | newTarget = SVGDocument.getElementById(targetId); | ||
| + | } | ||
| + | var newValue = newTarget.getAttributeNS(null, 'opacity') | ||
| + | |||
| + | if ('0' != newValue) | ||
| + | { | ||
| + | newValue = '0'; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | newValue = '1'; | ||
| + | } | ||
| + | newTarget.setAttributeNS(null, 'opacity', newValue); | ||
| + | |||
| + | if (targetId) | ||
| + | { | ||
| + | SVGDocument.getElementById(targetId + 'Exception').setAttributeNS(null, 'opacity', '1'); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | ]]></script> | ||
| + | <circle cx="100" cy="25" r="20" fill="orange" onclick="ToggleDisplay(evt)" display="none"/> | ||
| + | <text x="100" y="60" font-size="15px" text-anchor="middle">Display</text> | ||
| + | |||
| + | <circle cx="160" cy="25" r="20" fill="red" onclick="ToggleVisibilty(evt)" visibility="hidden"/> | ||
| + | <text x="160" y="60" font-size="15px" text-anchor="middle">Visibilty</text> | ||
| + | |||
| + | <circle cx="220" cy="25" r="20" fill="blue" onclick="ToggleOpacity(evt)" opacity="1"/> | ||
| + | <text x="220" y="60" font-size="15px" text-anchor="middle">Opacity</text> | ||
| + | |||
| + | <text x="10" y="80" font-size="17px"> | ||
| + | <tspan dx="1em" dy="1em"> | ||
| + | As you can see, by clicking each circle above, | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | once you toggle 'visibility' or 'display', you can't | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | change it back, because it no longer responds to | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | click events; setting 'opacity' to 0 still allows | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | you to target it. | ||
| + | </tspan> | ||
| + | <tspan x="10" dx="1em" dy="1.5em"> | ||
| + | However, 'opacity' is the most computationally | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | expensive of the three, followed by 'visibility'; | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | 'display: none' is the cheapest, because it simply | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | does not render at all. | ||
| + | </tspan> | ||
| + | <tspan x="10" dx="1em" dy="1.5em"> | ||
| + | If you are trying to hide an entire group, except | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | for one particular member of that group, use | ||
| + | </tspan> | ||
| + | <tspan x="10" dy="1em"> | ||
| + | 'visibility' as it is overrideable in inheritance. | ||
| + | </tspan> | ||
| + | </text> | ||
| + | |||
| + | <g id="DisplayGroup" onclick='ToggleDisplay(evt, "DisplayGroup")' display="none"> | ||
| + | <circle cx="100" cy="335" r="20" fill="orange"/> | ||
| + | <circle id="DisplayGroupException" cx="100" cy="335" r="5" fill="lime" display="inline"/> | ||
| + | </g> | ||
| + | <text x="100" y="370" font-size="15px" text-anchor="middle">Display</text> | ||
| + | |||
| + | <g id="VisibiltyGroup" onclick='ToggleVisibilty(evt, "VisibiltyGroup")' visibility="visible"> | ||
| + | <circle cx="160" cy="335" r="20" fill="red"/> | ||
| + | <circle id="VisibiltyGroupException" cx="160" cy="335" r="5" fill="lime" visibilty="visible" visibility="visible"/> | ||
| + | </g> | ||
| + | <text x="160" y="370" font-size="15px" text-anchor="middle">Visibilty</text> | ||
| + | |||
| + | <g id="OpacityGroup" onclick='ToggleOpacity(evt, "OpacityGroup")' opacity="1"> | ||
| + | <circle cx="220" cy="335" r="20" fill="blue"/> | ||
| + | <circle id="OpacityGroupException" cx="220" cy="335" r="5" fill="lime" opacity="1"/> | ||
| + | </g> | ||
| + | <text x="220" y="370" font-size="15px" text-anchor="middle">Opacity</text> | ||
| + | |||
| + | </svg> | ||
| + | </object> | ||
| + | </body> | ||
</html> | </html> | ||
| + | |||
| + | |||
| + | ---- | ||
| + | below ( view source ) is raw html | ||