title: How do you prevent a popover from overflowing viewport boundaries?
body: <p>I am trying to dynamically add annotations to a Highcharts chart. If you go to my <a href="https://codepen.io/fishfilet/pen/vjzzZE" rel="nofollow noreferrer">Codepen Example</a> and click on one of the data points near a chart extreme, you will see that the popover can get obscured.</p>
  
  <p><a href="https://i.stack.imgur.com/mQXa4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mQXa4.png" alt="enter image description here"></a></p>
  
  <p>I was trying to use a bootstrap popover ".popover()" for this but there did not seem to be a way to position the popover at the point of a mouse click. So I took some pointers from this <a href="https://stackoverflow.com/questions/14982224/how-to-open-a-popover-on-the-mouse-click-location">question</a>.</p>
  
  <pre><code>$('#popover').css('left', (selected_point.x+15) +'px')
  $('#popover').css('top',  (selected_point.y-(selected_point.h/2)-12) +'px')
  $('#popover').show()
  $("#annotation_text").focus()
  </code></pre>
  
  <p>The problem I am having is that when clicking on a data point near one of the chart edges, the popover can get cut off. How can I prevent the popover from overflowing outside of the viewport?</p>
  
  <p>I tried the suggestion from KrzysztofJaniszewski. However, the popover still had some undesirable traits. For instance, it will float away from the data point on resize. If the data is scrolled it does not stay with the data point.</p>
  
  <p>I decided to try something else. I have put my form inside of an annotation that is added to a point when it is clicked. When the form is saved the annotation is removed and replaced with a new annotation that contains the data from the form.</p>
  
  <p>This has some cool advantages such as the positioning of the popover being handled by Highcharts so there are no boundary issues. The form also stays with its data point on resize or when scrolling data. I have updated the <a href="https://codepen.io/fishfilet/pen/vjzzZE" rel="nofollow noreferrer">Codepen Example</a> to show these effects. I forgot to fork the Codepen and so my original has been overwritten, sorry.</p>
  
  <p>The only issues I am trying to overcome at this point seem to have to do with layer order or z-index of some sort. I applied some jquery to help with the focus on the form inputs but I am still having issues. For instance, try and create an annotation or note. Then try and select the text with your mouse. Instead of the mouse selecting the text, the mouse seems to be controlling the chart behind the popover and instead, it zooms the chart.</p>
  
  <p>Any ideas on how to make this form be on top of the chart? It makes sense that it's not since it is really an annotation but in this case, it would be good to override just the form.</p>