<commit_before>define( ['dojo/_base/declare',
         'dojo/on',
         'JBrowse/View/Track/Canvas',
         'JBrowse/View/Track/YScaleMixin',
         'JBrowse/View/Track/ExportMixin',
         'JBrowse/Util'
        ],
        function( declare, on, CanvasTrack, YScaleMixin, ExportMixin, Util ) {
var Wiggle = declare( CanvasTrack, {
    constructor: function( args ) {
        this.store = args.store;
        dojo.connect( this.store, 'loadSuccess', this, 'loadSuccess' );
        dojo.connect( this.store, 'loadFail',    this, 'loadFail' );
    }
});

/**
 * Mixin: JBrowse.View.Track.YScaleMixin.
 */
dojo.safeMixin( Wiggle.prototype, YScaleMixin );

/**
 * Mixin: JBrowse.View.Track.ExportMixin.
 */
dojo.safeMixin( Wiggle.prototype, ExportMixin );

/**
 * @lends JBrowse.View.Track.Wiggle.prototype
 */
Wiggle.extend({
    _defaultConfig: function() {
        return { maxExportSpan: 500000 };
    },

    load: function() {
        this.store.load();
    },

    loadSuccess: function(o,url) {
        this._calculateScaling();
        this.empty = this.store.empty || false;
        this.setLoaded();
    },

    loadFail: function() {
    },

    makeWiggleYScale: function() {
        if( ! this.scale )
            return;

        // bump minDisplayed to 0 if it is within 0.5% of it
        if( Math.abs( this.scale.min / this.scale.max ) < 0.005 )
            this.scale.min = 0;

        this.makeYScale({
            fixBounds: true,
            min: this.scale.min,
            max: this.scale.max
        });
        this.scale.min = this.ruler.scaler.bounds.lower;
        this.scale.max = this.ruler.scaler.bounds.upper;
        this.scale.range = this.scale.max - this.scale.min;
    },

    _calculateScaling: function() {
        // if either autoscale or scale is set to z_score, the other one should default to z_score
        if( this.config.autoscale == 'z_score' && ! this.config.scale
            || this.config.scale == 'z_score'  && !this.config.autoscale
          ) {
              this.config.scale = 'z_score';
              this.config.autoscale = 'z_score';
          }

        var z_score_bound = parseFloat( this.config.z_score_bound ) || 4;
        var s = this.getGlobalStats() || {};
        var min = 'min_score' in this.config ? parseFloat( this.config.min_score ) :
            (function() {
                 switch( this.config.autoscale ) {
                     case 'z_score':
                         return Math.max( -z_score_bound, (s.scoreMin-s.scoreMean) / s.scoreStdDev );
                     case 'global':
                         return s.scoreMin;;
                     case 'clipped_global':
                     default:
                         return Math.max( s.scoreMin, s.scoreMean - z_score_bound * s.scoreStdDev );
                 }
             }).call(this);
        var max = 'max_score' in this.config ? parseFloat( this.config.max_score ) :
            (function() {
                 switch( this.config.autoscale ) {
                     case 'z_score':
                         return Math.min( z_score_bound, (s.scoreMax-s.scoreMean) / s.scoreStdDev );
                     case 'global':
                         return s.scoreMax;
                     case 'clipped_global':
                     default:
                         return Math.min( s.scoreMax, s.scoreMean + z_score_bound * s.scoreStdDev );
                 }
             }).call(this);

        if( typeof max != 'number' || isNaN(max) ) {
            throw 'could not determine max_score for track "'+this.name+'", cannot draw track.';
        }
        if( typeof min != 'number' || isNaN(min) ) {
            throw 'could not determine min_score for track "'+this.name+'", cannot draw track.';
        }

        // if we have a log scale, need to take the log of the min and max
        if( this.config.scale == 'log' ) {
            max = Math.log(max);
            min = min ? Math.log(min) : 0;
        }

        var offset = parseFloat( this.config.data_offset ) || 0;
        var origin = (function() {
          if ( 'bicolor_pivot' in this.config ) {
            if ( this.config.bicolor_pivot == 'mean' ) {
              return s.scoreMean || 0;
            } else if ( this.config.bicolor_pivot == 'zero' ) {
              return 0;
            } else {
              return parseFloat( this.config.bicolor_pivot );
            }
          } else if ( this.config.scale == 'z_score' ) {<commit_msg>improve Wiggle track error messages when they cannot calculate the range to display<commit_after>define( ['dojo/_base/declare',
         'dojo/on',
         'JBrowse/View/Track/Canvas',
         'JBrowse/View/Track/YScaleMixin',
         'JBrowse/View/Track/ExportMixin',
         'JBrowse/Util'
        ],
        function( declare, on, CanvasTrack, YScaleMixin, ExportMixin, Util ) {
var Wiggle = declare( CanvasTrack, {
    constructor: function( args ) {
        this.store = args.store;
        dojo.connect( this.store, 'loadSuccess', this, 'loadSuccess' );
        dojo.connect( this.store, 'loadFail',    this, 'loadFail' );
    }
});

/**
 * Mixin: JBrowse.View.Track.YScaleMixin.
 */
dojo.safeMixin( Wiggle.prototype, YScaleMixin );

/**
 * Mixin: JBrowse.View.Track.ExportMixin.
 */
dojo.safeMixin( Wiggle.prototype, ExportMixin );

/**
 * @lends JBrowse.View.Track.Wiggle.prototype
 */
Wiggle.extend({
    _defaultConfig: function() {
        return { maxExportSpan: 500000 };
    },

    load: function() {
        this.store.load();
    },

    loadSuccess: function(o,url) {
        this._calculateScaling();
        this.empty = this.store.empty || false;
        this.setLoaded();
    },

    loadFail: function() {
    },

    makeWiggleYScale: function() {
        if( ! this.scale )
            return;

        // bump minDisplayed to 0 if it is within 0.5% of it
        if( Math.abs( this.scale.min / this.scale.max ) < 0.005 )
            this.scale.min = 0;

        this.makeYScale({
            fixBounds: true,
            min: this.scale.min,
            max: this.scale.max
        });
        this.scale.min = this.ruler.scaler.bounds.lower;
        this.scale.max = this.ruler.scaler.bounds.upper;
        this.scale.range = this.scale.max - this.scale.min;
    },

    _calculateScaling: function() {
        // if either autoscale or scale is set to z_score, the other one should default to z_score
        if( this.config.autoscale == 'z_score' && ! this.config.scale
            || this.config.scale == 'z_score'  && !this.config.autoscale
          ) {
              this.config.scale = 'z_score';
              this.config.autoscale = 'z_score';
          }

        var z_score_bound = parseFloat( this.config.z_score_bound ) || 4;
        var s = this.getGlobalStats() || {};
        var min = 'min_score' in this.config ? parseFloat( this.config.min_score ) :
            (function() {
                 switch( this.config.autoscale ) {
                     case 'z_score':
                         return Math.max( -z_score_bound, (s.scoreMin-s.scoreMean) / s.scoreStdDev );
                     case 'global':
                         return s.scoreMin;;
                     case 'clipped_global':
                     default:
                         return Math.max( s.scoreMin, s.scoreMean - z_score_bound * s.scoreStdDev );
                 }
             }).call(this);
        var max = 'max_score' in this.config ? parseFloat( this.config.max_score ) :
            (function() {
                 switch( this.config.autoscale ) {
                     case 'z_score':
                         return Math.min( z_score_bound, (s.scoreMax-s.scoreMean) / s.scoreStdDev );
                     case 'global':
                         return s.scoreMax;
                     case 'clipped_global':
                     default:
                         return Math.min( s.scoreMax, s.scoreMean + z_score_bound * s.scoreStdDev );
                 }
             }).call(this);

        if( typeof max != 'number' || isNaN(max) ) {
            throw 'cannot display track '+this.name+', could not determine max_score.  Do you need to set max_score in its configuration?';
        }
        if( typeof min != 'number' || isNaN(min) ) {
            throw 'cannot display track '+this.name+', could not determine min_score.  Do you need to set min_score in its configuration?';
        }

        // if we have a log scale, need to take the log of the min and max
        if( this.config.scale == 'log' ) {
            max = Math.log(max);
            min = min ? Math.log(min) : 0;
        }

        var offset = parseFloat( this.config.data_offset ) || 0;
        var origin = (function() {
          if ( 'bicolor_pivot' in this.config ) {
            if ( this.config.bicolor_pivot == 'mean' ) {
              return s.scoreMean || 0;
            } else if ( this.config.bicolor_pivot == 'zero' ) {
              return 0;
            } else {
              return parseFloat( this.config.bicolor_pivot );
            }
          } else if ( this.config.scale == 'z_score' ) {
{'fraction_non_alphanumeric': 0.12588028169014084, 'fraction_numerical': 0.004181338028169014, 'mean_word_length': 1.669309838472834, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3288980', 'n_tokens_mistral': 2827, 'n_tokens_neox': 2708, 'n_words': 607}