Skip to content

Drawing Pictures with SVG Information

Info

New in Atfinity 18.

An SVG information draws a picture from a template you write in its Jinja Template field. The template is an SVG document with Jinja in it, the same Jinja an ADX document uses, and Atfinity renders it for each instance where a rule requires the information.

Read the values

self is the instance the information belongs to, read as an instance is read in a document: self.first_name prints a value and self.translate('nationality') prints it translated. CASE holds the case meta information, and nothing else of the case can be read. A relationship or a structure is looped over, and each item reads its own values:

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="{{ 20 + self.is_related_to|length * 24 }}">
  {% for relative in self.is_related_to %}
  <text x="10" y="{{ 30 + loop.index0 * 24 }}">{{ relative.first_name }} {{ relative.last_name }}</text>
  {% endfor %}
</svg>

Unlike in a document, rich text prints as plain text.

TENANT.colors holds the colors set under Customization, as hex values such as #051D76, so a picture can follow the branding:

<svg xmlns="http://www.w3.org/2000/svg" width="120" height="40">
  <rect width="120" height="40" rx="8" fill="{{ TENANT.colors.app_main }}"/>
  <text x="60" y="26" text-anchor="middle" fill="{{ TENANT.colors.app_menu }}">{{ self.last_name }}</text>
</svg>
Name Setting
app_main Appearance, Colors: Main color
app_menu Appearance, Colors: Menu
login_background Appearance, Login: Background color
euw_main Wizard templates, Appearance: Main color
euw_navigation Wizard templates, Appearance: Navigation color
euw_sheet Wizard templates, Appearance: Sheet color
euw_progress_bar Wizard templates, Appearance: Progress bar
euw_progress_bar_background Wizard templates, Appearance: Progress bar background
euw_background Wizard templates, Appearance: Background color

TENANT.name prints the name of the tenant.

TENANT.logos holds the logos uploaded under Customization. A logo can only be shown as the whole href of an image, whose width and height are numbers of pixels, such as 120 or 120px. Printed anywhere else, in text, a title, a color or a size, Put Live rejects the template. The logo is fitted inside them without being stretched, so preserveAspectRatio is not allowed on the image. A tenant without that logo shows nothing, so the image is best wrapped in {% if %}:

{% if TENANT.logos.app %}<image href="{{ TENANT.logos.app }}" width="120" height="40"/>{% endif %}
Name Setting
app Appearance, Logos: Horizontal logo
login Appearance, Login: Logo
euw Wizard templates, Appearance: EUW logo
email Emails, Email appearance: Email logo

The picture keeps each logo as an image of at most 512 pixels a side, so an SVG logo blurs when it is shown larger. A logo with transparent parts is kept as a PNG, and any other logo as a JPEG, which keeps a photo-like logo small but can soften the edges of a flat one. A photo is turned upright as the camera recorded it. A logo that cannot be read, or that has more than 25 million pixels, shows nothing.

The picture is drawn once, so it shows the same colors and logos in the case, the End User Wizard and a document. After a change under Customization, a picture keeps the old ones until the rule engine runs on its case again. A draft case draws it with the draft colors and logos.

The width and height of the svg root are the size the picture is shown at. A template that prints nothing for an instance, for example one wrapped in {% if %}, shows nothing at all.

What a template cannot contain

A template may only draw. Shapes, text, groups, gradients, patterns, masks and markers are allowed, with the attributes that style and position them. Anything that could run, load or embed something is not: scripts, event handlers such as onclick, images other than a tenant logo, embedded HTML, data: URIs, and links or url(...) pointing anywhere but an id inside the same picture. Put Live names each element, attribute or Jinja tag it refuses, so the error tells you what to remove.

Three restrictions are less obvious from the error alone:

  • Print a value as text or into an attribute such as fill, never into style or into the name of an element or attribute.
  • Write comments as Jinja comments, {# ... #}, since XML comments are refused.
  • Print a macro directly between elements, as in {{ bar(3) }}, rather than into an attribute or a variable.

Make it appear in the case

Place the information on a tab where the picture belongs, and require it with a rule whose action is Require Information, for example p.risk_gauge on p is Person. Without such a rule, or a document that uses it, the picture is never drawn. It is redrawn whenever the rule engine runs on the case.

If drawing fails for an instance, for example because a calculation meets a missing value, the field shows "Error rendering field" and the rest of the tab is unaffected.

Show it in a document

A PDF document shows an SVG information in an INF (SVG) box. A picture is never enlarged: it keeps the size the template declares and is only scaled down when it is too large for the box, or, in a smart document, for the page between the margins. With Keep Aspect Ratio switched off on the information, only the sides that are too large are scaled down.

An ADX document passes the information to the informationSvg attribute of an image:

<image informationSvg="{{ p.risk_gauge }}" width="4cm" height="2cm"/>

Printed anywhere else in the template, the information is its SVG markup as text.

A document with "Create missing values" set to yes requires the information too, so the picture is drawn for its instances without a rule. A document draws nothing where the information has no picture.

Before you put it live

Put Live rejects a template that is not valid Jinja or does not produce valid SVG, and names the line. It also rejects:

  • A template that reads an information the ontology does not have, or a file or SVG information.
  • A template that prints a relationship or a structure itself rather than one of its values.
  • A template that reads TENANT other than by fixed names, such as TENANT.colors.app_main, or that assigns it.
  • An empty template, or a default value on the information.

An attribute that has no effect on its element, such as x on a circle, is only a warning, since the browser ignores it.