UNPKG

ngx-d3-tooltip

Version:

Add tooltips to your d3 visualizations using Angular Components.

77 lines (76 loc) 3.05 kB
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, Injector } from '@angular/core'; import { D3TooltipComponent } from './d3-tooltip.component'; /** * An interface for screen coordinates */ export interface ITooltipPosition { top: number; left: number; } /** * The available tooltip customization options */ export interface ITooltipOptions { /** * How long before tooltip appears */ delay?: number; /** * How long after mouseout the tooltip disappears */ offDelay?: number; /** * Where the tooltip is anchored (not to be confused with position) */ location?: 'mouse' | 'element'; /** * The direction from the anchor that the tooltip opens up from */ position?: 'auto' | 'top' | 'left' | 'bottom' | 'right' | 'topRight' | 'topLeft' | 'bottomRight' | 'bottomLeft'; /** * Additional classes added to the visible tooltip element. */ cssClasses?: string; } /** * The default tooltip options when not overridden. */ export declare const DEFAULT_OPTIONS: ITooltipOptions; /** * The injectable class with methods that allow for d3 tooltip creation. Injectable as `d3TooltipService`. */ export declare class D3TooltipService { private cfr; private appRef; private injector; constructor(cfr: ComponentFactoryResolver, appRef: ApplicationRef, injector: Injector); /** * This method returns a function that can be called with d3.Selection.call(). It adds * a tooltip/popover to the selection's elements which instantiates and inserts a component * specified by the first parameter. * * @param component The component class to insert into the tooltip * @param inputsFactory A function which returns an object for input values to the component * @param options Options for the returned tooltip function */ createFromComponent<T = any>(component: any, inputsFactory?: Function, outputsFactory?: Function, options?: ITooltipOptions): (selection) => void; /** * Displays the given component in a tooltip anchored * @param position The absolute coordinates of where the anchor for this tooltip is * @param component The component to instantiate * @param inputs The inputs to pass to the instantiated component * @param outputs The output subscribe handlers to attach to outputs * @param options Tooltip options object for further customization */ showTooltip(position: ITooltipPosition, component: any, inputs: any, outputs: any, options: ITooltipOptions): ComponentRef<D3TooltipComponent>; /** * Removes the given tooltip component reference. * @param tooltipRef The component reference of the open tooltip to remove */ removeTooltip(tooltipRef: ComponentRef<D3TooltipComponent>): void; /** * Given a component reference, returns the host DOM element. * @param componentRef The component reference whose DOM element will be returned */ private getDomElementFromComponentRef(componentRef); }