SVG Properties

From Mea Wiki
Revision as of 11:05, 6 April 2017 by TeeHiet (talk | contribs) (306989)
Jump to navigation Jump to search

An SVG presentation object can be used to draw svg images that scale with the panel size.

SVG Tag Parameters

All the SVG code needs to reside inside a single svg tag. The SVG needs to have the following parameters:

  • viewBox: used for resizing to work. See viewBox w3c documentation
  • xmlns: used by some browsers to show content properly.
  • xmlns:svg: used by some browsers to show content properly.

In addition, the preserveAspectRatio parameter can be used to fine-tune the appearance. See preserveAspectRatio w3c documentation

Defining Actions for the SVG

The SVG code can include embedded actions that are triggered by the SVG events, such as clicking the SVG. The actions are embedded by defining them inside the SVG tag as follows:

<svg <SVG event attribute name>=<#action name="actionname" escaping="escapingtype"></svg>

Where:

Context Variables in SVG Code

It's possible to use context variables in the SVG code definition. To do this, write the context variable reference as "{#variablename}" (without the quotes). It's even possible to put the whole SVG code into a context variable, and just use the context variable reference in the SVG code.

Example

The following example draws a simple circle. It uses the "color" context variable for setting the color of the circle. If there is no value for the context variable, the circle will be black by default. In addition, the SVG presentation object will display as text what is defined as the value for the "texthere" context variable.

<svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
    <circle fill="{#color}" cx="100" cy="100" r="100"/>
<text x="85" y="100" fill="white">{#texthere}</text>
</svg>

Template:MDBTutorialAddSVG