|
Creating Dynamic Vector Images |
Top Previous Next |
|
AggreGate platform provides an elegant way to allow static SVG images became alive and interactive. You can add custom parameters to an image. When SVG image with custom parameters is loaded into a Vector Drawing component, parameters are shown as component properties in a special tab of the GUI Builder's Properties Editor. Modifying them can dynamically alter various drawing's aspects: color, lines thickness, rotation angle, tank levels, turn animation on/off etc. Custom parameters is declared by special tags in SVG document. They define rules of changing SVG document elements when certain parameter gets a new value. The vector drawing is dynamically updated on every SVG document change. XML namespace All custom tags use a separate namespace: agg. So it must be declared in SVG document header to keep the document well formed: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:agg="http://www.example.com" ... > XML tags The structure of custom parameters declaration is the following:
agg:paramS This is simply a root container for all custom declarations. Only a single <agg:params> tag must present in a document. agg:PARAM It has attributes that:
Attributes used to define component property:
Level type implies that component property is an Integer number limited by a [0..100] range. Every property value within this range is proportionally translated to [min..max] range when applying to a document. Min and max numbers are defined by appropriate parameter attributes. Note, that min value can be greater then max value. State type is for applying fixed modifications to a document (see AGG:STATES).
Attributes that define SVG modification rules:
States are used to apply some predefined modifications (states) to a document. For example it can be used to turn on/off a fan rotation. State parameter is non scalar and displayed in Properties Editor as a combo box with predefined options. It is used to set multiple values to multiple DOM elements when the state is applied. The idea of defining a state is simple: create an <agg:param> with "state" type and enumerate states within it by <agg:state>. Each <agg:state> tag can have multiple <agg:param/> tags that define how the DOM should change when the state is applied. It has parameters:
Examples Style You can control styling of SVG document elements by modifying their CSS attributes. To change the color for different drawing parts the following parameter declaration can be used: <agg:params> <agg:param name="color" description="Color" type="C" cssAttributes="fill" classes="mainColor"/> </agg:params> When the drawing is loaded in GUI Builder it will have the Color component property. Every time the Color gets a new value the drawing engine will find all document elements where class is mainColor and set a new color value to their fill CSS attribute. This will change the drawing parts color.
Rotation Suppose that a SVG document have an element representing a knob with id knob. Applying a rotation transformation at point (61.542, 61.792) makes the knob to rotate. To create a parameter for rotation to a definite angle you can write the following: <agg:params> <agg:parameter name="angle" description="Angle" type="I" ids="knob" attributes="translation" pattern="rotate({0} 61.542 61.792)"/> </agg:params> This declares a single SVG parameter Angle with Integer type that will be shown as component property. If the parameter is set to 45 then the translation attribute of the knob DOM element will be set to rotate(45 61.542 61.792) and the knob will turn by 45 degrees. Level Let the fluid level in SVG image document of a reactor depends on y attribute value of a <clipPath id="clipPathId"...> tag: when y is 66.9 the reactor is full, when y is 660 the reactor is empty. So, to control the level we must create a parameter with level type: <agg:params> <agg:param name="level" description="Level" type="level" attributes="y" min="660" max="66" ids="clipPathId" forceRepaint="true"/> </agg:params> This parameter creates a component property with Integer type having 0 to 100 limits. Attributes min="660" and max="66" define the range of y attribute. Every time a component property gets a new value it is proportionally translated from [0, 100] range to [600, 66] range and the y attribute of the clipPathId element is set to this translated value. If the Level property of Vector Drawing is set to 0 then the y will be set to 660. If the Level property is set to 50 then the y will be set to 297. If the Level property is set to 100 then the y will be set to 66. The forceRepaint flag is used to completely repaint the drawing on every Level change. Because dynamic clip mask modifications are not supported and you might see unexpected results without repainting the whole image. States To manage drawing states like "the box is opened" or "the switch is turned on", you can use a state parameter. To create a dynamic left-right flip switch for example, you can create an SVG document with two groups of elements. One for the left switch state and another for the right state. Now to control a flip switch state you must control groups visibility. The parameter for switching the state can be defined like this: <agg:params> <agg:param name="state" description="State" type="state"> <agg:state name="left" description="Left"> <agg:param attributes="visibility" ids="switch-left" value="visible"/> <agg:param attributes="visibility" ids="switch-right" value="hidden"/> </agg:state> <agg:state name="right" description="Right"> <agg:param attributes="visibility" ids="switch-left" value="hidden"/> <agg:param attributes="visibility" ids="switch-right" value="visible"/> </agg:state> </agg:param> </agg:params> This defines a State component property with two values: Left and Right. When the State is set to Left then the visibility attribute of the switch-left DOM element gets visible value, and the visibility attribute of the switch-right DOM element gets "hidden" value. When the State is set to Right the switch-left becomes hidden and the switch-right becomes visible. Animation Suppose you have a fan drawing and it animated with: <animateTransform id="rotate" attributeName="transform" attributeType="XML" type="rotate" from="0 45 45" to="360 45 45" begin="indefinite" dur="10s" repeatCount="indefinite"/> To control animation you can define the following state parameter: <agg:params> <agg:param name="state" description="State" type="state"> <agg:state name="on" description="On"> <agg:param animation="play" ids="rotate"/> </agg:state> <agg:state name="off" description="Off"> <agg:param animation="stop" ids="rotate"/> </agg:state> </agg:param> </agg:params> This defines a State component property with two values: On and Off. When it gets the On value then the rotate animation is started. When the value is set to Off the rotate animation is stoped.
|