APL VectorGraphic (APL 2023.2)
(This is not the most recent version of APL. Use the Other Versions option to see the documentation for the most recent version of APL)
A VectorGraphic displays a scalable vector graphic image defined in a
package or loaded from a URL. Use the Alexa Vector Graphic (AVG) format to define the graphics.
VectorGraphic requires APL 1.1 or later. Provide an alternate experience for devices running older versions of APL.VectorGraphic component. See Import a Scalable Vector Graphic (SVG)Properties
The VectorGraphic component has the following properties:
- All actionable component properties
- All touchable component properties
- All base component properties
- The
VectorGraphicproperties listed in following table. See the meaning of the columns.
| Property | Type | Default | Styled | Dynamic | Description |
|---|---|---|---|---|---|
|
|
Alignment |
center |
Yes |
Yes |
Alignment of the vector graphic within the component. |
|
|
Array of commands |
[ ] |
No |
No |
Command or commands to run when the source fails to load. |
|
|
Array of commands |
[ ] |
No |
No |
Command or commands to run after the source loads. |
|
|
Scale |
none |
Yes |
Yes |
How the vector graphic will scale up or down within the component. |
|
|
URL or name |
<none> |
No |
Yes |
The URL or direct reference to a vector graphic. |
In addition to these properties, you can pass parameters specific to the AVG object.
When the VectorGraphic is the source or target of an event, the following values are reported in event.source or event.target:
{
// VectorGraphic-specific values
"type": "VectorGraphic",
"url": URL, // The URL of the vector graphic
// General component values
"bind": Map, // Access to component data-binding context
"checked": Boolean, // Checked state
"disabled": Boolean, // Disabled state
"focused": Boolean, // Focused state
"height": Number, // Height of the component, in dp (includes the padding)
"id": ID, // ID of the component
"opacity": Number, // Opacity of the component [0-1]
"pressed": Boolean, // Pressed state
"uid": UID, // Runtime-generated unique ID of the component
"width": Number // Width of the component, in dp (includes the padding)
}
height and width
When source is a URL, the component should also define the width and height property. When they are not defined, they default to 100 pixels.
When source is a reference to a local package or in the graphics property of the document, you can set set height and width to auto. This uses the height and width defined in the vector graphic object.
align
Positions the VectorGraphic within the component. Set to one of values shown in the following table.
| Name | Description |
|---|---|
|
|
Align to the bottom and center horizontally. |
|
|
Align the bottom-left corners |
|
|
Align the bottom-right corners |
|
|
Center horizontally and vertically. |
|
|
Align to the left side and center vertically. |
|
|
Align to the right side and center vertically. |
|
|
Align to the top and center horizontally. |
|
|
Align the top-left corners |
|
|
Align the top-right corners |
onFail
Commands to run when the requested URL source fails to load.
The handler runs one time when the source fails to load. After the handler runs, the component is considered invalid.
Setting a new value to the sources property can trigger the handler again. The onFail handler runs at most one time for any new source value.
The onFail handler doesn't affect the display status of the component and the display status doesn't affect the handler. For example, when the display property for the VectorGraphic component is invisible the component takes up space but doesn't display. The device still attempts to load the graphic and runs the commands in onFail if the graphic source fails to load.
The onMount handler for the component runs regardless of whether onFail runs. The onMount handler runs in this scenario because the component can mount and display before or after the component loads the graphic source.
onFail event handler can run for a VectorGraphic where the source is set to a URL. The onFail handler never runs for a VectorGraphic where the source is set to a graphic named in the graphics property of the document or an imported package.The onFail handler generates an event with the following form.
"event": {
"source": {
"type": "VectorGraphic",
"handler": "Fail",
... // Component source properties
},
"error": STRING, // The reason of failure
"errorCode": Number // Error identifier
}
Refer to Event source for a description of event.source properties.
The onFail event handler runs in fast mode.
onLoad
Commands to run after the requested URL source loads.
Setting a new value to the sources property can trigger the handler again. The onLoad handler runs at most one time for any new source value.
The onLoad handler doesn't affect the display status of the component and the display status doesn't affect the handler. For example, when the display property for the Image component is invisible the component takes up space but doesn't display. The device still attempts to load the graphic and runs the commands in onLoad after the graphic source loads.
The onMount handler for the component runs regardless of whether onLoad runs. The VectorGraphic component can mount and display before or after the component loads the graphic source.
onLoad event handler can run for a VectorGraphic where the source is set to a URL. The onLoad handler never runs for a VectorGraphic where the source is set to a graphic named in the graphics property of the document or an imported package.The event generated in case of a successful load has the following form.
"event": {
"source": {
"type": "VectorGraphic",
"handler": "Load",
... // Component source properties
}
}
Refer to Event source for a description of event.source properties.
The onLoad event handler runs in fast mode.
scale
Scales the vector graphic within the component. Set to one of the following.
| Name | Description |
|---|---|
|
|
Don't scale the graphic. The align property positions the graphic in the bounding box. The portions of the graphic that fall outside of the bounding box are clipped. |
|
|
Scale the graphic non-uniformly so that the width matches the bounding box width and the height matches the bounding box height. |
|
|
Scale the graphic uniformly up or down so that the entire graphic covers the bounding box. The "align" property positions the scaled graphic within the bounding box. |
|
|
Scale the graphic uniformly up or down so that the entire graphic fits within the bounding box. The |
source
Defines the location of the vector graphic data. Set the source to one of the following:
- A name defined in the
graphicsproperty of your document or an imported package. - A URL that points to a vector graphic definition
The following example shows a VectorGraphic with the source set to a dynamic value. When the user clicks the button, the SetValue command updates the GraphicIndex value, which then changes the graphic displayed.
Actionable properties
A VectorGraphic is an actionable component. The component inherits all of the actionable properties.
Because the VectorGraphic component doesn't have intrinsic key handlers, the component receives keyboard focus only when you define at least one of the following handlers:
- Actionable component onFocus
onBlurhandleKeyDownhandleKeyUp- Touchable component
onDown onPress
If none of the handlers are defined, the VectorGraphic never receives keyboard focus.
Touchable properties
A VectorGraphic is a touchable component. The component inherits all of the touchable properties.
For details about the source event generated when the user taps the component, see the properties in Touchable Component Properties. A VectorGraphic component uses the following specific values:
event.source.type = "VectorGraphic"
event.source.value = Boolean // The checked state of the vector graphic
The VectorGraphic component adds an additional viewport property to the event:
"event": {
"viewport": {
"x": Number, // X-position of the event in the viewport (internal drawing units)
"y": Number, // Y-position of the event in the viewport (internal drawing units)
"width": Number, // Width of the viewport (internal drawing units)
"height": Number, // Height of the viewport (internal drawing units)
"inBounds": Boolean, // True if the event is within the viewport bounds
}
}
The AVG displayed inside the bounding box for the VectorGraphic component can be smaller or larger than the VectorGraphic itself:
- Use the
event.viewport.inBoundsproperty to determine whether the event occurred within the transformed bounds of the AVG. - Use the
event.inBoundsproperty to determine whether the event occurred within the bounds of theVectorGraphiccompnent.
Any combination can occur. An event can be within the VectorGraphic component and outside of the AVG, or outside of the VectorGraphic component and inside of the AVG.
AVG object parameters
Alexa Vector Graphic (AVG) objects can accept parameters. You use parameters to pass colors or specific values (such as rotation) into the graphic. The parameter values are passed as normal properties on the VectorGraphic component itself. For example, if you have a graphic that takes fillColor as a parameter, you can render it with:
{
"type": "VectorGraphic",
"source": "iconBattery",
"fillColor": "#ffff00"
}
You can pass both explicit properties (such as the fillColor above) and styled properties. For example, to make a battery that changes color in the disabled state, define this style:
{
"styles": {
"batteryStyle": {
"values": [
{
"fillColor": "#ffff00"
},
{
"when": "${state.disabled}",
"fillColor": "#ff00ff"
}
]
}
}
}
Then use the style in the VectorGraphic component:
{
"type": "VectorGraphic",
"source": "iconBattery",
"style": "batteryStyle"
}
For details about the format to define a vector graphic, see Vector Graphic Format.
VectorGraphic examples
Basic VectorGraphic example
The following example shows a VectorGraphic that displays the AVG called iconWifi3 in a 100x100 box:
{
"type": "VectorGraphic",
"source": "iconWifi3",
"width": 100,
"height": 100,
"scale": "best-fit"
}
Toggle button VectorGraphic example
A VectorGraphic component is a touchable component. This means the component responds to pointer events. The following example demonstrates how to create a toggle button using the onPress handler.
Slider bar VectorGraphic example
The following example illustrates how to create a slider bar by using the onDown, onMove, and onUp handlers:
Related topics
Last updated: Nov 28, 2023