Public
Edited
Apr 17
1 fork
18 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ast = parser.parse(query)
Insert cell
Insert cell
pt = astToTree(ast.value)
Insert cell
// Very crude function that tries to create a d3 tree
function astToTree(pq) {
const pt = {};

pt.name = "";
pt.name += typeof pq.distinctOpt === "string" ? pq.distinctOpt + " : " : "";
pt.name += pq.type || "";
pt.name +=
typeof pq.value === "string" || typeof pq.value === "number"
? ": " + pq.value
: "";
pt.name += typeof pq === "string" || typeof pq === "number" ? pq : "";

pt.children = [];

[
"from",
"where",
"groupBy",
"orderBy",
"limit",
"partition",
"left",
"right"
].map((a) => {
pq[a] && pt.children.push(astToTree(pq[a]));
});

if (Array.isArray(pq.value)) {
pq.value.map((v) => pt.children.push(astToTree(v)));
} else if (pq.value && !(typeof pq.value === "string")) {
// pq.value is an object
pq.value && pt.children.push(astToTree(pq.value));
}

return pt;
}
Insert cell
import { Tree } from "@d3/tree"
Insert cell
import { Tree as RadialTree } from "@d3/radial-tree"
Insert cell
import { Icicle } from "@d3/icicle"
Insert cell
import {chart} with {pt as data} from "@d3/force-directed-tree"
Insert cell
// import {Editor} from '@cmudig/editor'
import {Editor} from "11c798ee666ebb7e" // set disabled
// import { Editor } from "11c798ee666ebb7e"
Insert cell
parser = require("js-sql-parser")
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