Hylograph.Behavior
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Imperative behaviours — the public counterpart to the declarative
Behavior ADT in Hylograph.Behavior.Types.
Most interaction should be declared, not attached: on (Zoom …) and
on (Drag …) inside a HATS tree are the ordinary route, and they carry
the behaviour along with the elements it belongs to. But three things
genuinely live outside a tree, and this module is where they belong:
- Zoom on a container you already hold, typically an
<svg>fetched bygetElementByIdin a Halogen component, where there is no HATS tree to hang aZoombehaviour from. - The simulation registry, which pairs with
simulationDragin the declarative API.simulationDrag "lesmis"names a simulation; some effectful code has to put one under that name. - Scrolling an element into view, which is not a behaviour of a visualisation at all, just a thing components need to do.
Zoom takes the same ZoomConfig the declarative path takes, so
defaultZoom (ScaleExtent 0.5 4.0) ".zoom-group" builds a value usable
either way. That also removes a real hazard: the underlying binding
takes the scale bounds as two adjacent bare Numbers, which nothing but
care keeps in the right order.
Everything here wraps Hylograph.Internal.Behavior.FFI, which consumers
had been importing directly for want of this module. Import this one.
#identityTransform Source
identityTransform :: ZoomTransformThe zoom transform with no scaling and no translation.
attachZoomWithTransform and attachZoomWithCallback both take a
transform to restore. Pass this one when there is nothing to restore —
on a first render, say — rather than writing the record out.
#attachZoom Source
attachZoom :: Element -> ZoomConfig -> Effect ElementAttach zoom and pan to an element, transforming whatever the config's selector matches.
The element is typically the <svg>; the selector names the group
inside it that actually moves.
_ <- attachZoom svgElem (defaultZoom (ScaleExtent 0.5 4.0) ".zoom-group")
Returns the element, for chaining.
#attachZoomWithTransform Source
attachZoomWithTransform :: Element -> ZoomConfig -> ZoomTransform -> Effect ElementAttach zoom and immediately apply a transform.
Use this to preserve the user's zoom across a re-render: read the
transform with readZoomTransform before tearing down, hand it back
here afterwards.
#attachZoomWithCallback Source
attachZoomWithCallback :: Element -> ZoomConfig -> ZoomTransform -> (ZoomTransform -> Effect Unit) -> Effect ElementAttach zoom, apply a transform, and run a callback on every zoom event.
The callback is for things that must track the zoom but are not inside the transformed group — annotations positioned in screen space, arrows whose stroke width should not scale, a readout of the current level.
#readZoomTransform Source
readZoomTransform :: Element -> Effect ZoomTransformThe element's current zoom transform, or identityTransform if it has
never been zoomed.
#registerSimulation Source
registerSimulation :: String -> Effect Unit -> Effect UnitMake a simulation reachable by name, so that simulationDrag can find
it.
simulationDrag "lesmis" in a HATS tree says which simulation a drag
should reheat; this says what is under that name. The second argument
is the reheat action, run whenever a drag on a registered node begins.
registerSimulation "lesmis" (Sim.reheat sim)
Names are global. Pair every call with unregisterSimulation when the
visualisation is torn down, or a finalised simulation stays reachable.
#unregisterSimulation Source
unregisterSimulation :: String -> Effect UnitRemove a simulation from the registry. Call this on teardown.
#ScrollBehavior Source
#ScrollBlock Source
#scrollToElement Source
scrollToElement :: String -> Effect UnitScroll the element with the given id into view: smoothly, centred.
These are the defaults you want almost always. Reach for
scrollToElementWith when they are not.
#scrollToElementWith Source
scrollToElementWith :: ScrollBehavior -> ScrollBlock -> String -> Effect UnitScroll the element with the given id into view, choosing the animation and the resting position.
Re-exports from Hylograph.Behavior.Types
#ZoomTransform Source
type ZoomTransform = { k :: Number, x :: Number, y :: Number }A zoom transform: scale k, and translation x/y.
Produced by every zoom event and accepted by the attach functions in
Hylograph.Behavior, which is how zoom state survives a re-render.
{ k: 1.0, x: 0.0, y: 0.0 } is the identity, available there as
identityTransform.
- Modules
- Data.
DependencyGraph - Hylograph.
Attribute - Hylograph.
Behavior - Hylograph.
Behavior. Types - Hylograph.
Brush - Hylograph.
Brush. FFI - Hylograph.
Brush. Types - Hylograph.
Classify - Hylograph.
Data. Graph - Hylograph.
Data. Graph. Algorithms - Hylograph.
Data. Node - Hylograph.
Data. Tree - Hylograph.
Element. Types - Hylograph.
Expr. Animation - Hylograph.
Expr. Attr - Hylograph.
Expr. Datum - Hylograph.
Expr. Expr - Hylograph.
Expr. Friendly - Hylograph.
Expr. Integration - Hylograph.
Expr. Interpreter. CodeGen - Hylograph.
Expr. Interpreter. Eval - Hylograph.
Expr. Interpreter. Meta - Hylograph.
Expr. Interpreter. PureSVG - Hylograph.
Expr. Interpreter. SVG - Hylograph.
Expr. Path - Hylograph.
Expr. Path. Generators - Hylograph.
Expr. Sugar - Hylograph.
Expr. Units - Hylograph.
Foreign. Types - Hylograph.
HATS - Hylograph.
HATS. Friendly - Hylograph.
HATS. InterpreterTick - Hylograph.
HATS. Transitions - Hylograph.
Interaction. Brush - Hylograph.
Interaction. Coordinated - Hylograph.
Interaction. Pointer - Hylograph.
Interaction. Zoom - Hylograph.
Internal. Attribute - Hylograph.
Internal. Behavior. FFI - Hylograph.
Internal. Behavior. Types - Hylograph.
Internal. Element. Operations - Hylograph.
Internal. Element. Types - Hylograph.
Internal. FFI - Hylograph.
Internal. Transition. FFI - Hylograph.
Internal. Transition. Manager - Hylograph.
Internal. Transition. Scene - Hylograph.
Internal. Transition. Types - Hylograph.
Internal. Types - Hylograph.
Interpreter. English - Hylograph.
Interpreter. Mermaid - Hylograph.
Interpreter. MetaHATS - Hylograph.
Interpreter. SemiQuine - Hylograph.
Interpreter. SemiQuine. TreeToCode - Hylograph.
Interpreter. SemiQuine. Types - Hylograph.
Scale - Hylograph.
Scale. ColorSchemes - Hylograph.
Scale. FP - Hylograph.
Scale. Interpolation - Hylograph.
Scale. Pure - Hylograph.
Scale. Sequential - Hylograph.
Shape. Arc - Hylograph.
Shape. Pie - Hylograph.
Shape. Polygon - Hylograph.
Tooltip - Hylograph.
Transform - Hylograph.
Transition. Types - Hylograph.
Unified - Hylograph.
Unified. Attribute - Hylograph.
Unified. DataDSL - Hylograph.
Unified. Display - Hylograph.
Unified. Sugar
Autodefers to the element's computedscroll-behavior.