Published
Edited
Mar 11, 2020
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 400
Insert cell
innerHeight = height - margin.top - margin.bottom
Insert cell
innerWidth = width - margin.left - margin.right
Insert cell
margin = ({left: 60, right: 30, top: 60, bottom: 60})
Insert cell
lineGenerator = d3.line()
.x(d => x(d.daysLeft))
.y(d => {
let utility = (expectancy * value) / (sensitivity * timeToDeadlineScale(d.daysLeft));
return y(utility)
})
.curve(d3.curveCardinal.tension(0));
Insert cell
areaGenerator = d3.area()
.x(d => x(d.daysLeft))
.y0(socializingValue)
.y1(d => y((expectancy * value) / (sensitivity * timeToDeadlineScale(d.daysLeft))))
.curve(d3.curveCardinal.tension(0));
Insert cell
transition = d3.transition()
.duration(50)
.ease(d3.easeLinear);
Insert cell
Insert cell
xAxis = g => g
.attr('transform', `translate(0,${innerHeight})`)
.call(d3.axisBottom(x).ticks(10).tickFormat(x => `${x}d`))
.call(g => g.select(".domain").remove())
.call(g => g.append('text')
.attr('x', innerWidth)
.attr('y', margin.bottom / 1.2)
.attr('fill', 'black')
.attr('text-anchor', 'end')
.style('font-size', 15)
.style('font-weight', 'bold')
.text('Days until deadline →'));
Insert cell
y = d3.scaleLinear()
.domain([0, 80])
.range([innerHeight, 0]);
Insert cell
x.domain()
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(data, d => d.daysLeft).reverse())
.range([0, innerWidth]);
Insert cell
timeToDeadlineScale = d3.scaleLinear()
.domain([0, data.length])
.range([0, 1]);
Insert cell
Insert cell
data = dateArray.map((d,i, arrayRef) => {
return {date: new Date(d), value: (expectancy * value) / (sensitivity * (arrayRef.length - i)),
daysLeft: arrayRef.length - i}
})
Insert cell
dateArray = getDates(new Date(), (new Date()).addDays(25));
Insert cell
Insert cell
function getDates(startDate, stopDate) {
var dateArray = new Array();
var currentDate = startDate;
while (currentDate <= stopDate) {
dateArray.push(new Date (currentDate));
currentDate = currentDate.addDays(1);
}
return dateArray;
}
Insert cell
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
Insert cell
d3 = require('d3@5')
Insert cell
import {slider, select} from "@jashkenas/inputs"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more