Published
Edited
Aug 3, 2020
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Run this once: set the collection to the original force layout
// comment out when done
// initialObject = {
// let obj = {};
// initialGroup.forEach(d => {
// let id = nodeId(d[0]);
// let o = (obj[id] = {
// x: d[0].x,
// y: d[0].y,
// name: d[0].data.name
// });
// db.collection('mindmap')
// .doc(id)
// .set(o);
// });
// return obj;
// }
Insert cell
Insert cell
Insert cell
firebaseLookup
Insert cell
uuid = require('uuid@8.3.0/dist/umd/uuid.min.js')
Insert cell
ColorHash = require('color-hash@1.0.3/dist/color-hash.js')
Insert cell
colorHash = new ColorHash()
Insert cell
userId = uuid.v4()
Insert cell
height = width * .67
Insert cell
svg
Insert cell
firebaseSvg
Insert cell
dragFirebase = function(simulation) {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
// d.fx = d.x;
// d.fy = d.y;

// this wont work because we lose our drag handler
// let id = nodeId(d.__proto__);
// console.log("d", id, d.fx, d.fy);
// db.collection("mindmap")
// .doc(id)
// .update({ fill: "orange" });
}

function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
// d.fx = d.tx;
// d.fy = d.ty;
// d.x = d.tx;
// d.y = d.ty;
// let id = nodeId(d.__proto__);
// console.log("d", id, d.fx, d.fy);
}

function dragended(d) {
// update firebase
// console.log("drag end", d);

let id = nodeId(d.__proto__);
console.log("d", id, d.fx, d.fy);
let fy = d.fy > height - 50 ? height - 50 : d.fy;
let fx = d.fx > width - 50 ? width - 50 : d.fx;
db.collection("mindmap")
.doc(id)
.update({ x: fx, y: fy, fill: "lightgray" });

d.editing = false;
// d.fx = null;
// d.fy = null;
}

return d3
.drag()
.filter(d => {
return !d3.event.click;
// return d.editing;
})
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
Insert cell
dragSim = simulation => {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}

function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}

function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}

return d3
.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
chart
Insert cell
Insert cell
root = d3.hierarchy(mindmapTree)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nodes = root.descendants().slice(1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more