<commit_before>class Flast {

  constructor(canvas, options = {}) {

    // public
    this.width = canvas.clientWidth;

    this.height = canvas.clientHeight;

    this.maxZoom = options.maxZoom || 4;

    this.zoomSpeed = options.zoomSpeed || 1.01;

    this.getTileUrl = options.getTileUrl || function(zoom, x, y) {
      return `http://useredline-api.s3.amazonaws.com/development/tiles/168d136e60b14850d7a671e8/tile_${zoom}_${x}x${y}.jpg`;
    };

    this.tools = options.tools || [
      Flast.ARROW,
      Flast.LINE,
      Flast.CIRCLE,
      Flast.RECTANGLE
    ];

    this.annotations = options.annotations || [];

    this.callbacks = options.callbacks || {};

    // private
    this._canvas = canvas;
    this._ctx = canvas.getContext('2d');
    this._dragStart;
    this._svg = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
    this._transform = this._svg.createSVGMatrix();
    this._currentAnnotation = null;
    this._currentShape = null;
    this._maxScale = 2;
    this._state = {
      mouse: 'up', // 'down'
      tool: 'none', // 'arrow', 'line', 'circle', 'rectangle', 'freehand'
      dragging: false,
      drawing: false
    }

    this._addEventListeners();
    this._configureCanvas();

    this.setTileSize(options.tileSize || {
      width: 624,
      height: 416
    });

    this.redraw();
  }

  setTool(toolName) {
    var tool = this.tools.find((tool) => {
      return tool.name === toolName;
    });
    if (tool) {
      this._state.tool = toolName;
      this.redraw();
    }
    else {
      console.error("Flask: That tool is not defined.");
    }
  }

  setTileSize(size) {
    this.tileSize = size;
    this._tileCache = {};
    this._contentSize = {
      width: this.tileSize.width * Math.pow(2, this.maxZoom),
      height: this.tileSize.height * Math.pow(2, this.maxZoom)
    };
    var minScaleX = this.width / this._contentSize.width;
    var minScaleY = this.height / this._contentSize.height;
    this._minScale = Math.max(minScaleX, minScaleY);
  }

  // clear the canvas and draw the tiles
  redraw() {
    // Clear the entire canvas
    var p1 = this._transformedPoint(0, 0);
    var p2 = this._transformedPoint(this.width, this.height);
    var rect = {
      x: p1.x,
      y: p1.y,
      width: p2.x - p1.x,
      height: p2.y - p1.y
    }
    this._ctx.clearRect(rect.x, rect.y, rect.width, rect.height);
    var mins = Math.log(this._minScale) / Math.LN2;
    var maxs = Math.log(this._maxScale) / Math.LN2;
    var s = Math.log(this._transform.a) / Math.LN2;
    var zoomPercent = (s - mins) / (maxs - mins);
    var zoomLevel = Math.max(Math.ceil(zoomPercent * this.maxZoom), 1);
    var numTiles = Math.pow(2, zoomLevel);
    var tileWidth = this._contentSize.width / numTiles;
    var tileHeight = this._contentSize.height / numTiles;
    for (var j = 0; j < numTiles; j++) {
      for (var k = 0; k < numTiles; k++) {
        var tile = {
          x: Math.floor(j * tileWidth),
          y: Math.floor(k * tileHeight),
          width: Math.floor(tileWidth),
          height: Math.floor(tileHeight)
        }
        if (this._intersectRect(rect, tile)) {
          var image = this._tileImage(zoomLevel, j, k);
          if (image.complete && image.naturalHeight !== 0) {
            this._ctx.drawImage(image, tile.x, tile.y, tile.width, tile.height);
          }
          // if the tile at that zoom level is not loaded, show the lower
          // res version at the lower zoom level
          else {
            let zl = zoomLevel - 1;
            while (zl > 0) {
              let parentJ = Math.floor((j / Math.pow(2, zoomLevel)) * Math.pow(2, zl));
              let parentK = Math.floor((k / Math.pow(2, zoomLevel)) * Math.pow(2, zl));
              let image = this._tileImage(zl, parentJ, parentK);
              if (image.complete && image.naturalHeight !== 0) {
                let childTilesPerParent = Math.pow(2, zoomLevel) / Math.pow(2, zl);
                let jRemainder = j - (childTilesPerParent * parentJ);
                let kRemainder = k - (childTilesPerParent * parentK);
                let sWidth = image.width / childTilesPerParent;
                let sHeight = image.height / childTilesPerParent;
                console.log('zl', zl);
                let sx = Math.floor(jRemainder * sWidth);
                let sy = Math.floor(kRemainder * sHeight);
                this._ctx.drawImage(image, sx, sy, sWidth, sHeight, tile.x, tile.y, tile.width, tile.height);
                break;
              }
              zl -= 1;
            }
          }
        }
      }
    }

    // draw in-progress annotation/shapes
    var currentAnnotation = this._currentAnnotation || { shapes: [] };

    // draw all annotations
    for (let annotation of this.annotations.concat(currentAnnotation)) {
      // when drawing, fade out all other shapes except the current annotation
      if (!this._currentAnnotation || annotation === this._currentAnnotation) {
        this._ctx.globalAlpha = 1.0;
      }
      else {<commit_msg>removing log statements<commit_after>class Flast {

  constructor(canvas, options = {}) {

    // public
    this.width = canvas.clientWidth;

    this.height = canvas.clientHeight;

    this.maxZoom = options.maxZoom || 4;

    this.zoomSpeed = options.zoomSpeed || 1.01;

    this.getTileUrl = options.getTileUrl || function(zoom, x, y) {
      return `http://useredline-api.s3.amazonaws.com/development/tiles/168d136e60b14850d7a671e8/tile_${zoom}_${x}x${y}.jpg`;
    };

    this.tools = options.tools || [
      Flast.ARROW,
      Flast.LINE,
      Flast.CIRCLE,
      Flast.RECTANGLE
    ];

    this.annotations = options.annotations || [];

    this.callbacks = options.callbacks || {};

    // private
    this._canvas = canvas;
    this._ctx = canvas.getContext('2d');
    this._dragStart;
    this._svg = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
    this._transform = this._svg.createSVGMatrix();
    this._currentAnnotation = null;
    this._currentShape = null;
    this._maxScale = 2;
    this._state = {
      mouse: 'up', // 'down'
      tool: 'none', // 'arrow', 'line', 'circle', 'rectangle', 'freehand'
      dragging: false,
      drawing: false
    }

    this._addEventListeners();
    this._configureCanvas();

    this.setTileSize(options.tileSize || {
      width: 624,
      height: 416
    });

    this.redraw();
  }

  setTool(toolName) {
    var tool = this.tools.find((tool) => {
      return tool.name === toolName;
    });
    if (tool) {
      this._state.tool = toolName;
      this.redraw();
    }
    else {
      console.error("Flask: That tool is not defined.");
    }
  }

  setTileSize(size) {
    this.tileSize = size;
    this._tileCache = {};
    this._contentSize = {
      width: this.tileSize.width * Math.pow(2, this.maxZoom),
      height: this.tileSize.height * Math.pow(2, this.maxZoom)
    };
    var minScaleX = this.width / this._contentSize.width;
    var minScaleY = this.height / this._contentSize.height;
    this._minScale = Math.max(minScaleX, minScaleY);
  }

  // clear the canvas and draw the tiles
  redraw() {
    // Clear the entire canvas
    var p1 = this._transformedPoint(0, 0);
    var p2 = this._transformedPoint(this.width, this.height);
    var rect = {
      x: p1.x,
      y: p1.y,
      width: p2.x - p1.x,
      height: p2.y - p1.y
    }
    this._ctx.clearRect(rect.x, rect.y, rect.width, rect.height);
    var mins = Math.log(this._minScale) / Math.LN2;
    var maxs = Math.log(this._maxScale) / Math.LN2;
    var s = Math.log(this._transform.a) / Math.LN2;
    var zoomPercent = (s - mins) / (maxs - mins);
    var zoomLevel = Math.max(Math.ceil(zoomPercent * this.maxZoom), 1);
    var numTiles = Math.pow(2, zoomLevel);
    var tileWidth = this._contentSize.width / numTiles;
    var tileHeight = this._contentSize.height / numTiles;
    for (var j = 0; j < numTiles; j++) {
      for (var k = 0; k < numTiles; k++) {
        var tile = {
          x: Math.floor(j * tileWidth),
          y: Math.floor(k * tileHeight),
          width: Math.floor(tileWidth),
          height: Math.floor(tileHeight)
        }
        if (this._intersectRect(rect, tile)) {
          var image = this._tileImage(zoomLevel, j, k);
          if (image.complete && image.naturalHeight !== 0) {
            this._ctx.drawImage(image, tile.x, tile.y, tile.width, tile.height);
          }
          // if the tile at that zoom level is not loaded, show the lower
          // res version at the lower zoom level
          else {
            let zl = zoomLevel - 1;
            while (zl > 0) {
              let parentJ = Math.floor((j / Math.pow(2, zoomLevel)) * Math.pow(2, zl));
              let parentK = Math.floor((k / Math.pow(2, zoomLevel)) * Math.pow(2, zl));
              let image = this._tileImage(zl, parentJ, parentK);
              if (image.complete && image.naturalHeight !== 0) {
                let childTilesPerParent = Math.pow(2, zoomLevel) / Math.pow(2, zl);
                let jRemainder = j - (childTilesPerParent * parentJ);
                let kRemainder = k - (childTilesPerParent * parentK);
                let sWidth = image.width / childTilesPerParent;
                let sHeight = image.height / childTilesPerParent;
                let sx = Math.floor(jRemainder * sWidth);
                let sy = Math.floor(kRemainder * sHeight);
                this._ctx.drawImage(image, sx, sy, sWidth, sHeight, tile.x, tile.y, tile.width, tile.height);
                break;
              }
              zl -= 1;
            }
          }
        }
      }
    }

    // draw in-progress annotation/shapes
    var currentAnnotation = this._currentAnnotation || { shapes: [] };

    // draw all annotations
    for (let annotation of this.annotations.concat(currentAnnotation)) {
      // when drawing, fade out all other shapes except the current annotation
      if (!this._currentAnnotation || annotation === this._currentAnnotation) {
        this._ctx.globalAlpha = 1.0;
      }
      else {
{'fraction_non_alphanumeric': 0.13568939771030364, 'fraction_numerical': 0.013539074166251866, 'mean_word_length': 2.1354556803995006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7597645', 'n_tokens_mistral': 3331, 'n_tokens_neox': 3191, 'n_words': 718}