Conveniently set the first rotation of the element's transform.
Conveniently set the first scale of the element's transform.
horizontal scale - either
define as full x-y point, or as a number. If scaleOrX is a number and
y is null, then both x and y will be equally scaled
y coordinate if scaleOrX is a number (null)
Set transform of element. Setting through this method will ensure
setTransfrom subscription will publish, and transform will be
appropriately clipped.
Returns true if a setColor command tagged with source from should be
ignored by this element (per ignoreSetColor). Untagged commands
(from == null) are never ignored.
Set transform, color and/or visibility to a predefined scenario.
Save the current transform, color and/or visibility to a scenario.
Return figure path of element
path of element relative to figure
Transform a point between 'draw', 'local', 'figure', 'gl' and 'pixel' spaces.
plane is only needed when converting from pixel space (a 2D space) to
'figure', 'local' or 'draw' spaces (a 3D space). A ray from the pixel is
drawn into the screen
and the intersection with the defined plane is returned.
'pixel' to 'gl' is also a 2D to 3D transformation, but in this case the XY plane at z = 0 is used in gl space.
space to convert point from
space to convert point to
Return a matrix that can transform from one coordinate space to another.
Return the first scale in the element's transform. Will return
[1, 1] if element's transform doesn't have a scale.
scale
Return the first rotation in the element's transform.
how to normalize the
returned angle where '' returns the raw angle
scale
Get position of element
By default the first translation of the element's transform is returned. This is effectively the element's location in 'local' coordinates.
The position of the element relative to its horizontal and vertical bounds
can also be returned. Use xAlign to find the x coordinate of the left,
center, right or percentage width from left of the element. Use yAlign
to find the bottom, middle, top or percentage height from bottom of the
element.
the space to return the position in
horizontal alignment of position. Use a number to define the horizontal
position in percentage width from the left.
vertical alignment of position. Use a number to define the vertical
position in percentage height from the bottom.
Set the element's position in local space such that it lines up with a figure space target.
Align element position in local space such that it is in the same position as the target element (even if that element is in a different local space)
true set this element as touchable and configures all parent elements
to accept touches for their children
false makes this element not touchable.
Configure all parents to make this element touchable, and make this element touchable and movable
true to make movable, false to not
Toggle hide/show of element
Get current transform of element.
true if element is moving
Move child elements to end of draw order - effectively moving to the start of the drawn collection. Later elements in the array will be further forward.
Move child elements to start of draw order - effectively moving them to
the back of the drawn collection. Later elements in the elements array
will be drawn further back.
Add a figure element to this collection.
If adding an array of elements, then the added elements will be returned in an array (even if only one element is added). If not adding an array, then that single element will be returned.
reference name of element
element to add
added element, or array of added elements
// Add name and element
const collection = figure.add({ make: 'collection' });
const element = figure.primitives.polygon({ radius: 1 });
collection.add('name', element);
// Element only (name will be autogenerated)
const collection = figure.add({ make: 'collection' });
const element = figure.primitives.polygon({ radius: 1 });
collection.add(element);
Pulse element.
An element can be pulsed in scale, a rotation or a translation.
The scale pulse can either be a single pulse, or a number of copies with a range of scales - which has the effect of making regular polygons thick.
Either pass in a callback, or an options object defining the pulse and callback.
Get element from an element path with '.' separators.
For instance, if a collection has a child collection 'a', which has a child primitive 'b', then the path would be: 'a.b'.
element at path. If elementPath
is null, then this element is returned. If elementPath is invalid
then null is returned.
// Get all the elements from a figure
figure.add(
{
name: 'c',
make: 'collection',
elements: [
{
name: 'tri',
make: 'triangle',
height: 0.4,
width: 0.4,
},
{
name: 'text',
make: 'text',
text: 'triangle',
position: [0, -0.4],
xAlign: 'center',
},
],
},
);
const c = figure.getElement('c');
// Elements within collections can be found with dot notation
const tri = figure.getElement('c.tri');
// Or the collection can be queried directly
const text = c.getElement('text');
Returns an array of result from getElement calls on an array of paths.
Array of getElement results
Returns an array of result from
getElement calls on an
array of paths. Same as getElements but more succinct
Array of getElement results
Show collection or specific elements within the collection
Hide collection or specific elements within the collection
Get the border or touchBorder of a FigureElementCollection in a defined coordinate space.
('local)
('border')
choose specific
children only - use null for all children (null)
if true then only children that are shown
will be used (true)
Set element color.
RGBA color from 0 to 1
also set the default color to this color
source label of this color command; if it
matches ignoreSetColor the command is ignored
Set element color to defaultColor
Set element color to dimColor
Get all elements within the collection that are primitives, including any primitives that are children of this element, and any primitives that are children of this element's children and so forth.
Get an array of all elements of in this collection, including this element, children, children of children and so forth.
Recreate all atlases associated with children of this collection.
Get array of all children elements.
true if element is animating
Set the current form series to 'name'
Get the current form series name
For equation layout. If an equation layout happens before a desired font is fully loaded, then use this method to re-layout the equation when the font is available.
Either the current form only, all forms already laid out (set), or all forms of the equation can be re-laid-out.
true will re-show current form
Update text of equation element or elements
elements to update
OptionallayoutForms: "none" | "all" | "current" = 'none'which forms to re-layout with the updated text
Conveniently set the first translation of the element's transform.
x coordinate or full point definition
y coordinate if pointOrX is just the x coordinate (0)
Return all the elements that are used in a form.
Return all the elements inside the named equation function within a form.
Any equation function (container, fraction, matrix, etc.) can be tagged
with a name property in its options — this has no layout effect, but
makes the function's sub-tree addressable here.
With mode: 'all' (default), walks the entire tree, collects every
matching function (including those nested inside other matches), and
returns the de-duplicated union of their elements. With mode: 'first',
returns only the elements inside the first matching function found by a
depth-first traversal.
If formName is null (default), the current form is used.
Returns an empty array if the form does not exist, or no matching function is found.
OptionalformName: string | null = null(null — uses current form)
Optionalmode: "all" | "first" = 'all'('all')
OptionalincludeHidden: boolean = false(false)
Return all the elements that are used in an equation phrase.
Get the current equation form
Set current equation form - Note, this does not show the form.
Show equation form.
the form, or its name, to show
if true, stops any in-progress element animations
before rendering the form (default true)
if true, publish a formChanged notification with
phase: 'showForm' (default true). Pass false to suppress the
event — useful for bulk updates or when this showForm is part of a
larger transition the caller is broadcasting separately. The internal
showForm calls made by goToForm use false so the goToForm*
event stream is not interleaved with stray showForm events.
Get an equation form object from a form name
Start an animation to an equation form
Animate to previous form in the current form series
Animate to next form in the current form series
Start from previous form and animate to current form
Equation parameters and functions
AnimationManager extended to include additional animation steps specific to equations
An Equation is a collection of elements that can be arranged into different forms.
Equationshould be instantiated from an object definition, or from thefigure.collections.equationmethod.Equation includes two additional animation steps in Equation.animations:
In addition to the notifications published by FigureElement, an Equation publishes a
formChangednotification whenever the displayed form may have changed. The payload is an object{ phase, form, fromForm?, progress? }wherephaseis one of:'showForm': a form was set viashowForm. Callers can suppress this event by passingnotify: falsetoshowForm; internalshowFormcalls made bygoToFormdo this so thegoToForm*event stream is not interleaved with strayshowFormevents.'goToFormStart': agoToFormcall has just begun'goToFormStep': published on every animation frame during agoToFormanimation;progressis the percentage (0-1) through the animation. A finalgoToFormStepwithprogress: 1is always published immediately beforegoToFormEnd'goToFormEnd': agoToFormcall has finishedfromFormis only included on thegoToForm*phases (it carries thefromWhereoption fromgoToForm); it is absent onshowForm.progressis only included ongoToFormStep. The event order for agoToFormcall is always:goToFormStart→ zero-or-moregoToFormStep→goToFormStepwithprogress: 1→goToFormEnd.A user-initiated
showFormmade while agoToFormanimation is running will publish itsshowFormevent interleaved with the ongoinggoToFormStepstream — listeners that drive UI from "the current transition" should account for this. Passnotify: falseto suppress.See
To test examples, append them to the boilerplate
Param: options
Example
Example