<commit_before>/** @jsx React.DOM */
var _ = window._;
var bows = window.bows;
var moment = window.moment;
var React = window.React;

// tideline dependencies & plugins
var tideline = window.tideline = require('../../js/index');
var blip = tideline.blip = require('../../plugins/blip/');
var chartDailyFactory = blip.oneday;

var Header = require('./header');
var Footer = require('./footer');

var Daily = React.createClass({
  chartType: 'daily',
  log: bows('One-Day View'),
  propTypes: {
    patientData: React.PropTypes.object.isRequired,
    chartPrefs: React.PropTypes.object.isRequired,
    initialDatetimeLocation: React.PropTypes.string,
    switchToDaily: React.PropTypes.func.isRequired,
    switchToSettings: React.PropTypes.func.isRequired,
    switchToWeekly: React.PropTypes.func.isRequired
  },
  getInitialState: function() {
    return {
      hiddenPools: {
        basalSettings: true
      }
    };
  },
  render: function() {
    this.log('Rendering...');
    /* jshint ignore:start */
    return (
      <div id="tidelineMain" className="grid">
        <Header 
          chartType={this.chartType}
          onClickBack={this.handlePanBack}
          onClickMostRecent={this.handleClickMostRecent}
          onClickNext={this.handlePanForward}
          onClickOneDay={this.handleClickOneDay}
          onClickTwoWeeks={this.handleClickTwoWeeks}
        ref="header" />
        <div id="tidelineOuterContainer">
          <DailyChart
            bgUnits={this.props.chartPrefs.bgUnits}
            hiddenPools={this.state.hiddenPools}
            initialDatetimeLocation={this.props.initialDatetimeLocation}
            patientData={this.props.patientData}
            // handlers
            onDatetimeLocationChange={this.handleDatetimeLocationChange}
            onHideBasalSettings={this.handleHideBasalSettings}
            onMostRecent={this.handleMostRecent}
            onShowBasalSettings={this.handleShowBasalSettings}
            onTransition={this.handleInTransition}
            ref="chart" />
        </div>
        <Footer
         chartType={this.chartType}
         onClickSettings={this.props.switchToSettings}
        ref="footer" />
      </div>
      );
    /* jshint ignore:end */
  },
  // handlers
  handleClickMostRecent: function() {
    this.refs.chart.goToMostRecent();
  },
  handleClickOneDay: function() {
    return;
  },
  handleClickTwoWeeks: function() {
    var datetime = this.refs.chart.getCurrentDay();
    this.props.switchToWeekly(datetime);
  },
  handleDatetimeLocationChange: function(datetimeLocationEndpoints) {
    console.log('Datetime location changed!');
    var title = moment(datetimeLocationEndpoints[1]).utc().format('dddd, MMMM Do');
    this.refs.header.updateTitle(title);
  },
  handleHideBasalSettings: function() {
    this.setState({
      hiddenPools: {
        basalSettings: true
      }
    });
    var chartOpts = {imagesBaseUrl: '../../img'};
    _.assign(chartOpts, this.state, this.props.chartPrefs);
    var chart = this.refs.chart;
    chart.unmountChart();
    chart.mountChart(chart.getDOMNode(), chartOpts);
    chart.initializeChart(this.props.patientData, chart.state.datetimeLocation);
  },
  handleInTransition: function(inTransition) {
    this.refs.header.arrowsInTransition(inTransition);
  },
  handleMostRecent: function(mostRecent) {
    this.refs.header.updateMostRecent(mostRecent);
  },
  handlePanBack: function() {
    this.refs.chart.panBack();
  },
  handlePanForward: function() {
    this.refs.chart.panForward();
  },
  handleShowBasalSettings: function() {
    this.setState({
      hiddenPools: {
        basalSettings: false
      }
    });
    var chartOpts = {imagesBaseUrl: '../../img'};
    _.assign(chartOpts, this.state, this.props.chartPrefs);
    var chart = this.refs.chart;
    chart.unmountChart();
    chart.mountChart(chart.getDOMNode(), chartOpts);
    chart.initializeChart(this.props.patientData, chart.state.datetimeLocation);
  }
});

var DailyChart = React.createClass({
  chartOpts: ['bgUnits', 'hiddenPools'],
  log: bows('Daily Chart'),
  propTypes: {
    bgUnits: React.PropTypes.string.isRequired,
    hiddenPools: React.PropTypes.object.isRequired,
    initialDatetimeLocation: React.PropTypes.string,
    patientData: React.PropTypes.object.isRequired,
    // handlers
    onDatetimeLocationChange: React.PropTypes.func.isRequired,
    onHideBasalSettings: React.PropTypes.func.isRequired,
    onMostRecent: React.PropTypes.func.isRequired,
    onShowBasalSettings: React.PropTypes.func.isRequired,
    onTransition: React.PropTypes.func.isRequired
  },
  componentDidMount: function() {
    var that = this;
    // this is a hack because webpack doesn't apply CSS fast enough
    // to yield an offsetHeight on the node
    setTimeout(function() {
      that.mountChart(that.getDOMNode());
      that.initializeChart(that.props.patientData, that.props.initialDatetimeLocation);
    }, 250);
  },
  mountChart: function(node, chartOpts) {
    this.log('Mounting...');
    chartOpts = chartOpts || {imagesBaseUrl: '../../img'};
    this.chart = chartDailyFactory(node, _.assign(chartOpts, _.pick(this.props, this.chartOpts)))
      .setupPools();
    this.bindEvents();
  },
  unmountChart: function() {<commit_msg>remove timeout hack<commit_after>/** @jsx React.DOM */
var _ = window._;
var bows = window.bows;
var moment = window.moment;
var React = window.React;

// tideline dependencies & plugins
var tideline = window.tideline = require('../../js/index');
var blip = tideline.blip = require('../../plugins/blip/');
var chartDailyFactory = blip.oneday;

var Header = require('./header');
var Footer = require('./footer');

var Daily = React.createClass({
  chartType: 'daily',
  log: bows('One-Day View'),
  propTypes: {
    patientData: React.PropTypes.object.isRequired,
    chartPrefs: React.PropTypes.object.isRequired,
    initialDatetimeLocation: React.PropTypes.string,
    switchToDaily: React.PropTypes.func.isRequired,
    switchToSettings: React.PropTypes.func.isRequired,
    switchToWeekly: React.PropTypes.func.isRequired
  },
  getInitialState: function() {
    return {
      hiddenPools: {
        basalSettings: true
      }
    };
  },
  render: function() {
    this.log('Rendering...');
    /* jshint ignore:start */
    return (
      <div id="tidelineMain" className="grid">
        <Header 
          chartType={this.chartType}
          onClickBack={this.handlePanBack}
          onClickMostRecent={this.handleClickMostRecent}
          onClickNext={this.handlePanForward}
          onClickOneDay={this.handleClickOneDay}
          onClickTwoWeeks={this.handleClickTwoWeeks}
        ref="header" />
        <div id="tidelineOuterContainer">
          <DailyChart
            bgUnits={this.props.chartPrefs.bgUnits}
            hiddenPools={this.state.hiddenPools}
            initialDatetimeLocation={this.props.initialDatetimeLocation}
            patientData={this.props.patientData}
            // handlers
            onDatetimeLocationChange={this.handleDatetimeLocationChange}
            onHideBasalSettings={this.handleHideBasalSettings}
            onMostRecent={this.handleMostRecent}
            onShowBasalSettings={this.handleShowBasalSettings}
            onTransition={this.handleInTransition}
            ref="chart" />
        </div>
        <Footer
         chartType={this.chartType}
         onClickSettings={this.props.switchToSettings}
        ref="footer" />
      </div>
      );
    /* jshint ignore:end */
  },
  // handlers
  handleClickMostRecent: function() {
    this.refs.chart.goToMostRecent();
  },
  handleClickOneDay: function() {
    return;
  },
  handleClickTwoWeeks: function() {
    var datetime = this.refs.chart.getCurrentDay();
    this.props.switchToWeekly(datetime);
  },
  handleDatetimeLocationChange: function(datetimeLocationEndpoints) {
    console.log('Datetime location changed!');
    var title = moment(datetimeLocationEndpoints[1]).utc().format('dddd, MMMM Do');
    this.refs.header.updateTitle(title);
  },
  handleHideBasalSettings: function() {
    this.setState({
      hiddenPools: {
        basalSettings: true
      }
    });
    var chartOpts = {imagesBaseUrl: '../../img'};
    _.assign(chartOpts, this.state, this.props.chartPrefs);
    var chart = this.refs.chart;
    chart.unmountChart();
    chart.mountChart(chart.getDOMNode(), chartOpts);
    chart.initializeChart(this.props.patientData, chart.state.datetimeLocation);
  },
  handleInTransition: function(inTransition) {
    this.refs.header.arrowsInTransition(inTransition);
  },
  handleMostRecent: function(mostRecent) {
    this.refs.header.updateMostRecent(mostRecent);
  },
  handlePanBack: function() {
    this.refs.chart.panBack();
  },
  handlePanForward: function() {
    this.refs.chart.panForward();
  },
  handleShowBasalSettings: function() {
    this.setState({
      hiddenPools: {
        basalSettings: false
      }
    });
    var chartOpts = {imagesBaseUrl: '../../img'};
    _.assign(chartOpts, this.state, this.props.chartPrefs);
    var chart = this.refs.chart;
    chart.unmountChart();
    chart.mountChart(chart.getDOMNode(), chartOpts);
    chart.initializeChart(this.props.patientData, chart.state.datetimeLocation);
  }
});

var DailyChart = React.createClass({
  chartOpts: ['bgUnits', 'hiddenPools'],
  log: bows('Daily Chart'),
  propTypes: {
    bgUnits: React.PropTypes.string.isRequired,
    hiddenPools: React.PropTypes.object.isRequired,
    initialDatetimeLocation: React.PropTypes.string,
    patientData: React.PropTypes.object.isRequired,
    // handlers
    onDatetimeLocationChange: React.PropTypes.func.isRequired,
    onHideBasalSettings: React.PropTypes.func.isRequired,
    onMostRecent: React.PropTypes.func.isRequired,
    onShowBasalSettings: React.PropTypes.func.isRequired,
    onTransition: React.PropTypes.func.isRequired
  },
  componentDidMount: function() {
    this.mountChart(this.getDOMNode());
    this.initializeChart(this.props.patientData, this.props.initialDatetimeLocation);
  },
  mountChart: function(node, chartOpts) {
    this.log('Mounting...');
    chartOpts = chartOpts || {imagesBaseUrl: '../../img'};
    this.chart = chartDailyFactory(node, _.assign(chartOpts, _.pick(this.props, this.chartOpts)))
      .setupPools();
    this.bindEvents();
  },
  unmountChart: function() {
{'fraction_non_alphanumeric': 0.13144678385165154, 'fraction_numerical': 0.0004829051574270813, 'mean_word_length': 3.30203572912339, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6059002', 'n_tokens_mistral': 3121, 'n_tokens_neox': 3113, 'n_words': 483}