I am trying to create a reusable chart component, but I cannot wrap my brain around me.
The idea is to reuse the next SVG using a reaction (lets call it "Axes") along with some functions and status, such as width and height, data → coordinate mapping, etc .:
<svg width={...} height={...}>
<g ref="area" transform={...}>
{chartElements}
</g>
<g ref="xAxis">...</g>
<g ref="yAxis">...</g>
</svg>
Id then uses this SVG and state for several components of the chart.
Ways to do this may be
Make Axes a component, use this.props.childreninstead chartElementsand define a chart component as follows:
render: function() {
return (
<Axes ref="axes" {...this.props}>
{this.props.data.map(function(d) {
return <rect x={this.refs.axes.state.xMap(d)} />
})}
</Axes>
)
}
But this will require access to Axes details and status that we cannot get during rendering.
mixin wrapAxes(chartElements) mixin, .
, wrapAxes
prop, / ? ?
???
, .