<commit_before>import * as cornerstone from 'cornerstone-core';

export default function (mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
  const element = mouseEventData.element;

  function moveCallback (e, eventData) {
    handle.active = true;
    handle.x = eventData.currentPoints.image.x;
    handle.y = eventData.currentPoints.image.y;

    if (preventHandleOutsideImage) {
      handle.x = Math.max(handle.x, 0);
      handle.x = Math.min(handle.x, eventData.image.width);

      handle.y = Math.max(handle.y, 0);
      handle.y = Math.min(handle.y, eventData.image.height);
    }

    cornerstone.updateImage(element);

    const eventType = 'CornerstoneToolsMeasurementModified';
    const modifiedEventData = {
      toolType,
      element,
      measurementData: data
    };

    $(element).trigger(eventType, modifiedEventData);
  }

  function whichMovement (e) {
    $(element).off('CornerstoneToolsMouseMove');
    $(element).off('CornerstoneToolsMouseDrag');

    $(element).on('CornerstoneToolsMouseMove', moveCallback);
    $(element).on('CornerstoneToolsMouseDrag', moveCallback);

    $(element).on('CornerstoneToolsMouseClick', moveEndCallback);
    if (e.type === 'CornerstoneToolsMouseDrag') {
      $(element).on('CornerstoneToolsMouseUp', moveEndCallback);
    }
  }

  function measurementRemovedCallback (e, eventData) {
    if (eventData.measurementData === data) {
      moveEndCallback();
    }
  }

  function toolDeactivatedCallback (e, eventData) {
    if (eventData.toolType === toolType) {
      $(element).off('CornerstoneToolsMouseMove', moveCallback);<commit_msg>Fix for https://github.com/chafey/cornerstoneTools/issues/217 - Highlight issue<commit_after>import * as cornerstone from 'cornerstone-core';

export default function (mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
  const element = mouseEventData.element;

  function moveCallback (e, eventData) {
    handle.active = true;
    handle.x = eventData.currentPoints.image.x;
    handle.y = eventData.currentPoints.image.y;

    if (preventHandleOutsideImage) {
      handle.x = Math.max(handle.x, 0);
      handle.x = Math.min(handle.x, eventData.image.width);

      handle.y = Math.max(handle.y, 0);
      handle.y = Math.min(handle.y, eventData.image.height);
    }

    cornerstone.updateImage(element);

    const eventType = 'CornerstoneToolsMeasurementModified';
    const modifiedEventData = {
      toolType,
      element,
      measurementData: data
    };

    $(element).trigger(eventType, modifiedEventData);
  }

  function whichMovement (e) {
    $(element).off('CornerstoneToolsMouseMove', whichMovement);
    $(element).off('CornerstoneToolsMouseDrag', whichMovement);

    $(element).on('CornerstoneToolsMouseMove', moveCallback);
    $(element).on('CornerstoneToolsMouseDrag', moveCallback);

    $(element).on('CornerstoneToolsMouseClick', moveEndCallback);
    if (e.type === 'CornerstoneToolsMouseDrag') {
      $(element).on('CornerstoneToolsMouseUp', moveEndCallback);
    }
  }

  function measurementRemovedCallback (e, eventData) {
    if (eventData.measurementData === data) {
      moveEndCallback();
    }
  }

  function toolDeactivatedCallback (e, eventData) {
    if (eventData.toolType === toolType) {
      $(element).off('CornerstoneToolsMouseMove', moveCallback);
{'fraction_non_alphanumeric': 0.12787950383933847, 'fraction_numerical': 0.002067336089781453, 'mean_word_length': 4.11631419939577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4102925', 'n_tokens_mistral': 1032, 'n_tokens_neox': 994, 'n_words': 177}