Published
Edited
Mar 4, 2019
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
top = p.y - b.y
Insert cell
Insert cell
bottom = b.y + b.height - p.y
Insert cell
left = p.x - b.x
Insert cell
Insert cell
closest = {
let value = top, side = TOP;
if (right < value) value = right, side = RIGHT;
if (bottom < value) value = bottom, side = BOTTOM;
if (left < value) value = left, side = LEFT;
if (value < 0) return null;
return {value, side};
}
Insert cell
Insert cell
function offset({x, y, width, height}, {dx = 0, dy = 0}) {
return {x: x + dx, y: y + dy, width, height};
}
Insert cell
Insert cell
o = {
if (closest === null) return b;
switch (closest.side) {
case TOP: return offset(b, {dy: closest.value});
case RIGHT: return offset(b, {dx: -closest.value});
case BOTTOM: return offset(b, {dy: -closest.value});
case LEFT: return offset(b, {dx: closest.value});
}
}
Insert cell
Insert cell
Insert cell
Insert cell
viewof p = new View({x: width / 2, y: 150})
Insert cell
b = ({x: width / 5, y: 120, width: width / 2, height: 100})
Insert cell
TOP = Symbol("top")
Insert cell
Insert cell
BOTTOM = Symbol("bottom")
Insert cell
LEFT = Symbol("left")
Insert cell
height = 300
Insert cell
import {View} from "@mbostock/synchronized-views"
Insert cell
d3 = require("d3@5")
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