/* -*- mode: javascript; c-basic-offset: 4; indent-tabs-mode: nil -*- */

//
// Dalliance Genome Explorer
// (c) Thomas Down 2006-2014
//
// numformats.js
//

function formatLongInt(n) {
    return (n|0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

function formatQuantLabel(v) {
    var t = '' + v;
    var dot = t.indexOf('.');
    if (dot < 0) {
        return t;
    } else {
        var dotThreshold = 2;
        if (t.substring(0, 1) == '-') {
            ++dotThreshold;
        }

        if (dot >= dotThreshold) {
            return t.substring(0, dot);
        } else {
            return t.substring(0, dot + 2);
        }
    }
}

if (typeof(module) !== 'undefined') {
    module.exports = {
        formatLongInt: formatLongInt,
        formatQuantLabel: formatQuantLabel
    };
}

/* -*- mode: javascript; c-basic-offset: 4; indent-tabs-mode: nil -*- */

//
// Dalliance Genome Explorer
// (c) Thomas Down 2006-2014
//
// numformats.js
//

function formatLongInt(n) {
    return (n|0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

function formatQuantLabel(v) {
    return ( ( typeof v === "string" ) ? parseFloat( v ) : v ).toPrecision( 1 );
}

if (typeof(module) !== 'undefined') {
    module.exports = {
        formatLongInt: formatLongInt,
        formatQuantLabel: formatQuantLabel
    };
}

Modify formatQuantLabel so it attempts to always show something
Modify formatQuantLabel so it attempts to always show something

As it stood, formatQuantLabel would simply show 0.0 for values in the
browser where the value was "too small". This meant that the upper and lower
values in the vertical "ruler" wouldn't be very helpful for tracks where the
min and max values were rather small.

This change attempts to retain the existing formatting for values that are
significant enough to show something sensible, but also work for smaller
values.

Also, because I'm not 100% sure that the value passed to formatQuantLabel
is *always* numeric, I've attempted to handle being passed a string
representation of a value too.
