in src/tooltipService.ts [64:160]
public addTooltip<T>(
selection: Selection<any, any, any, any>,
getTooltipInfoDelegate: (datapoint: T) => VisualTooltipDataItem[],
getDataPointIdentity?: (datapoint: T) => ISelectionId,
reloadTooltipDataOnMouseMove?: boolean): void {
if (!selection || !this.visualHostTooltipService.enabled()) {
return;
}
let rootNode: Element = this.rootElement;
let internalSelection = selectAll(selection.nodes());
// Mouse events
internalSelection.on("mouseover.tooltip", (event: Event, data: T) => {
// Ignore mouseover while handling touch events
if (!this.canDisplayTooltip(event)) {
return;
}
let coordinates = this.getCoordinates(event, rootNode, true);
let tooltipInfo = getTooltipInfoDelegate(data);
if (tooltipInfo == null) {
return;
}
let selectionIds: ISelectionId[] = getDataPointIdentity ? [getDataPointIdentity(data)] : [];
this.visualHostTooltipService.show({
coordinates: coordinates,
isTouchEvent: false,
dataItems: tooltipInfo,
identities: selectionIds
});
});
internalSelection.on("mouseout.tooltip", (event: Event, data: T) => {
this.visualHostTooltipService.hide({
isTouchEvent: false,
immediately: false,
});
});
internalSelection.on("mousemove.tooltip", (event: Event, data: T) => {
// Ignore mousemove while handling touch events
if (!this.canDisplayTooltip(event)) {
return;
}
let coordinates = this.getCoordinates(event, rootNode, true);
let tooltipInfo: VisualTooltipDataItem[];
if (reloadTooltipDataOnMouseMove) {
tooltipInfo = getTooltipInfoDelegate(data);
if (tooltipInfo == null) {
return;
}
}
let selectionIds: ISelectionId[] = getDataPointIdentity ? [getDataPointIdentity(data)] : [];
this.visualHostTooltipService.move({
coordinates: coordinates,
isTouchEvent: false,
dataItems: tooltipInfo,
identities: selectionIds
});
});
// --- Touch events ---
let touchStartEventName: string = touch.touchStartEventName();
let touchEndEventName: string = touch.touchEndEventName();
let isPointerEvent: boolean = touch.usePointerEvents();
internalSelection.on(touchStartEventName + ".tooltip", (event, data: T) => {
let coordinates = this.getCoordinates(event, rootNode, true);
let tooltipInfo = getTooltipInfoDelegate(data);
let selectionIds: ISelectionId[] = getDataPointIdentity ? [getDataPointIdentity(data)] : [];
this.handleTouchTimeoutId = window.setTimeout(() => {
this.visualHostTooltipService.show({
coordinates: coordinates,
isTouchEvent: true,
dataItems: tooltipInfo,
identities: selectionIds
});
this.handleTouchTimeoutId = undefined;
}, this.handleTouchDelay);
});
internalSelection.on(touchEndEventName + ".tooltip", () => {
this.cancelTouchTimeoutEvents();
});
}