<commit_before>/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

/**
 * Convert calcTrace to GeoJSON 'MultiLineString' coordinate arrays
 *
 * @param {object} calcTrace
 *  gd.calcdata item.
 *  Note that calcTrace[i].lonlat is assumed to be defined
 *
 * @return {array}
 *  return line coords array (or array of arrays)
 *
 */
exports.calcTraceToLineCoords = function(calcTrace) {
    var trace = calcTrace[0].trace,
        connectgaps = trace.connectgaps;

    var coords = [],
        lineString = [];

    for(var i = 0; i < calcTrace.length; i++) {
        var calcPt = calcTrace[i];

        lineString.push(calcPt.lonlat);

        if(!connectgaps && calcPt.gapAfter && lineString.length > 0) {
            coords.push(lineString);
            lineString = [];
        }
    }

    coords.push(lineString);

    return coords;
};


/**
 * Make line ('LineString' or 'MultiLineString') GeoJSON
 *
 * @param {array} coords
 *  results form calcTraceToLineCoords
 * @param {object} trace
 *  (optional) full trace object to be added on to output
 *
 * @return {object} out
 *  GeoJSON object
 *
 */
exports.makeLine = function(coords, trace) {
    var out = {};

    if(coords.length === 1) {
        out = {
            type: 'LineString',
            coordinates: coords[0]
        };
    }
    else {
        out = {
            type: 'MultiLineString',
            coordinates: coords
        };
    }

    if(trace) out.trace = trace;

    return out;
};

/**
 * Make polygon ('Polygon' or 'MultiPolygon') GeoJSON
 *
 * @param {array} coords
 *  results form calcTraceToLineCoords
 * @param {object} trace
 *  (optional) full trace object to be added on to output
 *
 * @return {object} out
 *  GeoJSON object
 */
exports.makePolygon = function(coords, trace) {
    var out = {};

    if(coords.length === 1) {
        out = {
            type: 'Polygon',
            coordinates: coords
        };
    }
    else {
        var _coords = new Array(coords.length);

        for(var i = 0; i < coords.length; i++) {
            _coords[i] = [coords[i]];
        }

        out = {
            type: 'MultiPolygon',
            coordinates: _coords
        };
    }

    if(trace) out.trace = trace;

    return out;
};

/**
 * Make blank GeoJSON
 *
 * @return {object}
 *  Blank GeoJSON object
 *
 */
exports.makeBlank = function() {
    return {
        type: 'Point',
        coordinates: []
    };
};
<commit_msg>don't add empty line strings to line coordinates<commit_after>/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

/**
 * Convert calcTrace to GeoJSON 'MultiLineString' coordinate arrays
 *
 * @param {object} calcTrace
 *  gd.calcdata item.
 *  Note that calcTrace[i].lonlat is assumed to be defined
 *
 * @return {array}
 *  return line coords array (or array of arrays)
 *
 */
exports.calcTraceToLineCoords = function(calcTrace) {
    var trace = calcTrace[0].trace,
        connectgaps = trace.connectgaps;

    var coords = [],
        lineString = [];

    for(var i = 0; i < calcTrace.length; i++) {
        var calcPt = calcTrace[i];

        lineString.push(calcPt.lonlat);

        if(!connectgaps && calcPt.gapAfter && lineString.length > 0) {
            coords.push(lineString);
            lineString = [];
        }
    }

    if(lineString.length > 0) {
        coords.push(lineString);
    }

    return coords;
};


/**
 * Make line ('LineString' or 'MultiLineString') GeoJSON
 *
 * @param {array} coords
 *  results form calcTraceToLineCoords
 * @param {object} trace
 *  (optional) full trace object to be added on to output
 *
 * @return {object} out
 *  GeoJSON object
 *
 */
exports.makeLine = function(coords, trace) {
    var out = {};

    if(coords.length === 1) {
        out = {
            type: 'LineString',
            coordinates: coords[0]
        };
    }
    else {
        out = {
            type: 'MultiLineString',
            coordinates: coords
        };
    }

    if(trace) out.trace = trace;

    return out;
};

/**
 * Make polygon ('Polygon' or 'MultiPolygon') GeoJSON
 *
 * @param {array} coords
 *  results form calcTraceToLineCoords
 * @param {object} trace
 *  (optional) full trace object to be added on to output
 *
 * @return {object} out
 *  GeoJSON object
 */
exports.makePolygon = function(coords, trace) {
    var out = {};

    if(coords.length === 1) {
        out = {
            type: 'Polygon',
            coordinates: coords
        };
    }
    else {
        var _coords = new Array(coords.length);

        for(var i = 0; i < coords.length; i++) {
            _coords[i] = [coords[i]];
        }

        out = {
            type: 'MultiPolygon',
            coordinates: _coords
        };
    }

    if(trace) out.trace = trace;

    return out;
};

/**
 * Make blank GeoJSON
 *
 * @return {object}
 *  Blank GeoJSON object
 *
 */
exports.makeBlank = function() {
    return {
        type: 'Point',
        coordinates: []
    };
};

{'fraction_non_alphanumeric': 0.12716873212583413, 'fraction_numerical': 0.005910390848427073, 'mean_word_length': 2.175544794188862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '1518580', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1639, 'n_words': 455}