Public
Edited
Aug 11, 2024
Paused
Comments locked
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
eras
Insert cell
Insert cell
viewof eras = parse(data, {
callback: (d, _, cols) => {
const [c1, c2, c3] = cols;
const values = d3.autoType.call(null, [
d[c1],
d[c2].replace(/^-/, "-00"),
d[c3].replace(/^-/, "-00")
]);
return Object.fromEntries(values.map((_, i) => [cols[i], values[i]]));
},
dismiss: /* discard comments */ /^;.*$/gm,
display
})
Insert cell
Insert cell
Insert cell
parse = {
const meta = "data:,";
const object = Object.assign(html`<object>`, {
type: "text/plain",
width
});

return function (
data,
{
callback = void 0,
dismiss = /* always fails to match */ /(?!)/,
display = true,
method = "csvParse"
} = {}
) {
if (Array.isArray(data) && data.raw) {
data = interpolate(arguments);
}

const stash = Object.assign(
object.cloneNode(),
{
data: meta + encodeURIComponent(data)
},
!!display ? {} : { height: 0 }
);

return Object.assign(stash, {
value: d3[method](
decodeURIComponent(stash.data.slice(meta.length))
.replace(dismiss, "")
.replace(/^\s+?/gm, ""),
callback
),
onload() {
stash.dispatchEvent(new CustomEvent("input"));
}
});
};
}
Insert cell
// @see {@link https://leanpub.com/understandinges6/read#leanpub-auto-tagged-templates}
function interpolate(args) {
/*
* Many thanks to Addy Osmani, Andrea Giammarchi, and Nicholas Zakas! - mg
*/
return args[0].map((x, i) => x + (args[1 + i] || "")).join("");
}
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