Skip to main content

Class: default

Defined in: src/lib/classes/StrokeLog/index.ts:94

Records when brush and eraser strokes start, end, are cancelled or are ignored, with timings for each stroke, plus other work done meanwhile (see BackgroundWork), for the debug panel. Times are in the same clock as event.timeStamp and performance.now(). Keeps only the most recent entries.

Each finished or cancelled stroke measures (in ms unless noted):

  • gap: time since the previous stroke ended
  • wait: how long the press waited before it was handled (the page was busy)
  • begin: time taken to start the stroke
  • moves: pointer events handled (count), maxMoveWait: longest one waited, moveMs: total time handling them
  • frames: frames drawn (count), maxFrame: longest frame to draw, maxFrameGap: longest time between frames (including after the last one), overlays: times the brush cursor was drawn (count)
  • end: time taken to write the stroke into its layer
  • duration: from press to release
  • layers: layers drawn (count) and zoomPct: the zoom as a percentage, when the stroke started (if given)

Records nothing while switched off (enabled); work given to measure still runs.

Dispatches a change event when entries are added or cleared.

Example​

const log = new StrokeLog();
log.begin("pen", event.timeStamp, 2);
log.move(event.timeStamp, 0.5);
log.end(event.timeStamp, 3); // entry with kind "end" and its measures

Extends​

  • EventTarget

Constructors​

Constructor​

new default(limit?): StrokeLog

Defined in: src/lib/classes/StrokeLog/index.ts:111

Parameters​

limit?​

number = DEFAULT_STROKE_LOG_LIMIT

Returns​

StrokeLog

Overrides​

EventTarget.constructor

Properties​

enabled​

enabled: boolean = true

Defined in: src/lib/classes/StrokeLog/index.ts:102

Whether anything is recorded


limit​

readonly limit: number

Defined in: src/lib/classes/StrokeLog/index.ts:96

Maximum number of entries kept


now​

now: () => number

Defined in: src/lib/classes/StrokeLog/index.ts:99

Current time in milliseconds (replaceable for tests)

Returns​

number

Accessors​

drawing​

Get Signature​

get drawing(): boolean

Defined in: src/lib/classes/StrokeLog/index.ts:122

Whether a stroke is being measured

Returns​

boolean


entries​

Get Signature​

get entries(): readonly StrokeLogEntry[]

Defined in: src/lib/classes/StrokeLog/index.ts:117

Logged entries, oldest first

Returns​

readonly StrokeLogEntry[]

Methods​

addEventListener()​

addEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | AddEventListenerOptions

Returns​

void

Inherited from​

EventTarget.addEventListener


begin()​

begin(pointerType, eventTime, beginMs, scene?): void

Defined in: src/lib/classes/StrokeLog/index.ts:130

A stroke started: the pointer type, when it pressed (event time), how long starting the stroke took, and what was on screen.

Parameters​

pointerType​

string

eventTime​

number

beginMs​

number

scene?​

StrokeScene

Returns​

void


cancel()​

cancel(reason): void

Defined in: src/lib/classes/StrokeLog/index.ts:205

The stroke in progress was abandoned, and why.

Parameters​

reason​

string

Returns​

void


clear()​

clear(): void

Defined in: src/lib/classes/StrokeLog/index.ts:255

Remove all entries.

Returns​

void


dispatchEvent()​

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

event​

Event

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


end()​

end(eventTime, endMs): void

Defined in: src/lib/classes/StrokeLog/index.ts:196

The stroke finished: when the pointer released (event time) and how long writing it into the layer took.

Parameters​

eventTime​

number

endMs​

number

Returns​

void


frame()​

frame(ms): void

Defined in: src/lib/classes/StrokeLog/index.ts:176

A frame was drawn, taking ms; counted towards the stroke in progress, if any.

Parameters​

ms​

number

Returns​

void


gesture()​

gesture(gesture, action): void

Defined in: src/lib/classes/StrokeLog/index.ts:221

A touch gesture did an action.

Parameters​

gesture​

string

action​

string

Returns​

void


ignore()​

ignore(pointerType, reason): void

Defined in: src/lib/classes/StrokeLog/index.ts:214

A pointer press didn't start a stroke, and why.

Parameters​

pointerType​

string

reason​

string

Returns​

void


measure()​

measure<T>(name, run): T

Defined in: src/lib/classes/StrokeLog/index.ts:241

Run some work and return its result, logging how long it kept the page busy, or for work that finishes later (a promise), how long it took altogether once it settles.

Type Parameters​

T​

T

Parameters​

name​

string

run​

() => T

Returns​

T

Example​

log.measure("map", () => drawMap()); // logs "map" with how long it took
log.measure("save", () => save()); // logs "save" with how long it took once saved (or failed)

move()​

move(eventTime, moveMs): void

Defined in: src/lib/classes/StrokeLog/index.ts:164

The stroke continued: when the pointer moved (event time) and how long handling it took.

Parameters​

eventTime​

number

moveMs​

number

Returns​

void


overlay()​

overlay(): void

Defined in: src/lib/classes/StrokeLog/index.ts:189

The brush cursor was drawn; counted towards the stroke in progress, if any.

Returns​

void


removeEventListener()​

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | EventListenerOptions

Returns​

void

Inherited from​

EventTarget.removeEventListener


work()​

work(name, measures): void

Defined in: src/lib/classes/StrokeLog/index.ts:229

Other work was done, with its measurements: ms for how long it kept the page busy, and total for how long work that finishes later took altogether (which can include waiting that doesn't keep the page busy).

Parameters​

name​

string

measures​
ms?​

number

total?​

number

Returns​

void