SpriteState
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");
More info: States
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: am4core.SpriteState */Inheritance
SpriteState extends BaseObject.
SpriteState is not extended by any other symbol.
Properties
adapterType
Adapter<this,A>Holds Adapter.
filtersType
List<Filter>Defaultnew List<Filter>()A list of
Filterelements to be applied to the relativeSpritewhen switching to this State.isTemplateType
booleanDefaultfalseIdentifies if this object is a "template" and should not be treated as real object that is drawn or actually used in the chart.
nameType
stringTitle of the state, i.e. "default", "hidden", etc.
propertiesType
PDefault<P>{}Collection of properties and their values that should be applied to
Spritewhen switching to this State.The property values set on a
SpriteStatewill override the ones set directly on aSprite.propertyFieldsType
objectA collection of key/value pairs that can be used to bind specific Sprite properties to
DataItem.For example:
fillproperty can be bound tomyCustomColorfield in DataItem. The Sprite will automatically get the value forfillfrom its DataItem.SpriteState-specific binding will override binding set directly on
Sprite. I.e. you can make Sprite use different fill color on hover by adding afillbinding to a different DataItem key for Sprite's "hover" state object.More info:
SpritespriteType
$type.Optional<Sprite>Reference to
Spriteelement this State is for.transitionDurationType
numberDefault0Duration of the transition to this state. 0 means instantenous transition.
Any number means the
Spritewill transit smoothly to this state, animating all animatable properties.More info: Animations about animations
transitionEasingType (value:
number) =>numberDefaultcubicOutEasing function to use when transitioning to this state.
More info:
EaseMore info: Animations about animations
4 inherited items
clonedFromType
$type.Optional<this>Inherited fromBaseObjectReference 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.
configType
objectInherited fromBaseObjectUse 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.
idType
$type.Optional<string>Inherited fromBaseObjectSets the user-defined id of the element.
uidType
stringInherited fromBaseObjectReturns object's internal unique ID.
Methods
constructor()Returns
SpriteStateConstructor
copyFrom(source:this)Returns
voidCopies all property and style values from another
SpriteStateobject.getPropertyValue(propertyName:Key)Returns
P[""]Returns
Spriteelement's property value.Will check if there are any bindings with
DataItemand if there are any method callbacks set up for the specific property.reset()Returns
voidResets the State to initial state - no values or Filters applied.
4 inherited items
clone(cloneId?:string)Returns
thisInherited fromBaseObjectMakes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.
dispose()Returns
voidInherited fromBaseObjectDestroys this object and all related data.
getCurrentThemes()Returns
ITheme[]Inherited fromBaseObjectReturns 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.
isDisposed()Returns
booleanInherited fromBaseObjectReturns if this object has been already been disposed.
Events
SpriteState does not have any events.
Adapters
SpriteState does not have any adapters.