Can't correctly extent vis.Timeline class

23 Views Asked by At

Here is my code

import {
  DataItemCollectionType,
  DateType,
  IdType,
  Timeline,
  TimelineOptions,
} from 'vis-timeline';

export default class Context extends Timeline {
  private myCustomTimes: IdType[] = [];

  constructor(
    container: HTMLElement,
    items: DataItemCollectionType,
    options?: TimelineOptions
  ) {
    super(container, items, options);
    this.myCustomTimes = [];
  }

  addCustomTime(time: DateType, id?: IdType): IdType {
    const res = super.addCustomTime(time, id);
    this.myCustomTimes.push(res);
    return res;
  }

  getAllCustomTimes(): [IdType, Date][] {
    return this.myCustomTimes.map((id: IdType) => [
      id,
      super.getCustomTime(id),
    ]);
  }
}


All I want is to extent vis.Timeline class and to add a custom method getAllCustomTimes which is missing in the library. Howewer, I receive an error when trying to create an instance of it: Something is wrong with the Timeline scale. Limited drawing of grid lines to 1000 lines. Here is the code where I try to create it:

export default class Timeline {
  private parent: HTMLElement;

  private context: Context;

  constructor(parent: HTMLElement) {
    this.parent = parent;
    const holder = d3.select(parent).select('div');
    const items = new DataSet();
    this.context = new Context(
      holder.node() as HTMLElement,
      items,
      undefined
    );
    const currentTime = this.context.getCurrentTime();
    this.context.addCustomTime(currentTime.getTime(), uuidv4());
    this.context.addCustomTime(currentTime.getTime() - 1000, uuidv4());
  }
}

Will be glad to receive any help!

0

There are 0 best solutions below