Goal: Apply functional techniques to make d3.compose easier to reason about, more testable, and better match d3's standard approach
Implementation: Use a "container"/"smart" and "presentation"/"dumb" components approach (reference) with "smart" component handling logic, state, and context and "dumb" component handling rendering.
The "dumb" component is stateless and is a simple, idempotent function that takes in a d3.selection and properties and renders the chart.
The "smart" component provides the API for interacting with Compose, prepares properties for the "dumb" component, and handles any logic/state
This PR applies this approach to the Axis component while being interoperable with the pre-existing architecture. Notable improvements to Axis with this new architecture:
Attaching sub-component (gridlines) is greatly simplified (compare attachGridlines and attach)
No scale fiddling in properties due to unclear interactions (handled simply in prepare)
Very simple (and testable) drawAxis (compare to onDataBind, onEnter, etc.)
Maintains strong property support with static properties object (including validation and defaults)
Roughly the same lines of code now, but when general methods are extracted (to helpers and base Chart class), it'll be smaller and much easier to understand compared to the existing implementation.
Goal: Apply functional techniques to make d3.compose easier to reason about, more testable, and better match d3's standard approach
Implementation: Use a "container"/"smart" and "presentation"/"dumb" components approach (reference) with "smart" component handling logic, state, and context and "dumb" component handling rendering.
d3.selection
and properties and renders the chart.This PR applies this approach to the Axis component while being interoperable with the pre-existing architecture. Notable improvements to Axis with this new architecture:
attachGridlines
andattach
)scale
fiddling in properties due to unclear interactions (handled simply inprepare
)drawAxis
(compare toonDataBind
,onEnter
, etc.)properties
object (including validation and defaults)Roughly the same lines of code now, but when general methods are extracted (to helpers and base
Chart
class), it'll be smaller and much easier to understand compared to the existing implementation.