<commit_before>part of treemap_view;

abstract class Node implements Attachable {

  static const String NO_LEFT_BORDER = 'noLeftBorder';
  static const String NO_TOP_BORDER = 'noTopBorder';
  static const String COLLAPSED_WIDTH = 'collapsedWidth';
  static const String COLLAPSED_HEIGHT = 'collapsedHeight';

  final Element container = new DivElement();
  final Orientation orientation;
  final Percentage width, height;
  final DataModel _dataModel;
  final ViewModel viewModel;
  final Completer<BranchNode> _parentCompleter = new Completer();
  BranchNode _parent;
  DivElement _content;
  NodeLabel _nodeLabel;
  Tooltip _tooltip;

  Node._internal(this._dataModel, this.viewModel, this.width, this.height, this.orientation) {
    container.classes.add("${viewModel.style._classNames[runtimeType.toString()]}");
    container.classes.add("${viewModel.style._classNames[orientation.toString()]}");
    container.style..width = width.toString()
                   ..height = height.toString();
    _nodeLabel = new NodeLabel(this);
    _tooltip = new Tooltip(this);
    _dataModel.onPropertyChange.listen((_) { 
      if (viewModel.treemap.automaticUpdates) { 
        repaintContent(); 
      } 
    });
    parent.then((_) {
      _rectifyAppearance();
    });
  }
  
  factory Node(DataModel dataModel, ViewModel viewModel, Percentage width, Percentage height, Orientation orientation)
    => dataModel.isLeaf ?
        new LeafNode(dataModel,viewModel,width,height,orientation) :
        new BranchNode(dataModel,viewModel,width,height,orientation);

  factory Node.forRoot(DataModel dataModel, ViewModel viewModel) {
    assert(dataModel.isRoot);
    final rootNode = new Node(dataModel, viewModel, Percentage.ONE_HUNDRED, Percentage.ONE_HUNDRED, Orientation.VERTICAL);
    rootNode.viewModel.treemapHtmlRoot.append(rootNode.container);
    rootNode.viewModel.currentViewRoot = rootNode;
    rootNode._nodeLabel.container.style.display = "none";
    return rootNode;
  }
  
  DataModel get dataModel;

  void repaintContent();

  bool get isLeaf => dataModel.isLeaf;

  bool get isBranch => dataModel.isBranch;

  bool get isModelRoot => dataModel.isRoot;

  int get clientWidth => _content.clientWidth;

  int get clientHeight => _content.clientHeight;
  
  Future<BranchNode> get parent => _parent == null ? 
      _parentCompleter.future : 
      _parentCompleter.complete(_parent); 
  
  void setParent(BranchNode parent) {
    _parent = parent;
    _parentCompleter.complete(_parent);
  }

  bool _isPositionedBelow(Node other) => this._parent == other._parent ?
    this.container.offsetTop > other.container.offsetTop :
    throw new RuntimeError("Can't tell. Are you comparing nodes from different branches?");

  bool _isPositionedRightOf(Node other) => this._parent == other._parent ?
    this.container.offsetLeft > other.container.offsetLeft :
    throw new RuntimeError("Can't tell. Are you comparing nodes from different branches?");

  void _rectifyAppearance() {
    container.classes.remove("${viewModel.style._classNames[NO_TOP_BORDER]}");
    container.classes.remove("${viewModel.style._classNames[NO_LEFT_BORDER]}");
    container.classes.remove("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
    container.classes.remove("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
    
    if (_parent.children.any((other) => this._isPositionedBelow(other))) {
      container.classes.add("${viewModel.style._classNames[NO_TOP_BORDER]}");
      if (container.offsetHeight <= viewModel.style.borderWidth) {
        container.classes.add("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
      }
    } else if (container.offsetHeight <= 2 * viewModel.style.borderWidth) {
      container.classes.add("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
    }    
    
    if (_parent.children.any((other) => this._isPositionedRightOf(other))) {
      container.classes.add("${viewModel.style._classNames[NO_LEFT_BORDER]}");
      if (container.offsetWidth <= viewModel.style.borderWidth) {
        container.classes.add("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
      } 
    } else if (container.offsetWidth <= 2 * viewModel.style.borderWidth) {
      container.classes.add("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
    }
    
    if (isBranch) {
      if (_nodeLabel.container.offsetHeight > viewModel.style.branchPadding ) {
        _content.style.top = "${_nodeLabel.container.offsetHeight}px";
      } else {
        _nodeLabel.container.style.height = "${viewModel.style.branchPadding}px";
      }
      final thisNode = this as BranchNode;
      thisNode.children.forEach((child) => child._rectifyAppearance());
    }
  }

}
<commit_msg>refactoring: asynchronous execution of rectifyAppearance method in Node class<commit_after>part of treemap_view;

abstract class Node implements Attachable {

  static const String NO_LEFT_BORDER = 'noLeftBorder';
  static const String NO_TOP_BORDER = 'noTopBorder';
  static const String COLLAPSED_WIDTH = 'collapsedWidth';
  static const String COLLAPSED_HEIGHT = 'collapsedHeight';

  final Element container = new DivElement();
  final Orientation orientation;
  final Percentage width, height;
  final DataModel _dataModel;
  final ViewModel viewModel;
  final Completer<BranchNode> _parentCompleter = new Completer();
  BranchNode _parent;
  DivElement _content;
  NodeLabel _nodeLabel;
  Tooltip _tooltip;

  Node._internal(this._dataModel, this.viewModel, this.width, this.height, this.orientation) {
    container.classes.add("${viewModel.style._classNames[runtimeType.toString()]}");
    container.classes.add("${viewModel.style._classNames[orientation.toString()]}");
    container.style..width = width.toString()
                   ..height = height.toString();
    _nodeLabel = new NodeLabel(this);
    _tooltip = new Tooltip(this);
    _rectifyAppearance();
    _dataModel.onPropertyChange.listen((_) { 
      if (viewModel.treemap.automaticUpdates) { 
        repaintContent(); 
      } 
    });
  }
  
  factory Node(DataModel dataModel, ViewModel viewModel, Percentage width, Percentage height, Orientation orientation)
    => dataModel.isLeaf ?
        new LeafNode(dataModel,viewModel,width,height,orientation) :
        new BranchNode(dataModel,viewModel,width,height,orientation);

  factory Node.forRoot(DataModel dataModel, ViewModel viewModel) {
    assert(dataModel.isRoot);
    final rootNode = new Node(dataModel, viewModel, Percentage.ONE_HUNDRED, Percentage.ONE_HUNDRED, Orientation.VERTICAL);
    rootNode.viewModel.treemapHtmlRoot.append(rootNode.container);
    rootNode.viewModel.currentViewRoot = rootNode;
    rootNode._nodeLabel.container.style.display = "none";
    return rootNode;
  }
  
  Future<BranchNode> get parent => _parent == null ? 
      _parentCompleter.future : 
      _parentCompleter.complete(_parent); 
  
  void setParent(BranchNode parent) {
    _parent = parent;
    _parentCompleter.complete(_parent);
  }

  void _rectifyAppearance() {
    parent.then((BranchNode parent) {
      container.classes.remove("${viewModel.style._classNames[NO_TOP_BORDER]}");
      container.classes.remove("${viewModel.style._classNames[NO_LEFT_BORDER]}");
      container.classes.remove("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
      container.classes.remove("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
      
      if (parent.children.any((other) => this._isPositionedBelow(other))) {
        container.classes.add("${viewModel.style._classNames[NO_TOP_BORDER]}");
        if (container.offsetHeight <= viewModel.style.borderWidth) {
          container.classes.add("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
        }
      } else if (container.offsetHeight <= 2 * viewModel.style.borderWidth) {
        container.classes.add("${viewModel.style._classNames[COLLAPSED_HEIGHT]}");
      }    
      
      if (parent.children.any((other) => this._isPositionedRightOf(other))) {
        container.classes.add("${viewModel.style._classNames[NO_LEFT_BORDER]}");
        if (container.offsetWidth <= viewModel.style.borderWidth) {
          container.classes.add("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
        } 
      } else if (container.offsetWidth <= 2 * viewModel.style.borderWidth) {
        container.classes.add("${viewModel.style._classNames[COLLAPSED_WIDTH]}");
      }
      
      if (isBranch) {
        if (_nodeLabel.container.offsetHeight > viewModel.style.branchPadding ) {
          _content.style.top = "${_nodeLabel.container.offsetHeight}px";
        } else {
          _nodeLabel.container.style.height = "${viewModel.style.branchPadding}px";
        }
        final thisNode = this as BranchNode;
        thisNode.children.forEach((child) => child._rectifyAppearance());
      }
    });
  }
  
  bool _isPositionedBelow(Node other) =>
    this.container.offsetTop > other.container.offsetTop;

  bool _isPositionedRightOf(Node other) =>
    this.container.offsetLeft > other.container.offsetLeft;
    
  bool get isLeaf => dataModel.isLeaf;

  bool get isBranch => dataModel.isBranch;

  bool get isModelRoot => dataModel.isRoot;

  int get clientWidth => _content.clientWidth;

  int get clientHeight => _content.clientHeight;
  
  DataModel get dataModel;

  void repaintContent();

}
{'fraction_non_alphanumeric': 0.11841396401249865, 'fraction_numerical': 0.0004309880400818877, 'mean_word_length': 4.03089430894309, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 37, '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': '1513042', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2737, 'n_words': 471}