<commit_before>'use strict';

import _ from 'lodash'
import React, {Component, PropTypes} from 'react'
import $ from 'jquery'

import Grid from '../grid/grid'
import Metric from './metric'
import styles from './canvas-space.styl'

import { connect } from 'react-redux';
import { addMetric } from '../../actions/metric-actions'
import { changeSelect } from '../../actions/selection-actions'
import { runSimulations } from '../../actions/simulation-actions'
import { canvasStateSelector } from '../../selectors/canvas-state-selector';
import * as spaceActions  from '../../actions/space-actions';
import e from '../../lib/engine/engine'

function mapStateToProps(state) {
  return {
    selected: state.selection,
    metrics: state.metrics,
    guesstimates: state.guesstimates,
    simulations: state.simulations,
    spaces: state.spaces
  }
}

@connect(mapStateToProps)
@connect(canvasStateSelector)
export default class CanvasSpace extends Component{
  static propTypes = {
    canvasState: PropTypes.oneOf([
      'selecting',
      'function',
      'estimate',
      'editing'
    ]),
    dispatch: PropTypes.func,
    guesstimateForm: PropTypes.object,
    guesstimates: PropTypes.array,
    isSelected: PropTypes.bool,
    metrics: PropTypes.array.isRequired,
    selected: PropTypes.object,
    simulations: PropTypes.array,
  }

  _handleSelect(event, location, item) {
    if (!_.isEqual(this.props.selected, location)){
      if ((this.props.canvasState == 'function') && item) {
        event.preventDefault()
        $(window).trigger('functionMetricClicked', item.props.metric)
      } else {
        this.props.dispatch(changeSelect(location))
      }
    }
  }
  _handleAddMetric(location) {
    this.props.dispatch(addMetric(location))
  }
  //todo: put this in grid instead
  size(){
    const lowestMetric = Math.max(...this.props.metrics.map(g => g.location.row)) + 2
    const selected = this.props.selected.row + 2
    const height = Math.max(3, lowestMetric, selected) || 3;
    return {columns: 4, rows: height}
  }
  testing() {
    this.props.dispatch(runSimulations(null))
  }
  dMetrics() {
    const {metrics, guesstimates, simulations} = this.props
    return e.graph.denormalize({metrics, guesstimates, simulations}).metrics
  }
  renderMetric(metric) {
    const {location} = metric
    return (
      <Metric
          canvasState={this.props.canvasState}
          key={metric.id}
          location={location}
          metric={metric}
      />
    )
  }
  render () {
    const size = this.size()
    const {selected} = this.props
    return (
      <div className="canvas-space">
        <div
            className='btn btn-large btn-primary'
            onClick={this.testing.bind(this)}
        >
          {'Foobar'}
        </div>
        <Grid
            handleSelect={this._handleSelect.bind(this)}
            onAddItem={this._handleAddMetric.bind(this)}
            selected={selected}
            size={size}
        >
          {this.dMetrics().map((m) => {
              return this.renderMetric(m)
          })}
        </Grid>
      </div>
    );
  }
}
<commit_msg>Run propogation on load<commit_after>'use strict';

import _ from 'lodash'
import React, {Component, PropTypes} from 'react'
import $ from 'jquery'

import Grid from '../grid/grid'
import Metric from './metric'
import styles from './canvas-space.styl'

import { connect } from 'react-redux';
import { addMetric } from '../../actions/metric-actions'
import { changeSelect } from '../../actions/selection-actions'
import { runSimulations } from '../../actions/simulation-actions'
import { canvasStateSelector } from '../../selectors/canvas-state-selector';
import * as spaceActions  from '../../actions/space-actions';
import e from '../../lib/engine/engine'

function mapStateToProps(state) {
  return {
    selected: state.selection,
    metrics: state.metrics,
    guesstimates: state.guesstimates,
    simulations: state.simulations,
    spaces: state.spaces
  }
}

@connect(mapStateToProps)
@connect(canvasStateSelector)
export default class CanvasSpace extends Component{
  static propTypes = {
    canvasState: PropTypes.oneOf([
      'selecting',
      'function',
      'estimate',
      'editing'
    ]),
    dispatch: PropTypes.func,
    guesstimateForm: PropTypes.object,
    guesstimates: PropTypes.array,
    isSelected: PropTypes.bool,
    metrics: PropTypes.array.isRequired,
    selected: PropTypes.object,
    simulations: PropTypes.array,
  }
  componentDidMount(){
    this.props.dispatch(runSimulations(null))
  }

  _handleSelect(event, location, item) {
    if (!_.isEqual(this.props.selected, location)){
      if ((this.props.canvasState == 'function') && item) {
        event.preventDefault()
        $(window).trigger('functionMetricClicked', item.props.metric)
      } else {
        this.props.dispatch(changeSelect(location))
      }
    }
  }
  _handleAddMetric(location) {
    this.props.dispatch(addMetric(location))
  }
  //todo: put this in grid instead
  size(){
    const lowestMetric = Math.max(...this.props.metrics.map(g => g.location.row)) + 2
    const selected = this.props.selected.row + 2
    const height = Math.max(3, lowestMetric, selected) || 3;
    return {columns: 4, rows: height}
  }
  testing() {
    this.props.dispatch(runSimulations(null))
  }
  dMetrics() {
    const {metrics, guesstimates, simulations} = this.props
    return e.graph.denormalize({metrics, guesstimates, simulations}).metrics
  }
  renderMetric(metric) {
    const {location} = metric
    return (
      <Metric
          canvasState={this.props.canvasState}
          key={metric.id}
          location={location}
          metric={metric}
      />
    )
  }
  render () {
    const size = this.size()
    const {selected} = this.props
    return (
      <div className="canvas-space">
        <div
            className='btn btn-large btn-primary'
            onClick={this.testing.bind(this)}
        >
          {'Foobar'}
        </div>
        <Grid
            handleSelect={this._handleSelect.bind(this)}
            onAddItem={this._handleAddMetric.bind(this)}
            selected={selected}
            size={size}
        >
          {this.dMetrics().map((m) => {
              return this.renderMetric(m)
          })}
        </Grid>
      </div>
    );
  }
}

{'fraction_non_alphanumeric': 0.13804020895994934, 'fraction_numerical': 0.0015830299192654742, 'mean_word_length': 2.6925774400935127, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '4929666', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1872, 'n_words': 387}