Sidebar.prototype.renderEntities = function()

in lib/@uncharted/strippets/src/strippets.outline.sidebar.js [95:120]


Sidebar.prototype.renderEntities = function() {
    var $entities;
    var factor;
    var visibleEntities = {};
    var numEntitySlots = Math.floor((this.height || this.$sidebarEntityContainer.height()) / this.entityHeight);
    if (numEntitySlots === this.numEntitySlots) {
        return;
    }
    this.numEntitySlots = numEntitySlots;
    visibleEntities = {};
    factor = 100 / this.numEntitySlots;
    this.entities.forEach(function(entity) {
        // round entityPosition to nearest multiple of the factor
        var entityPosition = String(Math.round(entity.data.firstPosition * 100 / factor) * factor);
        var visibleEntity = visibleEntities[entityPosition];
        if (!visibleEntity || entity.weight > visibleEntity.weight) {
            visibleEntities[entityPosition] = entity;
        }
    });
    $entities = Object.keys(visibleEntities).map(function(position) {
        var entity = visibleEntities[position];
        entity.setPosition(position);
        return entity.$entity;
    });
    this.$sidebarEntityContainer.html($entities);
};