<commit_before>import _ from 'lodash';
import i18n from 'i18next';
import React from 'react';
import serialport from '../../../lib/serialport';
import { DropdownButton, MenuItem } from 'react-bootstrap';
import {
    ACTIVE_STATE_IDLE,
    METRIC_UNIT
} from './constants';

class DisplayPanel extends React.Component {
    static propTypes = {
        port: React.PropTypes.string,
        unit: React.PropTypes.string,
        activeState: React.PropTypes.string,
        machinePos: React.PropTypes.object,
        workingPos: React.PropTypes.object
    }

    handleSendCommand(target, eventKey) {
        let cmd = eventKey;
        if (cmd) {
            serialport.writeln(cmd);
        }
    }
    toUnitString(val) {
        val = Number(val) || 0;
        if (this.props.unit === METRIC_UNIT) {
            val = (val / 1).toFixed(3);
        } else {
            val = (val / 25.4).toFixed(4);
        }
        return '' + val;
    }
    render() {
        let { port, unit, activeState } = this.props;
        let machinePos = _.mapValues(this.props.machinePos, (pos, axis) => this.toUnitString(pos));
        let workingPos = _.mapValues(this.props.workingPos, (pos, axis) => this.toUnitString(pos));
        let canClick = (!!port && (activeState === ACTIVE_STATE_IDLE));

        return (
            <div className="container-fluid display-panel">
                <div className="row no-gutter">
                    <div className="active-state">
                        {i18n._('Active state:')}&nbsp;{activeState}
                    </div>
                    <table className="table-bordered"><commit_msg>Shows Alarm state in red color<commit_after>import _ from 'lodash';
import colornames from 'colornames';
import i18n from 'i18next';
import React from 'react';
import serialport from '../../../lib/serialport';
import { DropdownButton, MenuItem } from 'react-bootstrap';
import {
    ACTIVE_STATE_IDLE,
    METRIC_UNIT
} from './constants';

class DisplayPanel extends React.Component {
    static propTypes = {
        port: React.PropTypes.string,
        unit: React.PropTypes.string,
        activeState: React.PropTypes.string,
        machinePos: React.PropTypes.object,
        workingPos: React.PropTypes.object
    }

    handleSendCommand(target, eventKey) {
        let cmd = eventKey;
        if (cmd) {
            serialport.writeln(cmd);
        }
    }
    toUnitString(val) {
        val = Number(val) || 0;
        if (this.props.unit === METRIC_UNIT) {
            val = (val / 1).toFixed(3);
        } else {
            val = (val / 25.4).toFixed(4);
        }
        return '' + val;
    }
    render() {
        let { port, unit, activeState } = this.props;
        let machinePos = _.mapValues(this.props.machinePos, (pos, axis) => this.toUnitString(pos));
        let workingPos = _.mapValues(this.props.workingPos, (pos, axis) => this.toUnitString(pos));
        let canClick = (!!port && (activeState === ACTIVE_STATE_IDLE));
        let styles = {
            activeState: {
                 color: (activeState === 'Alarm') ? colornames('crimson') : colornames('gray 20')
            }
        };

        return (
            <div className="container-fluid display-panel">
                <div className="row no-gutter">
                    <div className="active-state">
                        {i18n._('Active state:')}&nbsp;<span style={styles.activeState}>{activeState}</span>
                    </div>
                    <table className="table-bordered">
{'fraction_non_alphanumeric': 0.13384484228473997, 'fraction_numerical': 0.007956805910770106, 'mean_word_length': 2.1178033658104516, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '4545643', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1020, 'n_words': 222}