<commit_before>'use strict';

var domEvent = require('min-dom/lib/event');

function ZoomScroll(events, canvas) {

  var RANGE = { min: 0.2, max: 4 };

  var ZOOM_OFFSET = 5;
  var SCROLL_OFFSET = 50;

  function cap(scale) {
    return Math.max(RANGE.min, Math.min(RANGE.max, scale));
  }

  function reset() {
    canvas.zoom('fit-viewport');
  }

  function zoom(direction, position) {

    var currentZoom = canvas.zoom();
    var factor = 1 + (direction / ZOOM_OFFSET);

    canvas.zoom(cap(currentZoom * factor), position);
  }


  function init(element) {

    domEvent.bind(element, 'wheel', function(event) {

      var factor = event.deltaMode === 0 ? 1/40 : 1/2;

      var shift = event.shiftKey,
          ctrl = event.ctrlKey;

      var x = event.deltaX * factor,
          y = event.deltaY * factor;

      if (shift || ctrl) {
        var delta = {};

        if (ctrl) {
          delta.dx = SCROLL_OFFSET * (x || y);
        } else {
          delta.dy = SCROLL_OFFSET * (x || y);
        }

        canvas.scroll(delta);
      } else {
        var offset = {};

        // gecko=layer*, other=offset*
        if (isNaN(event.offsetX)) {
          offset = {
            x: event.layerX,
            y: event.layerY
          };
        } else {
          offset = {
            x: event.offsetX,
            y: event.offsetY
          };
        }

        // zoom in relative to diagram {x,y} coordinates
        zoom(y, offset);
      }

      event.preventDefault();
    });
  }

  events.on('canvas.init', function(e) {
    init(e.svg.node);
  });

  // API
  this.zoom = zoom;
  this.reset = reset;<commit_msg>fix(zoomscroll): zoom into the right dimension<commit_after>'use strict';

var domEvent = require('min-dom/lib/event');

function ZoomScroll(events, canvas) {

  var RANGE = { min: 0.2, max: 4 };

  var ZOOM_OFFSET = 5;
  var SCROLL_OFFSET = 50;

  function cap(scale) {
    return Math.max(RANGE.min, Math.min(RANGE.max, scale));
  }

  function reset() {
    canvas.zoom('fit-viewport');
  }

  function zoom(direction, position) {

    var currentZoom = canvas.zoom();
    var factor = 1 + (direction / ZOOM_OFFSET);

    canvas.zoom(cap(currentZoom * factor), position);
  }


  function init(element) {

    domEvent.bind(element, 'wheel', function(event) {

      var factor = event.deltaMode === 0 ? 1/40 : 1/2;

      var shift = event.shiftKey,
          ctrl = event.ctrlKey;

      var x = event.deltaX * factor,
          y = event.deltaY * factor;

      if (shift || ctrl) {
        var delta = {};

        if (ctrl) {
          delta.dx = SCROLL_OFFSET * (x || y);
        } else {
          delta.dy = SCROLL_OFFSET * (x || y);
        }

        canvas.scroll(delta);
      } else {
        var offset = {};

        // gecko=layer*, other=offset*
        if (isNaN(event.offsetX)) {
          offset = {
            x: event.layerX,
            y: event.layerY
          };
        } else {
          offset = {
            x: event.offsetX,
            y: event.offsetY
          };
        }

        // zoom in relative to diagram {x,y} coordinates
        zoom(y * -1, offset);
      }

      event.preventDefault();
    });
  }

  events.on('canvas.init', function(e) {
    init(e.svg.node);
  });

  // API
  this.zoom = zoom;
  this.reset = reset;
{'fraction_non_alphanumeric': 0.1435912938331318, 'fraction_numerical': 0.008162031438935914, 'mean_word_length': 1.8257899231426131, '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': '4809628', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1061, 'n_words': 243}