Published
Edited
Aug 22, 2022
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
allDays = flatUserArray.map((d) => d.days)
Insert cell
color = d3
.scaleLinear()
.domain([25, 13, 0])
.range(["#F081A1", "#E5ADFF", "#3AC9E9"])
.clamp(true)
Insert cell
expScale = d3.scalePow().exponent(Math.E).domain([0, 25])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
flatUserArray = Array.from(userDataByDays).map((value, key) => {
return {
id: value[0],
days: Array.from(value[1]).map((d) => {
let glucoseValues = d[1].map((e) => {
return e.value;
});
return {
day: d[0],
values: d[1],
deviation: d3.deviation(glucoseValues)
};
})
};
})
Insert cell
allUserDeviation = flatUserArray
.map((d) => {
return d.days.map((e) => {
return e.deviation;
});
})
.flat()
Insert cell
ids = Array.from(userDataByDays.keys())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// normal_curve = {
// const points = [];
// for (let value of d3.range(...x.domain(), bin_width / 10)) {
// points.push([
// value,
// dnorm(value, sample_mean, sample_sd) * bin_width * sample_size
// ]);
// }
// return points;
// }
Insert cell
sample_sd = ssd(sample)
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