Public
Edited
Oct 15, 2024
Paused
Importers
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
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
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
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
Insert cell
Insert cell
Insert cell
// function resample(data, timeframe) {
// const startOfPeriod = (date) => {
// switch (timeframe) {
// case 'Week':
// return d3.timeWeek.floor(date);
// case 'Month':
// return d3.timeMonth.floor(date);
// default:
// throw new Error("Unsupported timeframe: " + timeframe);
// }
// };

// const aggregated = d3.rollups(data,
// v => ({
// 'Animals affected': d3.sum(v, d => d['Animals affected']),
// 'Animals died': d3.sum(v, d => d['Animals died'])
// }),
// d => d3.timeFormat("%Y-%m-%d")(startOfPeriod(new Date(d['Received date']))) // Ensure date is formatted correctly
// ).map(([date, values]) => ({
// 'Received date': new Date(date + "T00:00:00Z"), // Parse back into a Date object without time
// ...values
// }));

// return aggregated;
// }
Insert cell
// weekly = resample(data, "Week")
Insert cell
// test = d3.filter(resample(data, "Week"), d => new Date(d["Received date"]) >= new Date("2024-04-01") && new Date(d["Received date"]) <= new Date("2024-05-31"));
Insert cell
// viewof affected_died_period = Inputs.radio(["Week", "Month"], {label: null, value: "Month"})
Insert cell
// us = d3.sum(weeklyByCountry, (d) => d["Animals affected"])
Insert cell
// Plot.plot({
// width: width,
// height: 600,
// x: { round: true },
// marginLeft: 35,
// marginRight: 35,
// marginBottom: 40,
// marginTop: 40,
// insetTop: -20,
// marks: [
// Plot.frame({fill: "#dddddd"}),
// Plot.rectY(weekly, {x: "Received date", y: "Animals affected", interval: "Week", fill: "#333333", inset: 0}),
// Plot.rectY(weekly, {x: "Received date", y: "Animals died", fill: "red", interval: "Week", inset: 0}),
// Plot.axisY({label: "Frequency"}),
// Plot.axisY({label: null, anchor: "right"}),
// Plot.gridY({stroke: "#333333", strokeOpacity: 0.2, strokeWidth: 1}),
// Plot.ruleY([0]),
// Plot.lineY(weekly, Plot.windowY({k: 30, anchor: "middle"}, {x: "Received date", y: "Animals affected", stroke: "#fefefe", strokeWidth: 2, curve: "basis"})),
// Plot.tip(weekly, Plot.pointerX({
// x: "Received date",
// y: "Animals affected",
// title: (d) => {
// const date = new Date(d["Received date"]);
// const dateFormat = date.toLocaleDateString('en-US', { timeZone: "UTC", month: 'short', day: 'numeric', year: 'numeric' });
// return `${dateFormat}\n\nAffected: ${d["Animals affected"]}\nDied: ${d["Animals died"]}`;
// }
// })),
// Plot.tip(
// [`This was likely a significant reporting delay by Zoetis or EVVet, and represents cases for the prior 6-9 months.`],
// {x: new Date("2022-02-06"), y: 600, dx: 40, anchor: "middle", background: "white"}
// ),
// ]
// })
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