@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
26 lines (25 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Helper = void 0;
const Assertions_1 = require("../../../../RcsbUtils/Helpers/Assertions");
var Helper;
(function (Helper) {
var assertDefined = Assertions_1.Assertions.assertDefined;
function mergeCharts(charts) {
const attributes = Array.from(new Set(charts.map(ch => ch.attribute)));
return attributes.map(attr => (mergeChartData(charts.filter(ch => ch.attribute == attr))));
}
Helper.mergeCharts = mergeCharts;
function mergeChartData(charts) {
return Object.assign(Object.assign({}, charts[0]), { data: mergeData(charts.map(ch => ch.data).flat()) });
}
function mergeData(data) {
const labels = Array.from(new Set(data.map(d => d.label)));
return labels.map(label => {
var _a, _b;
const d = data.find(d => d.label === label);
assertDefined(d);
return Object.assign(Object.assign({}, d), { population: (_b = (_a = data.filter(d => d.label === label)) === null || _a === void 0 ? void 0 : _a.reduce((prev, curr) => (prev + curr.population), 0)) !== null && _b !== void 0 ? _b : 0 });
});
}
})(Helper || (exports.Helper = Helper = {}));