<commit_before>import _ from 'lodash';
import moment from 'moment';
import React from 'react/addons';
import ReactGoogleMaps from './react-googlemaps';

require('./GoogleMap.scss');

const Props = React.PropTypes;
const classSet = React.addons.classSet;
const Map = ReactGoogleMaps.Map;
const Polyline = ReactGoogleMaps.Polyline;
const LatLng = window.google.maps.LatLng;

let GoogleMap = React.createClass({

  getInitialState() {
    return {
      center: new LatLng(41.879535, -87.624333),
      zoom: 3,
      linePath: [],
      height: 1000,
      width: 1000,
    };
  },

  propTypes: {
    flights: Props.array,
  },


  componentDidMount() {
    window.addEventListener('resize', this.handleWindowResize);
    this.setState({
      height: window.innerHeight,
      width: window.innerWidth,
      center: new LatLng(this.props.location.lat, this.props.location.lng),
    });
  },

  componentWillReceiveProps(nextProps) {
    let linePath, firstCoord;
    let {lat, lng} = nextProps.location;

    if (lat === null || lng === null) {
      console.log('Missing lat, lng something went wrong');
      return;
    }

    let firstLatLng = new LatLng(lat, lng);
    if (nextProps.flightHash === this.props.flightHash) {
      linePath = _.clone(this.state.linePath);
      let firstCoord = _.first(linePath);
      if (!firstCoord) {
        linePath.push(firstLatLng);
      }
    } else {
      linePath = [];
      linePath.push(firstLatLng);
    }

    if (nextProps.flights.length) {
      let lastCoord = _.last(linePath);
      let lastFlightCoord = new LatLng(
        _.last(nextProps.flights).arrivalCountry.lat,
        _.last(nextProps.flights).arrivalCountry.lon
      );

      if (lastCoord.k !== lastFlightCoord.k || lastCoord.D !== lastFlightCoord.D) {
        linePath.push(lastFlightCoord);
      }
    }
    this.setState({
      linePath: linePath,
      center: new LatLng(nextProps.location.lat, nextProps.location.lng),
    });
  },

  render() {
    return (
      <div className="GoogleMap">
        <Map
          initialZoom={this.state.zoom}
          center={this.state.center}
          width={this.state.width}
          height={this.state.height}
          onCenterChange={this.handleCenterChange}
        >
          <Polyline
            geodesic
            path={this.state.linePath}
            strokeColor="#F58C5C"
            strokeOpacity={0.8}
            strokeWeight={3}
          />
        </Map>
      </div>
    );
  },

  handleWindowResize(event) {
    this.setState({height: event.target.innerHeight, width: event.target.innerWidth});
  },

  handleCenterChange(mapNode) {
    this.setState({center: mapNode.getCenter()});
  },
});

export default GoogleMap;<commit_msg>Splitting PolyLine up to multiple lines<commit_after>import _ from 'lodash';
import moment from 'moment';
import React from 'react/addons';
import ReactGoogleMaps from './react-googlemaps';

require('./GoogleMap.scss');

const Props = React.PropTypes;
const classSet = React.addons.classSet;
const Map = ReactGoogleMaps.Map;
const Polyline = ReactGoogleMaps.Polyline;
const LatLng = window.google.maps.LatLng;

let GoogleMap = React.createClass({

  getInitialState() {
    return {
      center: new LatLng(41.879535, -87.624333),
      zoom: 3,
      linePath: [],
      height: 1000,
      width: 1000,
    };
  },

  propTypes: {
    flights: Props.array,
  },


  componentDidMount() {
    window.addEventListener('resize', this.handleWindowResize);
    this.setState({
      height: window.innerHeight,
      width: window.innerWidth,
      center: new LatLng(this.props.location.lat, this.props.location.lng),
    });
  },

  componentWillReceiveProps(nextProps) {
    let linePath, firstCoord;
    let {lat, lng} = nextProps.location;

    if (lat === null || lng === null) {
      console.log('Missing lat, lng something went wrong');
      return;
    }

    let firstLatLng = new LatLng(lat, lng);
    if (nextProps.flightHash === this.props.flightHash) {
      linePath = _.clone(this.state.linePath);
      let firstCoord = _.first(linePath);
      if (!firstCoord) {
        linePath.push(firstLatLng);
      }
    } else {
      linePath = [];
      linePath.push(firstLatLng);
    }

    if (nextProps.flights.length) {
      let lastCoord = _.last(linePath);
      let lastFlightCoord = new LatLng(
        _.last(nextProps.flights).arrivalCountry.lat,
        _.last(nextProps.flights).arrivalCountry.lon
      );

      if (lastCoord.k !== lastFlightCoord.k || lastCoord.D !== lastFlightCoord.D) {
        linePath.push(lastFlightCoord);
      }
    }
    this.setState({
      linePath: linePath,
      center: new LatLng(nextProps.location.lat, nextProps.location.lng),
    });
  },

  render() {
    let polyLineArrays = [];
    let linePath = this.state.linePath;
    for(var i = 0; i < linePath.length - 1; i++) {
      polyLineArrays.push([linePath[i], linePath[i + 1]]);
    }
    return (
      <div className="GoogleMap">
        <Map
          initialZoom={this.state.zoom}
          center={this.state.center}
          width={this.state.width}
          height={this.state.height}
          onCenterChange={this.handleCenterChange}
        >
          {_.map(polyLineArrays, array =>
            <Polyline
              geodesic
              path={array}
              strokeColor="#F58C5C"
              strokeOpacity={0.8}
              strokeWeight={3}
            />
          )}
        </Map>
      </div>
    );
  },

  handleWindowResize(event) {
    this.setState({height: event.target.innerHeight, width: event.target.innerWidth});
  },

  handleCenterChange(mapNode) {
    this.setState({center: mapNode.getCenter()});
  },
});

export default GoogleMap;
{'fraction_non_alphanumeric': 0.13337988826815642, 'fraction_numerical': 0.011347765363128492, 'mean_word_length': 2.5277093596059115, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '2247968', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1807, 'n_words': 329}