<commit_before>import {Component, NgZone} from 'angular2/core';
import {AppState} from '../app.service';
import {Http, Response} from 'angular2/http';

import {XLarge} from './directives/x-large';

@Component({
  // The selector is what angular internally uses
  // for `document.querySelectorAll(selector)` in our index.html
  // where, in this case, selector is the string 'home'
  selector: 'home',  // <home></home>
  // We need to tell Angular's Dependency Injection which providers are in our app.
  providers: [
    //ImageInfo
  ],
  // We need to tell Angular's compiler which directives are in our template.
  // Doing so will allow Angular to attach our behavior to an element
  directives: [
    XLarge
  ],
  // We need to tell Angular's compiler which custom pipes are in our template.
  pipes: [],
  // Our list of styles in our component. We may add more to compose many styles together
  styles: [require('./home.css')],
  // Every Angular template is first compiled by the browser before Angular runs it's compiler
  template: require('./home.html'),
  host: {
    '(document:keydown)': '_keydown($event)',
  }
})
export class Home {
  // Set our default values
  localState = { value: '' }
  currentImg: string
  currentIdx: number
  arrows: string[] = ['assets/img/left.svg', 'assets/img/right.svg']
  galleryBasePath: string = 'assets/img/gallery/'
  showBig: boolean = false
  leftArrowActive: boolean = true
  rightArrowActive: boolean = true
  images: any[]
  gallery: any[] = []

  // TypeScript public modifiers
  constructor(private _ngZone: NgZone, private http: Http) {

  }

  ngOnInit() {
    window.onresize = function(event) {
      this._ngZone.run(() => {
        this.calc()
      })
    }.bind(this)

    this.fetchDataAndRender()
  }

  fetchDataAndRender() {
    this.http.get(this.galleryBasePath + 'data.json')
      .map((res: Response) => res.json())
      .subscribe(
      data => {
        this.images = data

        var standardAmount = 8
        let tempRow = []
        let rowIndex = 0
        for (var i = 0; i < data.length; i++) {
          tempRow[i % standardAmount] = data[i]

          if (tempRow.length % standardAmount == 0) {
            this.gallery[rowIndex++] = tempRow
            tempRow = []
          }
          else if (i + 1 == data.length) {
            this.gallery[rowIndex] = tempRow
          }
        }

        this.calc()
      },
      err => console.error(err),
      () => console.log('done'))
  }

  calc() {
    this.gallery.forEach((imgRow) => {
      let xsum = 0
      imgRow.forEach((img) => {
        let individualRatio = 1 / img.height
        img.width = img.width * individualRatio
        img.height = 1
        xsum += img.width
      })

      let ratio = (window.outerWidth) / xsum
      // TODO: normalize height
      imgRow.forEach((img) => {
        img.width = img.width * ratio
        img.height = img.height * ratio
        console.log(img.width + ' ' + img.height)
      })
    })
  }

  isActive(index) {<commit_msg>fix(gallery): improved behaviour for last row<commit_after>import {Component, NgZone} from 'angular2/core';
import {AppState} from '../app.service';
import {Http, Response} from 'angular2/http';

import {XLarge} from './directives/x-large';

@Component({
  // The selector is what angular internally uses
  // for `document.querySelectorAll(selector)` in our index.html
  // where, in this case, selector is the string 'home'
  selector: 'home',  // <home></home>
  // We need to tell Angular's Dependency Injection which providers are in our app.
  providers: [
    //ImageInfo
  ],
  // We need to tell Angular's compiler which directives are in our template.
  // Doing so will allow Angular to attach our behavior to an element
  directives: [
    XLarge
  ],
  // We need to tell Angular's compiler which custom pipes are in our template.
  pipes: [],
  // Our list of styles in our component. We may add more to compose many styles together
  styles: [require('./home.css')],
  // Every Angular template is first compiled by the browser before Angular runs it's compiler
  template: require('./home.html'),
  host: {
    '(document:keydown)': '_keydown($event)',
  }
})
export class Home {
  // Set our default values
  localState = { value: '' }
  currentImg: string
  currentIdx: number
  arrows: string[] = ['assets/img/left.svg', 'assets/img/right.svg']
  galleryBasePath: string = 'assets/img/gallery/'
  showBig: boolean = false
  leftArrowActive: boolean = true
  rightArrowActive: boolean = true
  images: any[]
  gallery: any[] = []
  heightCoefficient = 8

  // TypeScript public modifiers
  constructor(private _ngZone: NgZone, private http: Http) {

  }

  ngOnInit() {
    window.onresize = function(event) {
      this._ngZone.run(() => {
        this.calc()
      })
    }.bind(this)

    this.fetchDataAndRender()
  }

  fetchDataAndRender() {
    this.http.get(this.galleryBasePath + 'data.json')
      .map((res: Response) => res.json())
      .subscribe(
      data => {
        this.images = data

        var standardAmount = 7
        let tempRow = []
        let rowIndex = 0
        for (var i = 0; i < data.length; i++) {
          tempRow[i % standardAmount] = data[i]

          if (tempRow.length % standardAmount == 0) {
            this.gallery[rowIndex++] = tempRow
            tempRow = []
          }
          else if (i + 1 == data.length) {
            // don't fill last row until complete width
            this.gallery[rowIndex] = tempRow
          }
        }

        this.calc()
      },
      err => console.error(err),
      () => console.log('done'))
  }

  calc() {
    let idealHeight = window.outerWidth / this.heightCoefficient

    this.gallery.forEach((imgRow) => {
      let xsum = 0
      imgRow.forEach((img) => {
        let individualRatio = idealHeight / img.height
        img.width = img.width * individualRatio
        img.height = idealHeight
        xsum += img.width
      })

      if (imgRow != this.gallery[this.gallery.length-1]) {
        let ratio = (window.outerWidth) / xsum
        // TODO: normalize height
        imgRow.forEach((img) => {
          img.width = img.width * ratio
          img.height = img.height * ratio
          console.log(img.width + ' ' + img.height)
        })
      }


    })
  }

  isActive(index) {
{'fraction_non_alphanumeric': 0.1299952614120992, 'fraction_numerical': 0.00315905860053704, 'mean_word_length': 2.380672717565403, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '6572051', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1861, 'n_words': 549}