<commit_before>import d3 from "d3";
import * as types from "../actions/types";
import { processNodes, calcLayouts } from "../util/processNodes";

/* A version increase (i.e. props.version !== nextProps.version) necessarily implies
that the tree is loaded as they are set on the same action */

const getDefaultState = function () {
  return {
    loaded: false,
    nodes: null,
    visibility: null,
    visibilityVersion: 0,
    nodeColors: null,
    nodeColorsVersion: 0,
    tipRadii: null,
    tipRadiiVersion: 0,
    branchThickness: null,
    branchThicknessVersion: 0,
    version: 0
  };
};

const Tree = (state = getDefaultState(), action) => {
  switch (action.type) {
  case types.NEW_DATASET:
    /* loaded returns to the default (false) */
    const nodes = processNodes(d3.layout.tree().size([1, 1]).nodes(action.tree));
    nodes[0].parent = nodes[0]; // make root its own parent
    calcLayouts(nodes, ["div", "num_date"]);
    return Object.assign({}, getDefaultState(), {
      inViewRootNodeIdx: 0,
      nodes: nodes
    });
  case types.DATA_VALID:
    return Object.assign({}, state, {<commit_msg>Start on refactor layout.tree in tree reducer<commit_after>import d3 from "d3";
import traverse from "traverse";
import * as types from "../actions/types";
import { processNodes, calcLayouts } from "../util/processNodes";

/* A version increase (i.e. props.version !== nextProps.version) necessarily implies
that the tree is loaded as they are set on the same action */

const getDefaultState = function () {
  return {
    loaded: false,
    nodes: null,
    visibility: null,
    visibilityVersion: 0,
    nodeColors: null,
    nodeColorsVersion: 0,
    tipRadii: null,
    tipRadiiVersion: 0,
    branchThickness: null,
    branchThicknessVersion: 0,
    version: 0
  };
};

const Tree = (state = getDefaultState(), action) => {
  switch (action.type) {
  case types.NEW_DATASET: {
    /* loaded returns to the default (false) */
    const nodesArray = [];
    const cladeIndexArray = [];
    traverse(action.tree).forEach((node) => {
      if (node.clade || node.clade === 0) {
        if (!cladeIndexArray.includes(node.clade)) {
          nodesArray.push(node);
          cladeIndexArray.push(node.clade);
        }
      }
    });
    const oldNodesArray = d3.layout.tree().size([1, 1]).nodes(action.tree); // TODO this is setting .parent, need to replace this with another function
    const nodes = processNodes(nodesArray);
    nodes[0].parent = nodes[0]; // make root its own parent 
    calcLayouts(nodes, ["div", "num_date"]);
    return Object.assign({}, getDefaultState(), {
      inViewRootNodeIdx: 0,
      nodes: nodes
    });
  }
  case types.DATA_VALID:
    return Object.assign({}, state, {
{'fraction_non_alphanumeric': 0.1332845111680703, 'fraction_numerical': 0.009886488465763456, 'mean_word_length': 3.2422360248447206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2317835', 'n_tokens_mistral': 844, 'n_tokens_neox': 827, 'n_words': 242}