Interface D3DragEvent<GElement, Datum, Subject>

D3 Drag event

The first generic refers to the type of element to be dragged. The second generic refers to the type of the datum of the dragged element. The third generic refers to the type of the drag behavior subject.

interface D3DragEvent {
    active: number;
    dx: number;
    dy: number;
    identifier: number | "mouse";
    sourceEvent: any;
    subject: Subject;
    target: DragBehavior<GElement, Datum, Subject>;
    type: string;
    x: number;
    y: number;
    on(typenames): ((this, event, d) => void);
    on(typenames, listener): D3DragEvent<GElement, Datum, Subject>;
    on(typenames, listener): D3DragEvent<GElement, Datum, Subject>;
}

Type Parameters

Methods

  • Return the first currently-assigned listener matching the specified typenames, if any.

    Equivalent to drag.on, but only applies to the current drag gesture. Before the drag gesture starts, a copy of the current drag event listeners is made. This copy is bound to the current drag gesture and modified by event.on. This is useful for temporary listeners that only receive events for the current drag gesture.

    Parameters

    • typenames: string

      The typenames is a string containing one or more typename separated by whitespace. Each typename is a type, optionally followed by a period (.) and a name, such as "drag.foo"" and "drag.bar"; the name allows multiple listeners to be registered for the same type. The type must be one of the following: start (after a new pointer becomes active [on mousedown or touchstart]), drag (after an active pointer moves [on mousemove or touchmove], or end (after an active pointer becomes inactive [on mouseup, touchend or touchcancel].)

    Returns ((this, event, d) => void)

      • (this, event, d): void
      • Parameters

        • this: GElement
        • event: any
        • d: Datum

        Returns void

  • Remove the current event listeners for the specified typenames, if any, return the drag behavior.

    Equivalent to drag.on, but only applies to the current drag gesture. Before the drag gesture starts, a copy of the current drag event listeners is made. This copy is bound to the current drag gesture and modified by event.on. This is useful for temporary listeners that only receive events for the current drag gesture.

    Parameters

    • typenames: string

      The typenames is a string containing one or more typename separated by whitespace. Each typename is a type, optionally followed by a period (.) and a name, such as "drag.foo"" and "drag.bar"; the name allows multiple listeners to be registered for the same type. The type must be one of the following: start (after a new pointer becomes active [on mousedown or touchstart]), drag (after an active pointer moves [on mousemove or touchmove], or end (after an active pointer becomes inactive [on mouseup, touchend or touchcancel].)

    • listener: null

      Use null to remove the listener.

    Returns D3DragEvent<GElement, Datum, Subject>

  • Set the event listener for the specified typenames and return the drag behavior. If an event listener was already registered for the same type and name, the existing listener is removed before the new listener is added. When a specified event is dispatched, each listener will be invoked with the same context and arguments as selection.on listeners.

    Equivalent to drag.on, but only applies to the current drag gesture. Before the drag gesture starts, a copy of the current drag event listeners is made. This copy is bound to the current drag gesture and modified by event.on. This is useful for temporary listeners that only receive events for the current drag gesture.

    Parameters

    • typenames: string

      The typenames is a string containing one or more typename separated by whitespace. Each typename is a type, optionally followed by a period (.) and a name, such as "drag.foo"" and "drag.bar"; the name allows multiple listeners to be registered for the same type. The type must be one of the following: start (after a new pointer becomes active [on mousedown or touchstart]), drag (after an active pointer moves [on mousemove or touchmove], or end (after an active pointer becomes inactive [on mouseup, touchend or touchcancel].)

    • listener: ((this, event, d) => void)

      An event listener function which is evaluated for each selected element, in order, being passed the current event (event) and datum d, with the this context as the current DOM element.

        • (this, event, d): void
        • Parameters

          • this: GElement
          • event: any
          • d: Datum

          Returns void

    Returns D3DragEvent<GElement, Datum, Subject>

Properties

active: number

The number of currently active drag gestures (on start and end, not including this one).

The event.active field is useful for detecting the first start event and the last end event in a sequence of concurrent drag gestures: it is zero when the first drag gesture starts, and zero when the last drag gesture ends.

dx: number

The change in x-coordinate since the previous drag event.

dy: number

The change in y-coordinate since the previous drag event.

identifier: number | "mouse"

The string “mouse”, or a numeric touch identifier.

sourceEvent: any

The underlying input event, such as mousemove or touchmove.

subject: Subject

The drag subject, defined by drag.subject.

target: DragBehavior<GElement, Datum, Subject>

The DragBehavior associated with the event

type: string

The event type for the DragEvent

x: number

The new x-coordinate of the subject, relative to the container

y: number

The new y-coordinate of the subject, relative to the container