Module

Hylograph.Data.Tree

Package
purescript-hylograph-selection
Repository
afcondon/purescript-hylograph-selection

#TreeJson_ Source

#TreeLayoutFn_ Source

#D3_TreeNode Source

data D3_TreeNode t0

D3 tree node (result of d3.hierarchy() and layout functions) Parameterized by datum type

#TreeType Source

#TreeModel Source

type TreeModel = { json :: TreeJson_, svgConfig :: { height :: Number, width :: Number }, treeLayout :: TreeLayout, treeLayoutFn :: TreeLayoutFn_, treeType :: TreeType }

#makeD3TreeJSONFromTreeID Source

makeD3TreeJSONFromTreeID :: forall d. Tree NodeID -> Map NodeID d -> TreeJson_

Convert a Tree of NodeIDs to D3 TreeJson format using a lookup map

This function is useful when you have a Tree structure where nodes contain only IDs, and you need to look up the full node data from a Map.

Example:

let tree = mkTree "root" $ L.fromFoldable [mkTree "child1" Nil, mkTree "child2" Nil]
let dataMap = M.fromFoldable [
  Tuple "root" {name: "Root", value: 100},
  Tuple "child1" {name: "Child 1", value: 50}
]
let d3Tree = makeD3TreeJSONFromTreeID tree dataMap

Note: If a node ID is not found in the map, an empty tree node is created.

#treeToD3Tree Source

treeToD3Tree :: forall d. Tree d -> TreeJson_

Convert a PureScript Tree directly to D3 TreeJson format

This is the simplest conversion - each node already contains its data, no lookup required.

Example:

let tree = mkTree {name: "Root", value: 100} $ L.fromFoldable
             [ mkTree {name: "Child 1", value: 50} Nil
             , mkTree {name: "Child 2", value: 30} Nil
             ]
let d3Tree = treeToD3Tree tree

#arrayToTree Source

arrayToTree :: forall d. { getId :: d -> NodeID, getParentId :: d -> Maybe NodeID, nodes :: Array d } -> Either String (Tree d)

Build a Tree from an array of nodes with parent pointers

This function constructs a tree from a flat array where each node knows its parent ID. Useful for loading hierarchical data from databases or JSON where parent-child relationships are encoded as references.

Example:

let nodes = [
  {id: "1", parentId: Nothing, name: "Root"},
  {id: "2", parentId: Just "1", name: "Child 1"},
  {id: "3", parentId: Just "1", name: "Child 2"}
]
let tree = arrayToTree {
  nodes: nodes,
  getId: _.id,
  getParentId: _.parentId
}

Returns Left with error message if:

  • No root node found (node with Nothing parent)
  • Multiple root nodes found
  • Circular references detected

Re-exports from Data.Graph.Layout

#TreeLayout Source

data TreeLayout

Tree layout orientation

Constructors

Instances

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