# Generated by detroit
# See https://github.com/bourbonut/detroit/tree/main/api_maker

from functools import partial
from operator import is_not

class drag:
    def __init__(self, content="drag"):
        self.content = content

    def __repr__(self):
        return self.content

    def __str__(self):
        return self.content

    def __call__(self, *args):
        arguments = ", ".join(map(repr, args))
        return f"{self}({arguments})"

    def container(self, container=None):
        """
        Source · If container is specified, sets the container accessor to the specified object
        or function and returns the drag behavior. If container is not specified, returns the
        current container accessor, which defaults to:
        .. code:: javascript

            function container() {
              return this.parentNode;
            }

        The container of a drag gesture determines the coordinate system of subsequent drag
        events, affecting event.x and event.y. The element returned by the container accessor
        is subsequently passed to pointer to determine the local coordinates of the pointer.
        The default container accessor returns the parent node of the element in the
        originating selection (see drag) that received the initiating input event. This is
        often appropriate when dragging SVG or HTML elements, since those elements are
        typically positioned relative to a parent. For dragging graphical elements with a
        Canvas, however, you may want to redefine the container as the initiating element
        itself:
        .. code:: javascript

            function container() {
              return this;
            }

        Alternatively, the container may be specified as the element directly, such as
        drag.container(canvas).

        See more informations `here <https://d3js.org/d3-drag#drag_container>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (container,))))
        return drag(content=f"{self.content}.container({arguments})")


    def filter(self, filter=None):
        """
        Source · If filter is specified, sets the event filter to the specified function and
        returns the drag behavior. If filter is not specified, returns the current filter,
        which defaults to:
        .. code:: javascript

            function filter(event) {
              return !event.ctrlKey && !event.button;
            }

        If the filter returns falsey, 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.

        See more informations `here <https://d3js.org/d3-drag#drag_filter>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (filter,))))
        return drag(content=f"{self.content}.filter({arguments})")


    def touchable(self, touchable=None):
        """
        Source · If touchable is specified, sets the touch support detector to the specified
        function and returns the drag behavior. If touchable is not specified, returns the
        current touch support detector, which defaults to:
        .. code:: javascript

            function touchable() {
              return navigator.maxTouchPoints || ("ontouchstart" in this);
            }

        Touch event listeners are only registered if the detector returns truthy for the
        corresponding element when the drag behavior is applied. The default detector works
        well for most browsers that are capable of touch input, but not all; Chrome’s mobile
        device emulator, for example, fails detection.

        See more informations `here <https://d3js.org/d3-drag#drag_touchable>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (touchable,))))
        return drag(content=f"{self.content}.touchable({arguments})")


    def subject(self, subject=None):
        """
        Source · If subject is specified, sets the subject accessor to the specified object or
        function and returns the drag behavior. If subject is not specified, returns the
        current subject accessor, which defaults to:
        .. code:: javascript

            function subject(event, d) {
              return d == null ? {x: event.x, y: event.y} : d;
            }

        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.
        The default subject is the datum of the element in the originating selection (see drag)
        that received the initiating input event; if this datum is undefined, an object
        representing the coordinates of the pointer is created. When dragging circle elements
        in SVG, the default subject is thus the datum of the circle being dragged. With Canvas,
        the default subject is the canvas element’s datum (regardless of where on the canvas
        you click). In this case, a custom subject accessor would be more appropriate, such as
        one that picks the closest circle to the mouse within a given search radius:
        .. code:: javascript

            function subject(event) {
              let n = circles.length,
                  i,
                  dx,
                  dy,
                  d2,
                  s2 = radius * radius,
                  circle,
                  subject;

              for (i = 0; i < n; ++i) {
                circle = circles[i];
                dx = event.x - circle.x;
                dy = event.y - circle.y;
                d2 = dx * dx + dy * dy;
                if (d2 < s2) subject = circle, s2 = d2;
              }

              return subject;
            }

        The returned subject should be an object that exposes x and y properties, so that the
        relative position of the subject and the pointer can be preserved during the drag
        gesture. If the subject is null or undefined, no drag gesture is started for this
        pointer; however, other starting touches may yet start drag gestures. See also
        drag.filter.
        The subject of a drag gesture may not be changed after the gesture starts. The subject
        accessor is 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.
        During the evaluation of the subject accessor, event is a beforestart drag event. Use
        event.sourceEvent to access the initiating input event and event.identifier to access
        the touch identifier. The event.x and event.y are relative to the container, and are
        computed using pointer.

        See more informations `here <https://d3js.org/d3-drag#drag_subject>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (subject,))))
        return drag(content=f"{self.content}.subject({arguments})")


    def clickDistance(self, distance=None):
        """
        Source · If distance is specified, sets the maximum distance that the mouse can move
        between mousedown and mouseup that will trigger a subsequent click event. If at any
        point between mousedown and mouseup the mouse is greater than or equal to distance from
        its position on mousedown, the click event following mouseup will be suppressed. If
        distance is not specified, returns the current distance threshold, which defaults to
        zero. The distance threshold is measured in client coordinates (event.clientX and
        event.clientY).

        See more informations `here <https://d3js.org/d3-drag#drag_clickDistance>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (distance,))))
        return drag(content=f"{self.content}.clickDistance({arguments})")


    def on(self, typenames=None, listener=None):
        """
        Source · 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:
        See dispatch.on for more.
        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.

        See more informations `here <https://d3js.org/d3-drag#drag_on>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (typenames, listener))))
        return drag(content=f"{self.content}.on({arguments})")

