dimple-js
Version:
Dimple is an object-oriented API allowing you to create flexible axis-based charts using [d3.js](http://d3js.org "d3.js").
11 lines (10 loc) • 731 B
JavaScript
// Copyright: 2015 AlignAlytics
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
// Source: /src/objects/aggregateMethod/avg.js
dimple.aggregateMethod.avg = function (lhs, rhs) {
lhs.value = (lhs.value === null || lhs.value === undefined ? 0 : parseFloat(lhs.value));
lhs.count = (lhs.count === null || lhs.count === undefined ? 1 : parseFloat(lhs.count));
rhs.value = (rhs.value === null || rhs.value === undefined ? 0 : parseFloat(rhs.value));
rhs.count = (rhs.count === null || rhs.count === undefined ? 1 : parseFloat(rhs.count));
return ((lhs.value * lhs.count) + (rhs.value * rhs.count)) / (lhs.count + rhs.count);
};