Drag

detroit_live.drag(extra_nodes: list[Element] | None = None)

Creates a new drag behavior. The returned behavior, drag, is both an object and a function, and is typically applied to selected elements via Selection.call.

Parameters:

extra_nodes (list[etree.Element] | None) – Extra nodes to update when the listener is called

class detroit_live.drag.drag.Drag(extra_nodes: list[Element] | None = None)

Creates a new drag behavior. The returned behavior, drag, is both an object and a function, and is typically applied to selected elements via Selection.call.

Parameters:

extra_nodes (list[etree.Element] | None) – Extra nodes to update when the listener is called

__call__(selection: LiveSelection)

Applies this drag behavior to the specified selection. This function is typically not invoked directly, and is instead invoked via Selection.call.

Parameters:

selection (LiveSelection) – Selection

set_filter(filter_func: Callable[[Element, T | None, list[Element]], bool]) Drag

Sets the event filter to the specified function and returns the drag behavior.

If the filter returns false, the initiating event is ignored and no drag gestures are started. Thus, the filter determines which input events are ignored; the default filter ignores mousedown events on secondary buttons, since those buttons are typically intended for other purposes, such as the context menu.

Parameters:

filter_func (EventFunction[T | None, bool]) – Filter function

Returns:

Itself

Return type:

Drag

set_subject(subject: Callable[[Element, T | None, list[Element]], T | dict[str, float]]) Drag

Sets the subject accessor to the specified object or function and returns the drag behavior.

The subject of a drag gesture represents the thing being dragged. It is computed when an initiating input event is received, such as a mousedown or touchstart, immediately before the drag gesture starts. The subject is then exposed as event.subject on subsequent drag events for this gesture.

Parameters:

subject (EventFunction[T | None, T | dict[str, float]]) – Subject function

Returns:

Itself

Return type:

Drag

set_touchable(touchable: Callable[[LiveSelection], Callable[[Element, T | None, list[Element]], bool]]) Drag

Sets the touch support detector to the specified function and returns the drag behavior.

Parameters:

touchable (Callable[[LiveSelection], EventFunction[T | None, bool]]) – Touchable function

Returns:

Itself

Return type:

Drag

on(typenames: str, callback: Callable[[...], None]) Drag

If listener is specified, sets the event listener for the specified typenames and returns 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. If listener is null, removes the current event listeners for the specified typenames, if any. If listener is not specified, returns the first currently-assigned listener matching the specified typenames, if any. When a specified event is dispatched, each listener will be invoked with the same context and arguments as selection.on listeners: the current event (event) and datum d, with the this context as the current DOM element.

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).

  • "end" - after an active pointer becomes inactive (on mouseup, touchend or touchcancel).

Changes to registered listeners via drag.on during a drag gesture do not affect the current drag gesture. Instead, you must use event.on, which also allows you to register temporary event listeners for the current drag gesture. Separate events are dispatched for each active pointer during a drag gesture. For example, if simultaneously dragging multiple subjects with multiple fingers, a start event is dispatched for each finger, even if both fingers start touching simultaneously. See Drag Events for more.

Parameters:
  • typenames (str) – Typenames

  • callback (Callable[..., None]) – Callback

Returns:

Itself

Return type:

Drag