-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
61 lines (51 loc) · 1.96 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<body>
From the following query for automatically selecting a mark:
<div><pre id="query"></pre></div>
we get the following Vega-Lite spec: (See this file's source code for steps to reproduce this!)
<div><pre id="spec"></pre></div>
<script src="./node_modules/d3/build/d3.min.js"></script>
<script src="./build/compassql.js"></script>
<script>
d3.json("node_modules/vega-datasets/data/cars.json", function (error, data) {
// 1) Specify a query config
var opt = {};
// 2) Build a data schema.
var schema = cql.schema.build(data, opt);
// 3) Specify a Query (e.g., a query for automatically selecting a mark)
var query = {
spec: {
data: { url: "node_modules/vega-datasets/data/cars.json" },
mark: "?",
encodings: [
{
channel: "x",
aggregate: "mean",
field: "Horsepower",
type: "quantitative",
},
{
channel: "y",
field: "Cylinders",
type: "ordinal",
},
],
},
chooseBy: "effectiveness",
};
// 4) Execute a CompassQL `query`.
var output = cql.recommend(query, schema, opt);
var result = output.result;
// 5) Convert the result tree of SpecQueryModel into a tree of Vega-Lite specifications.
var vlTree = cql.result.mapLeaves(result, function (item) {
return item.toSpec();
});
// 6) Use the result. In this case, the tree has only 2 levels (the root and leaves).
// We can just get the top visualization by accessing the 0-th item.
var topVlSpec = vlTree.items[0];
document.querySelector("#query").innerHTML = JSON.stringify(query, null, 2);
document.querySelector("#spec").innerHTML = JSON.stringify(topVlSpec, null, 2);
});
</script>
</body>
</html>