<commit_before>/*jslint indent: 2, nomen: true, maxlen: 100, white: true  plusplus: true */
/*global $, _, d3*/
/*global document, window*/
/*global modalDialogHelper, uiComponentsHelper */
/*global EventDispatcher*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
/* Archive
function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, dispatcherConfig) {
*/
function EventDispatcherControls(list, nodeShaper, edgeShaper, dispatcherConfig) {
  "use strict";
  
  if (list === undefined) {
    throw "A list element has to be given.";
  }
  /*
  if (cursorIconBox === undefined) {
    throw "The cursor decoration box has to be given.";
  }
  */
  if (nodeShaper === undefined) {
    throw "The NodeShaper has to be given.";
  }
  if (edgeShaper === undefined) {
    throw "The EdgeShaper has to be given.";
  }
  
  var self = this,
    /* archive
    firstButton = true, 
    currentListGroup,
    placeHolderBtn = uiComponentsHelper.createIconButton(
      "none",
      ""
    ),
    icons = {
      expand: "plus",
      add: "plus-sign",
      trash: "trash",
      drag: "move",
      edge: "resize-horizontal",
      edit: "pencil"
    },
    */
    icons = {
      expand: "expand",
      add: "add",
      trash: "trash",
      drag: "drag",
      edge: "connect",
      edit: "edit",
      view: "view"
    },
    baseClass = "event",
    dispatcher = new EventDispatcher(nodeShaper, edgeShaper, dispatcherConfig),
    
    setCursorIcon = function(icon) {
      //cursorIconBox.className = "mousepointer icon-" + icon;
    },
    
    appendToList = function(button) {
      list.appendChild(button);
      /* archive
      if (firstButton) {
        currentListGroup = document.createElement("div");
        currentListGroup.className = "btn btn-group";
        currentListGroup.appendChild(button);
        currentListGroup.appendChild(placeHolderBtn);
        firstButton = false;
        list.appendChild(currentListGroup);
      } else {
        currentListGroup.removeChild(placeHolderBtn);
        currentListGroup.appendChild(button);
        firstButton = true;
      }
      */
    },
    createButton = function(title, callback) {
      uiComponentsHelper.createButton(
        baseClass,
        list,
        title,
        "control_event_" + title,
        callback
      );
    },
    createIcon = function(icon, title, callback) {
      var btn = uiComponentsHelper.createIconButton(
        icon,
        "control_event_" + title,
        callback
      );
      appendToList(btn);
    },
    rebindNodes = function(actions) {
      dispatcher.rebind("nodes", actions);
    },
    rebindEdges = function(actions) {
      dispatcher.rebind("edges", actions);
    },
    rebindSVG = function(actions) {
      dispatcher.rebind("svg", actions);
    },
    
    getCursorPosition = function (ev) {
      var e = ev || window.event,
        res = {};
      res.x = e.clientX;
      res.y = e.clientY;
      res.x += document.body.scrollLeft;
      res.y += document.body.scrollTop;
      return res;
    },
    
    getCursorPositionInSVG = function (ev) {
      var pos = getCursorPosition(ev);
      pos.x -= $('svg').offset().left;
      pos.y -= $('svg').offset().top;
      return pos;
    };
    /* Archive
    moveCursorBox = function(ev) {
      var pos = getCursorPosition(ev);
      pos.x += 7;
      pos.y += 12;
      cursorIconBox.style.position = "absolute";
      cursorIconBox.style.left  = pos.x + 'px';
      cursorIconBox.style.top = pos.y + 'px';
    };
    */
  /* Archive
  dispatcher.fixSVG("mousemove", moveCursorBox);
  dispatcher.fixSVG("mouseout", function() {
    cursorIconBox.style.display = "none";
  });
  dispatcher.fixSVG("mouseover", function() {
    cursorIconBox.style.display = "block";
  });
  */
  /*******************************************
  * Raw rebind objects
  *
  *******************************************/
  
  this.dragRebinds = function() {
    return {
      nodes: {
        drag: dispatcher.events.DRAG
      }
    };
  };
  
  this.newNodeRebinds = function() {
    var prefix = "control_event_new_node",
      idprefix = prefix + "_",
      createCallback = function(n) {
        modalDialogHelper.createModalCreateDialog(
          "Create New Node",
          idprefix,
          {},
          function(data) {
            dispatcher.events.CREATENODE(data, function(node) {
              $("#" + idprefix + "modal").modal('hide');
              nodeShaper.reshapeNodes();
            })();<commit_msg>Made the create vertex option of GraphViewer aware of the mouse location. Not yet tested, hence disabled at some point before actual node positioning<commit_after>/*jslint indent: 2, nomen: true, maxlen: 100, white: true  plusplus: true */
/*global $, _, d3*/
/*global document, window*/
/*global modalDialogHelper, uiComponentsHelper */
/*global EventDispatcher*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
/* Archive
function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, dispatcherConfig) {
*/
function EventDispatcherControls(list, nodeShaper, edgeShaper, dispatcherConfig) {
  "use strict";
  
  if (list === undefined) {
    throw "A list element has to be given.";
  }
  /*
  if (cursorIconBox === undefined) {
    throw "The cursor decoration box has to be given.";
  }
  */
  if (nodeShaper === undefined) {
    throw "The NodeShaper has to be given.";
  }
  if (edgeShaper === undefined) {
    throw "The EdgeShaper has to be given.";
  }
  
  var self = this,
    /* archive
    firstButton = true, 
    currentListGroup,
    placeHolderBtn = uiComponentsHelper.createIconButton(
      "none",
      ""
    ),
    icons = {
      expand: "plus",
      add: "plus-sign",
      trash: "trash",
      drag: "move",
      edge: "resize-horizontal",
      edit: "pencil"
    },
    */
    icons = {
      expand: "expand",
      add: "add",
      trash: "trash",
      drag: "drag",
      edge: "connect",
      edit: "edit",
      view: "view"
    },
    baseClass = "event",
    dispatcher = new EventDispatcher(nodeShaper, edgeShaper, dispatcherConfig),
    
    setCursorIcon = function(icon) {
      //cursorIconBox.className = "mousepointer icon-" + icon;
    },
    
    appendToList = function(button) {
      list.appendChild(button);
      /* archive
      if (firstButton) {
        currentListGroup = document.createElement("div");
        currentListGroup.className = "btn btn-group";
        currentListGroup.appendChild(button);
        currentListGroup.appendChild(placeHolderBtn);
        firstButton = false;
        list.appendChild(currentListGroup);
      } else {
        currentListGroup.removeChild(placeHolderBtn);
        currentListGroup.appendChild(button);
        firstButton = true;
      }
      */
    },
    createButton = function(title, callback) {
      uiComponentsHelper.createButton(
        baseClass,
        list,
        title,
        "control_event_" + title,
        callback
      );
    },
    createIcon = function(icon, title, callback) {
      var btn = uiComponentsHelper.createIconButton(
        icon,
        "control_event_" + title,
        callback
      );
      appendToList(btn);
    },
    rebindNodes = function(actions) {
      dispatcher.rebind("nodes", actions);
    },
    rebindEdges = function(actions) {
      dispatcher.rebind("edges", actions);
    },
    rebindSVG = function(actions) {
      dispatcher.rebind("svg", actions);
    },
    
    getCursorPosition = function (ev) {
      var e = ev || window.event,
        res = {};
      res.x = e.clientX;
      res.y = e.clientY;
      res.x += document.body.scrollLeft;
      res.y += document.body.scrollTop;
      return res;
    },
    
    getCursorPositionInSVG = function (ev) {
      var pos = getCursorPosition(ev),
        off = $('svg').offset();
      // Hack for Firefox
      /*
      var off = {
        left: 166,
        top: 171
      };
      */
      pos.x -= off.left;
      pos.y -= off.top;
      return pos;
    };
    /* Archive
    moveCursorBox = function(ev) {
      var pos = getCursorPosition(ev);
      pos.x += 7;
      pos.y += 12;
      cursorIconBox.style.position = "absolute";
      cursorIconBox.style.left  = pos.x + 'px';
      cursorIconBox.style.top = pos.y + 'px';
    };
    */
  /* Archive
  dispatcher.fixSVG("mousemove", moveCursorBox);
  dispatcher.fixSVG("mouseout", function() {
    cursorIconBox.style.display = "none";
  });
  dispatcher.fixSVG("mouseover", function() {
    cursorIconBox.style.display = "block";
  });
  */
  /*******************************************
  * Raw rebind objects
  *
  *******************************************/
  
  this.dragRebinds = function() {
    return {
      nodes: {
        drag: dispatcher.events.DRAG
      }
    };
  };
  
  this.newNodeRebinds = function() {
    var prefix = "control_event_new_node",
      idprefix = prefix + "_",
      createCallback = function(ev) {
        var pos = getCursorPositionInSVG(ev);
        modalDialogHelper.createModalCreateDialog(
          "Create New Node",
          idprefix,
          {},
          function(data) {
            dispatcher.events.CREATENODE(data, function(node) {
              $("#" + idprefix + "modal").modal('hide');
              nodeShaper.reshapeNodes();
            }, pos.x, pos.y)();
{'fraction_non_alphanumeric': 0.16968023514741248, 'fraction_numerical': 0.005522401353879041, 'mean_word_length': 2.200684150513113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7153377', 'n_tokens_mistral': 3262, 'n_tokens_neox': 3164, 'n_words': 793}