<commit_before>library tree_table;

import 'package:polymer/polymer.dart';
import 'dart:html';

/**
 * A Polymer TreeTable element.
 */
@CustomTag('tree-table')
class TreeTable extends PolymerElement {
  List<LogicalRow> _rootNodes = [];

  TreeTable.created() : super.created() {}

  factory TreeTable() {
    return document.createElement("tree-table") as TreeTable;
  }

  /**
   * Adds a row to the table that is at the top level of the
   * tree in the structure.
   */
  LogicalRow addTopLevel(LogicalRow child) {
    _rootNodes.add(child);
    return child;
  }
  
  HtmlElement get tbody => this.$['inner_table_body'];

  /**
   * Sets the titles for the columns of the table.
   */
  void set columnTitles(List<String> names) {
    this.$["inner_table_head"].children.addAll(names.map((name) {
      var tableCell = new TableCellElement()..text = name;
      // TODO: special cases are bad
      if (name == "Bytes" || name == "%") {
        tableCell.style.width = "70px";
      }
      if (name == "Kind") {
        tableCell.style.width = "160px";
      }
      return tableCell;
    }));
  }

  // Sorts this TreeTable by creating a comparator function 
  // for LogicalRows sorting on a key in the data section.
  void sort(String key) {
    var comparator = (LogicalRow a, LogicalRow b) {
      var d1 = a.data[key];
      var d2 = b.data[key];
      if (d1 == null) d1 = "";
      if (d2 == null) d2 = "";
      if (d1 is num && d2 is num) {
        return d1.compareTo(d2);
      }
      return d2.toString().compareTo(d1.toString());
    };

    tbody.children.clear();
    this._rootNodes.sort(comparator);

    for (var child in this._rootNodes) {
      child._sort(comparator);
    }
    
    for (var child in this._rootNodes) {
      child.show();
    }
  }
}

/// The amount of padding to be added to each level in the tree.
final int _PADDING_SIZE = 25;

typedef void RenderFunction(TreeTableRow ttr, LogicalRow logicalRow);

/**
 * A TreeTableRow element.  TreeTableRows are only to be inserted into
 * a TreeTable element.  Because TreeTableRows are nodes in the tree
 * structure, they can have children added to them via the [addChild]
 * method.
 */
@CustomTag('tree-table-row')
class TreeTableRow extends TableRowElement with Polymer, Observable {
  LogicalRow logicalRow;
  bool populated = false;  
  
  TreeTableRow.created() : super.created() {
    polymerCreated();
  }
  
  factory TreeTableRow(LogicalRow logicalRow) {
    var ttr = document.createElement("tr", "tree-table-row") as TreeTableRow;
    ttr.logicalRow = logicalRow;
    ttr.onClick.listen((_) {ttr.logicalRow.click();});
    return ttr;
  }
  
  // Set the cells in this row.
  void set data(List<TableCellElement> elements) {
    if (elements.isNotEmpty) {
      this.$['content'].text = elements.first.text;
    }
    for (TableCellElement cell in elements.skip(1)) {
      this.shadowRoot.append(cell);
    }
  }
  
  void set _level(int level) {
     this.$['first-cell'].style.paddingLeft =
      (level * _PADDING_SIZE).toString() + "px";<commit_msg>fix mixing in non-existing mixin<commit_after>library tree_table;

import 'package:polymer/polymer.dart';
import 'dart:html';

/**
 * A Polymer TreeTable element.
 */
@CustomTag('tree-table')
class TreeTable extends PolymerElement {
  List<LogicalRow> _rootNodes = [];

  TreeTable.created() : super.created() {}

  factory TreeTable() {
    return document.createElement("tree-table") as TreeTable;
  }

  /**
   * Adds a row to the table that is at the top level of the
   * tree in the structure.
   */
  LogicalRow addTopLevel(LogicalRow child) {
    _rootNodes.add(child);
    return child;
  }
  
  HtmlElement get tbody => this.$['inner_table_body'];

  /**
   * Sets the titles for the columns of the table.
   */
  void set columnTitles(List<String> names) {
    this.$["inner_table_head"].children.addAll(names.map((name) {
      var tableCell = new TableCellElement()..text = name;
      // TODO: special cases are bad
      if (name == "Bytes" || name == "%") {
        tableCell.style.width = "70px";
      }
      if (name == "Kind") {
        tableCell.style.width = "160px";
      }
      return tableCell;
    }));
  }

  // Sorts this TreeTable by creating a comparator function 
  // for LogicalRows sorting on a key in the data section.
  void sort(String key) {
    var comparator = (LogicalRow a, LogicalRow b) {
      var d1 = a.data[key];
      var d2 = b.data[key];
      if (d1 == null) d1 = "";
      if (d2 == null) d2 = "";
      if (d1 is num && d2 is num) {
        return d1.compareTo(d2);
      }
      return d2.toString().compareTo(d1.toString());
    };

    tbody.children.clear();
    this._rootNodes.sort(comparator);

    for (var child in this._rootNodes) {
      child._sort(comparator);
    }
    
    for (var child in this._rootNodes) {
      child.show();
    }
  }
}

/// The amount of padding to be added to each level in the tree.
final int _PADDING_SIZE = 25;

typedef void RenderFunction(TreeTableRow ttr, LogicalRow logicalRow);

/**
 * A TreeTableRow element.  TreeTableRows are only to be inserted into
 * a TreeTable element.  Because TreeTableRows are nodes in the tree
 * structure, they can have children added to them via the [addChild]
 * method.
 */
@CustomTag('tree-table-row')
class TreeTableRow extends TableRowElement with Polymer {
  LogicalRow logicalRow;
  bool populated = false;  
  
  TreeTableRow.created() : super.created() {
    polymerCreated();
  }
  
  factory TreeTableRow(LogicalRow logicalRow) {
    var ttr = document.createElement("tr", "tree-table-row") as TreeTableRow;
    ttr.logicalRow = logicalRow;
    ttr.onClick.listen((_) {ttr.logicalRow.click();});
    return ttr;
  }
  
  // Set the cells in this row.
  void set data(List<TableCellElement> elements) {
    if (elements.isNotEmpty) {
      this.$['content'].text = elements.first.text;
    }
    for (TableCellElement cell in elements.skip(1)) {
      this.shadowRoot.append(cell);
    }
  }
  
  void set _level(int level) {
     this.$['first-cell'].style.paddingLeft =
      (level * _PADDING_SIZE).toString() + "px";
{'fraction_non_alphanumeric': 0.12771517230115956, 'fraction_numerical': 0.006532745386248571, 'mean_word_length': 2.8882539682539683, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4869497', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1953, 'n_words': 542}