<attractToConstraint>
<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)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. 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.disabledboolean. Whether this component is disabled and cannot be interacted with.
$a.fixedboolean. Whether this component's value is fixed and cannot be modified.
$a.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$a.thresholdnumber. Distance within which the position attracts to the constraint location.
Common to all components (4)
$a.doenetMLtext. The DoenetML source code that produced this component.
$a.hideboolean. Whether to hide this component from the rendered output.
$a.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$a.styleNumberinteger. 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 .
Property Examples
Property Example: threshold
The threshold attribute is also available as a property of a named <attractToConstraint>.