{"size": 1011, "ext": "js", "max_stars_repo_path": "robby-ui/src/ui/grid.js", "max_stars_repo_name": "gmamaladze/genetic-robby", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "robby-ui/src/ui/grid.js", "max_issues_repo_name": "gmamaladze/genetic-robby", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "robby-ui/src/ui/grid.js", "max_forks_repo_name": "gmamaladze/genetic-robby", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.4666666667, "max_line_length": 86, "alphanum_fraction": 0.4915924827}
'use strict';

export {Grid};

function Grid(element = 'body', title = '#title', pixel = 20, size = {x: 10, y: 10}) {
    /* global d3:true */
    this.title = title;
    let grid = this;
    this.svg = d3.select(element)
        .append('svg')
        .attr('width', size.x * pixel)
        .attr('height', size.y * pixel)
        .on("mousemove", () => {
            grid.hasFocus = true;
        })
        .on("mouseout", () => {
            grid.hasFocus = false;
        });
    this.pixel = pixel;
}

function draw(cells, text) {
    d3.select(this.title)
        .text(text);

    let blocks = this.svg
        .selectAll("rect")
        .data(cells, d => d.getId());

    blocks.enter()
        .append('rect')
        .merge(blocks)
        .attr('width', this.pixel)
        .attr('height', this.pixel)
        .attr('x', d => d.point.x * this.pixel)
        .attr('y', d => d.point.y * this.pixel)
        .attr('class', d => d.being);

    blocks.exit().remove();
}

Grid.prototype = {
    draw
};
