Published
Edited
Mar 3, 2021
2 stars
Insert cell
md`# label placement`
Insert cell
Insert cell
orientation = getOrientation(dx, dy)
Insert cell
viewof dx = Range([-100, 100], {value: 0, label: "dx"})
Insert cell
viewof dy = Range([-100, 100], { value: 0, label: "dy" })
Insert cell
angle = 1 - ((Math.atan2(dy, dx)-Math.PI/4) / Math.PI) * 2
Insert cell
angleRound = Math.round(angle)
Insert cell
angleDeg = angle / Math.PI * 180
Insert cell
import {Range} from "@observablehq/inputs"

Insert cell
getOrientation = function(dx, dy) {
return ['bottom-end', 'bottom-start', 'top-start', 'top-end'][
Math.round(1 - ((Math.atan2(dy, dx) - Math.PI / 4) / Math.PI) * 2)
];
}
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