Public
Edited
Nov 30, 2022
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
largeMealChart2 = {
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", glucoseBoxPlotHeight + margin.top + margin.bottom)
.attr("id", "scoreFrame ");

const container = svg
.append("g")
.attr("transform", `translate(${margin.left * 3}, 180)`)
.attr("class", "cell score-large");

let bars = container
.selectAll(".score-column")
.data(scoreGroupedFood)
.enter()
.append("rect")
.attr("width", 8)
.attr("rx", 2)
.attr("id", "scoreBar")
.attr("height", (d) => {
return scoreBarYScale(d.total);
})
.attr("transform", (d, i) => {
return `translate(${16 * i}, ${
scoreBarYScale.range()[1] - scoreBarYScale(d.total)
})`;
})
.style("fill", (d) => {
return zoneColor(d.score);
});

let barLabels = container
.selectAll(".score-bar-label")
.data(scoreGroupedFood)
.enter()
.append("text")
.attr("id", "scoreBarLabel")
.attr("transform", (d, i) => {
return `translate(${16 * i + 4}, ${scoreBarYScale.range()[1] + 15})`;
})
.style("fill", (d) => {
return zoneColor(d.score);
})
.text((d) => {
return d.score;
})
.style("font-size", "11")
.style("text-anchor", "middle")
.style("font-family", "sans-serif");

let circles = container
.selectAll(".score-circle")
.data(scoreGroupedFood)
.enter()
.append("circle")
.attr("id", "scoreCircle")
.attr("r", (d) => {
return scoreCircleScale(d.total);
})
.attr("transform", (d, i) => {
return `translate(${32 * i + 300}, -60)`;
})
.style("fill", (d) => {
return zoneColor(d.score);
});

return svg.node();
}
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
scoreGroupedFood = Array.from(
d3.group(sortedFood, (d) => {
return d["ZONE_SCORE"];
})
)
.map((d) => {
return {
score: d[0],
zones: d[1],
total: d[1].length
};
})
.sort((a, b) => {
return a.score - b.score;
})
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
minutesXScale = d3.scaleLinear().domain([0, 1440]).range([0, 800])
Insert cell
scoreCircleScale = d3
.scaleSqrt()
.domain([d3.max(scoreGroupedFood.map((d) => d.total)), 0])
.range([25, 1])
Insert cell
scoreBarYScale = d3
.scaleLinear()
.domain([d3.max(scoreGroupedFood.map((d) => d.total)), 0])
.range([130, 3])
Insert cell
Insert cell
Insert cell
glucoseBoxPlotHeight = 200
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
Maureen 1 - steps.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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