Hylograph.Unified.Attribute
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Hylograph.Unified.Attribute - Bridge between Display and Attributes
This module bridges the Display profunctor system with Hylograph's existing Attribute type, enabling gradual migration to the new display system.
Two Styles, One System
Old style (still works):
elem Circle
[ cx (num d.x)
, cy (num d.y)
, r (num d.radius)
]
New style (using Display):
elem Circle
[ attr "cx" _.x showNumD
, attr "cy" _.y showNumD
, attr "r" _.radius (roundD 1 >>> showNumD)
]
Both can be used together in the same visualization!
Benefits of New Style
- Composable formatting: Chain displays with
>>> - Reusable displays: Define once, use everywhere
- Type-safe adaptation:
lmapDadapts to different data types - Same display in sheet and viz: Unified formatting
#attr Source
attr :: forall datum a. String -> (datum -> a) -> Display a String -> Attribute datumCreate an attribute from extraction function and display
This is the primary way to create attributes in the new style.
Example:
attr "cx" _.x (scaleD 10.0 >>> showNumD)
attr "fill" _.category idD
attr "opacity" _.importance (clampD 0.0 1.0 >>> showNumD)
#attrStatic Source
attrStatic :: forall datum. String -> String -> Attribute datumCreate a static attribute (same for all data)
Example:
attrStatic "fill" "steelblue"
attrStatic "stroke-width" "2"
#textContentD Source
textContentD :: forall datum a. (datum -> a) -> Display a String -> Attribute datumtext content with display formatting
#transformD Source
transformD :: forall datum. (datum -> String) -> Attribute datumtransform attribute with display formatting
#toAttribute Source
toAttribute :: forall datum a. AttributeName -> (datum -> a) -> Display a String -> Attribute datumConvert a Display-based spec to an Attribute
This is useful when you have a Display and want to use it with existing attribute-based code.
#fromDisplay Source
fromDisplay :: forall a. AttributeName -> Display a String -> Attribute aCreate an attribute that just uses a Display for formatting
The extraction is identity - useful when datum is already the right type.
Re-exports from Hylograph.Internal.Attribute
#AttributeValue Source
data AttributeValueAttribute values
We support the most common value types. The ADT ensures type safety when setting attributes.
Instances
#AttributeName Source
newtype AttributeNameAttribute names (SVG/HTML properties)
We use a newtype to prevent typos and enable IDE autocomplete. The String inside is the actual DOM attribute name.
Instances
#Attribute Source
data Attribute datumType-safe attribute with datum phantom type
Attributes can be:
- Static: Same value for all elements
- Data-driven: Value computed from datum (with source metadata)
- Indexed: Value computed from datum and index (with source metadata)
The phantom type datum ensures attributes are only applied
to selections with matching data types.
The AttrSource field enables interpreters to inspect attribute origins
without evaluating the functions.
Instances
Show (Attribute datum)Contravariant Attribute
#AttrSource Source
data AttrSourceSource metadata for attributes
Describes where the attribute value comes from, enabling interpreters like MetaAST to show meaningful information about attribute bindings.
This is automatically captured when using the DSL (field, num, etc.)
but is UnknownSource for raw PureScript functions (escape hatches).
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
Contravariant instance for Attribute
Attributes consume data (they're data sinks), making them naturally contravariant. This enables attribute reuse via
cmap:The key insight:
cmapcomposes the projection function with the attribute's data accessor, allowing attributes written for simple types to work with complex types via field selection.