Published
Edited
Mar 14, 2020
Grappolo2 [WIP]
Grappolo [WIP]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
essevvuggi = html`<svg></svg>`
Insert cell
{
const simulation = d3.forceSimulation(acini)
.force("charge", d3.forceManyBody().strength( grosso? -200: -690))
.force("link", d3.forceLink(viticci).distance( grosso? 20: 100))
.force("x", d3.forceX())
.force("y", d3.forceY());

const groups = ["viticci","acini","punte"]
const g = d3.select(essevvuggi)
.attr("width", width)
.attr("height", height)
.attr("viewBox", [-width / 2, -height / 2, width, height])
.selectAll("g")
.data(groups, d => d)
.join("g")
const links = g.filter( d => d == "viticci")
.attr("class","viticcio")
.selectAll("path")
.data(viticci)
.join("path")
.attr("id",function(d){return"("+d.source.id+","+d.target.id+")"})
.attr("marker-end","url(#punta)")
.attr("marker-start",function(d){return "url('#w("+d.source.id+","+d.target.id+")')";});
const nodes = g.filter( d => d == "acini" )
.attr("class","uva_acerba")
.selectAll("circle")
.data(acini)
.join("circle")
.attr("r", grosso? 35: 15)
.attr("id",function(d){return d.id;})
.call(drag(simulation));
g.filter( d => d == "punte" ).selectAll("defs").data([1]).join("defs")
.selectAll("marker")
.data(["punta","punta_B","punta_T","punta_to","punta_F","punta_C"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 5)
.attr("markerHeight", 5)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5")

simulation.on("tick", () => {
links.attr("d", d => {
const dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" + d.source.x + "," + d.source.y + "A" + dr + "," +
dr + " 0 0,1 " + d.target.x + "," + d.target.y;
});
nodes.attr("transform", d => "translate(" + d.x + "," + d.y + ")");
});

invalidation.then(() => simulation.stop());

}
Insert cell
grosso_toggle = { /* update on button press */ grosso_toggle_button; return !this }
Insert cell
height = 680
Insert cell
drag = 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
Insert cell
Insert cell
import {grid} from "@bryangingechen/grid-inputs"
Insert cell
import {pt} from "@fil/pt"
Insert cell
import {slider,button} from "@jashkenas/inputs"
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