<commit_before>/*jslint evil: true*/

function Point(x, y, c) {
    this.x = x;
    this.y = y;
    this.c = c;
}
Point.prototype.toString = function () {
    return '{"x":' + this.x + ',"y":' + this.y + ',"c":' + this.c + '}';
};

function Sketch(canvasID) {

    var ctx;
    var drawing = false;
    var path = []; //array of Points
    var MOVE_TO = 0;
    var LINE_TO = 1;

    function clearScreen() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
    }

    function clear() {
        clearScreen();
        path = [];
    }

    function startLine(x, y) {
        drawing = true;
        ctx.beginPath();
        path.push(new Point(x, y, MOVE_TO));
        ctx.moveTo(x, y);
    }

    function drawLine(x, y) {
        path.push(new Point(x, y, LINE_TO));
        clearScreen();
        drawPath();
    }

    function drawPath() {
        var point;
        if (path.length === 0) {
            return;
        }
        ctx.beginPath();
        for (var p = 0; p < path.length; p++) {

            point = path[p];

            if (point.c == MOVE_TO) {
                ctx.moveTo(point.x, point.y);

            } else if (point.c == LINE_TO) {
                ctx.lineTo(point.x, point.y);

            } else {
                if (console && console.log) {
                    console.log("unknown command");
                }
            }
        }
        ctx.stroke();
    }

    function endLine(x, y) {
        drawLine(x, y);
        drawing = false;
    }

    function onMouseDown(e) {
        startLine(e.offsetX, e.offsetY);
    }

    function onMouseUp(e) {
        endLine(e.offsetX, e.offsetY);
    }

    function onMouseMove(e) {
        if (drawing) {
            drawLine(e.offsetX, e.offsetY);
        }
    }

    function init(canvasID) {

        if (typeof canvasID !== "string") {
            alert("Drawing requires id of canvas element as parameter");
            return;
        }

        canvas = document.getElementById(canvasID);

        if (!canvas) {
            alert("Drawing was not able to find a canvas element with ID == ".canvasID);
        }

        try {
            ctx = canvas.getContext("2d");
        } catch(e) {
            alert("Drawing was unable to initialize. Most likely you browser does not support Canvas");
            return;
        }

        ctx.strokeStyle = "#000000";
        ctx.lineWidth = 0;

        canvas.addEventListener("mousedown", onMouseDown);
        canvas.addEventListener("mouseup", onMouseUp);
        canvas.addEventListener("mousemove", onMouseMove);

    }

    function getData() {
        //return as array of point objects
        return path;
    }

    function getJSON() {
        //return as JSON string
        return "[" + path + "]";
    }

    function setData(pathData) {
        clear();
        path = pathData;
        drawPath();
    }

    function loadJSON(json) {
        if(json){
            clear();
            try {
                path = eval(json);<commit_msg>fixed bug where applyJSON was destroying Point objects<commit_after>/*jslint evil: true*/

function Point(x, y, c) {
    this.x = x;
    this.y = y;
    this.c = c;
}

function Sketch(canvasID) {

    var ctx;
    var drawing = false;
    var path = []; //array of Points
    var MOVE_TO = 0;
    var LINE_TO = 1;

    function clearScreen() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
    }

    function clear() {
        clearScreen();
        path = [];
    }

    function startLine(x, y) {
        drawing = true;
        ctx.beginPath();
        path.push(new Point(x, y, MOVE_TO));
        ctx.moveTo(x, y);
    }

    function drawLine(x, y) {
        path.push(new Point(x, y, LINE_TO));
        clearScreen();
        drawPath();
    }

    function drawPath() {
        var point;
        if (path.length === 0) {
            return;
        }
        ctx.beginPath();
        for (var p = 0; p < path.length; p++) {

            point = path[p];

            if (point.c == MOVE_TO) {
                ctx.moveTo(point.x, point.y);

            } else if (point.c == LINE_TO) {
                ctx.lineTo(point.x, point.y);

            } else {
                if (console && console.log) {
                    console.log("unknown command");
                }
            }
        }
        ctx.stroke();
    }

    function endLine(x, y) {
        drawLine(x, y);
        drawing = false;
    }

    function onMouseDown(e) {
        startLine(e.offsetX, e.offsetY);
    }

    function onMouseUp(e) {
        endLine(e.offsetX, e.offsetY);
    }

    function onMouseMove(e) {
        if (drawing) {
            drawLine(e.offsetX, e.offsetY);
        }
    }

    function init(canvasID) {

        if (typeof canvasID !== "string") {
            alert("Drawing requires id of canvas element as parameter");
            return;
        }

        canvas = document.getElementById(canvasID);

        if (!canvas) {
            alert("Drawing was not able to find a canvas element with ID == ".canvasID);
        }

        try {
            ctx = canvas.getContext("2d");
        } catch(e) {
            alert("Drawing was unable to initialize. Most likely you browser does not support Canvas");
            return;
        }

        ctx.strokeStyle = "#000000";
        ctx.lineWidth = 0;

        canvas.addEventListener("mousedown", onMouseDown);
        canvas.addEventListener("mouseup", onMouseUp);
        canvas.addEventListener("mousemove", onMouseMove);

    }

    function getData() {
        //return as array of point objects
        return path;
    }

    function getJSON() {
        //return as JSON string
        var jsonArr = [];
        var point;
        for (var p = 0; p < path.length; p++) {
            point = path[p];
            jsonArr.push('{"x":' + point.x + ',"y":' + point.y + ',"c":' + point.c + '}');
        }
        return "["+jsonArr.join(",")+"]";
    }

    function setData(pathData) {
        clear();
        path = pathData;
        drawPath();
    }

    function loadJSON(json) {
        if(json){
            clear();
            try {
                path = eval(json);
{'fraction_non_alphanumeric': 0.13499025341130605, 'fraction_numerical': 0.004710851202079272, 'mean_word_length': 1.5590191188694928, 'pattern_counts': {'":': 6, '<': 6, '<?xml version=': 0, '>': 3, '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': '4682163', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1835, 'n_words': 452}