@@ -12,8 +12,8 @@ export interface Options {
12
12
/**
13
13
* Transformation function to be applied in combination with "currency".
14
14
*
15
- * @param } value The original value.
16
- * @param options Plugin options.
15
+ * @param value - The original value.
16
+ * @param options - Plugin options.
17
17
* @returns Tooltip value for output.
18
18
*/
19
19
currencyFormatCallback ?: ( value : string , options : Options ) => string ;
@@ -46,15 +46,15 @@ export interface Options {
46
46
/**
47
47
* Custom function to generate tooltip (entire HTML markup).
48
48
*
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.
51
51
* @returns Tooltip markup.
52
52
*/
53
53
tooltipFnc ?: ( meta : string , value : string ) => string ;
54
54
/**
55
55
* Custom function to generate tooltip text (content only).
56
56
*
57
- * @param value Point's value.
57
+ * @param value - Point's value.
58
58
* @returns Tooltip text.
59
59
*/
60
60
transformTooltipTextFnc ?: ( value : string ) => string ;
@@ -67,7 +67,7 @@ export interface Options {
67
67
/**
68
68
* Chartist.js plugin to display a data label on top of the points in a line chart.
69
69
*/
70
- export function ChartistPluginTooltip < T extends BaseChart < any > > (
70
+ export function ChartistPluginTooltip < T extends BaseChart > (
71
71
chart : T ,
72
72
options ?: Partial < Options >
73
73
) : void {
@@ -126,9 +126,7 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
126
126
tt . classList . add ( 'chartist-tooltip' ) ;
127
127
if ( $options . class ) {
128
128
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 ) ) ;
132
130
} else {
133
131
tt . classList . add ( $options . class ) ;
134
132
}
@@ -148,7 +146,7 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
148
146
149
147
hide ( $toolTip ) ;
150
148
151
- $chart . addEventListener ( 'mouseover' , function ( event : MouseEvent ) : void {
149
+ $chart . addEventListener ( 'mouseover' , ( event : MouseEvent ) : void => {
152
150
if ( ! ( event . target as HTMLElement ) . classList . contains ( tooltipSelector ) ) {
153
151
return ;
154
152
}
@@ -234,13 +232,13 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
234
232
}
235
233
} ) ;
236
234
237
- $chart . addEventListener ( 'mouseout' , function ( event : MouseEvent ) {
235
+ $chart . addEventListener ( 'mouseout' , ( event : MouseEvent ) : void => {
238
236
if ( ( event . target as HTMLElement ) . classList . contains ( tooltipSelector ) ) {
239
237
$toolTip && hide ( $toolTip ) ;
240
238
}
241
239
} ) ;
242
240
243
- $chart . addEventListener ( 'mousemove' , function ( event : MouseEvent ) : void {
241
+ $chart . addEventListener ( 'mousemove' , ( event : MouseEvent ) : void => {
244
242
if ( ! $options . anchorToPoint && $toolTipIsShown ) {
245
243
setPosition ( event ) ;
246
244
}
@@ -294,37 +292,48 @@ export function ChartistPluginTooltip<T extends BaseChart<any>>(
294
292
}
295
293
296
294
/**
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
299
298
*/
300
- function show ( element : HTMLElement ) {
299
+ function show ( element : HTMLElement ) : void {
301
300
$toolTipIsShown = true ;
302
301
element . classList . add ( 'tooltip-show' ) ;
303
302
}
304
303
305
304
/**
306
- * Hides the tooltip element
307
- * @param element
305
+ * Hides the tooltip element.
306
+ *
307
+ * @param element - The HTML element to hide
308
308
*/
309
- function hide ( element : HTMLElement ) {
309
+ function hide ( element : HTMLElement ) : void {
310
310
$toolTipIsShown = false ;
311
311
element . classList . remove ( 'tooltip-show' ) ;
312
312
}
313
313
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 ;
315
323
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 ) ) ;
318
326
319
- return element ;
327
+ return nextEl ;
320
328
}
321
329
322
330
/**
331
+ * Get textual content of an element.
323
332
*
324
- * @param element
325
- * @return string
333
+ * @param element - HTML element to process
334
+ * @returns Text content of the element
326
335
*/
327
- function text ( element : HTMLElement ) {
328
- return element . innerText || element . textContent ;
336
+ function text ( element : HTMLElement ) : string {
337
+ return element . innerText || element . textContent || '' ;
329
338
}
330
339
}
0 commit comments