\Drupal\strata\Timeline TimelineWindow

A span of time and the resolution it is drawn at.

The resolution is derived from the span, never chosen by the caller. A timeline is pannable and zoomable down to the second, so the same code has to draw a ten-second window and a two-year one. Letting the caller pick a bucket size means a zoomed-out view asking for per-second buckets and building sixty million of them, which is a page that never renders. Instead the window picks the finest rung of the ladder that keeps the bucket count under the cap.

Buckets are aligned to the resolution rather than to the window's start, so panning by half a bucket does not shift every boundary and make the same commits appear to move between bars. A reader panning a chart expects the bars to stay put.

Everything is in unix microseconds, because that is the precision a commit is stamped with and rounding to seconds here would collapse two commits from the same flush into one point.

Summary

Methods
Properties
Constants
__construct
spanning
lastSeconds
seconds
bucketCount
boundaries
bucketFor
finer
coarser
pan
resolutionLabel
jsonSerialize
fromMicrotime
toMicrotime
resolution
MICROS_PER_SECOND
LADDER
MAX_BUCKETS
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

MICROS_PER_SECOND

MICROS_PER_SECOND = 1000000

Microseconds in a second.

LADDER

LADDER = [1, 5, 15, 60, 300, 900, 3600, 21600, 86400, 604800]

Bucket widths in seconds, finest first.

A second at the bottom because a flush interval of fifteen seconds means per-second detail is the finest that shows anything; a week at the top because a year drawn in weeks is 52 bars.

MAX_BUCKETS

MAX_BUCKETS = 480

Buckets one window may hold.

A chart wider than this has bars under a pixel, so the extra buckets cost work and show nothing.

Properties

$fromMicrotime

$fromMicrotime : int

Type

int

$toMicrotime

$toMicrotime : int

Type

int

$resolution

$resolution : int

Type

int

Methods

__construct()

__construct(int  $fromMicrotime, int  $toMicrotime, int  $resolution) : mixed

Constructs a window.

Parameters

int $fromMicrotime

Inclusive start, in unix microseconds.

int $toMicrotime

Inclusive end, in unix microseconds.

int $resolution

Bucket width in seconds.

Throws

\InvalidArgumentException

When the window ends before it starts, or the resolution is not positive.

Returns

mixed —

spanning()

spanning(int  $fromMicrotime, int  $toMicrotime, int  $maxBuckets = \self::MAX_BUCKETS) : self

A window over a span, at the finest resolution that fits.

Parameters

int $fromMicrotime

Inclusive start, in unix microseconds.

int $toMicrotime

Inclusive end, in unix microseconds.

int $maxBuckets

Buckets to stay under.

Returns

self —

The window.

lastSeconds()

lastSeconds(int  $seconds, int  $now, int  $maxBuckets = \self::MAX_BUCKETS) : self

A window covering the last stretch of time.

Parameters

int $seconds

How far back to look.

int $now

The unix second to end at.

int $maxBuckets

Buckets to stay under.

Returns

self —

The window.

seconds()

seconds() : float

How long the window covers.

Returns

float —

Seconds.

bucketCount()

bucketCount() : int

How many buckets the window holds.

Returns

int —

The count, at least one.

boundaries()

boundaries() : list<int>

The start of every bucket, in unix microseconds, oldest first.

Returns

list

Bucket starts.

bucketFor()

bucketFor(int  $microtime) : int

Which bucket a moment falls in.

Parameters

int $microtime

Unix microseconds.

Returns

int —

The bucket's start, in unix microseconds.

finer()

finer() : self

A window over the same span, one rung finer.

Returns

self —

The zoomed window, or this one when already at the finest rung.

coarser()

coarser() : self

A window over the same span, one rung coarser.

Returns

self —

The zoomed window, or this one when already at the coarsest rung.

pan()

pan(float  $fraction) : self

A window of the same width and resolution, moved along.

Parameters

float $fraction

How much of the window's width to move by; negative moves back in time.

Returns

self —

The panned window.

resolutionLabel()

resolutionLabel() : string

The resolution, named for a reader.

Returns

string —

Something such as "15 seconds" or "6 hours".

jsonSerialize()

jsonSerialize() : array

{@inheritdoc}

Returns

array —