Public
Edited
Dec 27, 2022
1 fork
Importers
1 star
Insert cell
Insert cell
function createMathCell({
visibility,
style,
id,
inputs,
params,
data,
config,
injections
}) {
if (!id) id = lib.generateId();
if (!style) style = "height: 5in";
const node = html`<div id="${id}" style="${style}" class="mathcell">`;
if (!visibility) visibility = () => Promises.tick(1);
visibility().then(() => {
if (!node.isConnected) {
throw new Error("Not connected to DOM");
}
lib.MathCell(id, inputs || [], params);
node.update = function (id) {
lib.evaluate(
id,
typeof data === "function" ? data(lib, node) : data,
typeof config === "function" ? config(lib, node) : config
);

// // TODO allow functions to be injected for animations?
// // see: https://paulmasson.github.io/mathcell/docs/animations.html
// if (injections) {
// lib.injectFunctions(
// id,
// typeof injections === "function" ? injections(lib, node) : injections
// );
// }
};
node.update(id);
});
return node;
}
Insert cell
lib = {
const string = await fetch(
"https://paulmasson.github.io/mathcell/build/mathcell.js"
).then((res) => res.text());
(1, eval)(string);

let module = {};
for (let key of [
"MathCell",
"generateId",
"evaluate",
"getVariable",
"setLimit",

// utilities, https://paulmasson.github.io/mathcell/docs/utilities.html
// basic
"lerp",
"linspace",
"minMax",
// rounding
"roundTo",
"floorTo",
"ceilTo",
// transformation
"normalize",
"translate",
"rotate",
// color
"color",
"colorFromHue",
"colorFromArg",
"colorStringFromHue",
"colormap",

// Plotting, https://paulmasson.github.io/mathcell/docs/plotting.html
"plot",
"polarPlot",
"listPlot",
"parametric",
"wireframe",
"surfaceFromLines",
"diskFromLines",
"slopeField",
"isoline",
"isoband",
"isosurface",

// Graphics Objects, https://paulmasson.github.io/mathcell/docs/graphics.html
"arrow",
"box",
"cone",
"cylinder",
"ellipsoid",
"line",
"point",
"sphere",
"text",

// Animations, https://paulmasson.github.io/mathcell/docs/animations.html
"injectFunctions"
])
module[key] = window[key];
return module;
}
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