{"size": 1549, "ext": "js", "max_stars_repo_path": "src/components/TextLabel/TextLabel.js", "max_stars_repo_name": "mjoblin/packscape", "max_stars_repo_stars_event_min_datetime": "2020-07-29T21:00:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-27T06:44:22.000Z", "max_issues_repo_path": "src/components/TextLabel/TextLabel.js", "max_issues_repo_name": "mjoblin/packscape", "max_issues_repo_issues_event_min_datetime": "2021-03-09T07:53:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T02:37:23.000Z", "max_forks_repo_path": "src/components/TextLabel/TextLabel.js", "max_forks_repo_name": "mjoblin/packscape", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 28.6851851852, "max_line_length": 77, "alphanum_fraction": 0.5145255003}
import React from 'react';
import THREE from 'three';


class TextLabel extends React.Component {
    /**
     * Generates a text label.  This is intended specifically for adding a
     * packet layer name next to a fountain base from the Fountain component,
     * so we take some liberties and hardcode position and rotation values.
     */
    constructor(props, context) {
        super(props, context);

        this.state = {};
        
        this.rotation = new THREE.Euler(-Math.PI / 2, 0, 0);
        this.position = new THREE.Vector3(20, 0, 10);
        this.text = props.text;
        this.size = props.size;
        this.font = false;
    }

    componentWillMount() {
        let loader = new THREE.FontLoader();
        loader.load('./static/optimer_regular.typeface.json', (inFont) => {
            this.font = inFont;
        });
    }
    
    render() {
        if (!this.font) {
            // Don't render anything until our font data has arrived.
            return false;
        }
        
        return (
            <mesh position={this.position} rotation={this.rotation}>
                <textGeometry
                    text={this.text}
                    font={this.font}
                    size={this.size}
                    curveSegments={3}
                    height={1}
                />
                <meshPhongMaterial
                    color={this.props.color ? this.props.color :
                        new THREE.Color(1, 1, 1)} />
            </mesh>
        );
    }
}

export default TextLabel;
