Open jameslaneconkling opened 7 years ago
would this make transitions harder to implement? Would have to be handled by React, rather than by d3 alone... possibly using react-motion.
Also, events should match the d3 callback, meaning pass data, index, and optionally the event object. The only way to match that functionality would be to create <D3Rect />
and <D3Circle />
(or just Rect/Circle?) components and do something like:
const BarChart = props => {
const { containerHeight, containerWidth, children, data, xScale, yScale, x, y } = props;
xScale.rangeRound([0, containerWidth]);
yScale.rangeRound([containerHeight, 0]);
const styles = extractStyles(props);
const events = extractEvents(props);
return (
<g>
{ React.Children.map(children, child => React.cloneElement(child, {containerWidth, containerHeight})) }
{data.map((d, i) => (
<Rect
key={x(d)}
className='bar'
width={xScale.bandwidth()}
height={containerHeight - yScale(y(d))}
x={xScale(x(d))}
y={yScale(y(d))}
data={d}
index={i}
{...styles}
{...events}
/>
))}
</g>
);
}
and have Rect pass all properties on to a child <rect />
element, holding on to data and index, and adding each as an argument to any event fired on <rect />
.
e.g.
this:
vs