<commit_before>// Amara, universalsubtitles.org
//
// Copyright (C) 2013 Participatory Culture Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see
// http://www.gnu.org/licenses/agpl-3.0.html.

var angular = angular || null;

(function() {
    var module = angular.module('amara.SubtitleEditor.timeline.directives', []);

    /*
     * Define a couple of helper classes to handle updating the timeline
     * elements.  Our basic strategy is to make a really wide div, so that we
     * have a bit of a buffer, then scroll the div instead of re-rendering
     * everything.
     */
    function durationToPixels(duration, scale) {
        // by default 1 pixel == 10 ms.  scope.scale can adjusts that,
        // although there isn't any interface for it.
        return Math.floor(scale * duration / 10);
    }

    function pixelsToDuration(width, scale) {
        return width * 10 / scale;
    }

    function BufferTimespan(scope) {
        /* Stores the time range of the entire div.*/
        this.duration = 60000; // Buffer 1 minute of subtitles.
        // Position the buffer so that most of it is in front of the current
        // time.
        if(scope.currentTime !== null) {
            var currentTime = scope.currentTime;
        } else {
            var currentTime = 0;
        }
        this.startTime = currentTime - this.duration / 4;
        // We don't want to buffer negative times, but do let startTime go to
        // -0.5 seconds because the left side of the "0" is slightly left of
        // time=0.
        if(this.startTime < -500) {
            this.startTime = -500;
        }
        this.endTime = this.startTime + this.duration;
        this.width = durationToPixels(this.duration, scope.scale);
    }

    function VisibleTimespan(scope, width, deltaMS) {
        /* Stores the portion of the video time that is displayed in the
         * timeline.
         */

        this.scale = scope.scale;
        this.duration = pixelsToDuration(width, this.scale);
        if(scope.currentTime !== null) {
            var currentTime = scope.currentTime;
        } else {
            var currentTime = 0;
        }
        this.startTime = currentTime - this.duration / 2;
        if(deltaMS) {
            this.startTime += deltaMS;
        }
        this.endTime = this.startTime + this.duration;
    }

    VisibleTimespan.prototype.fitsInBuffer = function(bufferTimespan) {
        if(this.startTime >= 0 && this.startTime < bufferTimespan.startTime) {
            return false;<commit_msg>Fix bug redrawing timeline.<commit_after>// Amara, universalsubtitles.org
//
// Copyright (C) 2013 Participatory Culture Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see
// http://www.gnu.org/licenses/agpl-3.0.html.

var angular = angular || null;

(function() {
    var module = angular.module('amara.SubtitleEditor.timeline.directives', []);

    /*
     * Define a couple of helper classes to handle updating the timeline
     * elements.  Our basic strategy is to make a really wide div, so that we
     * have a bit of a buffer, then scroll the div instead of re-rendering
     * everything.
     */
    function durationToPixels(duration, scale) {
        // by default 1 pixel == 10 ms.  scope.scale can adjusts that,
        // although there isn't any interface for it.
        return Math.floor(scale * duration / 10);
    }

    function pixelsToDuration(width, scale) {
        return width * 10 / scale;
    }

    function BufferTimespan(scope) {
        /* Stores the time range of the entire div.*/
        this.duration = 60000; // Buffer 1 minute of subtitles.
        // Position the buffer so that most of it is in front of the current
        // time.
        if(scope.currentTime !== null) {
            var currentTime = scope.currentTime;
        } else {
            var currentTime = 0;
        }
        this.startTime = currentTime - this.duration / 4;
        // We don't want to buffer negative times, but do let startTime go to
        // -0.5 seconds because the left side of the "0" is slightly left of
        // time=0.
        if(this.startTime < -500) {
            this.startTime = -500;
        }
        this.endTime = this.startTime + this.duration;
        this.width = durationToPixels(this.duration, scope.scale);
    }

    function VisibleTimespan(scope, width, deltaMS) {
        /* Stores the portion of the video time that is displayed in the
         * timeline.
         */

        this.scale = scope.scale;
        this.duration = pixelsToDuration(width, this.scale);
        if(scope.currentTime !== null) {
            var currentTime = scope.currentTime;
        } else {
            var currentTime = 0;
        }
        this.startTime = currentTime - this.duration / 2;
        if(deltaMS) {
            this.startTime += deltaMS;
        }
        this.endTime = this.startTime + this.duration;
    }

    VisibleTimespan.prototype.fitsInBuffer = function(bufferTimespan) {
        if(this.startTime < bufferTimespan.startTime) {
            return false;
{'fraction_non_alphanumeric': 0.0907196666132393, 'fraction_numerical': 0.011059464657797724, 'mean_word_length': 2.2398753894080996, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '249688', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1647, 'n_words': 640}