11/**
22 * --------------------------------------------------------------------------
3- * CoreUI Plugins - Custom Tooltips for Chart.js (v1.0 .0): custom-tooltips.js
3+ * CoreUI Plugins - Custom Tooltips for Chart.js (v1.1 .0): custom-tooltips.js
44 * Licensed under MIT (https://coreui.io/license)
55 * --------------------------------------------------------------------------
66 */
77
8+ function CustomTooltips ( tooltipModel ) {
9+ // Add unique id if not exist
10+ if ( ! this . _chart . canvas . id ) {
11+ const _hex = 16
12+ const _multiply = 0x10000
13+ const _idMaker = ( ) => ( ( 1 + Math . random ( ) ) * _multiply | 0 ) . toString ( _hex )
14+ const _canvasId = `_canvas${ _idMaker ( ) + _idMaker ( ) } `
15+ this . _chart . canvas . id = this . _chart . canvas . id || _canvasId
16+ }
817
9- const CustomTooltips = function ( tooltipModel ) {
1018 const ClassName = {
1119 ABOVE : 'above' ,
1220 BELOW : 'below' ,
@@ -21,15 +29,6 @@ const CustomTooltips = function (tooltipModel) {
2129 TOOLTIP_HEADER_ITEM : 'tooltip-header-item'
2230 }
2331
24-
25- if ( ! this . _chart . canvas . id ) {
26- const _hex = 16
27- const _multiply = 0x10000
28- const _idMaker = ( ) => ( ( 1 + Math . random ( ) ) * _multiply | 0 ) . toString ( _hex )
29- const _canvasId = `_canvas${ _idMaker ( ) + _idMaker ( ) } `
30- this . _chart . canvas . id = this . _chart . canvas . id || _canvasId
31- }
32-
3332 const Selector = {
3433 DIV : 'div' ,
3534 SPAN : 'span' ,
@@ -53,7 +52,11 @@ const CustomTooltips = function (tooltipModel) {
5352
5453 // Set caret Position
5554 tooltip . classList . remove ( ClassName . ABOVE , ClassName . BELOW , ClassName . NO_TRANSFORM )
56- tooltipModel . yAlign ? tooltip . classList . add ( tooltipModel . yAlign ) : tooltip . classList . add ( ClassName . NO_TRANSFORM )
55+ if ( tooltipModel . yAlign ) {
56+ tooltip . classList . add ( tooltipModel . yAlign )
57+ } else {
58+ tooltip . classList . add ( ClassName . NO_TRANSFORM )
59+ }
5760
5861 // Set Text
5962 if ( tooltipModel . body ) {
0 commit comments