<commit_before>const React = require('react');
const ReactDOM = require('react-dom');
const PropTypes = require('prop-types');
const Radium = require('radium');
const _throttle = require('lodash/throttle');

const { themeShape } = require('../constants/App');

const StyleUtils = require('../utils/Style');
const { deprecatePrimaryColor } = require('../utils/Deprecation');

class RangeSelector extends React.Component {
  static propTypes = {
    defaultLowerValue: PropTypes.number,
    defaultUpperValue: PropTypes.number,
    elementRef: PropTypes.func,
    formatter: PropTypes.func,
    interval: PropTypes.number,
    lowerBound: PropTypes.number,
    onLowerDragStop: PropTypes.func,
    onUpperDragStop: PropTypes.func,
    presets: PropTypes.array,
    selectedColor: PropTypes.string,
    theme: themeShape,
    updateOnDrag: PropTypes.bool,
    upperBound: PropTypes.number
  };

  static defaultProps = {
    defaultLowerValue: 0,
    defaultUpperValue: 1,
    interval: 1,
    formatter (value) {
      return value;
    },
    lowerBound: 0,
    onLowerDragStop () {},
    onUpperDragStop () {},
    presets: [],
    updateOnDrag: false,
    upperBound: 100
  };

  constructor (props, context) {
    super(props, context);
    const lowerValue = props.defaultLowerValue;
    const upperValue = props.defaultUpperValue;

    this.state = {
      dragging: null,
      lowerPixels: 0,
      lowerValue,
      range: props.upperBound - props.lowerBound,
      selectedLabel: this._getSelectedLabel(lowerValue, upperValue),
      showPresets: !!props.presets.length && !lowerValue && !upperValue,
      upperPixels: 1,
      upperValue,
      trackClicked: false
    };
  }

  componentDidMount () {
    deprecatePrimaryColor(this.props);
    this._setDefaultRangeValues();

    window.addEventListener('resize', _throttle(this._setDefaultRangeValues, 300));
  }

  componentWillUnmount () {
    window.removeEventListener('resize', _throttle(this._setDefaultRangeValues, 300));
  }

  _getSelectedLabel = (lowerValue, upperValue) => {
    if (this.props.presets) {
      const preset = this.props.presets.filter(preset => {
        return preset.lowerValue === lowerValue && preset.upperValue === upperValue;
      })[0];

      return preset ? preset.label : null;
    } else {
      return null;
    }
  };

  _setDefaultRangeValues = () => {
    const component = ReactDOM.findDOMNode(this.rangeSelectorRef);
    const componentStyles = window.getComputedStyle(component);
    const width = parseInt(componentStyles.width, 0);

    //convert our values to a 0-based scale
    const lowerPosition = this.state.lowerValue - (this.props.lowerBound);
    const upperPosition = this.state.upperValue - (this.props.lowerBound);

    //convert our 0-based values to pixels
    const lowerPixels = Math.round((lowerPosition * width / this.state.range) / this.props.interval * this.props.interval);
    const upperPixels = Math.round((upperPosition * width / this.state.range) / this.props.interval * this.props.interval);
<commit_msg>remove getComputedStyle<commit_after>const React = require('react');
const ReactDOM = require('react-dom');
const PropTypes = require('prop-types');
const Radium = require('radium');
const _throttle = require('lodash/throttle');

const { themeShape } = require('../constants/App');

const StyleUtils = require('../utils/Style');
const { deprecatePrimaryColor } = require('../utils/Deprecation');

class RangeSelector extends React.Component {
  static propTypes = {
    defaultLowerValue: PropTypes.number,
    defaultUpperValue: PropTypes.number,
    elementRef: PropTypes.func,
    formatter: PropTypes.func,
    interval: PropTypes.number,
    lowerBound: PropTypes.number,
    onLowerDragStop: PropTypes.func,
    onUpperDragStop: PropTypes.func,
    presets: PropTypes.array,
    selectedColor: PropTypes.string,
    theme: themeShape,
    updateOnDrag: PropTypes.bool,
    upperBound: PropTypes.number
  };

  static defaultProps = {
    defaultLowerValue: 0,
    defaultUpperValue: 1,
    interval: 1,
    formatter (value) {
      return value;
    },
    lowerBound: 0,
    onLowerDragStop () {},
    onUpperDragStop () {},
    presets: [],
    updateOnDrag: false,
    upperBound: 100
  };

  constructor (props, context) {
    super(props, context);
    const lowerValue = props.defaultLowerValue;
    const upperValue = props.defaultUpperValue;

    this.state = {
      dragging: null,
      lowerPixels: 0,
      lowerValue,
      range: props.upperBound - props.lowerBound,
      selectedLabel: this._getSelectedLabel(lowerValue, upperValue),
      showPresets: !!props.presets.length && !lowerValue && !upperValue,
      upperPixels: 1,
      upperValue,
      trackClicked: false
    };
  }

  componentDidMount () {
    deprecatePrimaryColor(this.props);
    this._setDefaultRangeValues();

    window.addEventListener('resize', _throttle(this._setDefaultRangeValues, 300));
  }

  componentWillUnmount () {
    window.removeEventListener('resize', _throttle(this._setDefaultRangeValues, 300));
  }

  _getSelectedLabel = (lowerValue, upperValue) => {
    if (this.props.presets) {
      const preset = this.props.presets.filter(preset => {
        return preset.lowerValue === lowerValue && preset.upperValue === upperValue;
      })[0];

      return preset ? preset.label : null;
    } else {
      return null;
    }
  };

  _setDefaultRangeValues = () => {
    const component = ReactDOM.findDOMNode(this.rangeSelectorRef);
    const width = component.offsetWidth;

    //convert our values to a 0-based scale
    const lowerPosition = this.state.lowerValue - (this.props.lowerBound);
    const upperPosition = this.state.upperValue - (this.props.lowerBound);

    //convert our 0-based values to pixels
    const lowerPixels = Math.round((lowerPosition * width / this.state.range) / this.props.interval * this.props.interval);
    const upperPixels = Math.round((upperPosition * width / this.state.range) / this.props.interval * this.props.interval);

{'fraction_non_alphanumeric': 0.11999335216885491, 'fraction_numerical': 0.006149243809207246, 'mean_word_length': 3.5453172205438066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5144433', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1752, 'n_words': 369}