DurationFormatter
Type class
Formats numbers as durations, such as 125 seconds as "02:05".
More info: Formatting durations
Sources
DurationFormatter can be used (imported) via one of the following packages.
// Import DurationFormatterimport * as am5 from "@amcharts/amcharts5";
// Create DurationFormatteram5.DurationFormatter.new(root, { // ... config if applicable});<!-- Load DurationFormatter --><script src="index.js"></script>
<script>// Create DurationFormatteram5.DurationFormatter.new(root, { // ... config if applicable});</script>Inheritance
DurationFormatter extends Entity.
DurationFormatter is not extended by any other symbol.
Settings
Set these settings on a DurationFormatter object using its set() and setAll() methods. Read about settings concept.
baseUnitType
TimeUnitDefault"second"Unit of the numbers being formatted:
"millisecond","second","minute","hour","day","week","month"or"year".More info: Formatting durations: base unit
durationFieldsType
string[]Data fields that hold durations. Text placeholders with these fields are formatted as durations even without
formatDuration().More info: Data placeholders: formatting placeholders
durationFormatType
undefined|stringFormat for every duration that is not given its own format. Overrides
durationFormats.durationFormatsType
PartialFormats picked when
durationFormatis not set, by base unit and by the largest unit the value reaches:durationFormats[baseUnit][unit]. Also used byDurationAxis.negativeBaseType
undefined|numberDefault0Values below this are negative: they use the negative part of the format (after the first
|) and get a minus sign. A value equal to it uses the zero part (after the second|).
9 inherited items
animationsType
ArrayInherited fromIEntitySettingsSince 5.20.8Animations the element plays on its own, described as data - so they can be set from a JSON config and saved with it.
Each one animates a setting of the element (or, with
target: "dataItem", a value of its data item - a map point'spositionOnLine, say). They start when the setting is applied, restart when it changes, and stop when the element is disposed. A saved config keeps what was configured, never a value caught half way through an animation.sprite.set("animations", [ { key: "rotation", to: 360, duration: 4000, loops: 0 }, { key: "scale", from: 1, to: 1.3, duration: 800, loops: 0, yoyo: true, easing: "sine" } ]);idType
undefined|stringInherited fromIEntitySettingsA unique ID for looking the element up in
root.entitiesById. Setting an ID that another element already has throws an error.ignoreThemesType
undefined|false|trueDefaultfalseInherited fromIEntitySettingsSince 5.15.6Ignores themes: no theme rule applies to the element, not even one of the default theme.
stateAnimationDurationType
undefined|numberDefault0Inherited fromIEntitySettingsHow long, in milliseconds, a switch from one state to another animates.
0switches at once.stateAnimationEasingType
$ease.EasingDefaultout(cubic)Inherited fromIEntitySettingsEasing of the animated switch from one state to another.
themesType
ArrayInherited fromIEntitySettingsThemes applied to the element and everything inside it.
themeTagsType
ArrayInherited fromIEntitySettingsTags that theme rules can target. They also count for the element's children, so a rule can match a child by a tag of its parent.
More info: Themes
themeTagsSelfType
ArrayInherited fromIEntitySettingsTags that theme rules can target, like
themeTags, but only for this element, not its children.More info: Themes
userDataType
anyInherited fromIEntitySettingsAny data of your own to keep with the element.
Private settings
These are read-only settings accessible from a DurationFormatter object using its getPrivate() method. Read about private settings.
DurationFormatter does not have any private settings.
Properties
classNameStaticType
stringDefault"DurationFormatter"classNamesStaticType
ArrayDefaultEntity.classNames.concat([DurationFormatter.className])
7 inherited items
adaptersType
AdaptersDefaultnew Adapters(this)Inherited fromEntityenableDisposeType
booleanDefaulttrueInherited fromSettingsSet to
falseto makedispose()do nothing.eventsType
EventDispatcherDefaultthis._createEvents()Inherited fromEntityrootType
RootInherited fromEntitySince 5.0.6The
Rootthe object belongs to.statestemplateType
Template|undefinedInherited fromEntityA
Templateapplied to the object. Its settings apply where the object has none set of its own.uidType
numberDefault++counterInherited fromSettingsA unique number, given to each object as it is created.
Methods
format(value:number|string,
format?:undefined|string,
base?:TimeUnit)Returns
stringFormats a number as a duration. For example
1000with base unit"second"gives"16:40": 16 minutes and 40 seconds.getFormat(value:number,
maxValue?:undefined|number,
baseUnit?:TimeUnit)Returns
stringReturns the format for
value:durationFormatif set, otherwise the entry ofdurationFormatsfor the largest unit the value reaches.With
maxValue, the unit comes from the larger of the two, so a range of values shares one format. With base unit"second",10alone gets"ss", but withmaxValue600it gets"mm:ss"and shows as00:10.getMilliseconds(value:number,
baseUnit?:TimeUnit)Returns
numberConverts a value in
baseUnitto milliseconds.getValueUnit(value:number,
baseUnit?:TimeUnit)Returns
TimeUnit|undefinedReturns the largest unit the value holds more than one of: 100 seconds is
"minute", 59 seconds is still"second".toTimeStamp(value:number,
baseUnit:TimeUnit)Returns
numberConverts a value in
baseUnitto milliseconds.
22 inherited items
animate(options:AnimationOptions)Returns
AnimationInherited fromSettingsAnimates a setting from its current value (or
from) toto. The setting jumps tofromat once. Withduration0, or no value to start from, it is set totoat once and the returned animation is already stopped.More info: Animations: animating settings
dispose()Returns
voidInherited fromSettingsDisposes the object, freeing everything it holds. A disposed object can't be used again.
get(key:Key,
fallback:F)Returns
NonNullable|FInherited fromEntityReturns the value of setting
key, run through any adapters, orfallbackif it is not set.More info: Settings
has(key:Key)Returns
booleanInherited fromSettingsReturns
trueif settingkeyis set.More info: Settings
isDisposed()Returns
booleanInherited fromSettingsReturns
trueif the object has been disposed.isType(type:string)Returns
thisInherited fromEntityReturns
trueif the object is of classtypeor extends it.new(root:Root,
settings:ITSettings,
template?:Template)StaticReturns
TInherited fromEntityCreates an instance of the class. Use it instead of
new Class().More info: Getting started: new element syntax
off(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsSince 5.9.2Removes a callback added with
on(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offDebounced(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsRemoves a callback added with
onDebounced(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offDebouncedPrivate(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsRemoves a callback added with
onPrivateDebounced(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offPrivate(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsSince 5.9.2Removes a callback added with
onPrivate(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
on(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsCalls
callbackeach time the value of settingkeychanges or is removed. Setting the same value again does not call it.More info: Events: settings value change
once(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsSince 5.20.4Like
on(), but the callback is removed after it is called once.More info: Events: settings value change
onceDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsSince 5.20.4Like
onDebounced(), but the callback is removed after it is called once.More info: Events: settings value change
onDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsLike
on(), but waits until settingkeyhas not changed fordebounceDelaymilliseconds, then callscallbackonce with the latest value.More info: Events: settings value change
onPrivate(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsCalls
callbackeach time the value of private settingkeychanges.More info: Events: settings value change
onPrivateDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsLike
onPrivate(), but waits until private settingkeyhas not changed fordebounceDelaymilliseconds, then callscallbackonce with the latest value.More info: Events: settings value change
remove(key:Key)Returns
voidInherited fromEntityRemoves the value set for setting
key. The setting goes back to the value from a theme or template, if one has it.More info: Settings
removeAll()Returns
voidInherited fromSettingsRemoves all settings, as
remove()does for each one.More info: Settings
set(key:Key,
value:Value)Returns
ValueInherited fromEntitySets setting
keytovalueand returnsvalue. A value set this way overrides themes and templates, and stops any animation of the setting.More info: Settings
setAll(settings:Partial)Returns
voidInherited fromSettingsSets several settings at once, from an object of key-value pairs.
More info: Settings
setTimeout(fn: () =>void,
delay:number)Returns
IDisposerInherited fromEntityCalls
fnafterdelaymilliseconds, unless the object is disposed first. Disposing the returned disposer cancels it.
Events
DurationFormatter does not have any events.