molstar
Version:
A comprehensive macromolecular library.
30 lines (29 loc) • 1.39 kB
JavaScript
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { Iterator } from '../../../../mol-data';
export function getFieldDigitCount(field) {
if (field.defaultFormat && typeof field.defaultFormat.digitCount !== 'undefined')
return Math.max(0, Math.min(field.defaultFormat.digitCount, 16));
return 6;
}
export function getIncludedFields(category) {
return category.fields.some(function (f) { return !!f.shouldInclude; })
? category.fields.filter(function (f) { return !f.shouldInclude || category.source.some(function (src) { return f.shouldInclude(src.data); }); })
: category.fields;
}
export function getCategoryInstanceData(category, ctx) {
var instance = category.instance(ctx);
var sources = instance.source.filter(function (s) { return s.rowCount > 0; });
if (!sources.length)
return { instance: instance, rowCount: 0, source: [] };
var rowCount = sources.reduce(function (a, c) { return a + c.rowCount; }, 0);
var source = sources.map(function (c) { return ({
data: c.data,
keys: function () { return c.keys ? c.keys() : Iterator.Range(0, c.rowCount - 1); },
rowCount: c.rowCount
}); });
return { instance: instance, rowCount: rowCount, source: source };
}