File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -120,13 +120,26 @@ function CustomTooltips(tooltipModel) {
120
120
tooltip . appendChild ( tooltipBody )
121
121
}
122
122
123
+ const position = this . _chart . canvas . getBoundingClientRect ( )
124
+
123
125
const positionY = this . _chart . canvas . offsetTop
124
126
const positionX = this . _chart . canvas . offsetLeft
125
127
128
+ let positionLeft = positionX + tooltipModel . caretX
129
+ const positionTop = positionY + tooltipModel . caretY
130
+ // eslint-disable-next-line
131
+ const halfWidth = tooltipModel . width / 2
132
+
133
+ if ( positionLeft + halfWidth > position . width ) {
134
+ positionLeft -= halfWidth
135
+ } else if ( positionLeft < halfWidth ) {
136
+ positionLeft += halfWidth
137
+ }
138
+
126
139
// Display, position, and set styles for font
127
140
tooltip . style . opacity = 1
128
- tooltip . style . left = `${ positionX + tooltipModel . caretX } px`
129
- tooltip . style . top = `${ positionY + tooltipModel . caretY } px`
141
+ tooltip . style . left = `${ positionLeft } px`
142
+ tooltip . style . top = `${ positionTop } px`
130
143
}
131
144
132
145
export default CustomTooltips
You can’t perform that action at this time.
0 commit comments