Public
Edited
Mar 19, 2023
2 forks
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tutorial_project = newProject()
Insert cell
Insert cell
cell = chartGen(tutorial_project)
Insert cell
Insert cell
cell(`(10 to 100) * (5 to 20)`)
Insert cell
cell(`List.concat([1, 2, 3], [4, 5, 6])`)
Insert cell
Insert cell
Insert cell
viewof oneplusone = cell(`1 + 1`)
Insert cell
Insert cell
result_value = tutorial_project.getResult(oneplusone).value.value
Insert cell
Insert cell
viewof define_x = cell(`x = 1
x`)
Insert cell
viewof use_x_1 = cell(`x + 1`, define_x)
Insert cell
define_x
Insert cell
tutorial_project.getSourceIds()
Insert cell
Insert cell
viewof define_y = cell(`y = 2`)
Insert cell
viewof use_x_y = cell(`x + y`, [define_x, define_y])
Insert cell
Insert cell
run = runGen(tutorial_project)
Insert cell
y times 2 is ${run(`y * 2`, define_y).value.value}
Insert cell
Insert cell
Insert cell
exampleImport = ({"y": [1, 2, 3], "z": {u: [[3]]}})
Insert cell
cell(`$exampleImport.z.u[0][0]`, undefined, {jsImports: {exampleImport: exampleImport}})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cell(`Plot.dists({dists: [{name: "Result 1", value: normal(0, 1)}, {name: "Result 2", value: normal(5, 1)}]})`)
Insert cell
Insert cell
Insert cell
cell(`10 to 10000`, undefined, {distributionChartSettings: {logX: true}})
Insert cell
Insert cell
cell(`normal(5, 2)`, undefined, { distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
Insert cell
cell(`500 to 2000`, undefined, { distributionChartSettings: {tickFormat: "$,f"}})
Insert cell
Insert cell
cell(`5000 to 20000`, undefined, {distributionChartSettings: {tickFormat: "$,f", title: "Grant sizes"}})
Insert cell
Insert cell
Insert cell
cell(`f(x) = normal(x, 1)
f`, [], {functionChartSettings: {start: 3, stop: 12, count: 10}})
Insert cell
cell(`1 to 20`, [], {distributionChartSettings: {minX: 1, maxX: 20}})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
runGen = (project) =>
(code, bindings, other) => {
let includes = bindings ? (typeof bindings === "string" ? [bindings] : bindings) : []
project.setSource("temp", code)
project.setContinues("temp", includes)
project.run("temp")
const result = project.getResult("temp")
project.clean("temp")
return result;
}
Insert cell
saveProject = (project) => {
const sourceIds = project.getSourceIds();
const sources = sourceIds.map(sourceId => ({source: project.getSource(sourceId), continues: project.getContinues(sourceId), id: sourceId}));
const text = JSON.stringify(sources);
return DOM.download(new Blob([text]), "myproject.json", "Download Project");
}
Insert cell
saveProject(tutorial_project)
Insert cell
viewof result = cell(`SampleSet.fromDist(normal(0, 1))`)
Insert cell
exportSampleSet(tutorial_project, "SampleSet.fromDist(normal(0, 1))")
Insert cell
runGen(tutorial_project)("SampleSet.fromDist(normal(0, 1))").value["_value"].value.samples
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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