Class links.StepDate
StepDate
The class StepDate is an iterator for dates. You provide a start date and an
end date. The class itself determines the best scale (step size) based on the
provided start Date, end Date, and minimumStep.
If minimumStep is provided, the step size is chosen as close as possible
to the minimumStep but larger than minimumStep. If minimumStep is not
provided, the scale is set to 1 DAY.
The minimumStep should correspond with the onscreen size of about 6 characters
Alternatively, you can set a scale by hand.
After creation, you can initialize the class by executing start(). Then you
can iterate from the start date to the end date via next(). You can check if
the end date is reached with the function end(). After each step, you can
retrieve the current date via get().
The class step has scales ranging from milliseconds, seconds, minutes, hours,
days, to years.
Version: 0.9
Defined in: timeline.js.
Constructor Attributes | Constructor Name and Description |
---|---|
links.StepDate(start, end, minimumStep)
|
Method Attributes | Method Name and Description |
---|---|
addZeros(value, len)
Add leading zeros to the given value to match the desired length.
|
|
end()
Check if the end date is reached
|
|
Get the current datetime
|
|
getLabelMajor(optional)
Returns formatted text for the major axislabel, depending on the current
date and the scale.
|
|
Returns formatted text for the minor axislabel, depending on the current
date and the scale.
|
|
isMajor()
Check if the current step is a major step (for example when the step
is DAY, a major step is each first day of the MONTH)
|
|
next()
Do the next step
|
|
Round the current date to the first minor date value
This must be executed once when the current date is set to start Date
|
|
setAutoScale(enable)
Enable or disable autoscaling
|
|
setMinimumStep(minimumStep)
Automatically determine the scale that bests fits the provided minimum step
|
|
setRange(start, end, minimumStep)
Set a new range
If minimumStep is provided, the step size is chosen as close as possible
to the minimumStep but larger than minimumStep.
|
|
setScale(newScale, newStep)
Set a custom scale.
|
|
snap(date)
Snap a date to a rounded value.
|
|
start()
Set the step iterator to the start date.
|
- Parameters:
- {Date} start
- The start date, for example new Date(2010, 9, 21) or new Date(2010, 9,21,23,45,00)
- {Date} end
- The end date
- {int} minimumStep
- Optional. Minimum step size in milliseconds
- Parameters:
- {int} value
- A value
- {int} len
- Desired final length
- Returns:
- {string} value with leading zeros
- Returns:
- {boolean} true if the current date has passed the end date
- Returns:
- {Date} current The current date
- Parameters:
- {Date} optional
- custom date. if not provided, current date is taken
- Returns:
- {string} major axislabel
- Returns:
- {string} minor axislabel
- Returns:
- true if current date is major, else false.
- Parameters:
- {boolean} enable
- If true, autoascaling is set true
- Parameters:
- {int} minimumStep
- The minimum step size in milliseconds
- Parameters:
- {Date} start
- The start date and time.
- {Date} end
- The end date and time.
- {int} minimumStep
- Optional. Minimum step size in milliseconds
- Parameters:
- {Step.SCALE} newScale
- A scale. Choose from SCALE.MILLISECOND, SCALE.SECOND, SCALE.MINUTE, SCALE.HOUR, SCALE.DAY, SCALE.MONTH, SCALE.YEAR.
- {int} newStep
- A step size, by default 1. Choose for example 1, 2, 5, or 10.
- Parameters:
- {Date} date
- the date to be snapped