Published
Edited
Sep 26, 2021
Fork of Hello Draco
16 forks
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
### Collaboration

You are encouraged to discuss ideas for this assignment with your peers and work in teams of up to 2!
List the peers you worked with here:

I COLLABORATED WITH: ---<list names here>------

Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
embed(vlspec);
Insert cell
Insert cell
Insert cell
vlspec = await (computeSpec(g1));
Insert cell
// This block will print the vega-lite spec that computeSpec generates.
// If it is blank, it probably means a valid spec was not generated.
vlspec
Insert cell
Insert cell
createDracoProgram = function(data) {
// Replace me
return `
% ====== Data definitions ======
data("data/cars.json").
num_rows(2).

fieldtype("a",number).
cardinality("a",2).

fieldtype("b",number).
cardinality("b",2).

% ====== Query constraints ======
encoding(e0).
:- not field(e0,"a").

encoding(e1).
:- not field(e1,"b").
`;
}
Insert cell
computeSpec = function(query) {
return db.exec(query).then((data) => {
var asp = createDracoProgram(data);
var result = draco.solve(asp);
console.log(result);
var spec = result.specs[0];

// Ensures that the spec embeds the data rather than fetch from a URLkj
delete spec.data.url;
spec.data.values = data;
return spec;
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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