Public
Edited
Apr 24, 2023
1 fork
Insert cell
Insert cell
draw = {
const d = data();
const className = d.map((d) => d.class);
const color = d3.scaleOrdinal().domain(className).range(d3.schemeAccent);

return Plot.plot({
x: {
label: null,
tickSize: 0
},
marks: [
Plot.ruleY([0]),
Plot.ruleX(d, { x: "time", y: "viability", fill: color("class") }),
Plot.dot(d, { x: "time", y: "viability", fill: color("class"), r: 4 })
]
});
}
Insert cell
Insert cell
Insert cell
chart = LineChart(data(), {
x: (d) => d.time,
y: (d) => d.viability,
z: (d) => d.class,
yLabel: "↑ Viability ($)",
width,
height: 500,
color: "steelblue"
})
Insert cell
cell_chart = LineChart(data(), {
x: (d) => d.time,
y: (d) => d.cell_size,
z: (d) => d.class,
yLabel: "↑ Cell Size ($)",
width,
height: 500,
color: "crimson"
})
Insert cell
Plotly = require("https://cdn.plot.ly/plotly-1.41.1.min.js")
Insert cell
{
const d = dat;

const time = [],
classes = [],
viability = [],
cell_size = [],
text = [];

for (let i = 0; i < d.length; i++) {
let row = d[i];
time.push(row.time);
classes.push(row.class);
viability.push(row.viability);
cell_size.push(row.cell_size);
text.push(
"<b>" +
row.class +
"</b><br>time:" +
row.time.toLocaleString() +
"<br>viability:" +
row.viability +
"<br>cell size:" +
row.cell_size
);
}

var trace2 = {
x: time,
y: viability,
text: "Viability",
name: "Viability",
marker: {
size: cell_size,
sizeref: (2 * d3.max(cell_size)) / 17 ** 2,
sizemode: "area"
},
transforms: [{ type: "groupby", groups: classes }],
hovertext: text,
hoverinfo: "text",
mode: "lines+markers",
type: "scatter"
};

var traces = [trace2];
const div = DOM.element("div");
Plotly.newPlot(div, traces, {
width: width,
hovermode: "closest",
hoverlabel: { bgcolor: "#FFF" },
yaxis: { title: "Viability (%)" },
yaxis2: { title: "Cell Size (um)" }
});
return div;
}
Insert cell
{
const d = dat;

const time = [],
classes = [],
viability = [],
cell_size = [],
text = [];

for (let i = 0; i < d.length; i++) {
let row = d[i];
time.push(row.time);
classes.push(row.class);
viability.push(row.viability);
cell_size.push(row.cell_size);
text.push(
"<b>" +
row.class +
"</b><br>time:" +
row.time.toLocaleString() +
"<br>viability:" +
row.viability +
"<br>cell size:" +
row.cell_size
);
}

var trace3 = {
x: time,
y: cell_size,
transforms: [{ type: "groupby", groups: classes }],
hovertext: text,
hoverinfo: "text",
mode: "lines+markers",
type: "scatter"
};

var traces = [trace3];
const div = DOM.element("div");
Plotly.newPlot(div, traces, {
width: width,
hovermode: "closest",
hoverlabel: { bgcolor: "#FFF" },
yaxis: { title: "Cell Size (um)" }
});
return div;
}
Insert cell
import { LineChart } from "@d3/multi-line-chart"
Insert cell
data1 = FileAttachment("data.json").json()
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