Published
Edited
May 6, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
shippedOrders = data.filter(
(d) =>
d.shipDate &&
d.shipDate >= new Date("2022-04-10") &&
d.shipDate <= new Date()
)
Insert cell
shippingProjection = d3
// y = mx + b mapping of
.scaleLinear()
// shipped order number
.domain(d3.extent(shippedOrders, (d) => d.orderID).reverse())
// to shipping dates
.range(d3.extent(shippedOrders, (d) => d.shipDate))
Insert cell
predictionLine = [
d3.least(shippedOrders, (d) => d.orderID),
{
shipDate: shippingProjection(finalOrderToShip.orderID),
orderID: finalOrderToShip.orderID
}
]
Insert cell
shippingGroupsPoints = d3
// take the point with the highest order number in each group
.flatRollup( data, (g) => d3.least(g, (d) => d.orderID), (d) => d.group)
// and generate a shipping projection
.map(([groupNumber, datum]) => ({
...datum,
projectedShipDate: shippingProjection.copy()(datum.orderID),
label: `group ${groupNumber}`
}))
Insert cell
finalOrderToShip = d3.least(data, (d) => d.orderID)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const cleaned = massaged.map((d) => ({
...d,
shipDate: isNaN(d.shipDate)
? null
: new Date(new Date(d.shipDate).setFullYear(2022))
}));

return cleaned.filter((d) => !(d[col.orderID] === "448XX" && d.group === 2));
}
Insert cell
// clean up raw data and assign reasonable column names
massaged = raw
.filter((d) => d["What is your order ID?"] !== "")
.map((d) => ({
...d,
status: d[col.status],
isShipping: d[col.isShipping] === "Yes",
shipDate: new Date(d[col.shipDate]),
consoleOrCombo: d[col.consoleOrCombo],
orderID: +d[col.orderID].replace(/[xX#\*]/g, "0").replace(/\D/g, "") * -1,
group: +d[col.group]
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more