Type class
Defines a state for Sprite
.
A "state" is a special object that has all the same properties as the Sprite
of the same type, and which can be used to quickly apply a set of property values. (set state) When Sprite
(or any object that extends Sprite) is created it creates a "default" state. You can modify the "default" state so that when the Sprite returns to default state certain properties are added.
Default state can be accessed using Sprite's defaultState
getter.
sprite.defaultState.properties.fillOpacity = 0.5;
sprite.defaultState.properties.fillOpacity = 0.5;
{ // ... "defaultState": { "properties": { "fillOpacity": 0.5 } } }
If Sprite is "hoverable", it automatically adds a "hover" state, which is applied when it has a cursor over it.
let hoverstate = sprite.states.create("hover"); hoverstate.properties.fillOpacity = 1;
var hoverstate = sprite.states.create("hover"); hoverstate.properties.fillOpacity = 1;
{ // ... "states": { "hover": { "properties": { "fillOpacity": 0.5 } } } }
The above will automatically apply "hover" state when the Sprite is hovered, thus will set its fillOpacity
property to 1, and will reset it to 0.5 when it's no longer hovered.
Every object that inherits from Sprite
can and will add their own properties to the available list.
User can create their own states, and apply them as needed:
let myCustomState = sprite.states.create("mystate"); myCustomState.properties.fillOpacity = 0.5; myCustomState.properties.strokeOpacity = 0.8; sprite.setState("mystate");
var myCustomState = sprite.states.create("mystate"); myCustomState.properties.fillOpacity = 0.5; myCustomState.properties.strokeOpacity = 0.8; sprite.setState("mystate");
Sources
SpriteState can be used (imported) via one of the following packages.
/** * -------------------------------------------------------- * Import from: "core.ts" * Use like: am4core.SpriteState * -------------------------------------------------------- */ import * as am4core from "@amcharts/amcharts4/core";
/** * -------------------------------------------------------- * Include via: <script src="core.js"></script> * Access items like: am4.SpriteState * -------------------------------------------------------- */
Inheritance
SpriteState extends BaseObject
.
SpriteState is not extended by any other symbol.
Properties
adapter # |
Type Holds Adapter. |
---|---|
clonedFrom # |
Type Inherited from Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed. |
config # |
Type Inherited from Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc. Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations. |
filters # |
Default A list of @param |
id # |
Type Inherited from Sets the user-defined id of the element. |
isTemplate # |
Type Default Identifies if this object is a "template" and should not be treated as real object that is drawn or actually used in the chart. |
name # |
Type Title of the state, i.e. "default", "hidden", etc. |
properties # |
Type Default Collection of properties and their values that should be applied to The property values set on a |
propertyFields # |
Type A collection of key/value pairs that can be used to bind specific Sprite properties to For example: SpriteState-specific binding will override binding set directly on |
sprite # |
Type Reference to |
transitionDuration # |
Type Default Duration of the transition to this state. 0 means instantenous transition. Any number means the Click here for more info about animations |
transitionEasing # |
Type ( value: Default Easing function to use when transitioning to this state.
|
uid # |
Type Inherited from Returns object's internal unique ID. |
There are 4 inherited items currently hidden from this list. |
Methods
clone( cloneId?: ) |
Returns Inherited from Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them. |
---|---|
constructor() |
Returns Constructor |
copyFrom( source: ) |
Returns Copies all property and style values from another |
dispose() |
Returns Inherited from Destroys this object and all related data. |
getCurrentThemes() |
Returns Inherited from Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide. |
getPropertyValue( propertyName: ) |
Returns Returns Will check if there are any bindings with |
isDisposed() |
Returns Inherited from Returns if this object has been already been disposed. |
reset() |
Returns Resets the State to initial state - no values or Filters applied. |
There are 4 inherited items currently hidden from this list. |
Events
SpriteState does not have any events.
Adapters
SpriteState does not have any adapters.