Quartz / Chartbuilder

A front-end charting application that facilitates easy creation of simple beautiful charts
http://quartz.github.io/Chartbuilder
MIT License
2.1k stars 354 forks source link

Decimal separator for bars in Chart Grid mode #254

Closed fdaudens closed 7 years ago

fdaudens commented 7 years ago

Hi,

I'd like to use a comma for decimal separators in the Chart Grid renderer. Do you know which line I should modify?

capture d ecran 2016-11-21 a 18 58 48

I've already configured helper.js for the XYRenderer.jsx with the following code, but can't find what to change in ChartGridRenderer.jsk:

function round_to_precision(num, precision, supress_thou_sep) {
    if (num === 0) {
        //zero should always be "0"
        return "0";
    }

    var s = Math.round(num * Math.pow(10,precision)) / Math.pow(10,precision);
    s = s + "";

    s = s.split(".");

    if (s.length == 1) {
        s[1] = "";
    }

    if (s[1].length < precision) {
        s[1] += Array(precision-s[1].length + 1).join("0");
    }

    if (s[0].length > 4) {
        s[0] = d3.format(",")(parseInt(s[0]));
        s[0] = s[0]+"";
        s[0] = s[0].replace(/,/g, " ");
    }

    if (precision === 0) {
        return s[0];
    }

    return s.join(",");
}

Thank you!

yanofsky commented 7 years ago

It think this will do what you need and change the code less

function round_to_precision(num, precision, supress_thou_sep) {
    if (num === 0) {
        //zero should always be "0"
        return "0";
    }

    var s = Math.round(num * Math.pow(10,precision)) / Math.pow(10,precision);
    s = s + "";

    s = s.split(".");

    if (s.length == 1) {
        s[1] = "";
    }

    if (s[1].length < precision) {
        s[1] += Array(precision-s[1].length + 1).join("0");
    }

    if (!supress_thou_sep) {
        // add commas as thousands separator then swap it with a space
        s[0] = d3.format(",")(parseInt(s[0])).split(",").join(" ");
    }

    if (precision === 0) {
        return s[0];
    }
    // join the integer and decimal strings with a comma
    return s.join(",");
}
yanofsky commented 7 years ago

oh sorry, i see the bug, fixing now

fdaudens commented 7 years ago

Thank you so much! It works perfectly.