github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/components/TimelineChart/centerTimelineData.ts (about)

     1  import type { Timeline } from '@webapp/models/timeline';
     2  
     3  export interface TimelineData {
     4    data?: Timeline;
     5    color?: string;
     6  }
     7  
     8  function decodeTimelineData(timeline: Timeline) {
     9    if (!timeline) {
    10      return [];
    11    }
    12    let time = timeline.startTime;
    13    return timeline.samples.map((x) => {
    14      const res = [time * 1000, x];
    15      time += timeline.durationDelta;
    16      return res;
    17    });
    18  }
    19  
    20  // Since profiling data is chuked by 10 seconds slices
    21  // it's more user friendly to point a `center` of a data chunk
    22  // as a bar rather than starting point, so we add 5 seconds to each chunk to 'center' it
    23  export function centerTimelineData(timelineData: TimelineData) {
    24    return timelineData.data
    25      ? decodeTimelineData(timelineData.data).map((x) => [
    26          x[0] + 5000,
    27          x[1] === 0 ? 0 : x[1] - 1,
    28        ])
    29      : [[]];
    30  }