|
(function (react, d3, ReactDOM) { |
|
'use strict'; |
|
|
|
ReactDOM = ReactDOM && Object.prototype.hasOwnProperty.call(ReactDOM, 'default') ? ReactDOM['default'] : ReactDOM; |
|
|
|
const parseRow = (d) => { |
|
d.sepal_length = +d.sepal_length; |
|
d.sepal_width = +d.sepal_width; |
|
d.petal_length = +d.petal_length; |
|
d.petal_width = +d.petal_width; |
|
return d; |
|
}; |
|
|
|
const useData = (outputPath) => { |
|
const [data, setData] = react.useState(null); |
|
|
|
react.useEffect(async () => { |
|
setData(await d3.csv('data.csv', parseRow)); |
|
}, []); |
|
|
|
return data; |
|
}; |
|
|
|
const axes = ( |
|
selection, |
|
{ height, margin, xScale, yScale } |
|
) => { |
|
const { left, bottom } = margin; |
|
|
|
selection |
|
.selectAll('g.axis-y') |
|
.data([null]) |
|
.join('g') |
|
.attr('class', 'axis axis-y') |
|
.attr('transform', `translate(${left},0)`) |
|
.call(d3.axisLeft(yScale)); |
|
|
|
selection |
|
.selectAll('g.axis-x') |
|
.data([null]) |
|
.join('g') |
|
.attr('class', 'axis axis-x') |
|
.attr( |
|
'transform', |
|
`translate(0,${height - bottom})` |
|
) |
|
.call(d3.axisBottom(xScale)); |
|
}; |
|
|
|
const viz = ( |
|
selection, |
|
{ |
|
data, |
|
xValue, |
|
yValue, |
|
width, |
|
height, |
|
margin, |
|
circleRadius, |
|
} |
|
) => { |
|
const { top, right, bottom, left } = margin; |
|
|
|
const xScale = d3.scaleLinear() |
|
.domain(d3.extent(data, xValue)) |
|
.range([left, width - right]); |
|
|
|
const yScale = d3.scaleLinear() |
|
.domain(d3.extent(data, yValue)) |
|
.range([height - bottom, top]); |
|
|
|
selection |
|
.selectAll('circle') |
|
.data(data) |
|
.join('circle') |
|
.attr('r', circleRadius) |
|
.attr('fill-opacity', 0.5) |
|
.attr('cx', (d) => xScale(xValue(d))) |
|
.attr('cy', (d) => yScale(yValue(d))); |
|
|
|
axes(selection, { |
|
height, |
|
margin, |
|
xScale, |
|
yScale, |
|
}); |
|
}; |
|
|
|
const VizWrapper = ({ data }) => { |
|
const ref = react.useRef(); |
|
|
|
const width = window.innerWidth; |
|
const height = window.innerHeight; |
|
|
|
react.useEffect(() => { |
|
viz(d3.select(ref.current), { |
|
data, |
|
xValue: (d) => d.sepal_length, |
|
yValue: (d) => d.petal_length, |
|
width, |
|
height, |
|
margin: { |
|
top: 20, |
|
right: 20, |
|
bottom: 40, |
|
left: 40, |
|
}, |
|
circleRadius: 10, |
|
}); |
|
}, [data]); |
|
|
|
return ( |
|
React.createElement( 'svg', { |
|
width: width, height: height, ref: ref }) |
|
); |
|
}; |
|
|
|
const App = () => { |
|
const data = useData(); |
|
return data ? ( |
|
React.createElement( VizWrapper, { data: data }) |
|
) : ( |
|
// Could be expanded with a real loading indicator. |
|
'Loading...' |
|
); |
|
}; |
|
|
|
ReactDOM.render( |
|
React.createElement( App, { outputPath: "" }), |
|
document.getElementById('root') |
|
); |
|
|
|
}(React, d3, ReactDOM)); |
|
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbInVzZURhdGEuanMiLCJheGVzLmpzIiwidml6LmpzIiwiVml6V3JhcHBlci5qcyIsIkFwcC5qcyIsImluZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHVzZVN0YXRlLCB1c2VFZmZlY3QgfSBmcm9tICdyZWFjdCc7XG5pbXBvcnQgeyBjc3YgfSBmcm9tICdkMyc7XG5cbmNvbnN0IHBhcnNlUm93ID0gKGQpID0+IHtcbiAgZC5zZXBhbF9sZW5ndGggPSArZC5zZXBhbF9sZW5ndGg7XG4gIGQuc2VwYWxfd2lkdGggPSArZC5zZXBhbF93aWR0aDtcbiAgZC5wZXRhbF9sZW5ndGggPSArZC5wZXRhbF9sZW5ndGg7XG4gIGQucGV0YWxfd2lkdGggPSArZC5wZXRhbF93aWR0aDtcbiAgcmV0dXJuIGQ7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