UNPKG

molstar

Version:

A comprehensive macromolecular library.

36 lines (35 loc) 1.72 kB
"use strict"; /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getCategoryInstanceData = exports.getIncludedFields = exports.getFieldDigitCount = void 0; var mol_data_1 = require("../../../../mol-data"); function getFieldDigitCount(field) { if (field.defaultFormat && typeof field.defaultFormat.digitCount !== 'undefined') return Math.max(0, Math.min(field.defaultFormat.digitCount, 16)); return 6; } exports.getFieldDigitCount = getFieldDigitCount; 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; } exports.getIncludedFields = getIncludedFields; 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() : mol_data_1.Iterator.Range(0, c.rowCount - 1); }, rowCount: c.rowCount }); }); return { instance: instance, rowCount: rowCount, source: source }; } exports.getCategoryInstanceData = getCategoryInstanceData;