<commit_before>import React from 'react';
import { connect } from 'react-redux';
import { playAudio, stopAudio } from '../../actions/audio';
import { selectSound, toggleHoveringSound } from '../../actions/sounds';
import { lighten } from '../../utils/colors';
import { DEFAULT_RADIUS, DEFAULT_FILL_OPACITY, DEFAULT_STROKE_WIDTH, DEFAULT_STROKE_OPACITY }
  from '../../constants';

const propTypes = {
  sound: React.PropTypes.object,
  playOnHover: React.PropTypes.bool,
  isSelected: React.PropTypes.bool,
  playAudio: React.PropTypes.func,
  stopAudio: React.PropTypes.func,
  selectSound: React.PropTypes.func,
  toggleHoveringSound: React.PropTypes.func,
};

class MapCircle extends React.PureComponent {
  constructor(props) {
    super(props);
    this.onMouseEnter = this.onMouseEnter.bind(this);
    this.onMouseLeave = this.onMouseLeave.bind(this);
    this.onClick = this.onClick.bind(this);
  }

  shouldComponentUpdate(nextProps) {
    return (
      (nextProps.sound !== this.props.sound) ||
      (nextProps.isSelected !== this.props.isSelected)
    );
  }

  onMouseEnter() {
    if (this.props.playOnHover) {
      this.props.playAudio(this.props.sound);
    }
    this.props.toggleHoveringSound(this.props.sound.id);
  }

  onMouseLeave() {
    if (this.props.playOnHover && this.props.sound.isPlaying) {
      this.props.stopAudio(this.props.sound);
    }
    this.props.toggleHoveringSound(this.props.sound.id);
  }

  onClick() {
    if (this.props.sound.isPlaying) {
      this.props.stopAudio(this.props.sound);<commit_msg>Performace improvement: don't render out-of-screen map circles<commit_after>import React from 'react';
import { connect } from 'react-redux';
import { playAudio, stopAudio } from '../../actions/audio';
import { selectSound, toggleHoveringSound } from '../../actions/sounds';
import { lighten } from '../../utils/colors';
import { DEFAULT_RADIUS, DEFAULT_FILL_OPACITY, DEFAULT_STROKE_WIDTH, DEFAULT_STROKE_OPACITY }
  from '../../constants';

const propTypes = {
  sound: React.PropTypes.object,
  playOnHover: React.PropTypes.bool,
  isSelected: React.PropTypes.bool,
  playAudio: React.PropTypes.func,
  stopAudio: React.PropTypes.func,
  selectSound: React.PropTypes.func,
  toggleHoveringSound: React.PropTypes.func,
};

const isSoundVisible = (props) => {
  const position = props.sound.position;
  if (!position) {
    return false;
  }
  const isVerticallyOutOfScreen = (position.cy < -DEFAULT_RADIUS
    || position.cy > window.innerHeight + DEFAULT_RADIUS);
  const isHorizontallyOutOfScreen = (position.cx < -DEFAULT_RADIUS
    || position.cx > window.innerWidth + DEFAULT_RADIUS);
  return !(isVerticallyOutOfScreen || isHorizontallyOutOfScreen);
};

const isSoundStayingNotVisible = (currentProps, nextProps) =>
  (!isSoundVisible(currentProps) && !isSoundVisible(nextProps));

class MapCircle extends React.PureComponent {
  constructor(props) {
    super(props);
    this.onMouseEnter = this.onMouseEnter.bind(this);
    this.onMouseLeave = this.onMouseLeave.bind(this);
    this.onClick = this.onClick.bind(this);
  }

  shouldComponentUpdate(nextProps) {
    return (
      ((nextProps.sound !== this.props.sound) ||
      (nextProps.isSelected !== this.props.isSelected))
      && !isSoundStayingNotVisible(this.props, nextProps)
    );
  }

  onMouseEnter() {
    if (this.props.playOnHover) {
      this.props.playAudio(this.props.sound);
    }
    this.props.toggleHoveringSound(this.props.sound.id);
  }

  onMouseLeave() {
    if (this.props.playOnHover && this.props.sound.isPlaying) {
      this.props.stopAudio(this.props.sound);
    }
    this.props.toggleHoveringSound(this.props.sound.id);
  }

  onClick() {
    if (this.props.sound.isPlaying) {
      this.props.stopAudio(this.props.sound);
{'fraction_non_alphanumeric': 0.1392136025504782, 'fraction_numerical': 0.0, 'mean_word_length': 3.9344692005242465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4655637', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1240, 'n_words': 196}