Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that numberDisplay is better than dataCount #1076

Closed
ubershmekel opened this issue Dec 23, 2015 · 3 comments
Closed

Document that numberDisplay is better than dataCount #1076

ubershmekel opened this issue Dec 23, 2015 · 3 comments
Labels

Comments

@ubershmekel
Copy link
Contributor

I want to show what's the percentage of the filtered items. I'm not sure how to do that with dc.dataCount.

I could have easily implemented it if .html took a function that allowed me to do anything instead of the string manipulation in the current API. https://github.com/dc-js/dc.js/blob/master/web/docs/api-latest.md#datacounthtml--object--datacount

    .html({
        some: '<strong>%filter-count</strong> selected out of <strong>%total-count</strong> records' +
            ' | <a href=\'javascript:dc.filterAll(); dc.renderAll();\'\'>Reset All</a>',
        all: 'All <strong>%total-count</strong> records shown. Click on the graphs to apply filters.'
    })

Would you be interested in such a pull request?

@gordonwoodhull
Copy link
Contributor

I think you probably want to use the numberDisplay, which is more general.

@ubershmekel
Copy link
Contributor Author

Yes. That worked. Thank you. Perhaps I can mention in the docs of dataCount and numberDisplay that they are related.

For future searchers this was my solution:

var createRowCounter = function() {
    var humanize = function(x) {
        // http://stackoverflow.com/questions/661562/how-to-format-a-float-in-javascript/29249277#29249277
        return x.toFixed(2).replace(/\.?0*$/,'');
    }

    var rowCounterId = 'rowCounter'
    addDiv(rowCounterId);
    var rowCounter = dc.numberDisplay ('#' + rowCounterId);
    rowCounter
        .dimension(ndx)
        .group(ndx.groupAll())
        .formatNumber(function() {
            var selectedCount = rowCounter.group().value();
            var total = rowCounter.dimension().size();
            if(selectedCount == total) {
                return 'All <strong>' + total + '</strong> records shown. Click on the graphs to apply filters.'
            }
            var resetButton = '<a href="javascript:dc.filterAll(); dc.renderAll();">Reset All</a>';
            var percent = humanize(100 * selectedCount / total);
            return 'Selected ' + percent + '% (' + selectedCount + ' out of ' + total + ' records) | ' + resetButton;
    });
}

@gordonwoodhull
Copy link
Contributor

Good idea. Thanks for the report!

@gordonwoodhull gordonwoodhull changed the title Can't show percentage filtered in dataCount Document that numberDisplay is better than dataCount Dec 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants