Time Class
Class for time-related operations, such as calculating the scale of the time axis, calculating the time based on the x coordinate, and calculating the x coordinate based on the time.
Constructor
constructor
// constructor function, which takes the Gantt instance as a parameter
constructor(gantt: Gantt): TimeInstance Properties
gantt
Gantt instance
ticks
Caculate the number of ticks based on the user-defined column.
timeTicks
Caculate the time interval between each tick based on the user-defined column.
stepTime
Transform the user-defined column timeMetric into a step size in milliseconds.
fixUnit
Find the appropriate unit for adding or subtracting dayjs when the user-defined column timeMetric is fixed.
fixUnitStepTime
Transform fixUnit into milliseconds.
startTime
View start time
endTime
View end time, which is different from the gantt instance's endTime, because the view may be larger than the gantt content, so the view's endTime may be greater than the gantt's endTime.
Instance Methods
time2x
// Calculate the x coordinate based on the time and start time
time2x(time: Dayjs, startTime?: Dayjs): numberx2time
// Get time by x
x2time(x: number, startTime?: Dayjs): DayjscontainerScrollLeftTime
// Calculates the time corresponding to the position of the left scroll bar of the container
containerScrollLeftTime(): DayjsstageWidthTime
// Calculates the time corresponding to the width of the stage
stageWidthTime(): Dayjslength2milliseconds
// Calculates the milliseconds based on the length of the time axis
length2milliseconds(length: number): numbergetWidthByTwoTime
// Calculates the width of the time axis based on two times
getWidthByTwoTime(time1: Dayjs, time2: Dayjs): numberdayjs2duration
// Convert Dayjs time object to duration format (in seconds)
dayjs2duration(time: Dayjs): numbergetTickByIndex
// Get the tick time by tick index
getTickByIndex(index: number): DayjsgetTimeTickByIndex
// Get the time tick by time tick index
getTimeTickByIndex(index: number): DayjslastTick
// Get the last tick time
lastTick(): DayjslastTimeTick
// Get the last time tick
lastTimeTick(): DayjsgetTicksIterator
// Get ticks iterator for traversing ticks within the visible area
getTicksIterator(): GeneratorgetTimeTicksIterator
// Get time ticks iterator for traversing time ticks within the visible area
getTimeTicksIterator(): GeneratorgetNoneEventStartTime
// Get the start time when there are no events
getNoneEventStartTime(): Dayjs