@@ -242,6 +242,9 @@ function resolveOptions(options) {
242
242
options . bodyFontStyle = valueOrDefault ( options . bodyFontStyle , defaults . fontStyle ) ;
243
243
options . bodyFontSize = valueOrDefault ( options . bodyFontSize , defaults . fontSize ) ;
244
244
245
+ options . boxHeight = valueOrDefault ( options . boxHeight , options . bodyFontSize ) ;
246
+ options . boxWidth = valueOrDefault ( options . boxWidth , options . bodyFontSize ) ;
247
+
245
248
options . titleFontFamily = valueOrDefault ( options . titleFontFamily , defaults . fontFamily ) ;
246
249
options . titleFontStyle = valueOrDefault ( options . titleFontStyle , defaults . fontStyle ) ;
247
250
options . titleFontSize = valueOrDefault ( options . titleFontSize , defaults . fontSize ) ;
@@ -259,9 +262,10 @@ function resolveOptions(options) {
259
262
function getTooltipSize ( tooltip ) {
260
263
const ctx = tooltip . _chart . ctx ;
261
264
const { body, footer, options, title} = tooltip ;
262
- const { bodyFontSize, footerFontSize, titleFontSize} = options ;
265
+ const { bodyFontSize, footerFontSize, titleFontSize, boxWidth , boxHeight } = options ;
263
266
const titleLineCount = title . length ;
264
267
const footerLineCount = footer . length ;
268
+ const bodyLineItemCount = body . length ;
265
269
266
270
let height = options . yPadding * 2 ; // Tooltip Padding
267
271
let width = 0 ;
@@ -276,7 +280,10 @@ function getTooltipSize(tooltip) {
276
280
+ options . titleMarginBottom ;
277
281
}
278
282
if ( combinedBodyLength ) {
279
- height += combinedBodyLength * bodyFontSize
283
+ // Body lines may include some extra height depending on boxHeight
284
+ const bodyLineHeight = options . displayColors ? Math . max ( boxHeight , bodyFontSize ) : bodyFontSize ;
285
+ height += bodyLineItemCount * bodyLineHeight
286
+ + ( combinedBodyLength - bodyLineItemCount ) * bodyFontSize
280
287
+ ( combinedBodyLength - 1 ) * options . bodySpacing ;
281
288
}
282
289
if ( footerLineCount ) {
@@ -301,7 +308,7 @@ function getTooltipSize(tooltip) {
301
308
helpers . each ( tooltip . beforeBody . concat ( tooltip . afterBody ) , maxLineWidth ) ;
302
309
303
310
// Body lines may include some extra width due to the color box
304
- widthPadding = options . displayColors ? ( bodyFontSize + 2 ) : 0 ;
311
+ widthPadding = options . displayColors ? ( boxWidth + 2 ) : 0 ;
305
312
helpers . each ( body , ( bodyItem ) => {
306
313
helpers . each ( bodyItem . before , maxLineWidth ) ;
307
314
helpers . each ( bodyItem . lines , maxLineWidth ) ;
@@ -757,22 +764,24 @@ export class Tooltip extends Element {
757
764
const me = this ;
758
765
const options = me . options ;
759
766
const labelColors = me . labelColors [ i ] ;
760
- const bodyFontSize = options . bodyFontSize ;
767
+ const { boxHeight , boxWidth , bodyFontSize} = options ;
761
768
const colorX = getAlignedX ( me , 'left' ) ;
762
769
const rtlColorX = rtlHelper . x ( colorX ) ;
770
+ const yOffSet = boxHeight < bodyFontSize ? ( bodyFontSize - boxHeight ) / 2 : 0 ;
771
+ const colorY = pt . y + yOffSet ;
763
772
764
773
// Fill a white rect so that colours merge nicely if the opacity is < 1
765
774
ctx . fillStyle = options . multiKeyBackground ;
766
- ctx . fillRect ( rtlHelper . leftForLtr ( rtlColorX , bodyFontSize ) , pt . y , bodyFontSize , bodyFontSize ) ;
775
+ ctx . fillRect ( rtlHelper . leftForLtr ( rtlColorX , boxWidth ) , colorY , boxWidth , boxHeight ) ;
767
776
768
777
// Border
769
778
ctx . lineWidth = 1 ;
770
779
ctx . strokeStyle = labelColors . borderColor ;
771
- ctx . strokeRect ( rtlHelper . leftForLtr ( rtlColorX , bodyFontSize ) , pt . y , bodyFontSize , bodyFontSize ) ;
780
+ ctx . strokeRect ( rtlHelper . leftForLtr ( rtlColorX , boxWidth ) , colorY , boxWidth , boxHeight ) ;
772
781
773
782
// Inner square
774
783
ctx . fillStyle = labelColors . backgroundColor ;
775
- ctx . fillRect ( rtlHelper . leftForLtr ( rtlHelper . xPlus ( rtlColorX , 1 ) , bodyFontSize - 2 ) , pt . y + 1 , bodyFontSize - 2 , bodyFontSize - 2 ) ;
784
+ ctx . fillRect ( rtlHelper . leftForLtr ( rtlHelper . xPlus ( rtlColorX , 1 ) , boxWidth - 2 ) , colorY + 1 , boxWidth - 2 , boxHeight - 2 ) ;
776
785
777
786
// restore fillStyle
778
787
ctx . fillStyle = me . labelTextColors [ i ] ;
@@ -781,14 +790,15 @@ export class Tooltip extends Element {
781
790
drawBody ( pt , ctx ) {
782
791
const me = this ;
783
792
const { body, options} = me ;
784
- const { bodyFontSize, bodySpacing, bodyAlign, displayColors} = options ;
793
+ const { bodyFontSize, bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth} = options ;
794
+ let bodyLineHeight = bodyFontSize ;
785
795
let xLinePadding = 0 ;
786
796
787
797
const rtlHelper = getRtlHelper ( options . rtl , me . x , me . width ) ;
788
798
789
799
const fillLineOfText = function ( line ) {
790
- ctx . fillText ( line , rtlHelper . x ( pt . x + xLinePadding ) , pt . y + bodyFontSize / 2 ) ;
791
- pt . y += bodyFontSize + bodySpacing ;
800
+ ctx . fillText ( line , rtlHelper . x ( pt . x + xLinePadding ) , pt . y + bodyLineHeight / 2 ) ;
801
+ pt . y += bodyLineHeight + bodySpacing ;
792
802
} ;
793
803
794
804
const bodyAlignForCalculation = rtlHelper . textAlign ( bodyAlign ) ;
@@ -805,7 +815,7 @@ export class Tooltip extends Element {
805
815
helpers . each ( me . beforeBody , fillLineOfText ) ;
806
816
807
817
xLinePadding = displayColors && bodyAlignForCalculation !== 'right'
808
- ? bodyAlign === 'center' ? ( bodyFontSize / 2 + 1 ) : ( bodyFontSize + 2 )
818
+ ? bodyAlign === 'center' ? ( boxWidth / 2 + 1 ) : ( boxWidth + 2 )
809
819
: 0 ;
810
820
811
821
// Draw body lines now
@@ -820,17 +830,21 @@ export class Tooltip extends Element {
820
830
// Draw Legend-like boxes if needed
821
831
if ( displayColors && lines . length ) {
822
832
me . _drawColorBox ( ctx , pt , i , rtlHelper ) ;
833
+ bodyLineHeight = Math . max ( bodyFontSize , boxHeight ) ;
823
834
}
824
835
825
836
for ( j = 0 , jlen = lines . length ; j < jlen ; ++ j ) {
826
837
fillLineOfText ( lines [ j ] ) ;
838
+ // Reset for any lines that don't include colorbox
839
+ bodyLineHeight = bodyFontSize ;
827
840
}
828
841
829
842
helpers . each ( bodyItem . after , fillLineOfText ) ;
830
843
}
831
844
832
845
// Reset back to 0 for after body
833
846
xLinePadding = 0 ;
847
+ bodyLineHeight = bodyFontSize ;
834
848
835
849
// After body lines
836
850
helpers . each ( me . afterBody , fillLineOfText ) ;
0 commit comments