Skip to content

charton API


charton API / @chart-on/core / index / nearestInterval

Function: nearestInterval() ​

nearestInterval(requested, supported): Interval

Defined in: packages/core/src/data/interval.ts:172

The supported interval to show when requested may not be supported: requested itself when supported lists it or lists no interval the chart can parse (any interval then), else the one nearest by nominal length, compared as a ratio so 1h is as far from 30m as from 2h. A tie goes to the shorter interval. Activity intervals ('100T', '5000V') have no length: an unlisted one becomes the listed one of the same unit nearest in count, else the shortest listed time interval. When supported lists no time interval and nothing of the same unit, the first listed one wins. The result is always listed.

Parameters ​

requested ​

Interval

supported ​

readonly string[] | undefined

Returns ​

Interval