Skip to the content

Chizu地図

Draw SVG maps, frame regions, place numbered callouts and build geography quizzes with English and Japanese names.

Chizu is the Japanese word 地図 for map. About the name

Contents

Reference · Framing, geometry and quiz tools

placeHandlesfunction

Places every handle clear of the ones before it.

Greedy and order-dependent by design: the caller has already sorted the marks into the order they are numbered, and a handle that has found a home does not move to make room for a later one. With a handful of choices on a board that is enough, and it keeps the placement stable as tones change mid-question.

Import it

import { placeHandles } from "@johnmorrisdotca/chizu";

Definition

function placeHandles<T>(entries: ReadonlyArray<{ item: T; centroid: readonly [number, number]; }>, radius: number, bounds?: HandleBounds): Array<HandleSpot & { item: T; }>

Parameters

NameTypeDescription
entriesreadonly { item: T; centroid: readonly [number, number]; }[]

Native places to order or lay out.

radiusnumber

The circle or label radius in native map units.

bounds (optional)HandleBounds | undefined

The allowed label placement bounds in native map units.

Returns

(HandleSpot & { item: T; })[]

Places every handle clear of the ones before it.

Examples

import { placeHandles } from "@johnmorrisdotca/chizu";

const spots = placeHandles([{ item: "a", centroid: [50, 50] }, { item: "b", centroid: [52, 50] }], 4);
console.log(spots.map((spot) => spot.item).join(" "), Math.hypot(spots[0]!.hx - spots[1]!.hx, spots[0]!.hy - spots[1]!.hy) >= 8);
// a b true
a b true

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/chizu 1.5.0.