JSFiddle - React, Tailwind, and code Playground

HTML

<canvas id="myCanvas"></canvas>

CSS

#myCanvas {
    width: 250px;
    height: 250px;
}

JavaScript

var $canvas = $("#myCanvas"),
    ctx = $canvas[0].getContext("2d");

ctx.canvas.width = $canvas.width();
ctx.canvas.height = $canvas.height();

function Grid(ctx) {
    this._ctx = ctx;
    this._lines = [];
    this._table = [];
    this._tableScale = 10;
    this._createLookupTable();
}
Grid.prototype._createLookupTable = function() {
    this._table = [];
    for (var y = 0; y < Math.ceil(ctx.canvas.height / this._tableScale); y++) {
        this._table[y] = [];
        for (var x = 0; x < Math.ceil(ctx.canvas.width / this._tableScale); x++)
            this._table[y][x] = null;
    }
};
Grid.prototype._updateLookupTable = function(line) {
    var x0 = line.from[0],
        y0 = line.from[1],
        x1 = line.to[0],
        y1 = line.to[1],
        dx = Math.abs(x1 - x0),
        dy = Math.abs(y1 - y0),
        sx = (x0 < x1) ? 1 : -1,
        sy = (y0 < y1) ? 1 : -1,
        err = dx - dy;
    while(true) {
        this._table[Math.floor(y0 / 10)][Math.floor(x0 / 10)] = line;
        if ((x0 == x1) && (y0 == y1)) break;
        var e2 = 2 * err;
        if (e2 >- dy) { err -= dy; x0 += sx; }
        if (e2 < dx) { err += dx; y0 += sy; }
    }    
};
Grid.prototype.hitTest = function(x, y) {
    var ctx = this._ctx,
        hoverLine = this._table[Math.floor(y / 10)][Math.floor(x / 10)];
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    this._lines.forEach(function(line) {
        line.draw(ctx, line === hoverLine ? "red" : "black");
    });
};
Grid.prototype.drawLookupTable = function() {
    ctx.beginPath();
    for (var y = 0; y < this._table.length; y++)
        for (var x = 0; x < this._table[y].length; x++)
        {
            if (this._table[y][x])
                ctx.rect(x * 10, y * 10, 10, 10);
        }
    ctx.strokeStyle = "rgba(0, 0, 0, 0.2)";
    ctx.stroke();
};
Grid.prototype.addLine = function(line) {
    this._lines.push(line);
    this._updateLookupTable(line);
};
Grid.prototype.draw = function() {
    var ctx =...