placeLabelfunction
Put a name on one side of a star: right, left, above (centred over it) or below (centred under it), with the star's catalogue letter under the name when designation is true. Writes into out and answers whether the whole block, and its line, are inside the view.
createStarNames tries the four sides in order and takes the first that covers no other name and no star.
Import it
import { placeLabel } from "@johnmorrisdotca/hoshi-stars/sky-labels";
Definition
function placeLabel(x: number, y: number, width: number, style: LabelStyle, view: SkyView, out: StarNameLabel, designation?: boolean, side?: LabelSide): boolean
Parameters
| Name | Type | Description |
|---|---|---|
x | number | The star's x on the screen. |
y | number | The star's y on the screen. |
width | number | The widest line's width in pixels ( |
style | LabelStyle | A complete look. |
view | SkyView | The part of the screen names may use. |
out | StarNameLabel | Where the answer is written. |
designation (optional) | boolean | True when a line for the catalogue letter goes under the name. |
side (optional) | "below" | "right" | "left" | "above" | Which side; |
Returns
boolean
true when it fits.
Examples
import { labelStyle, labelWidth, placeLabel, type StarNameLabel } from "@johnmorrisdotca/hoshi-stars/sky-labels";
const style = labelStyle({ leader: 14 });
const out = {} as StarNameLabel;
console.log(placeLabel(395, 100, labelWidth("Rigel", style), style, { width: 400, height: 300 }, out), placeLabel(395, 100, labelWidth("Rigel", style), style, { width: 400, height: 300 }, out, false, "left"), out.anchor);false true endWhat it prints (run when this page was built)