<commit_before>import {
  AfterViewInit,
  ChangeDetectorRef,
  Component,
  Directive,
  ElementRef,
  HostListener,
  Input,
  ViewContainerRef,
  ViewEncapsulation,
  NgModule,
  ModuleWithProviders
} from '@angular/core';
import { CommonModule } from '@angular/common';
import {
  Overlay,
  OverlayState,
  OverlayRef,
  ComponentPortal,
  OVERLAY_PROVIDERS
} from '../core';

export type TooltipPosition = 'before' | 'after' | 'above' | 'below';

@Directive({
  selector: '[tooltip]'
})
export class Md2Tooltip {
  private visible: boolean = false;
  private timer: any;

  _overlayRef: OverlayRef;
  _tooltipInstance: Md2TooltipComponent;

  @Input('tooltip') message: string;
  @Input('tooltip-position') position: TooltipPosition = 'below';
  @Input('tooltip-delay') delay: number = 0;

  constructor(private _viewContainer: ViewContainerRef, private _overlay: Overlay) { }

  /**
   * show tooltip while mouse enter or focus of element
   * @param event
   */
  @HostListener('focusin', ['$event'])
  @HostListener('mouseenter', ['$event'])
  public show(event: Event): void {
    if (this.visible) {
      return;
    }
    this.visible = true;

    clearTimeout(this.timer);
    this.timer = setTimeout(() => {
      this.timer = 0;

      let strategy = this._overlay.position().global().fixed().top('0').left('0');
      let config = new OverlayState();
      config.positionStrategy = strategy;

      this._overlayRef = this._overlay.create(config);
      let portal = new ComponentPortal(Md2TooltipComponent);
      this._tooltipInstance = this._overlayRef.attach(portal).instance;

      this._tooltipInstance.message = this.message;
      this._tooltipInstance.position = this.position;
      this._tooltipInstance.hostEl = this._viewContainer.element;
    }, this.delay);
  }

  /**
   * hide tooltip while mouse our/leave or blur of element
   * @param event
   */
  @HostListener('focusout', ['$event'])
  @HostListener('mouseleave', ['$event'])
  public hide(event: Event): void {
    clearTimeout(this.timer);
    if (!this.visible) {
      return;
    }
    this.visible = false;
    if (this._tooltipInstance) {
      this._overlayRef.dispose();
      this._overlayRef = null;
      this._tooltipInstance = null;
    }
  }
}

@Component({
  moduleId: module.id,
  selector: 'md2-tooltip',
  template: `
    <div class="md2-tooltip-container" [ngStyle]="{top: top, left: left}">
      <div class="md2-tooltip {{position}}" [class.visible]="_isVisible">{{message}}</div>
    </div>
  `,
  styleUrls: ['tooltip.css'],
  host: {
    'role': 'tooltip',
  },
  encapsulation: ViewEncapsulation.None
})
export class Md2TooltipComponent implements AfterViewInit {
  private _isVisible: boolean;
  private top: string = '-1000px';
  private left: string = '-1000px';
  message: string;
  position: string;
  hostEl: ElementRef;

  constructor(private _element: ElementRef, private _changeDetector: ChangeDetectorRef) {
    this._isVisible = false;
  }

  ngAfterViewInit() {
    let _position = this.positionElements(this.hostEl.nativeElement, this._element.nativeElement.children[0], this.position);
    this.top = _position.top + 'px';
    this.left = _position.left + 'px';<commit_msg>chore(tooltip) position and display variables should be public<commit_after>import {
  AfterViewInit,
  ChangeDetectorRef,
  Component,
  Directive,
  ElementRef,
  HostListener,
  Input,
  ViewContainerRef,
  ViewEncapsulation,
  NgModule,
  ModuleWithProviders
} from '@angular/core';
import { CommonModule } from '@angular/common';
import {
  Overlay,
  OverlayState,
  OverlayRef,
  ComponentPortal,
  OVERLAY_PROVIDERS
} from '../core';

export type TooltipPosition = 'before' | 'after' | 'above' | 'below';

@Directive({
  selector: '[tooltip]'
})
export class Md2Tooltip {
  private visible: boolean = false;
  private timer: any;

  _overlayRef: OverlayRef;
  _tooltipInstance: Md2TooltipComponent;

  @Input('tooltip') message: string;
  @Input('tooltip-position') position: TooltipPosition = 'below';
  @Input('tooltip-delay') delay: number = 0;

  constructor(private _viewContainer: ViewContainerRef, private _overlay: Overlay) { }

  /**
   * show tooltip while mouse enter or focus of element
   * @param event
   */
  @HostListener('focusin', ['$event'])
  @HostListener('mouseenter', ['$event'])
  public show(event: Event): void {
    if (this.visible) {
      return;
    }
    this.visible = true;

    clearTimeout(this.timer);
    this.timer = setTimeout(() => {
      this.timer = 0;

      let strategy = this._overlay.position().global().fixed().top('0').left('0');
      let config = new OverlayState();
      config.positionStrategy = strategy;

      this._overlayRef = this._overlay.create(config);
      let portal = new ComponentPortal(Md2TooltipComponent);
      this._tooltipInstance = this._overlayRef.attach(portal).instance;

      this._tooltipInstance.message = this.message;
      this._tooltipInstance.position = this.position;
      this._tooltipInstance.hostEl = this._viewContainer.element;
    }, this.delay);
  }

  /**
   * hide tooltip while mouse our/leave or blur of element
   * @param event
   */
  @HostListener('focusout', ['$event'])
  @HostListener('mouseleave', ['$event'])
  public hide(event: Event): void {
    clearTimeout(this.timer);
    if (!this.visible) {
      return;
    }
    this.visible = false;
    if (this._tooltipInstance) {
      this._overlayRef.dispose();
      this._overlayRef = null;
      this._tooltipInstance = null;
    }
  }
}

@Component({
  moduleId: module.id,
  selector: 'md2-tooltip',
  template: `
    <div class="md2-tooltip-container" [ngStyle]="{top: _top, left: _left}">
      <div class="md2-tooltip {{position}}" [class.visible]="_isVisible">{{message}}</div>
    </div>
  `,
  styleUrls: ['tooltip.css'],
  host: {
    'role': 'tooltip',
  },
  encapsulation: ViewEncapsulation.None
})
export class Md2TooltipComponent implements AfterViewInit {
  _isVisible: boolean;
  _top: string = '-1000px';
  _left: string = '-1000px';
  message: string;
  position: string;
  hostEl: ElementRef;

  constructor(private _element: ElementRef, private _changeDetector: ChangeDetectorRef) {
    this._isVisible = false;
  }

  ngAfterViewInit() {
    let _position = this.positionElements(this.hostEl.nativeElement, this._element.nativeElement.children[0], this.position);
    this._top = _position.top + 'px';
    this._left = _position.left + 'px';
{'fraction_non_alphanumeric': 0.1384878124514827, 'fraction_numerical': 0.006210215804999223, 'mean_word_length': 3.7895910780669144, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5971977', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1984, 'n_words': 439}