<commit_before>Polymer({
  close: function() {
    this.fire('closed');
    this.remove();
  },
  doReposition: function() {
    // TODO The below code is in place to deal with the fact that nearly all
    // the elements we use are initially in the DOM but hidden until the user
    // switches to their view.  In this state, they do not have a well-defined
    // position, which causes us to be unable to correctly position the elemnt.
    // In the future, it would be nice to move to a model where elements are
    // not created until we want to show them, this chunk of code can be
    // removed once that happens.

    var prev = this.previousSibling;
    if (prev.offsetLeft === 0 && prev.offsetTop === 0 && prev.offsetWidth === 0
        && prev.offsetHeight === 0) {
      this.async(this.doReposition, null, 500);
      return;
    }

    this.reposition();
  },
  reposition: function() {
    var prev = this.previousSibling;
    if (!prev) {
      /* we should only see this if a callback was pending when we destroyed the dom element */
      return;
    }

    var prevCntr = prev.offsetLeft + prev.offsetWidth / 2;
    var prevHeight;

    this.style.top = (prev.offsetHeight + prev.offsetTop) + 'px';
    if (prevCntr < 200) {
      /* position our left edge near the center */
      this.style.width = '200px';
      this.style.left = (prevCntr - 10) + 'px';
      this.$.arrow.style.left = '0px';
    } else if (this.parentElement.offsetWidth - prevCntr < 200) {
      /* position our right edge near the center */
      this.style.width = '200px';
      this.style.left = (prevCntr - 190) + 'px';
      this.$.arrow.style.right = '0px';
    } else {
      this.style.left = (prevCntr - this.offsetWidth / 2) + 'px';

      this.$.arrow.style.left = '50%';
      this.$.arrow.style['margin-left'] = '-10px';
    }
  },
  attached: function() {
    this.repositionCallback = () => {
      /* pretty much just binding the function to this */
      this.doReposition();
    }
    window.addEventListener('resize', this.repositionCallback);
  },
  detached: function() {
    window.removeEventListener('resize', this.repositionCallback);
  },
  domReady: function() {
    this.doReposition();
  }
});
<commit_msg>Add more logic for the display of "tip"s<commit_after>Polymer({
  close: function() {
    this.fire('closed');
    this.remove();
  },
  doReposition: function() {
    // TODO The below code is in place to deal with the fact that nearly all
    // the elements we use are initially in the DOM but hidden until the user
    // switches to their view.  In this state, they do not have a well-defined
    // position, which causes us to be unable to correctly position the elemnt.
    // In the future, it would be nice to move to a model where elements are
    // not created until we want to show them, this chunk of code can be
    // removed once that happens.

    var prev = this.previousSibling;
    if (prev.offsetLeft === 0 && prev.offsetTop === 0 && prev.offsetWidth === 0
        && prev.offsetHeight === 0) {
      this.async(this.doReposition, null, 500);
      return;
    }

    this.reposition();
  },
  reposition: function() {
    var prev = this.previousSibling;
    if (!prev) {
      /* we should only see this if a callback was pending when we destroyed the dom element */
      return;
    }

    var prevCntr = prev.offsetLeft + prev.offsetWidth / 2;
    var parentWidth = this.parentElement.offsetWidth;

    this.style.top = (prev.offsetHeight + prev.offsetTop) + 'px';

    /* width should be half of the parent width, between min and max */
    if (parentWidth < 400) {
      this.style.width = '200px';
    } else if (parentWidth < 800) {
      this.style.width = (parentWidth / 2) + 'px';
    } else {
      this.style.width = '400px';
    }

    if (prevCntr * 3 < parentWidth) {
      /* center is in the left third of the screen, arrow on left side */
      this.style.left = (prevCntr - 10) + 'px';

      this.$.arrow.style.left = '0px';
      this.$.arrow.style['margin-left'] = '0';
    } else if (prevCntr * 3 / 2 < parentWidth) {
      /* center is in the middle third of the screen, arrow in middle */
      this.style.left = (prevCntr - this.offsetWidth / 2) + 'px';

      this.$.arrow.style.left = '50%';
      this.$.arrow.style['margin-left'] = '-10px';
    } else {
      /* center is in the right third of the screen, arrow on right side */
      this.style.left = (prevCntr - (this.offsetWidth - 10)) + 'px';

      this.$.arrow.style.right = '0px';
      this.$.arrow.style['margin-left'] = '0';
    }
  },
  attached: function() {
    this.repositionCallback = () => {
      /* pretty much just binding the function to this */
      this.doReposition();
    }
    window.addEventListener('resize', this.repositionCallback);
  },
  detached: function() {
    window.removeEventListener('resize', this.repositionCallback);
  },
  domReady: function() {
    this.doReposition();
  }
});

{'fraction_non_alphanumeric': 0.13202983269502117, 'fraction_numerical': 0.01390848619229994, 'mean_word_length': 2.519148936170213, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3841440', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1498, 'n_words': 493}