<commit_before>'use strict'

// A Block is an svg group that do any behavior, this can contain Fields or other Blocks

BB.Block = BB.Component.prototype.create({
  constructor: function(name, options, customOptions)  {
    this.parentClass_.constructor.call(this, 'Block');
    this.name = name;
    this.id = null;
    this.x = 0;
    this.y = 0;
    this.width = 20;
    this.height = 20;
    this.container = null; // contains attached elements(border) and SVG document
    this.childContainer = null; // svg group that contains all children
    this.statement = true;
    this.root = null;
    this.rootDark = null; //shadow effect
    this.nested = true; // Blocks are nested by default, allows toTopPropagate
    this.fields = [];
    this.attachDraggable = [];
    this.metrics = {
      borderRadius: 2,
      borderWidth: 1,
      initialSpace: {x: 4, y: 0},
      finalSpace: {x: 4, y: 4},
      fieldSpace: 5,
      rowSpace: 5, // same as borderRadius is recommended
      widthType: 'globalWidth',
    };
    if (customOptions) { //options of a custom blocks
      this.customOptions = customOptions;
    }
    if (!options) {
      return;
    }
    if (options.x) {
      this.x = options.x;
    }
    if (options.y) {
      this.y = options.y;
    }
    if (options.stylingFunction) {
      this.stylingFunction = options.stylingFunction;
    }
    if (options.colorPalette) {
      this.colorPalette = options.colorPalette;
    }
    if (options.metrics) {
      this.metrics = options.metrics;
    }
    if (options.render) {
      this.render();
    }
  },

  appendField: function(field) {
      this.fields.push(field);
      return field;
  },

  newRow: function() {
      this.fields.push('newRow');
  },

  widthType: function(type) {
    if (type == 'grouped') {
      this.fields.push('groupedWidth');
    } else if (type == 'global') {
      this.fields.push('globalWidth');
    } else if (type == 'single') {
      this.fields.push('singleWidth');
    } else {
      throw 'Unknown width type';
    }
  },

  render: function() {
    if (!this.workspace) {
      throw 'Blocks must have a workspace to be rendered';
      return;
    }
    if (!this.rendered) {
      this.init(this.customOptions); // attributes of custom Block
      //needs create container before initSVG, because it render the fields
      this.container = this.workspace.root.group();
      this.container.move(this.x, this.y);
      this.initSvg(); // compute graphics for rendering
      if (!this.colorPalette) {
        this.colorPalette = BB.colorPalettes.block.light; //default palette
      }
      // styling
      this.bgColor = this.colorPalette.background;
      this.shadowColor = this.colorPalette.shadowColor;
      this.lightColor = this.colorPalette.lightColor;
      this.borderColor = this.colorPalette.border;
      if (this.stylingFunction) {
        this.stylingFunction();
      }
      //render block - render fields and all block svg
      this.renderBlock_();
      // render children
      this.childContainer = this.workspace.root.group(); 
      for (var i = 0; i < this.children.length; i++) {
        this.children[i].render();
        this.childContainer.add(this.children[i].container);
      }
      this.container.add(this.rootDark);
      this.container.add(this.rootLight);
      this.container.add(this.root);
      this.container.add(this.childContainer);
      // add fields to top of container
      for (var i = 0; i < this.fields.length; i++) {
        if (typeof(this.fields[i]) == 'object') {
          this.fields[i].toTop();
        }
      }
      this.attachDraggable.push(this.rootDark);
      this.attachDraggable.push(this.rootLight);
      this.attachDraggable.push(this.root);
      this.container.draggable(this, null, this.attachDraggable);
      var el = this; //for the next closure
      this.container.dragstart = function() {
        el.toTopPropagate(); //focus workspace
      };
      this.workspace.childContainer.add(this.container);
      this.workspace.childRendered(this);
      if (this.attach) {
        this.attach(); // attach additional svg elements to block
      }
      this.rendered = true;
    }
  },

  attachEvents: function(child) {
    this.attachDraggable.push(child);
    this.container.draggable(this.workspace, null, this.attachDraggable);
  },

  // calculate metrics
  initSvg: function() {
    var globalWidth = this.metrics.initialSpace.x, box, maxHeight = 0;
    var metrics = {
      width: this.metrics.initialSpace.x,
      y: this.metrics.initialSpace.y
    };
    this.metrics.rows = [];
    this.metrics.numRows = 0;
    for (var i = 0; i < this.fields.length; i++) {
      if (typeof(this.fields[i]) == 'string') { //field control commands
        switch (this.fields[i]) {
            case 'newRow':
              metrics.y += maxHeight + this.metrics.rowSpace + this.metrics.initialSpace.y;
              metrics.width  += this.metrics.finalSpace.x - this.metrics.fieldSpace;
              this.metrics.rows[this.metrics.numRows] = {
                width: metrics.width,
                y: metrics.y,
                height: maxHeight,
                widthType: this.metrics.widthType
              };
              this.metrics.numRows++;
              globalWidth = Math.max(metrics.width, globalWidth);
              metrics.width = this.metrics.initialSpace.x;
              maxHeight = 0;
              break;
            case 'globalWidth':
              this.metrics.widthType = 'globalWidth';
              break;
            case 'groupedWidth':
              this.metrics.widthType = 'groupedWidth';
              break;
            case 'singleWidth':
              this.metrics.widthType = 'singleWidth';
              break;
            default:
            throw 'Unknown width type';
        }
      } else {
        // updates incrementally metrics for dinamic fields rendering
        this.metrics.rows[this.metrics.numRows] = {
          width: metrics.width,
          y: metrics.y,
          height: maxHeight,
          widthType: this.metrics.widthType
        };
        this.fields[i].row = this.metrics.numRows;
        this.fields[i].render();
        box = this.fields[i].container.bbox();
        this.fields[i].container.move(metrics.width, metrics.y); // position of field
        metrics.width += box.width + this.metrics.fieldSpace;<commit_msg>rowSpace is divided in top and bottom rowSpace<commit_after>'use strict'

// A Block is an svg group that do any behavior, this can contain Fields or other Blocks

BB.Block = BB.Component.prototype.create({
  constructor: function(name, options, customOptions)  {
    this.parentClass_.constructor.call(this, 'Block');
    this.name = name;
    this.id = null;
    this.x = 0;
    this.y = 0;
    this.width = 20;
    this.height = 20;
    this.container = null; // contains attached elements(border) and SVG document
    this.childContainer = null; // svg group that contains all children
    this.statement = true;
    this.root = null;
    this.rootDark = null; //shadow effect
    this.nested = true; // Blocks are nested by default, allows toTopPropagate
    this.fields = [];
    this.attachDraggable = [];
    this.metrics = {
      borderRadius: 2,
      borderWidth: 1,
      initialSpace: {x: 4, y: 0},
      finalSpace: {x: 4, y: 4},
      fieldSpace: 5,
      topRowSpace: 2.5,
      bottomRowSpace: 2.5,
      widthType: 'globalWidth',
    };
    if (customOptions) { //options of a custom blocks
      this.customOptions = customOptions;
    }
    if (!options) {
      return;
    }
    if (options.x) {
      this.x = options.x;
    }
    if (options.y) {
      this.y = options.y;
    }
    if (options.stylingFunction) {
      this.stylingFunction = options.stylingFunction;
    }
    if (options.colorPalette) {
      this.colorPalette = options.colorPalette;
    }
    if (options.metrics) {
      this.metrics = options.metrics;
    }
    if (options.render) {
      this.render();
    }
  },

  appendField: function(field) {
      this.fields.push(field);
      return field;
  },

  newRow: function() {
      this.fields.push('newRow');
  },

  widthType: function(type) {
    if (type == 'grouped') {
      this.fields.push('groupedWidth');
    } else if (type == 'global') {
      this.fields.push('globalWidth');
    } else if (type == 'single') {
      this.fields.push('singleWidth');
    } else {
      throw 'Unknown width type';
    }
  },

  render: function() {
    if (!this.workspace) {
      throw 'Blocks must have a workspace to be rendered';
      return;
    }
    if (!this.rendered) {
      this.init(this.customOptions); // attributes of custom Block
      //needs create container before initSVG, because it render the fields
      this.container = this.workspace.root.group();
      this.container.move(this.x, this.y);
      this.initSvg(); // compute graphics for rendering
      if (!this.colorPalette) {
        this.colorPalette = BB.colorPalettes.block.light; //default palette
      }
      // styling
      this.bgColor = this.colorPalette.background;
      this.shadowColor = this.colorPalette.shadowColor;
      this.lightColor = this.colorPalette.lightColor;
      this.borderColor = this.colorPalette.border;
      if (this.stylingFunction) {
        this.stylingFunction();
      }
      //render block - render fields and all block svg
      this.renderBlock_();
      // render children
      this.childContainer = this.workspace.root.group(); 
      for (var i = 0; i < this.children.length; i++) {
        this.children[i].render();
        this.childContainer.add(this.children[i].container);
      }
      this.container.add(this.rootDark);
      this.container.add(this.rootLight);
      this.container.add(this.root);
      this.container.add(this.childContainer);
      // add fields to top of container
      for (var i = 0; i < this.fields.length; i++) {
        if (typeof(this.fields[i]) == 'object') {
          this.fields[i].toTop();
        }
      }
      this.attachDraggable.push(this.rootDark);
      this.attachDraggable.push(this.rootLight);
      this.attachDraggable.push(this.root);
      this.container.draggable(this, null, this.attachDraggable);
      var el = this; //for the next closure
      this.container.dragstart = function() {
        el.toTopPropagate(); //focus workspace
      };
      this.workspace.childContainer.add(this.container);
      this.workspace.childRendered(this);
      if (this.attach) {
        this.attach(); // attach additional svg elements to block
      }
      this.rendered = true;
    }
  },

  attachEvents: function(child) {
    this.attachDraggable.push(child);
    this.container.draggable(this.workspace, null, this.attachDraggable);
  },

  // calculate metrics
  initSvg: function() {
    var globalWidth = this.metrics.initialSpace.x, box, maxHeight = 0;
    var metrics = {
      width: this.metrics.initialSpace.x,
      y: this.metrics.initialSpace.y
    };
    this.metrics.rows = [];
    this.metrics.numRows = 0;
    for (var i = 0; i < this.fields.length; i++) {
      if (typeof(this.fields[i]) == 'string') { //field control commands
        switch (this.fields[i]) {
            case 'newRow':
              metrics.y += maxHeight + this.metrics.bottomRowSpace + this.metrics.initialSpace.y + this.metrics.topRowSpace;
              metrics.width  += this.metrics.finalSpace.x - this.metrics.fieldSpace;
              this.metrics.rows[this.metrics.numRows] = {
                width: metrics.width,
                y: metrics.y,
                height: maxHeight + this.metrics.topRowSpace,
                widthType: this.metrics.widthType
              };
              this.metrics.numRows++;
              globalWidth = Math.max(metrics.width, globalWidth);
              metrics.width = this.metrics.initialSpace.x;
              maxHeight = 0;
              break;
            case 'globalWidth':
              this.metrics.widthType = 'globalWidth';
              break;
            case 'groupedWidth':
              this.metrics.widthType = 'groupedWidth';
              break;
            case 'singleWidth':
              this.metrics.widthType = 'singleWidth';
              break;
            default:
            throw 'Unknown width type';
        }
      } else {
        // updates incrementally metrics for dinamic fields rendering
        this.metrics.rows[this.metrics.numRows] = {
          width: metrics.width,
          y: metrics.y,
          height: maxHeight + this.metrics.topRowSpace,
          widthType: this.metrics.widthType
        };
        this.fields[i].row = this.metrics.numRows;
        this.fields[i].render();
        box = (this.fields[i].container.type == 'svg')?this.fields[i].container.viewbox():this.fields[i].container.bbox();
        this.fields[i].container.move(metrics.width, metrics.y + this.metrics.topRowSpace); // position of field
        metrics.width += box.width + this.metrics.fieldSpace;
{'fraction_non_alphanumeric': 0.12640665947279173, 'fraction_numerical': 0.003314320949591491, 'mean_word_length': 2.200542673902319, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5164645', 'n_tokens_mistral': 3884, 'n_tokens_neox': 3817, 'n_words': 834}