<commit_before>define(function (require) {
  'use strict';

  var modules = require('modules');
  var angular = require('angular');
  var _ = require('lodash');

  require('scripts/tosca/services/tosca_service');
  require('scripts/topology/services/common_node_renderer_service');
  require('scripts/common/services/list_to_map_service');

  modules.get('a4c-topology-editor', ['a4c-common', 'a4c-styles', 'a4c-common-graph']).factory('defaultNodeRendererService', ['commonNodeRendererService', 'toscaService', 'listToMapService', 'runtimeColorsService', 'd3Service',
    function(commonNodeRendererService, toscaService, listToMapService, runtimeColorsService, d3Service) {
      var ConnectorRenderer = function(cssClass) {
        this.cssClass = cssClass;
      };

      ConnectorRenderer.prototype = {
        constructor: ConnectorRenderer,
        enter: function(enterSelection) {
          return enterSelection.append('g').attr('class', this.cssClass);
        },
        create: function(group, element) {
          d3Service.circle(group, element.coordinate.relative.x, element.coordinate.relative.y, 5).attr('class', 'connector');
          // actually create bigger circle for user interactions to make it easier.
          var actionCircle = d3Service.circle(group, element.coordinate.relative.x, element.coordinate.relative.y, 10).attr('class', 'connectorAction');
          actionCircle.on('mouseover', this.actions.mouseover).on('mouseout', this.actions.mouseout);
          actionCircle.call(this.actions.connectorDrag);
        },
        update: function(group, element) {
          // we have to update the drag behavior to work with the new selection element (if not it will keep the creation element).
          var actionCircle = group.select('.connectorAction');
          actionCircle.call(this.actions.connectorDrag);
        }
      };

      var requirementRenderer = new ConnectorRenderer('requirement');
      var capabilityRenderer = new ConnectorRenderer('capability');

      return {
        isRuntime: false,
        networkStyles: 10,

        setRuntime: function(isRuntime) {
          this.isRuntime = isRuntime;
          if (isRuntime) {
            this.height = 85;
          } else {
            this.height = 50;
          }
        },

        size: function(node) {
          var connectorCount = Math.max(node.capabilities.length, node.requirements.length);
          var connectorHeight = connectorCount * 10 + (connectorCount+1) * 5;
          var height = Math.max(50, connectorHeight);
          // inject the relative coordinates of the connectors
          this.placeConnectors(node.capabilities);
          this.placeConnectors(node.requirements);
          return {
            width: 200,
            height: height
          }
        },

        placeConnectors: function(connectors) {
          var relativeY = 10;
          _.each(connectors, function(connector) {
            connector.coordinate = {
              relative: {
                x: 0,
                y: relativeY
              }
            }
            relativeY += 15;
          });
        },

        createNode: function(layout, nodeGroup, node, nodeTemplate, nodeType, topology, actions) {
          var backRect = d3Service.rect(nodeGroup, 0, 0, node.bbox.width(), node.bbox.height(), 0, 0).attr('class', 'background');

          if (nodeType.tags) {
            var tags = listToMapService.listToMap(nodeType.tags, 'name', 'value');
            if (tags.icon) {
              nodeGroup.append('image').attr('x', 8).attr('y', 8).attr('width', '32').attr('height', '32').attr('xlink:href',
                'img?id=' + tags.icon + '&quality=QUALITY_32');
            }
          }

          if (nodeType.abstract) {
            var icoSize = 16;
            var x = 180;
            var y = 3;
            nodeGroup.append('image').attr('x', x).attr('y', y).attr('width', icoSize).attr('height', icoSize).attr('xlink:href', 'images/abstract_ico.png');
          }

          nodeGroup.append('text').attr('text-anchor', 'start').attr('class', 'title').attr('x', 44).attr('y', 20);
          nodeGroup.append('text').attr('text-anchor', 'end').attr('class', 'version').attr('x', node.bbox.width()-10).attr('y', 40);

          // if the node has some children we should add the collapse bar.
          if(_.defined(node.children) && node.children.length>0) {
            d3Service.rect(nodeGroup, .5, 45, node.bbox.width()-1, 10, 0, 0).attr('class', 'collapsebar');
          }

          // specific to the runtime view
          if (this.isRuntime) {
            nodeGroup.append('g').attr('id', 'runtime');
          }

          // specific to networks
          if (toscaService.isOneOfType(['tosca.nodes.Network'], nodeTemplate.type, topology.nodeTypes)) {
            var netX = node.bbox.width();<commit_msg> - Revert WIP on collapse / will be done later.<commit_after>define(function (require) {
  'use strict';

  var modules = require('modules');
  var angular = require('angular');
  var _ = require('lodash');

  require('scripts/tosca/services/tosca_service');
  require('scripts/topology/services/common_node_renderer_service');
  require('scripts/common/services/list_to_map_service');

  modules.get('a4c-topology-editor', ['a4c-common', 'a4c-styles', 'a4c-common-graph']).factory('defaultNodeRendererService', ['commonNodeRendererService', 'toscaService', 'listToMapService', 'runtimeColorsService', 'd3Service',
    function(commonNodeRendererService, toscaService, listToMapService, runtimeColorsService, d3Service) {
      var ConnectorRenderer = function(cssClass) {
        this.cssClass = cssClass;
      };

      ConnectorRenderer.prototype = {
        constructor: ConnectorRenderer,
        enter: function(enterSelection) {
          return enterSelection.append('g').attr('class', this.cssClass);
        },
        create: function(group, element) {
          d3Service.circle(group, element.coordinate.relative.x, element.coordinate.relative.y, 5).attr('class', 'connector');
          // actually create bigger circle for user interactions to make it easier.
          var actionCircle = d3Service.circle(group, element.coordinate.relative.x, element.coordinate.relative.y, 10).attr('class', 'connectorAction');
          actionCircle.on('mouseover', this.actions.mouseover).on('mouseout', this.actions.mouseout);
          actionCircle.call(this.actions.connectorDrag);
        },
        update: function(group, element) {
          // we have to update the drag behavior to work with the new selection element (if not it will keep the creation element).
          var actionCircle = group.select('.connectorAction');
          actionCircle.call(this.actions.connectorDrag);
        }
      };

      var requirementRenderer = new ConnectorRenderer('requirement');
      var capabilityRenderer = new ConnectorRenderer('capability');

      return {
        isRuntime: false,
        networkStyles: 10,

        setRuntime: function(isRuntime) {
          this.isRuntime = isRuntime;
          if (isRuntime) {
            this.height = 85;
          } else {
            this.height = 50;
          }
        },

        size: function(node) {
          var connectorCount = Math.max(node.capabilities.length, node.requirements.length);
          var connectorHeight = connectorCount * 10 + (connectorCount+1) * 5;
          var height = Math.max(50, connectorHeight);
          // inject the relative coordinates of the connectors
          this.placeConnectors(node.capabilities);
          this.placeConnectors(node.requirements);
          return {
            width: 200,
            height: height
          }
        },

        placeConnectors: function(connectors) {
          var relativeY = 10;
          _.each(connectors, function(connector) {
            connector.coordinate = {
              relative: {
                x: 0,
                y: relativeY
              }
            }
            relativeY += 15;
          });
        },

        createNode: function(layout, nodeGroup, node, nodeTemplate, nodeType, topology, actions) {
          var backRect = d3Service.rect(nodeGroup, 0, 0, node.bbox.width(), node.bbox.height(), 0, 0).attr('class', 'background');

          if (nodeType.tags) {
            var tags = listToMapService.listToMap(nodeType.tags, 'name', 'value');
            if (tags.icon) {
              nodeGroup.append('image').attr('x', 8).attr('y', 8).attr('width', '32').attr('height', '32').attr('xlink:href',
                'img?id=' + tags.icon + '&quality=QUALITY_32');
            }
          }

          if (nodeType.abstract) {
            var icoSize = 16;
            var x = 180;
            var y = 3;
            nodeGroup.append('image').attr('x', x).attr('y', y).attr('width', icoSize).attr('height', icoSize).attr('xlink:href', 'images/abstract_ico.png');
          }

          nodeGroup.append('text').attr('text-anchor', 'start').attr('class', 'title').attr('x', 44).attr('y', 20);
          nodeGroup.append('text').attr('text-anchor', 'end').attr('class', 'version').attr('x', node.bbox.width()-10).attr('y', 40);

          // if the node has some children we should add the collapse bar.
          // if(_.defined(node.children) && node.children.length>0) {
          //   d3Service.rect(nodeGroup, .5, 45, node.bbox.width()-1, 10, 0, 0).attr('class', 'collapsebar');
          // }

          // specific to the runtime view
          if (this.isRuntime) {
            nodeGroup.append('g').attr('id', 'runtime');
          }

          // specific to networks
          if (toscaService.isOneOfType(['tosca.nodes.Network'], nodeTemplate.type, topology.nodeTypes)) {
            var netX = node.bbox.width();
{'fraction_non_alphanumeric': 0.13957542816121424, 'fraction_numerical': 0.013947287457696647, 'mean_word_length': 2.4692280327285663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6965508', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2680, 'n_words': 553}