InteractionObject
Type class
Interaction object represents an object that is subject for any kind of interaction with it with any input devices: mouse, touch or keyboard.
Any DOM element can be wrapped into an Internaction object which in turn enables attaching various interaction events to it, such as: hit, drag, swipe, etc.
To create an InteractionObject out of a Sprite, use:
interaction.getInteractionFromSprite(sprite: Sprite) To create an InteractionObject out of a a regular element:
interaction.getInteraction(element: HTMLElement)
Sources
InteractionObject can be used (imported) via one of the following packages.
/** * Import from: "core.ts" * Use like: am4core.InteractionObject */import * as am4core from "@amcharts/amcharts4/core";/** * Include via: <script src="core.js"></script> * Access items like: am4core.InteractionObject */Inheritance
InteractionObject extends BaseObjectEvents.
InteractionObject is not extended by any other symbol.
Properties
clickableType
booleanIs element clickable? Clickable elements will generate "hit" events when clicked or tapped.
contextMenuDisabledType
booleanDefaultfalseShould element prevent context menu to be displayed, e.g. when right-clicked?
cursorOptionsType
ICursorOptionsCursor options.
downPointersA list of pointers currently pressing down on this element.
More info:
PointerdraggableType
booleanIndicates if element can be dragged. (moved)
elementType
HTMLElement|SVGSVGElementA DOM element associated with this element.
eventsType
InteractionObjectEventDispatcher<AMEvent<this,IInteractionObjectEvents>>An
EventDispatcherinstance which holds events for this objectfocusableType
$type.Optional<boolean>Indicates if element can gain focus.
hitOptionsType
IHitOptionsHit options.
hoverableType
booleanIndicates if element should generate hover events.
hoverOptionsType
IHoverOptionsHover options.
inertType
booleanIndicates if element is inert, i.e. if it should carry movement momentum after it is dragged and released.
inertiaOptionsType
Dictionary<InertiaTypes,IInertiaOptions>Inertia options.
isDownType
booleanIndicates if this element has currently any pointers pressing on it.
isFocusedType
booleanIndicates if this element is currently focused.
isHoverType
booleanIndicates if this element is currently hovered.
isHoverByTouchType
booleanIndicates if this element is currently hovered.
keyboardOptionsType
IKeyboardOptionsKeyboard options.
mouseOptionsType
IMouseOptionsSince 4.5.14Mouse options.
Enables controlling options related to the mouse, for example sensitivity of its mouse wheel.
E.g. the below will reduce chart's wheel-zoom speed to half its default speed:
chart.plotContainer.mouseOptions.sensitivity = 0.5;chart.plotContainer.mouseOptions.sensitivity = 0.5;{ // ... "plotContainer": { "mouseOptions": { "sensitivity": 0.5 } } }overPointersA list of pointers currently over the element.
More info:
PointerresizableType
booleanIndicates if element can be resized.
spriteType
SpriteA related
Spriteif any.swipeableType
booleanIndicates whether element should react to swipe gesture.
swipeOptionsType
ISwipeOptionsSwipe options.
tabindexType
numberElement's tab index.
trackableType
booleanIndicates if pointer movement over element should be tracked.
wheelableType
booleanIndicates whether track moouse wheel rotation over element.
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(element:HTMLElement|SVGSVGElement)Returns
InteractionObjectConstructor
copyFrom(source:this)Returns
voidCopies all properties and related assets from another object of the same type.
dispose()Returns
voidDisposes object.
5 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.
dispatch(eventType:Key,
data?:any)Returns
voidInherited fromBaseObjectEventsDispatches an event using own event dispatcher. Will automatically populate event data object with event type and target (this element).
It also checks if there are any handlers registered for this sepecific event.
dispatchImmediately(eventType:Key,
data?:any)Returns
voidInherited fromBaseObjectEventsWorks like
dispatch, except event is triggered immediately, without waiting for the next frame cycle.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
blurParam { type:
"blur", target:InteractionObject, event:FocusEvent}Invoked when
focusableobject loses focus, e.g. by clicking outside it or pressing TAB button to focus on the next focusable object.doublehitParam { type:
"doublehit", target:InteractionObject} &PointerTypeEvent&PointEvent&MouseTouchEventInvoked when object is clicked or touched twice in rapid succession.
Check
IHitOptionsfor settings about double hit.downParam { type:
"down", target:InteractionObject} &PointerTypeEvent&PointerEvent&MouseTouchEventInvoked when the mouse button is pressed or touch starts.
dragParam { type:
"drag", target:InteractionObject, event:MouseEvent|TouchEvent|KeyboardEvent, startPoint:IPoint} &PointerTypeEvent&ShiftEvent&PointEventInvoked when
draggableobject is being dragged. (using mouse, touch or keyboard)dragstartParam { type:
"dragstart", target:InteractionObject, event:MouseEvent|TouchEvent|KeyboardEvent} &PointerTypeEventInvoked when
draggableobject dragging starts. This event is not invoked immediatelly afterdown, but only if there's a movement of the pointer.dragstopParam { type:
"dragstop", target:InteractionObject, event:MouseTouchEvent|KeyboardEvent} &PointerTypeEventInvoked when
draggableobject is released. This event will not fire if position of the object did not change.focusParam { type:
"focus", target:InteractionObject, event:FocusEvent}Invoked when
focusableobject gains focus, e.g. by using TAB button.hitParam { type:
"hit", target:InteractionObject} &PointerTypeEvent&PointEvent&MouseTouchEventInvoked when object is clicked or touched.
inputParam { type:
"input", target:InteractionObject, event:KeyboardEvent}Invoked whenever information changes in the textual input elements, like
<input>,<textarea>, etc.keydownParam { type:
"keydown", target:InteractionObject, event:KeyboardEvent}Invoked when the key is pressed on the keyboard.
keypressParam { type:
"keypress", target:InteractionObject, event:KeyboardEvent}Invoked when the key generates a "press", e.g. pressing and holding a letter key will generate repeated "keypress" events.
keyupParam { type:
"keyup", target:InteractionObject, event:KeyboardEvent}Invoked when the key is released on the keyboard.
outParam { type:
"out", target:InteractionObject} &PointerTypeEvent&MouseTouchEvent&PointerEventInvoked when mouse cursor moves out of
hoverableobject or it is no longer touched.NOTE: this event might not always contains
pointerparameter as event might be triggered by API?overParam { type:
"over", target:InteractionObject} &PointerTypeEvent&MouseTouchEvent&PointerEventInvoked when mouse cursor moves over
hoverableobject or it is touched.NOTE: this event might not always contains
pointerparameter as event might be triggered by API?resizeParam { type:
"resize", target:InteractionObject, point1:IPoint, point2:IPoint, startPoint1:IPoint, startPoint2:IPoint} &PointerTypeEvent&ScaleEvent&MouseTouchEventInvoked when
resizableobject is being resized either by mouse or touch pinch gesture.rightclickParam { type:
"rightclick", target:InteractionObject} &MouseTouchEventInvoked when right mouse button is clicked on the object.
swipeParam { type:
"swipe", target:InteractionObject} &PointerTypeEvent&MouseTouchEventInvoked when user performs "swiping" gesture (quick horizontal movement) on the object, either using mouse or touch.
swipeleftParam { type:
"swipeleft", target:InteractionObject} &PointerTypeEvent&MouseTouchEventInvoked when user performs "swiping" gesture towards left.
swiperightParam { type:
"swiperight", target:InteractionObject} &PointerTypeEvent&MouseTouchEventInvoked when user performs "swiping" gesture towards right.
trackParam { type:
"track", target:InteractionObject} &PointerTypeEvent&PointEvent&PointerEvent&MouseTouchEventInvoked when pointer (mouse cursor or touch point) moves over
trackableobject.upParam { type:
"up", target:InteractionObject} &PointerTypeEvent&PointerEvent&MouseTouchEventInvoked when the mouse button is released or touch ends.
wheelParam { type:
"wheel", target:InteractionObject, event:WheelEvent} &PointEvent&ShiftEventInvoked when user turns mouse wheel while over the object.
wheeldownParam { type:
"wheeldown", target:InteractionObject, event:WheelEvent} &PointEvent&ShiftEventInvoked when user turns mouse wheel downwards while over the object.
wheelleftParam { type:
"wheelleft", target:InteractionObject, event:WheelEvent} &PointEvent&ShiftEventInvoked when user turns mouse wheel leftwards while over the object.
wheelrightParam { type:
"wheelright", target:InteractionObject, event:WheelEvent} &PointEvent&ShiftEventInvoked when user turns mouse wheel rightwards while over the object.
wheelupParam { type:
"wheelup", target:InteractionObject, event:WheelEvent} &PointEvent&ShiftEventInvoked when user turns mouse wheel upwards while over the object.