{"size": 996, "ext": "js", "max_stars_repo_path": "node_modules/d3fc/src/indicator/algorithm/calculator/percentageChange.js", "max_stars_repo_name": "chrisprice/creating-d3-components", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/d3fc/src/indicator/algorithm/calculator/percentageChange.js", "max_issues_repo_name": "chrisprice/creating-d3-components", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/d3fc/src/indicator/algorithm/calculator/percentageChange.js", "max_forks_repo_name": "chrisprice/creating-d3-components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9, "max_line_length": 69, "alphanum_fraction": 0.4769076305}
(function(d3, fc) {
    'use strict';

    fc.indicator.algorithm.calculator.percentageChange = function() {

        var baseIndex = d3.functor(0),
            value = fc.util.fn.identity;

        var percentageChange = function(data) {

            if (data.length === 0) {
                return [];
            }

            var baseValue = value(data[baseIndex(data)]);

            return data.map(function(d, i) {
                    return (value(d, i) - baseValue) / baseValue;
                });
        };

        percentageChange.baseIndex = function(x) {
            if (!arguments.length) {
                return baseIndex;
            }
            baseIndex = d3.functor(x);
            return percentageChange;
        };
        percentageChange.value = function(x) {
            if (!arguments.length) {
                return value;
            }
            value = x;
            return percentageChange;
        };

        return percentageChange;
    };
}(d3, fc));
