<commit_before>'use strict';
/* jshint browser:true */
var _ = require('lodash');
var VideoMediaObject = require('./media-object/video-media-object');
var variableThrottle = require('./variable-throttle');
var ImageMediaObject = require('./media-object/image-media-object');
var TextMediaObject = require('./media-object/text-media-object');


function RandomVisualPlayer (stageElement, queue) {

    
    var showMediaLastRun;

    var showMedia = variableThrottle(function() {
        _.forEach([VideoMediaObject, ImageMediaObject, TextMediaObject], function(moType) {
            var obj = queue.take([moType]);
            if (obj) {
                obj.on('done', moDoneHandler);
                obj.on('transition', moTransitionHandler);

                obj.makeElement(function() {
                    obj.onReady(function() {
                        if (obj instanceof ImageMediaObject || obj instanceof TextMediaObject) {
                            stageElement.appendChild(obj.element);
                            placeAtRandomPosition(obj.element);
                        }

                        obj.play({
                            transitionDuration: queue.transitionDuration,
                            // only applicable to atemporal media (images and text)
                            displayDuration: queue.displayDuration
                        });
                        obj.element.classList.add('show-media-object');
                    });

                    if (obj instanceof VideoMediaObject) {
                        stageElement.appendChild(obj.element);
                        placeAtRandomPosition(obj.element);    
                    }
                });
            }    
        });
    }, function() {
        return queue.displayInterval;
    });


    function calcDimension(dim, element) {
        return Math.round(Math.random() * (stageElement[dim] - element[dim])) + 'px';
    }

    function placeAtRandomPosition(element) {
        element.style.left = calcDimension('clientWidth', element);
        element.style.top = calcDimension('clientHeight', element);
    }

    this.setMediaObjectQueue = function(newQueue) {
        queue = newQueue;
    };

    function moDoneHandler (mediaObject) {
        mediaObject.removeListener('done', moDoneHandler);
        stageElement.removeChild(mediaObject.element);
        showMedia();
    }

    function moTransitionHandler (mediaObject) {
        mediaObject.removeListener('transition', moTransitionHandler);
        mediaObject.element.classList.remove('show-media-object');
        showMedia();
    }

    this.start = function() {
        showMedia();

        if (queue.displayInterval) {
            window.setInterval(showMedia, queue.displayInterval);
        }
    };<commit_msg>random visual player places elements up to 30% offscreen<commit_after>'use strict';
/* jshint browser:true */
var _ = require('lodash');
var VideoMediaObject = require('./media-object/video-media-object');
var variableThrottle = require('./variable-throttle');
var ImageMediaObject = require('./media-object/image-media-object');
var TextMediaObject = require('./media-object/text-media-object');


function RandomVisualPlayer (stageElement, queue) {

    
    var showMediaLastRun;

    var showMedia = variableThrottle(function() {
        _.forEach([VideoMediaObject, ImageMediaObject, TextMediaObject], function(moType) {
            var obj = queue.take([moType]);
            if (obj) {
                obj.on('done', moDoneHandler);
                obj.on('transition', moTransitionHandler);

                obj.makeElement(function() {
                    obj.onReady(function() {
                        if (obj instanceof ImageMediaObject || obj instanceof TextMediaObject) {
                            stageElement.appendChild(obj.element);
                            placeAtRandomPosition(obj.element);
                        }

                        obj.play({
                            transitionDuration: queue.transitionDuration,
                            // only applicable to atemporal media (images and text)
                            displayDuration: queue.displayDuration
                        });
                        obj.element.classList.add('show-media-object');
                    });

                    if (obj instanceof VideoMediaObject) {
                        stageElement.appendChild(obj.element);
                        placeAtRandomPosition(obj.element);    
                    }
                });
            }    
        });
    }, function() {
        return queue.displayInterval;
    });


    function calcDimension(dim, element) {
        var elementDimensionSize = element[dim];

        var randomNonOverlapPosition = Math.random() * (stageElement[dim] - elementDimensionSize);
        // allow potential overlap of up to 30% of element's dimension
        var potentialOverlap = _.random(-0.3, 0.3) * elementDimensionSize;

        
        return Math.round(randomNonOverlapPosition + potentialOverlap) + 'px';
    }

    function placeAtRandomPosition(element) {
        element.style.left = calcDimension('clientWidth', element);
        element.style.top = calcDimension('clientHeight', element);
    }

    this.setMediaObjectQueue = function(newQueue) {
        queue = newQueue;
    };

    function moDoneHandler (mediaObject) {
        mediaObject.removeListener('done', moDoneHandler);
        stageElement.removeChild(mediaObject.element);
        showMedia();
    }

    function moTransitionHandler (mediaObject) {
        mediaObject.removeListener('transition', moTransitionHandler);
        mediaObject.element.classList.remove('show-media-object');
        showMedia();
    }

    this.start = function() {
        showMedia();

        if (queue.displayInterval) {
            window.setInterval(showMedia, queue.displayInterval);
        }
    };
{'fraction_non_alphanumeric': 0.10689597032540887, 'fraction_numerical': 0.0013488450514247176, 'mean_word_length': 1.9779116465863453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2539764', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1391, 'n_words': 260}