You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.5 KiB
72 lines
1.5 KiB
const WIDTH = 800;
|
|
const HEIGHT = 600;
|
|
|
|
let instances;
|
|
let xScale, yScale;
|
|
const parseTime = d3.timeParse("%B %e, %Y");
|
|
const formatTime = d3.timeFormat("%B %e, %Y");
|
|
|
|
|
|
const renderPoints = () => {
|
|
const circles = d3.select('#points')
|
|
.selectAll('circle')
|
|
.data(instances, (datum) => {
|
|
return datum.id
|
|
});
|
|
circles.enter().append('circle');
|
|
|
|
d3.selectAll('circle')
|
|
.attr('cy', (datum, index) => {
|
|
return yScale(datum.ninety_day_outcomes);
|
|
});
|
|
|
|
d3.selectAll('circle')
|
|
.attr('cx', (datum, index) => {
|
|
return xScale(parseTime(datum.graduation_date));
|
|
});
|
|
|
|
}
|
|
|
|
const setupGraph = ()=>{
|
|
d3.select('svg');
|
|
d3.select('svg')
|
|
.style('width', WIDTH)
|
|
.style('height', HEIGHT);
|
|
|
|
xScale = d3.scaleTime();
|
|
xScale.range([0,WIDTH]);
|
|
const xDomain = d3.extent(instances, (datum, index) => {
|
|
return parseTime(datum.graduation_date);
|
|
});
|
|
xScale.domain(xDomain);
|
|
|
|
yScale = d3.scaleLinear();
|
|
yScale.range([HEIGHT, 0]);
|
|
const yDomain = d3.extent(instances, (datum, index) => {
|
|
return datum.ninety_day_outcomes;
|
|
})
|
|
yScale.domain(yDomain);
|
|
}
|
|
|
|
const createAxes = () => {
|
|
const bottomAxis = d3.axisBottom(xScale);
|
|
d3.select('#container')
|
|
.append('g')
|
|
.attr('id', 'x-axis')
|
|
.call(bottomAxis)
|
|
.attr('transform', 'translate(0,'+HEIGHT+')');
|
|
|
|
const leftAxis = d3.axisLeft(yScale);
|
|
d3.select('#container')
|
|
.append('g')
|
|
.attr('id', 'y-axis')
|
|
.call(leftAxis);
|
|
}
|
|
|
|
window.onload = async ()=>{
|
|
instances = await d3.json('/instances');
|
|
setupGraph();
|
|
createAxes();
|
|
renderPoints();
|
|
}
|