import { Edge, Node, NodeList, EdgeList, ItemList, ItemId, Item } from "@linkurious/ogma"; import { TimelineOptions as VTimelineOptions, DataGroup, Graph2d, Timeline, TimelineEventPropertiesResult, Graph2dOptions, DataItem, IdType } from "vis-timeline"; import { click, rangechanged, scaleChange, redraw, timechange, timechanged, rangechange, select } from "./constants"; export type FilterStrategy = "before" | "after" | "between" | "outside"; export type FilterTolerance = "strict" | "loose"; export type FilterOptions = { enabled: boolean; strategy: FilterStrategy; tolerance: FilterTolerance; }; export type IdFunction = (item: ElementType) => string; export type GroupFunction = (groupId: string, items: ElementType) => string; export type ItemGenerator = (elements: ElementType, groupId: string) => Partial; export interface BaseOptions { nodeGroupIdFunction?: IdFunction; nodeGroupContent?: GroupFunction; nodeItemGenerator?: ItemGenerator; getNodeClass?: ItemGenerator; edgeGroupIdFunction?: IdFunction; edgeGroupContent?: GroupFunction; edgeItemGenerator?: ItemGenerator; getEdgeClass?: ItemGenerator; } /** * @typedef {object} BarchartOptions * @property {Graph2dOptions} graph2dOptions (https://visjs.github.io/vis-timeline/docs/graph2d/#graph2dOptions) to pass to the barchart * @property {Function} groupIdFunction Similar to [Ogma addNodeGrouping](https://doc.linkurious.com/ogma/latest/api.html#Ogma-transformations-addNodeGrouping) groupIdFunction * @property {Function} groupContent Generates the content of the group. See [Visjs groups](https://visjs.github.io/vis-timeline/docs/graph2d/#groups) */ export interface BarchartOptions extends BaseOptions, NodeList, EdgeList> { graph2dOptions?: Graph2dOptions; } export interface TimelineOptions extends BaseOptions, Node, Edge> { timelineOptions?: VTimelineOptions; } /** * @typedef {object} Options * @property {TimelineOptions} graph2dOptions (https://visjs.github.io/vis-timeline/docs/graph2d/#graph2dOptions) to pass to the barchart * @property {BarchartOptions} groupIdFunction Similar to [Ogma addNodeGrouping](https://doc.linkurious.com/ogma/latest/api.html#Ogma-transformations-addNodeGrouping) groupIdFunction * @property {Function} groupContent Generates the content of the group. See [Visjs groups](https://visjs.github.io/vis-timeline/docs/graph2d/#groups) */ export interface Options { timeline?: TimelineOptions; barchart?: BarchartOptions; timeBars?: TimebarOptions[]; edgeFilter?: FilterOptions; nodeFilter?: FilterOptions; nodeStartPath?: string; nodeEndPath?: string; edgeStartPath?: string; edgeEndPath?: string; switchOnZoom?: boolean; showBarchart?: boolean; start?: number | Date; end?: number | Date; } export type Id = number | string; export type Lookup = { [key in Id]: T; }; export type BarChartItem = { ids: ItemId[]; group: string; label: string; x: number; y: number; }; export type TimeToIds = Map>; export type ItemByScale = { items: BarChartItem[]; itemToElements: Lookup; groups: DataGroup[]; timeToIds: TimeToIds; tooZoomed: boolean; maxY: number; }; export type TimelineData = { items: DataItem[]; groups: DataGroup[]; itemToElements: Lookup; elementToItem: Lookup; }; export type TimelineMode = "barchart" | "timeline"; export type NAND = Omit & Omit; export type AND = Omit>; export type VChart = AND; export type ScaleChangeEvt = { scale: number; tooZoomed: boolean; }; export type ClickEvt = { edges?: EdgeList | Edge; nodes?: NodeList | Node; evt: TimelineEventPropertiesResult; }; export type SelectEvt = { edges?: EdgeList | Edge; nodes?: NodeList | Node; evt: MouseEvent; }; export type Events = { [scaleChange]: (evt: ScaleChangeEvt) => void; [click]: (evt: ClickEvt) => void; [rangechanged]: () => void; [rangechange]: () => void; [timechange]: () => void; [timechanged]: () => void; [redraw]: () => void; [select]: (evt: SelectEvt) => void; }; export type ControlerEvents = { [timechange]: () => void; [select]: (evt: SelectEvt) => void; }; export type Timebar = { delta: number; id: IdType; fixed: boolean; }; /** * @typedef {object} TimebarOptions Options to setup filter bars in the chart. * It can be a number, a date or an object. */ export type TimebarOptions = { fixed?: boolean; date: Date; } | number | Date; export type Scale = { name: string; millis: number; round?: (date: Date) => number; };