<commit_before>/**
 * Created by andreas on 23.02.16.
 */

import React from "react";
import PropTypes from 'prop-types';
import Helper from '../util/helper.js';
import Value from './Value.jsx';
import GuiHelper from '../util/GuiHelpers.js';

class DirectWidget extends React.Component{
    constructor(props){
        super(props);
        GuiHelper.nameKeyEventHandler(this,"widget")
    }
    shouldComponentUpdate(nextProps,nextState) {
        return Helper.compareProperties(this.props,nextProps,{value:1,isAverage:1});
    }
    render(){
        let classes="widget ";
        if (this.props.isAverage) classes+=" average";
        if (this.props.className) classes+=" "+this.props.className;
        let val;
        let vdef=this.props.default||'0';
        if (this.props.value !== undefined) {
            val=this.props.formatter?this.props.formatter(this.props.value):vdef+"";
        }
        else{
            if (! isNaN(vdef) && this.props.formatter) val=this.props.formatter(vdef);
            else val=vdef+"";
        }
        let style=this.props.style||{};

        return (
        <div className={classes} onClick={this.props.onClick} style={style}>
            <div className="resize">
            <div className='widgetData'>
                <Value value={val}/>
            </div>
            </div>
            <div className='infoLeft'>{this.props.caption}</div>
            {this.props.unit !== undefined?
                <div className='infoRight'>{this.props.unit}</div>
                :<div className='infoRight'></div>
            }
        </div>
        );
    }
};

DirectWidget.propTypes={
    name: PropTypes.string,
    unit: PropTypes.string,
    caption: PropTypes.string,
    value: PropTypes.any,
    isAverage: PropTypes.bool,
    formatter: PropTypes.func.isRequired,
    onClick: PropTypes.func,
    className: PropTypes.string,
    style: PropTypes.object,
    default: PropTypes.string
};

DirectWidget.editableParameters={
    caption:true,
    unit:true,
    formatter:true,
    formatterParameters: true,
    value: true
};

export default DirectWidget;<commit_msg>#221: make translateFunction also work for simple user widgets<commit_after>/**
 * Created by andreas on 23.02.16.
 */

import React from "react";
import PropTypes from 'prop-types';
import Helper from '../util/helper.js';
import Value from './Value.jsx';
import GuiHelper from '../util/GuiHelpers.js';
import assign from 'object-assign';

class DirectWidget extends React.Component{
    constructor(props){
        super(props);
        GuiHelper.nameKeyEventHandler(this,"widget");
        this.getProps=this.getProps.bind(this);
    }
    shouldComponentUpdate(nextProps,nextState) {
        return Helper.compareProperties(this.getProps(this.props),
            this.getProps(nextProps),{value:1,isAverage:1});
    }
    getProps(props){
        if (! this.props.translateFunction){
            return props;
        }
        else{
            return this.props.translateFunction(assign({},props));
        }
    }
    render(){
        let classes="widget ";
        let props=this.getProps(this.props);
        if (props.isAverage) classes+=" average";
        if (props.className) classes+=" "+props.className;
        let val;
        let vdef=props.default||'0';
        if (props.value !== undefined) {
            val=this.props.formatter?this.props.formatter(props.value):vdef+"";
        }
        else{
            if (! isNaN(vdef) && this.props.formatter) val=this.props.formatter(vdef);
            else val=vdef+"";
        }
        let style=props.style||{};

        return (
        <div className={classes} onClick={this.props.onClick} style={style}>
            <div className="resize">
            <div className='widgetData'>
                <Value value={val}/>
            </div>
            </div>
            <div className='infoLeft'>{props.caption}</div>
            {this.props.unit !== undefined?
                <div className='infoRight'>{props.unit}</div>
                :<div className='infoRight'></div>
            }
        </div>
        );
    }
};

DirectWidget.propTypes={
    name: PropTypes.string,
    unit: PropTypes.string,
    caption: PropTypes.string,
    value: PropTypes.any,
    isAverage: PropTypes.bool,
    formatter: PropTypes.func.isRequired,
    onClick: PropTypes.func,
    className: PropTypes.string,
    style: PropTypes.object,
    default: PropTypes.string,
    translateFunction: PropTypes.func
};

DirectWidget.editableParameters={
    caption:true,
    unit:true,
    formatter:true,
    formatterParameters: true,
    value: true
};

export default DirectWidget;
{'fraction_non_alphanumeric': 0.13785698947820485, 'fraction_numerical': 0.004509340777324458, 'mean_word_length': 2.4683544303797467, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '4650458', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1334, 'n_words': 261}