<commit_before>/*
 * == BSD2 LICENSE ==
 * Copyright (c) 2017, Tidepool Project
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the associated License, which is identical to the BSD 2-Clause
 * License as published by the Open Source Initiative at opensource.org.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the License for more details.
 *
 * You should have received a copy of the License along with this program; if
 * not, you can obtain one from Tidepool Project at tidepool.org.
 * == BSD2 LICENSE ==
 */

import _ from 'lodash';
import cx from 'classnames';
import React, { Component, PropTypes } from 'react';
import { TransitionMotion, spring } from 'react-motion';

import { classifyBgValue } from '../../../utils/bloodglucose';
import withDefaultYPosition from '../common/withDefaultYPosition';

import styles from './CBGSliceAnimated.css';

export class CBGSliceAnimated extends Component {
  static defaultProps = {
    cornerRadius: 2,
    medianHeight: 10,
    medianWidth: 14,
    sliceWidth: 16,
  };

  static propTypes = {
    bgBounds: PropTypes.shape({
      veryHighThreshold: PropTypes.number.isRequired,
      targetUpperBound: PropTypes.number.isRequired,
      targetLowerBound: PropTypes.number.isRequired,
      veryLowThreshold: PropTypes.number.isRequired,
    }).isRequired,
    cornerRadius: PropTypes.number.isRequired,
    datum: PropTypes.shape({
      firstQuartile: PropTypes.number,
      id: PropTypes.string.isRequired,
      max: PropTypes.number,
      median: PropTypes.number,
      min: PropTypes.number,
      msFrom: PropTypes.number.isRequired,
      msTo: PropTypes.number.isRequired,
      msX: PropTypes.number.isRequired,
      ninetiethQuantile: PropTypes.number,
      tenthQuantile: PropTypes.number,
      thirdQuartile: PropTypes.number,
    }).isRequired,
    defaultY: PropTypes.number.isRequired,
    displayFlags: PropTypes.shape({
      cbg100Enabled: PropTypes.bool.isRequired,
      cbg80Enabled: PropTypes.bool.isRequired,
      cbg50Enabled: PropTypes.bool.isRequired,
      cbgMedianEnabled: PropTypes.bool.isRequired,
    }).isRequired,
    focusSlice: PropTypes.func.isRequired,
    isFocused: PropTypes.bool.isRequired,
    medianHeight: PropTypes.number.isRequired,
    medianWidth: PropTypes.number.isRequired,
    sliceWidth: PropTypes.number.isRequired,
    tooltipLeftThreshold: PropTypes.number.isRequired,
    unfocusSlice: PropTypes.func.isRequired,
    xScale: PropTypes.func.isRequired,
    yScale: PropTypes.func.isRequired,
  };

  constructor(props) {
    super(props);
    this.getBinLeftX = this.getBinLeftX.bind(this);
    this.willEnter = this.willEnter.bind(this);
    this.willLeave = this.willLeave.bind(this);
  }

  getBinLeftX(width) {
    const { datum, xScale } = this.props;
    return xScale(datum.msX) - width / 2 + styles.stroke / 2;
  }

  getWidth(width) {
    return width - styles.stroke;
  }

  isMedian(segment) {
    return segment.key === 'median';
  }

  willEnter(entered) {
    const { style } = entered;
    const { defaultY } = this.props;

    return {
      binLeftX: style.binLeftX,
      bottom10Height: 0,
      cornerRadius: style.cornerRadius,
      firstQuartile: defaultY,
      innerQuartilesHeight: 0,
      lower15Height: 0,
      max: defaultY,
      medianHeight: 0,
      median: defaultY,
      ninetiethQuantile: defaultY,
      tenthQuantile: defaultY,
      thirdQuartile: defaultY,
      top10Height: 0,
      upper15Height: 0,
      width: style.width,
    };
  }

  willLeave(exited) {
    const { style } = exited;
    const { defaultY } = this.props;
    const defaultYSpring = spring(defaultY);
    const shrinkOut = spring(0);
    return {
      binLeftX: style.binLeftX,
      cornerRadius: style.cornerRadius,
      bottom10Height: shrinkOut,
      firstQuartile: defaultYSpring,
      innerQuartilesHeight: shrinkOut,
      lower15Height: shrinkOut,<commit_msg>squash da bug with crashing on change of CGM slice opts<commit_after>/*
 * == BSD2 LICENSE ==
 * Copyright (c) 2017, Tidepool Project
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the associated License, which is identical to the BSD 2-Clause
 * License as published by the Open Source Initiative at opensource.org.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the License for more details.
 *
 * You should have received a copy of the License along with this program; if
 * not, you can obtain one from Tidepool Project at tidepool.org.
 * == BSD2 LICENSE ==
 */

import _ from 'lodash';
import cx from 'classnames';
import React, { Component, PropTypes } from 'react';
import { TransitionMotion, spring } from 'react-motion';

import { classifyBgValue } from '../../../utils/bloodglucose';
import withDefaultYPosition from '../common/withDefaultYPosition';

import styles from './CBGSliceAnimated.css';

export class CBGSliceAnimated extends Component {
  static defaultProps = {
    cornerRadius: 2,
    medianHeight: 10,
    medianWidth: 14,
    sliceWidth: 16,
  };

  static propTypes = {
    bgBounds: PropTypes.shape({
      veryHighThreshold: PropTypes.number.isRequired,
      targetUpperBound: PropTypes.number.isRequired,
      targetLowerBound: PropTypes.number.isRequired,
      veryLowThreshold: PropTypes.number.isRequired,
    }).isRequired,
    cornerRadius: PropTypes.number.isRequired,
    datum: PropTypes.shape({
      firstQuartile: PropTypes.number,
      id: PropTypes.string.isRequired,
      max: PropTypes.number,
      median: PropTypes.number,
      min: PropTypes.number,
      msFrom: PropTypes.number.isRequired,
      msTo: PropTypes.number.isRequired,
      msX: PropTypes.number.isRequired,
      ninetiethQuantile: PropTypes.number,
      tenthQuantile: PropTypes.number,
      thirdQuartile: PropTypes.number,
    }).isRequired,
    defaultY: PropTypes.number.isRequired,
    displayFlags: PropTypes.shape({
      cbg100Enabled: PropTypes.bool.isRequired,
      cbg80Enabled: PropTypes.bool.isRequired,
      cbg50Enabled: PropTypes.bool.isRequired,
      cbgMedianEnabled: PropTypes.bool.isRequired,
    }).isRequired,
    focusSlice: PropTypes.func.isRequired,
    isFocused: PropTypes.bool.isRequired,
    medianHeight: PropTypes.number.isRequired,
    medianWidth: PropTypes.number.isRequired,
    sliceWidth: PropTypes.number.isRequired,
    tooltipLeftThreshold: PropTypes.number.isRequired,
    unfocusSlice: PropTypes.func.isRequired,
    xScale: PropTypes.func.isRequired,
    yScale: PropTypes.func.isRequired,
  };

  constructor(props) {
    super(props);
    this.getBinLeftX = this.getBinLeftX.bind(this);
    this.willEnter = this.willEnter.bind(this);
    this.willLeave = this.willLeave.bind(this);
  }

  getBinLeftX(width) {
    const { datum, xScale } = this.props;
    return xScale(datum.msX) - width / 2 + styles.stroke / 2;
  }

  getWidth(width) {
    return width - styles.stroke;
  }

  isMedian(segment) {
    return segment.key === 'median';
  }

  willEnter(entered) {
    const { style } = entered;
    const { defaultY } = this.props;

    return {
      binLeftX: style.binLeftX,
      bottom10Height: 0,
      firstQuartile: defaultY,
      innerQuartilesHeight: 0,
      lower15Height: 0,
      max: defaultY,
      medianHeight: 0,
      median: defaultY,
      ninetiethQuantile: defaultY,
      tenthQuantile: defaultY,
      thirdQuartile: defaultY,
      top10Height: 0,
      upper15Height: 0,
      width: style.width,
    };
  }

  willLeave(exited) {
    const { style } = exited;
    const { defaultY } = this.props;
    const defaultYSpring = spring(defaultY);
    const shrinkOut = spring(0);
    return {
      binLeftX: style.binLeftX,
      bottom10Height: shrinkOut,
      firstQuartile: defaultYSpring,
      innerQuartilesHeight: shrinkOut,
      lower15Height: shrinkOut,
{'fraction_non_alphanumeric': 0.09640322975287496, 'fraction_numerical': 0.01027648642035723, 'mean_word_length': 3.3414763674986725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2485395', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2436, 'n_words': 629}