@@ -12,8 +12,8 @@ export interface Options {
1212 /**
1313 * Transformation function to be applied in combination with "currency".
1414 *
15- * @param } value The original value.
16- * @param options Plugin options.
15+ * @param value - The original value.
16+ * @param options - Plugin options.
1717 * @returns Tooltip value for output.
1818 */
1919 currencyFormatCallback ?: ( value : string , options : Options ) => string ;
@@ -46,15 +46,15 @@ export interface Options {
4646 /**
4747 * Custom function to generate tooltip (entire HTML markup).
4848 *
49- * @param meta Point's meta value.
50- * @param value Point's value.
49+ * @param meta - Point's meta value.
50+ * @param value - Point's value.
5151 * @returns Tooltip markup.
5252 */
5353 tooltipFnc ?: ( meta : string , value : string ) => string ;
5454 /**
5555 * Custom function to generate tooltip text (content only).
5656 *
57- * @param value Point's value.
57+ * @param value - Point's value.
5858 * @returns Tooltip text.
5959 */
6060 transformTooltipTextFnc ?: ( value : string ) => string ;
@@ -67,7 +67,7 @@ export interface Options {
6767/**
6868 * Chartist.js plugin to display a data label on top of the points in a line chart.
6969 */
70- export function ChartistPluginTooltip < T extends BaseChart < any > > (
70+ export function ChartistPluginTooltip < T extends BaseChart > (
7171 chart : T ,
7272 options ?: Partial < Options >
7373) : void {
@@ -126,9 +126,7 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
126126 tt . classList . add ( 'chartist-tooltip' ) ;
127127 if ( $options . class ) {
128128 if ( Array . isArray ( $options . class ) ) {
129- $options . class . forEach ( function ( c : string ) {
130- tt ?. classList . add ( c ) ;
131- } ) ;
129+ $options . class . forEach ( ( c : string ) : void => tt ?. classList . add ( c ) ) ;
132130 } else {
133131 tt . classList . add ( $options . class ) ;
134132 }
@@ -148,7 +146,7 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
148146
149147 hide ( $toolTip ) ;
150148
151- $chart . addEventListener ( 'mouseover' , function ( event : MouseEvent ) : void {
149+ $chart . addEventListener ( 'mouseover' , ( event : MouseEvent ) : void => {
152150 if ( ! ( event . target as HTMLElement ) . classList . contains ( tooltipSelector ) ) {
153151 return ;
154152 }
@@ -234,13 +232,13 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
234232 }
235233 } ) ;
236234
237- $chart . addEventListener ( 'mouseout' , function ( event : MouseEvent ) {
235+ $chart . addEventListener ( 'mouseout' , ( event : MouseEvent ) : void => {
238236 if ( ( event . target as HTMLElement ) . classList . contains ( tooltipSelector ) ) {
239237 $toolTip && hide ( $toolTip ) ;
240238 }
241239 } ) ;
242240
243- $chart . addEventListener ( 'mousemove' , function ( event : MouseEvent ) : void {
241+ $chart . addEventListener ( 'mousemove' , ( event : MouseEvent ) : void => {
244242 if ( ! $options . anchorToPoint && $toolTipIsShown ) {
245243 setPosition ( event ) ;
246244 }
@@ -294,37 +292,48 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
294292 }
295293
296294 /**
297- * Shows the tooltip element, if not shown
298- * @param element
295+ * Shows the tooltip element, if not shown.
296+ *
297+ * @param element - The HTML element to show
299298 */
300- function show ( element : HTMLElement ) {
299+ function show ( element : HTMLElement ) : void {
301300 $toolTipIsShown = true ;
302301 element . classList . add ( 'tooltip-show' ) ;
303302 }
304303
305304 /**
306- * Hides the tooltip element
307- * @param element
305+ * Hides the tooltip element.
306+ *
307+ * @param element - The HTML element to hide
308308 */
309- function hide ( element : HTMLElement ) {
309+ function hide ( element : HTMLElement ) : void {
310310 $toolTipIsShown = false ;
311311 element . classList . remove ( 'tooltip-show' ) ;
312312 }
313313
314- function next ( element : HTMLElement , className : string ) {
314+ /**
315+ * Find the next element that has a specific class.
316+ *
317+ * @param element - Base element to start off the search
318+ * @param className - Class name to search for
319+ * @returns Matching HTML element of NULL, if none was found
320+ */
321+ function next ( element : HTMLElement , className : string ) : HTMLElement | null {
322+ let nextEl : HTMLElement | null = element ;
315323 do {
316- element = element . nextSibling as HTMLElement ;
317- } while ( element && ! element . classList . contains ( className ) ) ;
324+ nextEl = element . nextSibling as HTMLElement | null ;
325+ } while ( nextEl && ! nextEl . classList . contains ( className ) ) ;
318326
319- return element ;
327+ return nextEl ;
320328 }
321329
322330 /**
331+ * Get textual content of an element.
323332 *
324- * @param element
325- * @return string
333+ * @param element - HTML element to process
334+ * @returns Text content of the element
326335 */
327- function text ( element : HTMLElement ) {
328- return element . innerText || element . textContent ;
336+ function text ( element : HTMLElement ) : string {
337+ return element . innerText || element . textContent || '' ;
329338 }
330339}
0 commit comments