Difference between revisions of "SVG Properties"

From Mea Wiki
Jump to navigation Jump to search
Line 32: Line 32:
 
* '''eventAttributeName''' can be for example '''onclick''', '''ondoubleclick''', '''onmouseover''', '''onmouseout''', '''onmousedown''', '''onmouseup''', '''onmousemove'''. List of all available SVG events: [https://www.w3.org/TR/SVG/interact.html#SVGEvents SVG Event]
 
* '''eventAttributeName''' can be for example '''onclick''', '''ondoubleclick''', '''onmouseover''', '''onmouseout''', '''onmousedown''', '''onmouseup''', '''onmousemove'''. List of all available SVG events: [https://www.w3.org/TR/SVG/interact.html#SVGEvents SVG Event]
 
* '''ActionName''' is defined in the "Define SVG actions" text field similarly as with [[Data_Grid_Properties#Data_Grid_Click_and_Popup_Menu_Events|Data Grid click and popup menu events]].
 
* '''ActionName''' is defined in the "Define SVG actions" text field similarly as with [[Data_Grid_Properties#Data_Grid_Click_and_Popup_Menu_Events|Data Grid click and popup menu events]].
 +
 +
Action tag is used to trigger QPR UI actions. The tag can be used in a JavaScript code of an [[SVG_Properties|SVG presentation object]]. The tag is replaced by a call to a QPR UI's internal JavaScript function which triggers the action. All context variables in the effective context are automatically passed to the triggered action.
 +
 +
Parameters:
 +
* '''name''': Referenced action identifier. This parameter is mandatory.
 +
* '''[action parameters]''' are name-value pairs of assigned action parameters. (will be supported in future)
 +
 +
An error is caused, if the referenced action is not found.
 +
 +
Examples:
 +
* Tag '''<#action name="DrilldownToDetails">''' can be embedded into SVG code as follows: <svg onclick="'''<#action name="DrilldownToDetails">'''">
 +
* Action with parameter assignments: '''<#action name="drilldownToCities" param1="value1" param2="value2">'''
  
 
== Examples ==
 
== Examples ==

Revision as of 15:41, 7 December 2018

SVG presentation objects can be used for graphical drawing that contain e.g. shapes, text and images. SVG drawings scale with the dashboard size.

Security note: SVG presentation objects can embed JavaScript code into the dashboards, which may cause information security issues, because the embedded code is executed when users open the dashboard. Thus the dashboard designer persons need to be trusted. Viewer users are not able to change dashboards and embed JavaScript code into dashboards.

Defining SVG code

Here is a simple SVG code, which draws a black square:

<svg viewBox="0 0 1 1" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <rect x="0" y="0" width="1" height="1" />
</svg>

Following definitions are mandatory in the SVG code for QPR UI:

  • Whole SVG code needs to reside inside a single svg tag, i.e. the code must start with <svg ...> and end with </svg>.
  • SVG tag must have a viewBox attribute, which contains following four numbers separated by spaces: top left x coordinate, top left y coordinate, width, height. Note that SVG's coordinates are not pixels but SVG uses own coordinate system. Note also that the SVG can contain shapes that are outside the defined viewbox area. Usually it's practical to have the top left x and y coordinates set to zero and set the width and height so that there is a suitable granularity for the drawing.
  • SVG tag must have following namespace definitions: xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink". There may also be other namespace definitions if they are needed by SVG elements.

The SVG tag has an optional attribute preserveAspectRatio, which determines how the SVG drawing is scaled when aspect ratios of the SVG's and presentation object's drawing area don't match. It has a default value xMidYMid meet, which is used when the preserveAspectRatio is not defined. The default value means that the aspect ratio is not changed and the SVG is drawn in the middle of the presentation object's area. The value may be none, which means that the aspect ratio is allowed to change freely to fit the SVG to the presentation object's area (usually this is not used when the SVG contains text because the text will then become distorted). More information about preserveAspectRatio attribute: Mozilla MDN.

The SVG tag may also contain width and height attributes but they are overwritten by QPR UI so those attributes don't have any effect.

More information about SVG:

Actions in the SVG presentation object

The SVG code can contain SVG events (such as clicking shapes), which will trigger QPR UI actions. The events are defined in the SVG code as follows:

<tag eventAttributeName=<#action name="ActionName">>

Where:

  • tag can be any tag that can be used in the SVG code, such as svg, g, rect, circle or text.
  • eventAttributeName can be for example onclick, ondoubleclick, onmouseover, onmouseout, onmousedown, onmouseup, onmousemove. List of all available SVG events: SVG Event
  • ActionName is defined in the "Define SVG actions" text field similarly as with Data Grid click and popup menu events.

Action tag is used to trigger QPR UI actions. The tag can be used in a JavaScript code of an SVG presentation object. The tag is replaced by a call to a QPR UI's internal JavaScript function which triggers the action. All context variables in the effective context are automatically passed to the triggered action.

Parameters:

  • name: Referenced action identifier. This parameter is mandatory.
  • [action parameters] are name-value pairs of assigned action parameters. (will be supported in future)

An error is caused, if the referenced action is not found.

Examples:

  • Tag <#action name="DrilldownToDetails"> can be embedded into SVG code as follows: <svg onclick="<#action name="DrilldownToDetails">">
  • Action with parameter assignments: <#action name="drilldownToCities" param1="value1" param2="value2">

Examples

External SVG editors

Instead of editing SVG code as a text, it's possible use an external graphical editor to create SVG drawings. SVG editors:

The SVG code is exported from the external editor and pasted to QPR UI. Check that the SVG code contains the viewBox attribute instead of width and height.

Microsoft PowerPoint presentation can converted to SVG using Inkscape: Export the PowerPoint presentation as a PDF and import the PDF to Inkscape where it can be saved as SVG. Template:MDBTutorialAddSVG