<commit_before>var React = require('react');

var c3 = require('c3')

function coerceNum( str ){
    var num = parseFloat(str.replace(/[,$]+/g, ""))
    if( isNaN(num)){
        return str
    } else{
        return num
    }
}

function cleanData( data ){
    // console.log(data);
    data.forEach( function(row, i){
        row.forEach( function(col, j){
            data[i][j] = coerceNum( data[i][j] )
        })
    })
    // console.log(data);
    return data
}

var Chart = React.createClass({
    // ...
    _renderChart: function (item) {
        // save reference to our chart to the instance
        this.chart = c3.generate({
            bindto: '#'+this.props.id,
            data: {
                rows: cleanData( item.data ),
                x : 'x',
                type: item.chart_type,
                types: item.types
            },
            axis: {
                x: {
                    type: 'category'
                }
            }
        })

        var self = this;

        setTimeout(function () {
            self.chart.groups( item.groups )
        }, 1000);
    },

    componentDidMount: function () {
        // console.log("re-render chart");
        var self = this;
        try {
            this._renderChart(this.props.item);
        }
        catch(err) {
            alert( "Incorrect data for chart: " + err)
        }

        // FIXME: This shouldn't be necessary - prop updates should work too
        this.props.subscribeToLayoutChange( function(){ 
            if( self.chart ){
                self.chart.resize()                 
            }
        })
    },


    componentWillReceiveProps: function (newProps) {
        // TODO: Update graph data if new data is loaded.
        // this would allow the graph to be dynamic..
    },

    render: function(){
        return <div id={this.props.id}/>
    }
});

module.exports = Chart<commit_msg>error handling reports chart ID now<commit_after>var React = require('react');

var c3 = require('c3')

function coerceNum( str ){
    var num = parseFloat(str.replace(/[,$]+/g, ""))
    if( isNaN(num)){
        return str
    } else{
        return num
    }
}

function cleanData( data ){
    // console.log(data);
    data.forEach( function(row, i){
        row.forEach( function(col, j){
            data[i][j] = coerceNum( data[i][j] )
        })
    })
    // console.log(data);
    return data
}

var Chart = React.createClass({
    // ...
    _renderChart: function (item) {
        // save reference to our chart to the instance
        this.chart = c3.generate({
            bindto: '#'+this.props.id,
            data: {
                rows: cleanData( item.data ),
                x : 'x',
                type: item.chart_type,
                types: item.types
            },
            axis: {
                x: {
                    type: 'category'
                }
            }
        })

        var self = this;

        setTimeout(function () {
            self.chart.groups( item.groups )
        }, 1000);
    },

    componentDidMount: function () {
        // console.log("re-render chart");
        var self = this;
        try {
            this._renderChart(this.props.item);
        }
        catch(err) {
            alert( "Incorrect data for chart "+this.props.id+": " + err)
        }

        // FIXME: This shouldn't be necessary - prop updates should work too
        this.props.subscribeToLayoutChange( function(){ 
            if( self.chart ){
                self.chart.resize()                 
            }
        })
    },


    componentWillReceiveProps: function (newProps) {
        // TODO: Update graph data if new data is loaded.
        // this would allow the graph to be dynamic..
    },

    render: function(){
        return <div id={this.props.id}/>
    }
});

module.exports = Chart
{'fraction_non_alphanumeric': 0.1302542812662169, 'fraction_numerical': 0.0036325895173845357, 'mean_word_length': 1.4321766561514195, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, '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': '643253', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1074, 'n_words': 269}