Graphics
********

class psynet.graphics.Animation(final_attributes, duration, easing='linear')

   Bases: "object"

   An "psynet.graphic.Animation" can be added to an
   "psynet.graphic.Object" to provide motion.

   Parameters:
      * **final_attributes** ("dict") -- The final set of attributes
        that the object should attain by the end of the animation.
        Only animated attributes need to be mentioned. For example, to
        say that the object should reach an x position of 60 by the
        end of the animation, we write "final_attributes={"x": 60}".
        See https://dmitrybaranovskiy.github.io/raphael/reference.html
        #Element.attr and https://www.w3.org/TR/SVG/ for available
        attributes. Note that the x and y coordinates for circles and
        ellipses are called "cx" and "cy".

      * **duration** ("float") -- The time that the animation should
        take to complete, in seconds.

      * **easing** ("str") -- Determines the dynamics of the
        transition between initial and final attributes. Permitted
        values are ""linear"", ""ease-in"", ""ease-out"", ""ease-in-
        out"", ""back-in"", ""back-out"", ""elastic"", and ""bounce"".

class psynet.graphics.Circle(id_, x, y, radius, **kwargs)

   Bases: "GraphicObject"

   A circle object.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **x** ("int") -- x coordinate.

      * **y** ("int") -- y coordinate.

      * **radius** ("int") -- The circle's radius.

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".

class psynet.graphics.Ellipse(id_, x, y, radius_x, radius_y, **kwargs)

   Bases: "GraphicObject"

   An ellipse object. Note that for a rotated ellipse you should use
   the "transform" attribute.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **x** ("int") -- x coordinate.

      * **y** ("int") -- y coordinate.

      * **radius_x** ("int") -- The ellipse's x radius.

      * **radius_y** ("int") -- The ellipses's y radius.

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".

class psynet.graphics.Frame(objects, duration=None, audio_id=None, activate_control_response=False, activate_control_submit=False)

   Bases: "object"

   A "psynet.graphic.Frame" defines an image to show to the
   participant.

   Parameters:
      * **objects** ("List"["GraphicObject"]) -- A list of
        "psynet.graphic.Object" objects to include in the frame.

      * **duration** ("Optional"["float"]) -- The duration of the
        frame, in seconds. If "None", then the frame lasts forever.

      * **audio_id** ("Optional"["str"]) -- An optional ID for an
        audio file to play when the frame starts. This audio file must
        be provided in the "media" slot of the parent
        "psynet.graphic.GraphicMixin".

      * **activate_control_response** ("bool") -- If "True", then
        activate responses for the page's
        "psynet.modular_page.Control" object once this frame is
        reached.

      * **activate_control_submit** ("bool") -- If "True", then enable
        response submission for the page's
        "psynet.modular_page.Control" object once this frame is
        reached.

class psynet.graphics.GraphicControl(auto_advance_after=None, **kwargs)

   Bases: "GraphicMixin", "Control"

   A graphic control for use in "psynet.modular_page.ModularPage".

   Parameters:
      * **auto_advance_after** (*float*) -- If not "None", a time in
        seconds after which the page will automatically advance to the
        next page.

      * ****kwargs** -- Parameters passed to "GraphicMixin" and
        "Control".

   get_bot_response(experiment, bot, page, prompt)

      This function is used when a bot simulates a participant
      responding to a given page. In the simplest form, the function
      just returns the value of the answer that the bot returns, which
      is saved without passing through "format_answer()". For more
      sophisticated treatment, the function can return a "BotResponse"
      object which contains other parameters such as "blobs" and
      "metadata". PsyNet's built-in answer controls return
      "BotResponse(raw_answer=...)" with what the browser would
      submit, so that bot answers pass through the same
      "format_answer" methods as browser answers and are saved with
      the same type and shape. Controls without a meaningful answer,
      such as "NullControl", return the answer directly.

class psynet.graphics.GraphicMixin(id_, frames, dimensions, viewport_width=0.6, max_viewport_height=None, loop=False, media=None, *args, **kwargs)

   Bases: "object"

   A mix-in corresponding to a graphic panel.

   Parameters:
      * **id** -- An identifier for the graphic, should be parsable as
        a valid variable name.

      * **frames** ("List"["Frame"]) -- List of "psynet.graphic.Frame"
        objects. These frames will be displayed in sequence to the
        participant.

      * **dimensions** ("List") -- A list containing two positive
        finite real numbers, corresponding to the x and y dimensions
        of the graphic. Strings are not accepted. The ratio of these
        numbers determines the aspect ratio of the graphic. They
        define the coordinate system according to which objects are
        plotted. However, the absolute size of the graphic is
        independent of the size of these numbers (i.e. a 200x200
        graphic occupies the same size on the screen as a 100x100
        graphic).

      * **viewport_width** ("float") -- The width of the graphic
        display, expressed as a fraction of the browser window's
        width. The default value (0.6) means that the graphic occupies
        60% of the window's width. Must be a positive finite real
        number. The used width is the minimum of that fraction, the
        content surface, the width implied by "max_viewport_height",
        and the width implied by leaving room for page chrome ("--
        psynet-graphic-vertical-chrome"), so the blueprint aspect
        ratio is preserved when any of those caps bind. The chrome cap
        will not shrink the graphic below "--psynet-graphic-min-size",
        so a landscape phone cannot collapse it to zero.

      * **max_viewport_height** ("Optional"["float"]) -- Upper bound
        on the graphic's height, expressed as a fraction of the
        browser window's height. Default: "0.6". Reaching this bound
        reduces the width too. On short windows the page-chrome cap
        usually binds first, so the graphic shrinks further and the
        prompt, Next button and footer still fit. Must be a positive
        finite real number.

      * **loop** ("bool") -- Whether the graphic should loop back to
        the first frame once the last frame has finished.

      * **media** ("Optional"["MediaSpec"]) -- Optional
        "psynet.timeline.MediaSpec" object providing audio and image
        files to be used within the graphic.

      * ****kwargs** -- Additional parameters passed to parent
        classes.

   border_color: str = '#cfcfcf'

      CSS border-color property for the graphic panel.

   border_style: str = 'solid'

      CSS border-style property for the graphic panel.

   border_width: str = '1px'

      CSS border-width property for the graphic panel.

   css_box_width()

      Return a CSS "width" that keeps the blueprint aspect ratio.

      Four caps are applied as width constraints: the requested window
      fraction, the parent content surface ("100%"), the width implied
      by "max_viewport_height", and the width implied by leaving room
      for page chrome ("--psynet-graphic-vertical-chrome"). The chrome
      cap is floored at "--psynet-graphic-min-size" so a short window
      cannot collapse the graphic to zero. Height then follows from
      "aspect-ratio", so a landscape graphic on a wide window cannot
      outgrow the surface, and a square graphic on a laptop window
      cannot make the page scroll.

      Return type:
         "str"

   margin: str = '25px'

      CSS margin property for the graphic panel.

   max_viewport_height: float = 0.6

      Upper bound on the graphic's height, expressed as a fraction of
      the browser window's height. This stops a wide graphic from
      pushing the response controls underneath the footer on short
      screens. The blueprint aspect ratio is always preserved, so
      reaching this bound reduces the width too. A separate page-
      chrome cap ("--psynet-graphic-vertical-chrome") shrinks the
      graphic further when 60% of the window would leave the page able
      to scroll, but never below "--psynet-graphic-min-size".

   validate_dimensions(dimensions)

      Reject dimensions that would emit invalid CSS or divide by zero.

   validate_max_viewport_height(max_viewport_height)

      Reject a height cap that would collapse the graphic to zero.

   validate_viewport_width(viewport_width)

      Reject a viewport width that cannot produce a visible graphic.

class psynet.graphics.GraphicObject(id_, click_to_answer=False, persist=False, attributes=None, animations=None, loop_animations=False)

   Bases: "object"

   An object that is displayed as part of a "psynet.graphic.Frame".

   Parameters:
      * **id** -- A unique identifier for the object. This should be
        parsable as a valid variable name.

      * **click_to_answer** ("bool") -- Whether clicking on the object
        constitutes a valid answer, thereby advancing to the next
        page.

      * **persist** ("bool") -- Whether the object should persist into
        successive frames. In this case, the object must not share an
        ID with any objects in these successive frames.

      * **attributes** ("Optional"["dict"]) -- A collection of
        attributes to give the object. See https://dmitrybaranovskiy.g
        ithub.io/raphael/reference.html#Element.attr for valid
        attributes, and https://www.w3.org/TR/SVG/ for further
        details. For example, one might write "{"fill": "red",
        "opacity" = 0.5}".

      * **animations** ("Optional"["List"]) -- A list of
        "psynet.graphic.Animation" objects .

      * **loop_animations** ("bool") -- If "True", then the object's
        animations will be looped back to the beginning once they
        finish.

class psynet.graphics.GraphicPage(label, *, time_estimate, **kwargs)

   Bases: "ModularPage"

   A page that contains a single graphic.

   Parameters:
      * **label** -- A label for the page.

      * **time_estimate** -- A time estimate for the page (seconds).

      * ****kwargs** -- Parameters passed to "GraphicControl".

class psynet.graphics.GraphicPrompt(*, prevent_control_response=False, prevent_control_submit=False, **kwargs)

   Bases: "GraphicMixin", "Prompt"

   A graphic prompt for use in "psynet.modular_page.ModularPage".

   Parameters:
      * **prevent_control_response** ("bool") -- If "True", the
        response interface in the "psynet.modular_page.Control" object
        is not activated until explicitly instructed by one of the
        "psynet.graphic.Frame" objects.

      * **prevent_control_submit** ("bool") -- If "True", participants
        are not allowed to submit responses until explicitly
        instructed by one of the "psynet.graphic.Frame" objects.

      * ****kwargs** -- Parameters passed to "GraphicMixin" and
        "Prompt".

class psynet.graphics.Image(id_, media_id, x, y, width, height=None, anchor_x=0.5, anchor_y=0.5, **kwargs)

   Bases: "GraphicObject"

   An image object.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **media_id** ("str") -- The ID for the media source, which
        will be looked up in the graphic's
        *:class:`psynet.timeline.MediaSpec* object.

      * **x** ("int") -- x coordinate.

      * **y** ("int") -- y coordinate.

      * **width** ("int") -- Width of the drawn image.

      * **height** ("Optional"["int"]) -- Height of the drawn image.
        If "None", the height is set automatically with reference to
        "width".

      * **anchor_x** ("float") -- Determines the x-alignment of the
        image. A value of 0.5 (default) means that the image is
        center-aligned. This alignment is achieved using the
        "transform" attribute of the image, bear this in mind when
        overriding this attribute.

      * **anchor_y** ("float") -- Determines the y-alignment of the
        image. A value of 0.5 (default) means that the image is
        center-aligned. This alignment is achieved using the
        "transform" attribute of the image, bear this in mind when
        overriding this attribute.

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".

class psynet.graphics.Path(id_, path_string, **kwargs)

   Bases: "GraphicObject"

   A path object. Paths provide the most flexible way to draw
   arbitrary vector graphics.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **path_string** ("str") -- The object's path string. This
        should be in SVG format, see https://dmitrybaranovskiy.github.
        io/raphael/reference.html#Paper.path and
        https://www.w3.org/TR/SVG/paths.html#PathData for information.

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".

class psynet.graphics.Rectangle(id_, x, y, width, height, corner_radius=0, **kwargs)

   Bases: "GraphicObject"

   A rectangle object.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **x** ("int") -- x coordinate.

      * **y** ("int") -- y coordinate.

      * **width** ("int") -- Width.

      * **height** ("int") -- Height.

      * **corner_radius** ("int") -- Radius of the rounded corners,
        defaults to zero (no rounding).

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".

class psynet.graphics.Text(id_, text, x, y, **kwargs)

   Bases: "GraphicObject"

   A text object.

   Parameters:
      * **id** -- A unique identifier for the object.

      * **text** ("str") -- Text to display.

      * **x** ("int") -- x coordinate.

      * **y** ("int") -- y coordinate.

      * ****kwargs** -- Additional parameters passed to
        "GraphicObject".
