<commit_before>/**
 * Created by freddyrondon on 4/17/16.
 */

import React, {Component, PropTypes} from 'react';
import {Sparklines, SparklinesLine, SparklinesSpots} from 'react-sparklines';
import ReactHighstock from 'react-highcharts';
import {Modal} from 'react-bootstrap';
import Moment from 'moment'
import classSet from 'classnames'

class TableCell extends Component {

    constructor() {
        super();
        this.state = {
            showChartModal: false
        }
    }

    closeChartModal() {
        this.setState({showChartModal: false});
    }

    openChartModal() {
        this.setState({showChartModal: true});
    }

    changeChevron() {
        this.props.handleOpenCloseRow();
    }

    changeSwitch() {
        this.props.handleRowActivation();
    }

    renderCellValue(value, type) {
        if (type === "number" || type === "currency") {
            value = value.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
        }
        if (type === "date") {
            value = Moment(value).format()
        }
        if (type === "currency") {
            value = '<i class="fa fa-usd"></i>' + value;
            value = <div dangerouslySetInnerHTML={ { __html: value } }></div>
        }
        if (type === "p_l") {
            let classes = '';
            if (!isNaN(value)) {
                value = value.toFixed(0).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
                classes = classSet('fa', {
                    'winning': value >= 0,
                    'losing': value < 0
                });
                value = (value >= 0 ? '+' : '') + value;
            }
            value = <span className={classes}>{value}</span>;
        }
        if (type === "switch") {
            const classes = classSet('fa', {
                'fa-toggle-on': this.props.isRowOn,
                'fa-toggle-off': !this.props.isRowOn
            });
            const classesLink = classSet('switch-link', {<commit_msg>fix(tablebox): if datatype is currency and value is between 0 and 1 don’t fix the decimal<commit_after>/**
 * Created by freddyrondon on 4/17/16.
 */

import React, {Component, PropTypes} from 'react';
import {Sparklines, SparklinesLine, SparklinesSpots} from 'react-sparklines';
import ReactHighstock from 'react-highcharts';
import {Modal} from 'react-bootstrap';
import Moment from 'moment'
import classSet from 'classnames'

class TableCell extends Component {

    constructor() {
        super();
        this.state = {
            showChartModal: false
        }
    }

    closeChartModal() {
        this.setState({showChartModal: false});
    }

    openChartModal() {
        this.setState({showChartModal: true});
    }

    changeChevron() {
        this.props.handleOpenCloseRow();
    }

    changeSwitch() {
        this.props.handleRowActivation();
    }

    renderCellValue(value, type) {
        if (type === "number" || type === "currency") {
            value = +value;
            if (Number.isNaN(value)){
                value = ""
            } else {
                if (value < 1 && value > 0){
                    value = String(value)
                } else {
                    value = value.toFixed(2)
                }
                value = value.replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
            }
        }
        if (type === "date") {
            value = Moment(value).format()
        }
        if (type === "currency") {
            if (value === ""){
                value = ""
            } else {
                value = '<i class="fa fa-usd"></i>' + value;
                value = <div dangerouslySetInnerHTML={ { __html: value } }></div>
            }
        }
        if (type === "p_l") {
            let classes = '';
            if (!isNaN(value)) {
                value = value.toFixed(0).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
                classes = classSet('fa', {
                    'winning': value >= 0,
                    'losing': value < 0
                });
                value = (value >= 0 ? '+' : '') + value;
            }
            value = <span className={classes}>{value}</span>;
        }
        if (type === "switch") {
            const classes = classSet('fa', {
                'fa-toggle-on': this.props.isRowOn,
                'fa-toggle-off': !this.props.isRowOn
            });
            const classesLink = classSet('switch-link', {
{'fraction_non_alphanumeric': 0.16039242527948894, 'fraction_numerical': 0.00730093543235227, 'mean_word_length': 1.6537530266343825, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '5082126', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1240, 'n_words': 275}