<commit_before>var httpRequest,
    mapData,
    canvas = document.getElementById("mapCanvas"),
    ctx = canvas.getContext("2d"),
    startCoords = {x: 0, y: 0},
    last = {x: 0, y: 0},
    viewCenter = {x: 0, y: 0},
    isDown = false,
    scale = 1,
    mapSize = 128 * 8,
    mapAdjust = mapSize / 2;

function drawMap() {
    'use strict';
    var x,
        y,
        img,
        map,
        mapName;
    // resize the canvas to fit the window
    // canvas.width = window.innerWidth;
    // canvas.height = window.innerHeight;
    // clear canvas with a white background
    ctx.save();
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.fillStyle = "#FFFFFF";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    // reapply scale and translation
    ctx.restore();
    // draw maps
    for (mapName in mapData.results) {
        if (mapData.results.hasOwnProperty(mapName)) {
            map = mapData.results[mapName].printouts;
            // coords are map centers, need top left corners
            x = map['X coord'] - mapAdjust;
            // n/s is measured as z in minecraft
            y = map['Z coord'] - mapAdjust;
            img = document.createElement("img");
            img.src = map['Image location'];
            // window.alert(img.src);
            ctx.drawImage(img, x, y, mapSize, mapSize);
        }
    }
}

canvas.onmousemove = function (e) {
    'use strict';
    var xVal = e.pageX - canvas.offsetLeft - startCoords.x,
        yVal = e.pageY - canvas.offsetTop - startCoords.y;
    if (isDown) {
        ctx.setTransform(scale, 0, 0, scale, xVal, yVal);
    }
};

canvas.onmousedown = function (e) {
    'use strict';
    isDown = true;
    startCoords = {x: e.pageX - canvas.offsetLeft - last.x,
                   y: e.pageY - canvas.offsetTop - last.y};
};

document.body.onmouseup = function (e) {
    'use strict';
    isDown = false;
    last = {x: e.pageX - canvas.offsetLeft - startCoords.x,
            y: e.pageY - canvas.offsetTop - startCoords.y};
};

function mapDataReceived() {
    'use strict';
    var curX,
        curY,
        maxX = -Infinity,
        maxY = -Infinity,
        minX = Infinity,
        minY = Infinity,
        mapName,
        map;<commit_msg>Closes #9, issues with map jumping after missing mouseup<commit_after>var httpRequest,
    mapData,
    canvas = document.getElementById("mapCanvas"),
    ctx = canvas.getContext("2d"),
    startCoords = {x: 0, y: 0},
    last = {x: 0, y: 0},
    viewCenter = {x: 0, y: 0},
    isDown = false,
    scale = 1,
    mapSize = 128 * 8,
    mapAdjust = mapSize / 2;

function drawMap() {
    'use strict';
    var x,
        y,
        img,
        map,
        mapName;
    // resize the canvas to fit the window
    // canvas.width = window.innerWidth;
    // canvas.height = window.innerHeight;
    // clear canvas with a white background
    ctx.save();
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.fillStyle = "#FFFFFF";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    // reapply scale and translation
    ctx.restore();
    // draw maps
    for (mapName in mapData.results) {
        if (mapData.results.hasOwnProperty(mapName)) {
            map = mapData.results[mapName].printouts;
            // coords are map centers, need top left corners
            x = map['X coord'] - mapAdjust;
            // n/s is measured as z in minecraft
            y = map['Z coord'] - mapAdjust;
            img = document.createElement("img");
            img.src = map['Image location'];
            // window.alert(img.src);
            ctx.drawImage(img, x, y, mapSize, mapSize);
        }
    }
}

document.body.onmousemove = function (e) {
    'use strict';
    var xVal = e.pageX - canvas.offsetLeft - startCoords.x,
        yVal = e.pageY - canvas.offsetTop - startCoords.y;
    if (isDown) {
        ctx.setTransform(scale, 0, 0, scale, xVal, yVal);
    }
};

canvas.onmousedown = function (e) {
    'use strict';
    // check this in case the cursor was released outside the document
    // in which case the event would have been missed
    if (isDown) {
        last = {x: e.pageX - canvas.offsetLeft - startCoords.x,
                y: e.pageY - canvas.offsetTop - startCoords.y};
    }
    isDown = true;
    startCoords = {x: e.pageX - canvas.offsetLeft - last.x,
                   y: e.pageY - canvas.offsetTop - last.y};
};

document.body.onmouseup = function (e) {
    'use strict';
    // check that the click started on the canvas
    if (isDown) {
        isDown = false;
        last = {x: e.pageX - canvas.offsetLeft - startCoords.x,
                y: e.pageY - canvas.offsetTop - startCoords.y};
    }
};

function mapDataReceived() {
    'use strict';
    var curX,
        curY,
        maxX = -Infinity,
        maxY = -Infinity,
        minX = Infinity,
        minY = Infinity,
        mapName,
        map;
{'fraction_non_alphanumeric': 0.1295496607032696, 'fraction_numerical': 0.009664815957228049, 'mean_word_length': 1.9425287356321839, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1916451', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1573, 'n_words': 432}