ScheduleTooltip
A feature that displays a tooltip containing the time at the mouse position when hovering empty parts of the schedule.
By default, in DayView and WeekView, the time is rounded to the view's increment
unless the precise config is set to true.
The example below illustrates how to use this feature in a Calendar instance and add a custom renderer to the tooltip. It shows the time at the pointer position, and if the pointer is outside of the core hours.
It also validates that any event being created or moved does not extend outside of the core hours:
//<code-header>
fiddle.title = 'Schedule tooltip';
//</code-header>
const calendar = new Calendar({
appendTo : targetElement,
height : 700,
// We have a little less width in our context, so reduce the responsive breakpoints
responsive : {
small : {
when : 480
},
medium : {
when : 640
}
},
// Start life looking at this date
date : '2020-03-01',
// Used to create view titles
dateFormat : 'DD MMM YYYY',
// CrudManager arranges loading and syncing of data in JSON form from/to a web service
crudManager : {
transport : {
load : {
url : 'data/Calendar/examples/feature/company-events.json'
}
},
autoLoad : true
},
// Features named by the properties are included.
// An object is used to configure the feature.
features : {
scheduleTooltip : {
// Add to the default content of the tooltip if hovering outside core hours.
renderer(view, date, preciseDate) {
const
{ coreHours } = view,
content = this.defaultRenderer(view, preciseDate),
hour = preciseDate.getHours();
if (hour < coreHours.start || hour >= coreHours.end) {
return `<strong>Outside core hours</strong>${content}`;
}
return content;
}
},
drag : {
// Each drag mode has a separate validation callback.
// We route them all to one on the calendar instance
validateCreateFn : 'up.validateDrag',
validateMoveFn : 'up.validateDrag',
validateResizeFn : 'up.validateDrag'
}
},
// Modes are the views available in the Calendar.
// An object is used to configure the view.
modes : {
agenda : null,
year : null,
week : {
dayStartTime : 8,
coreHours : {
overlayDay : true,
start : 9,
end : 18
}
},
day : {
dayStartTime : 8,
coreHours : {
overlayDay : true,
start : 9,
end : 18
}
}
},
onBeforeAutoCreate({ view, startDate, endDate }) {
return this.validateEventDates(view, startDate, endDate);
},
validateDrag({ drag, eventRecord }) {
return this.validateEventDates(drag.target.view, eventRecord.startDate, eventRecord.endDate);
},
validateEventDates(view, startDate, endDate) {
const
{ coreHours } = view,
endHour = endDate.getHours() + (endDate.getMinutes() / 60) + (endDate.getSeconds() / 3600);
// Enforce core hours.
if (startDate.getHours() < coreHours.start || endHour > coreHours.end) {
Toast.show(`Events can only be between ${coreHours.start}:00 and ${coreHours.end}:00`);
return false;
}
}
});const calendar = new Calendar({
features : {
scheduleTooltip : true
}
});
This feature is disabled by default.
Configs
15
Configs
15Other
Configure whether the tooltip should anchor to the day cell when not in a DayView.
By default, when not in a DayView, the tooltip will follow the mouse pointer.
If you enable this config, the tooltip will anchor to the day cell under the pointer instead.
When in a DayView, this config determines whether the tooltip should show the time at the pointer position
with a precision of seconds, or rounded to the nearest increment.
The function or the name of a function to use to create the tooltip content. The function is passed the full context of the pointer position.
An implementation may call the defaultRenderer method to get the default HTML string content.
| Parameter | Type | Description |
|---|---|---|
view | CalendarView | The Calendar view that the pointer is over. |
date | Date | The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any. |
preciseDate | Date | The precise date at the pointer position. This may differ from |
events | EventModel[] | The events which coincide with the pointer position. |
timeRanges | TimeRangeModel[] | The time ranges which coincide with the pointer position.
Each time range has a |
resource | ResourceModel | The resource record if any at the pointer position. |
The HTML or DOM configuration to display in the tooltip. A falsy return value will hide the tooltip.
Configure whether the tooltip should also show when hovering events.
By default, the tooltip only shows when hovering empty parts of the schedule.
If you enable this config, the tooltip will also show when hovering events.
The anchorToDayCell config will remove this conflict.
A function (or name of a function in the ownership hierarchy) which decides whether to show the ScheduleTooltip depending on the active view. The active view is passed, and if a truthy value is returned, the tip is shown, otherwise it is hidden.
This defaults to only showing for DayViews
| Parameter | Type | Description |
|---|---|---|
view | CalendarView | The Calendar view that the pointer is over. Return |
date | Date | The date at the pointer position as accurately as can be determined. If the view is a DayView, this date will have hour and minute resolution. |
Whether to show the ScheduleTooltip.
This config is used to directly configure the associated Tooltip.
Misc
Properties
22
Properties
22Common
Class hierarchy
Other
Configure whether the tooltip should anchor to the day cell when not in a DayView.
By default, when not in a DayView, the tooltip will follow the mouse pointer.
If you enable this config, the tooltip will anchor to the day cell under the pointer instead.
When in a DayView, this config determines whether the tooltip should show the time at the pointer position
with a precision of seconds, or rounded to the nearest increment.
The function or the name of a function to use to create the tooltip content. The function is passed the full context of the pointer position.
An implementation may call the defaultRenderer method to get the default HTML string content.
| Parameter | Type | Description |
|---|---|---|
view | CalendarView | The Calendar view that the pointer is over. |
date | Date | The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any. |
preciseDate | Date | The precise date at the pointer position. This may differ from |
events | EventModel[] | The events which coincide with the pointer position. |
timeRanges | TimeRangeModel[] | The time ranges which coincide with the pointer position.
Each time range has a |
resource | ResourceModel | The resource record if any at the pointer position. |
The HTML or DOM configuration to display in the tooltip. A falsy return value will hide the tooltip.
Configure whether the tooltip should also show when hovering events.
By default, the tooltip only shows when hovering empty parts of the schedule.
If you enable this config, the tooltip will also show when hovering events.
The anchorToDayCell config will remove this conflict.
A function (or name of a function in the ownership hierarchy) which decides whether to show the ScheduleTooltip depending on the active view. The active view is passed, and if a truthy value is returned, the tip is shown, otherwise it is hidden.
This defaults to only showing for DayViews
| Parameter | Type | Description |
|---|---|---|
view | CalendarView | The Calendar view that the pointer is over. Return |
date | Date | The date at the pointer position as accurately as can be determined. If the view is a DayView, this date will have hour and minute resolution. |
Whether to show the ScheduleTooltip.
Gets the Tooltip instance that this feature is using.
Functions
29
Functions
29Other
The default renderer for the tooltip, which shows the time at the pointer position.
If the view is a day view, it will also show the time in the format
specified by the timeFormat config of the view.
| Parameter | Type | Description |
|---|---|---|
view | CalendarView | The view that the pointer is over. |
date | Date | The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any. |
preciseDate | Date | The precise date at the pointer position. This may differ from |
events | EventModel[] | The events which coincide with the pointer position. |
timeRanges | TimeRangeModel[] | The time ranges which coincide with the pointer position. |
resource | ResourceModel | The resource record if any at the pointer position. |
The HTML to display in the tooltip.