<commit_before>var wrapText = (function () {
    "use strict";

    function wrapText(context, text, x, y, maxWidth, lineHeight) {
        var words = text.split(' ');
        var line = '';

        for (var n = 0; n < words.length; n++) {
            var testLine = line + words[n] + ' ';
            var metrics = context.measureText(testLine);
            var testWidth = metrics.width;
            if (testWidth > maxWidth && n > 0) {
                context.fillText(line, x, y);
                line = words[n] + ' ';
                y += lineHeight;
            } else {
                line = testLine;
            }
        }
        context.fillText(line, x, y);
    }

    return wrapText;
})();<commit_msg>better positioning for text with more than one line refs #69 #core (cherry picked from commit a19ece2)<commit_after>var wrapText = (function () {
    "use strict";

    function wrapText(context, text, x, y, maxWidth, lineHeight) {
        var words = text.split(' ');
        var line = '';

        var readyLines = [];

        for (var n = 0; n < words.length; n++) {
            var testLine = line + words[n] + ' ';
            var metrics = context.measureText(testLine);
            var testWidth = metrics.width;
            if (testWidth > maxWidth && n > 0) {
                readyLines.push(line);
                line = words[n] + ' ';
            } else {
                line = testLine;
            }
        }
        readyLines.push(line);

        var totalHeight = readyLines.length * lineHeight / 2;
        var newStartY = y - Math.floor(totalHeight / 2);

        for (var i = 0; i < readyLines.length; i++) {
            context.fillText(readyLines[i], x, newStartY);
            newStartY += lineHeight;
        }
    }

    return wrapText;
})();
{'fraction_non_alphanumeric': 0.12897822445561138, 'fraction_numerical': 0.006700167504187605, 'mean_word_length': 1.631424375917768, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '5893621', 'n_tokens_mistral': 543, 'n_tokens_neox': 513, 'n_words': 142}