<commit_before>import Component from '@ember/component';
import $ from 'jquery';
import {inject as service} from '@ember/service';

export default Component.extend({

    additionalData: service(),

    didRender(){
        this._super(...arguments);

        if (this.get('additionalData.popupContent')){
            this.setPopupPosition();
        }
    },

    setPopupPosition(){
        let popupData = this.get('additionalData.popupContent');

        const popoverDiv = $('.popover');
        const containerDiv = $('.main-content');

        const containerTopOffset = containerDiv.offset().top;
        const containerLeftOffset = containerDiv.offset().left;
    
        const popupTopOffset = popoverDiv.height();
        const popupLeftOffset = popoverDiv.width() / 2;

        const popupTopPosition = containerTopOffset + popupData.mouseY - popupTopOffset;
        const popupLeftPosition = containerLeftOffset + popupData.mouseX - popupLeftOffset;

        $('.popover').css('top', popupTopPosition + 'px');
        $('.popover').css('left', popupLeftPosition + 'px');
    }
})<commit_msg>Prevent popup positioning outside of canvas<commit_after>import Component from '@ember/component';
import $ from 'jquery';
import { inject as service } from '@ember/service';

export default Component.extend({

  additionalData: service(),

  didRender() {
    this._super(...arguments);

    if (this.get('additionalData.popupContent')) {
      this.setPopupPosition();
    }
  },

  setPopupPosition() {
    let popupData = this.get('additionalData.popupContent');

    const popoverDiv = $('.popover');

    // Sorrounding div for position calculations
    const containerDiv = $('.main-content');

    const containerTopOffset = containerDiv.offset().top;
    const containerLeftOffset = containerDiv.offset().left;

    const popupTopOffset = popoverDiv.height() + 10;
    const popupLeftOffset = popoverDiv.width() / 2;

    let popupTopPosition = containerTopOffset + popupData.mouseY - popupTopOffset;
    let popupLeftPosition = containerLeftOffset + popupData.mouseX - popupLeftOffset;

    // Prevent popup positioning on top of rendering canvas => 
    // position under mouse cursor
    if (popupTopPosition < containerTopOffset) {
      popupTopPosition = containerTopOffset + popupData.mouseY + 35;
    }

    // Prevent popup positioning right(outside) of rendering canvas => 
    // position at right edge of canvas
    if (popupLeftPosition + popoverDiv.width() > containerLeftOffset + containerDiv.width()) {
      popupLeftPosition = containerLeftOffset + containerDiv.width() - popoverDiv.width() - 5;
    }

    // Prevent popup positioning left(outside) of rendering canvas => 
    // position at left edge of canvas
    if (popupLeftPosition < containerLeftOffset) {
      popupLeftPosition = containerLeftOffset;
    }

    // Set popup position
    $('.popover').css('top', popupTopPosition + 'px');
    $('.popover').css('left', popupLeftPosition + 'px');
  }
})
{'fraction_non_alphanumeric': 0.12157648630594522, 'fraction_numerical': 0.002338009352037408, 'mean_word_length': 3.410898379970545, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563502', 'n_tokens_mistral': 843, 'n_tokens_neox': 767, 'n_words': 198}