{"size": 1959, "ext": "js", "max_stars_repo_path": "packages/tracestar-web/src/components/grid/GridNode.js", "max_stars_repo_name": "louisgv/astarfi", "max_stars_repo_stars_event_min_datetime": "2018-03-11T23:14:41.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-11T23:14:41.000Z", "max_issues_repo_path": "packages/tracestar-web/src/components/grid/GridNode.js", "max_issues_repo_name": "louisgv/astarfi", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/tracestar-web/src/components/grid/GridNode.js", "max_forks_repo_name": "louisgv/astarfi", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.2083333333, "max_line_length": 115, "alphanum_fraction": 0.494129658}
/*
	Author: LAB

	Grid Node module.
	Used to draw interactive grid node into the canvas.

    LICENSE: MIT
*/

"use strict";
var app = app || {};

(function() {
    const {Square, Vector2} = app;

    app.GridNode = class extends Square {
        constructor(pos = new Vector2(), size = 10, textConfig = {}, color = 'white', textColor = 'black', text = {
            topLeft: 0,
            topRight: 0,
            bottomCenter: 0
        }) {
            super(pos, size, color);
            this.text = text;
            this.textColor = textColor;

            this.textSize = textConfig.textSize;

            this.textAlignAndBaseline = textConfig.textAlignAndBaseline;

            this.textArgv = textConfig.textArgv;

            this.texts = textConfig.texts;

            this.textLabel = textConfig.textLabel;
        }

        // Draw the grid into the canvas
        draw(ctx) {
            ctx.save();
            ctx.fillStyle = this.color;

            ctx.translate(this.pos.x - this.halfSize, this.pos.y - this.halfSize);

            if (this.imageCache) {
                ctx.globalAlpha = 0.7;
                ctx.drawImage(this.imageCache, 0, 0, this.size, this.size);
                ctx.globalAlpha = 1.0;
            } else {
                ctx.fillRect(0, 0, this.size, this.size);
                ctx.fillStyle = this.textColor;
            }

            this.texts.forEach((t) => {
                if (this.text[t] == 0) {
                    return;
                }
                ctx.save();

                ctx.font = `${this.textSize[t]}px comfortaa`;
                ctx.textAlign = this.textAlignAndBaseline[t][0];
                ctx.baseline = this.textAlignAndBaseline[t][1];
                ctx.translate.apply(ctx, this.textArgv[t]);
                ctx.fillText(`${this.textLabel[t]||''}${this.text[t]}`, 0, 0);

                ctx.restore();
            });

            ctx.restore();
        }
    };
}());
