<commit_before>import { GoogleMap, Marker, InfoWindow } from "react-google-maps";
import { default as MarkerClusterer } from "react-google-maps/lib/addons/MarkerClusterer";
import ReactMixin from 'react-mixin';
import PureRenderMixin from 'react/lib/ReactComponentWithPureRenderMixin';
import _ from 'lodash';
import ReactList from 'react-list';

import MapEvent from '../events/MapEvent';

/**
 * The map view that the user sees after 
 * clicking "Show Map" from the main Dashboard page
 *
 * @class
 * @extends React.Component
 */

@ReactMixin.decorate(PureRenderMixin)
export default class MapView extends React.Component {
  static propTypes = {
    events: React.PropTypes.array.isRequired
  };

  state = {
    activeMarker: null,
    activeCluster: null,
    clusteredEvents: []
  };

  /**
   * getMapStyles defines styles defined in Google Maps
   */
  _getMapStyles() {
    return [
      {
        "featureType": "road",
        "stylers": [
          {
            "hue": "#5e00ff"
          },
          {
            "saturation": -79
          }
        ]
      },
      {
        "featureType": "poi",
        "stylers": [
          {
            "saturation": -78
          },
          {
            "hue": "#6600ff"
          },
          {
            "lightness": -47
          },
          {
            "visibility": "off"
          }
        ]
      },
      {
        "featureType": "road.local",
        "stylers": [
          {
            "lightness": 22
          }
        ]
      },
      {
        "featureType": "landscape",
        "stylers": [
          {
            "hue": "#5c6bc0"
          },
          {
            "saturation": -11
          }
        ]
      },
      {},
      {},
      {
        "featureType": "water",
        "stylers": [
          {
            "saturation": -65
          },
          {
            "hue": "#1900ff"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        "featureType": "road.local",
        "stylers": [
          {
            "weight": 1.3
          },
          {
            "lightness": 30
          }
        ]
      },
      {
        "featureType": "transit",
        "stylers": [
          {
            "visibility": "simplified"
          },
          {
            "hue": "#5e00ff"
          },
          {
            "saturation": -16
          }
        ]
      },
      {
        "featureType": "transit.line",
        "stylers": [
          {
            "saturation": -72
          }
        ]
      },
      {}
    ];

  };

  // on event click, focus and popup event info
  _handleMarkerClick(marker) {
    if (this.state.activeMarker != marker.id)
      this.setState({activeMarker: marker.id, activeCluster: null});
    else
      this.setState({activeMarker: null});
  };

  // info windo for event clicked on
  _renderInfoWindow(ref, marker) {
    return (
      // You can nest components inside of InfoWindow!
      <InfoWindow
        key={`${ref}_info_window`}
        onCloseClick={this._handleMarkerClick.bind(this, marker)}
      >
        <MapEvent event={marker}/>
      </InfoWindow>
    );
  };


  _closeClusterInfo() {
    this.setState({activeCluster: null, clusteredEvents: []});
  };


  _renderItem(index, key) {
    return (
      <div key={key}>
        <MapEvent event={this.state.clusteredEvents[index]}/>
        {index < this.state.clusteredEvents.length - 1 ? <br/> : null}
      </div>
    );
  };

  // 
  _handleClusterClick(cluster) {
    this.setState({activeCluster: null, clusteredEvents: []});

    if (cluster.getMarkers().length == 0) {
      return;
    }
    let firstPosition = cluster.getMarkers()[0].position;
    let position = [firstPosition.lat(), firstPosition.lng()];
    // If all markers are not at the same position, then return.
    for (var i = 1; i < cluster.getMarkers().length; ++i) {
      let thisPosition = cluster.getMarkers()[i].position;
      if (thisPosition.lat() !== position[0] || thisPosition.lng() !== position[1]) {
        this.setState({activeCluster: null, clusteredEvents: []});
        return;
      }
    }

    let clusteredEvents = [];
    _.each(this.props.events, function(event) {
      if (Math.abs(event.position.lat - position[0]) < 0.0001 && Math.abs(event.position.lng - position[1]) < 0.0001) {
        clusteredEvents.push(event);
      }
    });
    this.setState({activeCluster: position, clusteredEvents});
  };


  _displayOverview() {
    if (!this.state.activeCluster)<commit_msg>updated jsdoc<commit_after>import { GoogleMap, Marker, InfoWindow } from "react-google-maps";
import { default as MarkerClusterer } from "react-google-maps/lib/addons/MarkerClusterer";
import ReactMixin from 'react-mixin';
import PureRenderMixin from 'react/lib/ReactComponentWithPureRenderMixin';
import _ from 'lodash';
import ReactList from 'react-list';

import MapEvent from '../events/MapEvent';

/**
 * The map view that the user sees after 
 * clicking "Show Map" from the main Dashboard page
 *
 * @class
 * @extends React.Component
 */

@ReactMixin.decorate(PureRenderMixin)
export default class MapView extends React.Component {
  static propTypes = {
    events: React.PropTypes.array.isRequired
  };

  state = {
    activeMarker: null,
    activeCluster: null,
    clusteredEvents: []
  };

  /**
   * getMapStyles defines styles defined in Google Maps
   */
  _getMapStyles() {
    return [
      {
        "featureType": "road",
        "stylers": [
          {
            "hue": "#5e00ff"
          },
          {
            "saturation": -79
          }
        ]
      },
      {
        "featureType": "poi",
        "stylers": [
          {
            "saturation": -78
          },
          {
            "hue": "#6600ff"
          },
          {
            "lightness": -47
          },
          {
            "visibility": "off"
          }
        ]
      },
      {
        "featureType": "road.local",
        "stylers": [
          {
            "lightness": 22
          }
        ]
      },
      {
        "featureType": "landscape",
        "stylers": [
          {
            "hue": "#5c6bc0"
          },
          {
            "saturation": -11
          }
        ]
      },
      {},
      {},
      {
        "featureType": "water",
        "stylers": [
          {
            "saturation": -65
          },
          {
            "hue": "#1900ff"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        "featureType": "road.local",
        "stylers": [
          {
            "weight": 1.3
          },
          {
            "lightness": 30
          }
        ]
      },
      {
        "featureType": "transit",
        "stylers": [
          {
            "visibility": "simplified"
          },
          {
            "hue": "#5e00ff"
          },
          {
            "saturation": -16
          }
        ]
      },
      {
        "featureType": "transit.line",
        "stylers": [
          {
            "saturation": -72
          }
        ]
      },
      {}
    ];

  };

  // on event click, focus and popup event info
  _handleMarkerClick(marker) {
    if (this.state.activeMarker != marker.id)
      this.setState({activeMarker: marker.id, activeCluster: null});
    else
      this.setState({activeMarker: null});
  };

  // info windo for event clicked on
  _renderInfoWindow(ref, marker) {
    return (
      // You can nest components inside of InfoWindow!
      <InfoWindow
        key={`${ref}_info_window`}
        onCloseClick={this._handleMarkerClick.bind(this, marker)}
      >
        <MapEvent event={marker}/>
      </InfoWindow>
    );
  };

  // close cluster
  _closeClusterInfo() {
    this.setState({activeCluster: null, clusteredEvents: []});
  };

  // render event click on clustered events
  _renderItem(index, key) {
    return (
      <div key={key}>
        <MapEvent event={this.state.clusteredEvents[index]}/>
        {index < this.state.clusteredEvents.length - 1 ? <br/> : null}
      </div>
    );
  };

  // handles user clicks on event clusters
  _handleClusterClick(cluster) {
    this.setState({activeCluster: null, clusteredEvents: []});

    if (cluster.getMarkers().length == 0) {
      return;
    }
    let firstPosition = cluster.getMarkers()[0].position;
    let position = [firstPosition.lat(), firstPosition.lng()];
    // If all markers are not at the same position, then return.
    for (var i = 1; i < cluster.getMarkers().length; ++i) {
      let thisPosition = cluster.getMarkers()[i].position;
      if (thisPosition.lat() !== position[0] || thisPosition.lng() !== position[1]) {
        this.setState({activeCluster: null, clusteredEvents: []});
        return;
      }
    }

    let clusteredEvents = [];
    _.each(this.props.events, function(event) {
      if (Math.abs(event.position.lat - position[0]) < 0.0001 && Math.abs(event.position.lng - position[1]) < 0.0001) {
        clusteredEvents.push(event);
      }
    });
    this.setState({activeCluster: position, clusteredEvents});
  };

  // displays overview of events
  _displayOverview() {
    if (!this.state.activeCluster)
{'fraction_non_alphanumeric': 0.1414559721011334, 'fraction_numerical': 0.012205754141238012, 'mean_word_length': 1.6515457960127131, 'pattern_counts': {'":': 68, '<': 25, '<?xml version=': 0, '>': 17, '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': '5554166', 'n_tokens_mistral': 2875, 'n_tokens_neox': 2770, 'n_words': 534}