Public
Edited
Jan 4, 2024
Importers
Insert cell
Insert cell
traverseObj = import("https://cdn.skypack.dev/object-traversal@1.0.1?min")
Insert cell
example = ({
encoding: [
{
x: { field: "xxx", other: [] },
y: { field: "yyy" },
z: { field: "z_in", input_domain: [0,1] }
}
]
})
Insert cell
mappings = (spec) => {
let v = [];
traverseObj.traverse(spec, (a) => {
console.log(a);
if (a.key == "field")
v.push({ field: a.value, input_domain: a.parent.input_domain });
});
return _.uniq(v.map((d) => d.field));
}
Insert cell
mappings(example)
Insert cell
mappings({
datasets: { data: [] },
width: "container",
height: 250,
mark: "text",
encoding: {
x: { field: "formula" },
y: { field: "i_in", title: "iteration" },
text: { field: "value" }
}
}).includes("value")
Insert cell
import { calcudata } from "@declann/little-calculang-helpers"
Insert cell
calcudata2 = ({ models, spec, domains, input_cursors }) => {
let mapped = mappings(spec),
outputs,
pivot;

if (mapped.includes("value")) {
outputs = domains.formula;
pivot = false;
} else {
outputs = mappings(spec)
.filter((d) => d.slice(-3) != "_in")
.filter((d) => models[0][d] != undefined);
pivot = true;
}

console.log(models, domains, input_cursors, outputs, pivot);
return calcudata({
models,
input_domains: domains,
input_cursors,
outputs,
pivot
});
}
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