All files / player-ui/src/components timing-graph.ts

14.28% Statements 1/7
0% Branches 0/2
0% Functions 0/2
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36            48x                                                          
import { html, nothing, type CSSResultGroup, type TemplateResult } from 'lit';
import { DataElement } from '../base.ts';
import type { BeMusicTimingData } from '../models.ts';
import { structureStyles } from '../styles/structure.ts';
 
export class BeMusicTimingGraphElement extends DataElement<BeMusicTimingData> {
  static override styles: CSSResultGroup = structureStyles;
  protected override render(): TemplateResult | typeof nothing {
    if (!this.data) return nothing;
    const hits = this.data.timings.slice(-32);
    const points = hits
      .map((hit, i) => `${(i / 31) * 220},${22 + Math.max(-100, Math.min(100, hit.deltaMs)) * 0.22}`)
      .join(' ');
    return html`<section class="panel" part="panel">
      <h3>Timing</h3>
      <svg
        part="graph"
        viewBox="0 0 220 44"
        preserveAspectRatio="none"
        role="img"
        aria-label="Recent timing offsets; early above and late below center"
      >
        <path d="M0 22H220" stroke="currentColor" stroke-dasharray="3 3"></path>
        <polyline
          fill="none"
          stroke="var(--be-music-timing-color,#ffa8b3)"
          stroke-width="1.5"
          stroke-linejoin="round"
          points=${points}
        ></polyline>
      </svg>
      <p class="muted">±100 ms · latest 32 timed hits</p>
    </section>`;
  }
}