Hylograph.Internal.Selection.Join
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Internal: Data join algorithm implementation.
Computes the enter/update/exit sets when binding new data to existing elements. This is the core of D3's data join pattern, implemented in pure PureScript.
computeJoin: Index-based matching (by position)computeJoinWithKey: Key-based matching (by identity function)
Returns JoinSets containing:
enter: New data without existing elementsupdate: Data matched to existing elementsexit: Existing elements without matching data
Internal module - use joinData / joinDataWithKey from Hylograph.Selection.
#computeJoin Source
computeJoin :: forall datum. Eq datum => Array datum -> Array (ElementBinding datum) -> JoinSets datumPure join algorithm matching D3 semantics with support for duplicate datums
This implements the data join pattern:
- New data not in old elements -> enter
- Data matching existing elements -> update
- Old elements not in new data -> exit
Handles duplicates correctly by matching in order. For example, if old data is "HELLO" and new data is "WORLD", the two 'L's in "HELLO" will match correctly with elements in order.
Users control identity semantics via their Eq instance:
instance Eq Node where
eq (Node a) (Node b) = a.id == b.id -- Identity by ID
Time complexity: O(n * m) worst case, where n = new data length, m = old elements length Space complexity: O(m) for tracking remaining elements
Properties:
- Disjoint: No element appears in multiple sets
- Complete: All new data appears in enter ∪ update
- Complete: All old elements appear in update ∪ exit
- Order: enter and update preserve input order
- Duplicates: Handles duplicate datums by matching in order
#computeJoinWithKey Source
computeJoinWithKey :: forall datum key. Eq key => Array datum -> Array (ElementBinding datum) -> (datum -> key) -> JoinSets datumPure join algorithm with custom key function
Like computeJoin, but uses a key function to extract comparable keys instead of requiring Eq on the data itself.
This is essential for data types that don't have lawful Eq instances (e.g., opaque foreign types like D3Link_Swizzled).
Example:
computeJoinWithKey newLinks oldLinks (\l -> unsafeCoerce l # _.id)
#ElementBinding Source
type ElementBinding datum = { datum :: datum, element :: Element }Represents an element with its bound datum
#EnterBinding Source
type EnterBinding datum = { datum :: datum, newIndex :: Int }Represents a datum entering with its index in the new data array
#UpdateBinding Source
type UpdateBinding datum = { element :: Element, newDatum :: datum, newIndex :: Int, oldDatum :: datum }Represents an element being updated from old to new datum
#JoinSets Source
type JoinSets datum = { enter :: Array (EnterBinding datum), exit :: Array (ElementBinding datum), update :: Array (UpdateBinding datum) }The three disjoint sets resulting from a join
- Modules
- Data.
DependencyGraph - Hylograph.
AST - Hylograph.
Axis. Axis - Hylograph.
Brush - Hylograph.
Brush. FFI - Hylograph.
Brush. Types - Hylograph.
Classify - Hylograph.
Data. Graph - Hylograph.
Data. Graph. Algorithms - Hylograph.
Data. Node - Hylograph.
Data. Tree - 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.
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. Capabilities. Selection - Hylograph.
Internal. Capabilities. Transition - Hylograph.
Internal. FFI - Hylograph.
Internal. Selection. Join - Hylograph.
Internal. Selection. Operations - Hylograph.
Internal. Selection. Operations. Conversions - Hylograph.
Internal. Selection. Operations. Helpers - Hylograph.
Internal. Selection. Operations. Selection - Hylograph.
Internal. Selection. Query - Hylograph.
Internal. Selection. Types - Hylograph.
Internal. Transition. FFI - Hylograph.
Internal. Transition. Manager - Hylograph.
Internal. Transition. Scene - Hylograph.
Internal. Transition. Types - Hylograph.
Internal. Types - Hylograph.
Interpreter. D3 - Hylograph.
Interpreter. English - Hylograph.
Interpreter. Mermaid - Hylograph.
Interpreter. MetaAST - Hylograph.
Interpreter. SemiQuine - Hylograph.
Interpreter. SemiQuine. TreeToCode - Hylograph.
Interpreter. SemiQuine. Types - Hylograph.
Render - Hylograph.
Scale - Hylograph.
Scale. FP - Hylograph.
Shape. Arc - Hylograph.
Shape. Pie - Hylograph.
Shape. Polygon - Hylograph.
Tooltip - Hylograph.
Transform - Hylograph.
TreeDSL - Hylograph.
TreeDSL. ShapeTree - Hylograph.
Unified - Hylograph.
Unified. Attribute - Hylograph.
Unified. DataDSL - Hylograph.
Unified. Display - Hylograph.
Unified. Examples - Hylograph.
Unified. Join - Hylograph.
Unified. Sugar