Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • v5
2 results

Gemfile

Blame
  • This project manages its dependencies using Bundler. Learn more
    map-model.js 40.34 KiB
    /*jslint forin: true, nomen: true*/
    /*global _, MAPJS, observable*/
    MAPJS.MapModel = function (layoutCalculatorArg, selectAllTitles, clipboardProvider, defaultReorderMargin) {
      'use strict';
      var self = this,
          layoutCalculator = layoutCalculatorArg,
          reorderMargin = defaultReorderMargin || 20,
          clipboard = clipboardProvider || new MAPJS.MemoryClipboard(),
          analytic,
          currentLayout = {
            nodes: {},
            connectors: {}
          },
          idea,
          currentLabelGenerator,
          isInputEnabled = true,
          isEditingEnabled = true,
          currentlySelectedIdeaId,
          activatedNodes = [],
          setActiveNodes = function (activated) {
            var wasActivated = _.clone(activatedNodes);
            if (activated.length === 0) {
              activatedNodes = [currentlySelectedIdeaId];
            } else {
              activatedNodes = activated;
            }
            self.dispatchEvent('activatedNodesChanged', _.difference(activatedNodes, wasActivated), _.difference(wasActivated, activatedNodes));
          },
          horizontalSelectionThreshold = 300,
          isAddLinkMode,
          applyLabels = function (newLayout) {
            var labelMap;
            if (!currentLabelGenerator) {
              return;
            }
            labelMap = currentLabelGenerator(idea);
            _.each(newLayout.nodes, function (node, id) {
              if (labelMap[id] || labelMap[id] === 0) {
                node.label = labelMap[id];
              }
            });
          },
          updateCurrentLayout = function (newLayout, sessionId) {
            self.getYsy().log.debug("updateCurrentLayout", "redraw");
            self.dispatchEvent('layoutChangeStarting', _.size(newLayout.nodes) - _.size(currentLayout.nodes));
            applyLabels(newLayout);
    
            _.each(currentLayout.connectors, function (oldConnector, connectorId) {
              var newConnector = newLayout.connectors[connectorId];
              if (!newConnector || newConnector.from !== oldConnector.from || newConnector.to !== oldConnector.to) {
                self.dispatchEvent('connectorRemoved', oldConnector);
              }
            });
            _.each(currentLayout.links, function (oldLink, linkId) {
              var newLink = newLayout.links && newLayout.links[linkId];
              if (!newLink) {
                self.dispatchEvent('linkRemoved', oldLink);
              }
            });
            _.each(currentLayout.nodes, function (oldNode, nodeId) {
              var newNode = newLayout.nodes[nodeId],
                  newActive;
              if (!newNode) {
                /*jslint eqeq: true*/
                if (nodeId == currentlySelectedIdeaId) {
                  self.selectNode(idea.id);
                }
                newActive = _.reject(activatedNodes, function (e) {
                  return e == nodeId;
                });