<commit_before>'use strict';

var _ = require('lodash');
var React = require('react');
var Reflux = require('reflux');
var moment = require('moment');

var DropdownMenu = require('component/DropdownMenu.jsx');
var CampaignDropdownMenu = require('component/CampaignDropdownMenu.jsx');
var IndicatorDropdownMenu = require('component/IndicatorDropdownMenu.jsx');
var Chart = require('component/Chart.jsx');
var ChartBuilderActions = require('actions/ChartBuilderActions');
var ChartBuilderStore = require("stores/ChartBuilderStore");
var ChartSelect = require('./ChartSelect.jsx');
var List = require('component/list/List.jsx');
var MenuItem = require('component/MenuItem.jsx');
var RadioGroup = require('component/radio-group/RadioGroup.jsx');
var TitleInput = require('component/TitleInput.jsx');

function findMatches(item, re) {
  var matches = [];

  if (re.test(_.get(item, 'title'))) {
    matches.push(_.assign({}, item, {filtered: true}));
  }

  if (!_.isEmpty(_.get(item, 'children'))) {
    _.each(item.children, function (child) {
      matches = matches.concat(findMatches(child, re));
    })
  }

  return matches;
};

function filterMenu(items, pattern) {
  if (_.size(pattern) < 3) {
    return items;
  }

  var match = _.partial(findMatches, _, new RegExp(pattern, 'gi'));

  return _(items).map(match).flatten().value();
}

function campaignDisplayFormat(campaign) {
  return moment(campaign.start_date).format('MMMM YYYY');
}

module.exports = React.createClass({
  mixins: [Reflux.connect(ChartBuilderStore, "store")],
  getInitialState: function () {
    return {
      title: ''
    }
  },
  componentDidMount: function () {
    ChartBuilderActions.initialize(
        this.props.chartDef,
        this.props.location,
        this.props.campaign
      );
    this.setState({title: this.props.chartDef.title});
  },
  _updateTitle: function (newText) {
    //this.setState({title:e.currentTarget.value});

    //clearTimeout(this.timer);
    //this.timer = setTimeout(function(){
    ChartBuilderActions.updateTitle(newText);
    // }.bind(this), 1000);
  },

  _updateDescription: function (e) {
    ChartBuilderActions.updateDescription(e.target.value);<commit_msg>fix the create chart console error.<commit_after>'use strict';

var _ = require('lodash');
var React = require('react');
var Reflux = require('reflux');
var moment = require('moment');

var DropdownMenu = require('component/DropdownMenu.jsx');
var CampaignDropdownMenu = require('component/CampaignDropdownMenu.jsx');
var IndicatorDropdownMenu = require('component/IndicatorDropdownMenu.jsx');
var Chart = require('component/Chart.jsx');
var ChartBuilderActions = require('actions/ChartBuilderActions');
var ChartBuilderStore = require("stores/ChartBuilderStore");
var ChartSelect = require('./ChartSelect.jsx');
var List = require('component/list/List.jsx');
var MenuItem = require('component/MenuItem.jsx');
var RadioGroup = require('component/radio-group/RadioGroup.jsx');
var TitleInput = require('component/TitleInput.jsx');

function findMatches(item, re) {
  var matches = [];

  if (re.test(_.get(item, 'title'))) {
    matches.push(_.assign({}, item, {filtered: true}));
  }

  if (!_.isEmpty(_.get(item, 'children'))) {
    _.each(item.children, function (child) {
      matches = matches.concat(findMatches(child, re));
    })
  }

  return matches;
};

function filterMenu(items, pattern) {
  if (_.size(pattern) < 3) {
    return items;
  }

  var match = _.partial(findMatches, _, new RegExp(pattern, 'gi'));

  return _(items).map(match).flatten().value();
}

function campaignDisplayFormat(campaign) {
  return moment(campaign.start_date).format('MMMM YYYY');
}

module.exports = React.createClass({
  mixins: [Reflux.connect(ChartBuilderStore, "store")],
  getInitialState: function () {
    return {
      title: ''
    }
  },
  componentDidMount: function () {
    ChartBuilderActions.initialize(
        this.props.chartDef,
        this.props.location,
        this.props.campaign
      );
    this.props.chartDef && this.setState({title: this.props.chartDef.title});
  },
  _updateTitle: function (newText) {
    //this.setState({title:e.currentTarget.value});

    //clearTimeout(this.timer);
    //this.timer = setTimeout(function(){
    ChartBuilderActions.updateTitle(newText);
    // }.bind(this), 1000);
  },

  _updateDescription: function (e) {
    ChartBuilderActions.updateDescription(e.target.value);
{'fraction_non_alphanumeric': 0.15856141144537436, 'fraction_numerical': 0.002261931689662972, 'mean_word_length': 4.548306148055207, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6807612', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1342, 'n_words': 247}