Published
Edited
Aug 30, 2020
Insert cell
Insert cell
Insert cell
Insert cell
y = {
const minValue = 0;
const maxValue = d3.max(data, d => d.value);
const minY = height - margin.bottom;
const maxY = margin.top;
return function(value) {
return (value - minValue)
/ (maxValue - minValue)
* (maxY - minY)
+ minY;
};
}
Insert cell
Insert cell
foo = "🌎" // Uma célula nomeada foo
Insert cell
bar = foo + "bar" // Uma referência (reativa) para a célula foo.
Insert cell
Insert cell
baz = {
let foo = "🏠"; // Varíavel local foo, mascarando a célula foo.
return foo + "baz"; // Uma referência à variável local foo.
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cycle1 = cycle2 + 1
Insert cell
cycle2 = cycle1 + 1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function computeNodes() {
const map = new Map;
function get(name) {
let node = map.get(name);
if (!node) map.set(name, node = new Node(name));
return node;
}
for (const [i, o] of edges) {
const nodeIn = get(i);
const nodeOut = get(o);
nodeIn.outputs.add(nodeOut);
nodeOut.inputs.add(nodeIn);
}
return [...map.values()];
}
Insert cell
function* computeSequence() {
const nodes = computeNodes();
const queue = [];
for (const node of nodes) {
if (!(node.indegree = node.inputs.size)) {
queue.push(node);
}
}
let node;
yield {nodes, first: true};
while (node = queue.pop()) {
node.computed = true;
for (const output of node.outputs) {
if (!--output.indegree) {
queue.push(output);
}
}
yield {node, nodes};
}
yield {nodes};
}
Insert cell
class Node {
constructor(name) {
this.name = name;
this.computed = false;
this.indegree = 0;
this.inputs = new Set;
this.outputs = new Set;
}
}
Insert cell
edges = [
["d3", "chart"],
["DOM", "chart"],
["width", "chart"],
["height", "chart"],
["data", "chart"],
["x", "chart"],
["y", "chart"],
["xAxis", "chart"],
["yAxis", "chart"],
["require", "data"],
["d3", "x"],
["data", "x"],
["margin", "x"],
["width", "x"],
["d3", "y"],
["data", "y"],
["height", "y"],
["margin", "y"],
["d3", "xAxis"],
["height", "xAxis"],
["margin", "xAxis"],
["x", "xAxis"],
["d3", "yAxis"],
["margin", "yAxis"],
["y", "yAxis"],
["require", "d3"]
]
Insert cell
import {d3, data, height, margin} from "@d3/bar-chart"
Insert cell
dot = require("@observablehq/graphviz@0.2")
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