ReferenceattractToConstraint

<attractToConstraint>

Wraps another constraint so it acts as a soft attraction within a threshold

<attractToConstraint> is a Graphical component that wraps another constraint (such as <constrainToInterior>, <constrainToGraph>, or a <constraintUnion>) and applies it only when the constrained location is within threshold of the unconstrained location. The wrapped constraint therefore behaves like a soft attraction rather than a hard snap.

Use the dedicated components first. For wrapping a single <constrainTo>, use <attractTo>; for wrapping a single <constrainToGrid>, use <attractToGrid>. <attractToConstraint> is the right choice for constraints that have no dedicated “attract” form (such as <constrainToInterior>) or for combining several constraint types under a single threshold via <constraintUnion>.

Attributes and Properties

Attributes for <attractToConstraint>

Other (1)

number. Default value: 0.5. Distance within which the position attracts to the constraint location.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <attractToConstraint name="a">

Other (5)
$a.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$a.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$a.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$a.hidden

boolean. Whether this component is hidden from the rendered output.

number. Distance within which the position attracts to the constraint location.

Common to all components (4)
$a.doenetML

text. The DoenetML source code that produced this component.

$a.hide

boolean. Whether to hide this component from the rendered output.

$a.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$a.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Soft-snap a <point> into the interior of a region

<constrainToInterior> has no dedicated “attract” form. Wrapping it in <attractToConstraint> lets the point move freely outside the triangle and snap into the interior once it is dragged within the default threshold of the polygon.


Example: Combine several constraint types under one threshold

A <constraintUnion> lets the point switch freely among its constituent constraints, and the single <attractToConstraint> wrapper applies one threshold to the entire union. Writing this with separate <attractTo> and <attractToGrid> siblings would attract the point independently to each, with no shared threshold.

Attribute Examples

Attribute Example: threshold

The threshold attribute sets how close the point must be (in graph units) to the constrained location before the wrapped constraint takes effect. The default value is 0.50.5.

Property Examples

Property Example: threshold

The threshold attribute is also available as a property of a named <attractToConstraint>.