<commit_before>/*
 * api.js
 * @flow strict
 */

// only relative imports are followed by documentationjs
import _ from "lodash";
import app from "app";
import { InputKeyboardNoLoop } from "libs/input";
import OxalisModel from "oxalis/model";
import Store from "oxalis/store";
import Binary from "oxalis/model/binary";
import { updateUserSettingAction, updateDatasetSettingAction } from "oxalis/model/actions/settings_actions";
import { setActiveNodeAction, createCommentAction } from "oxalis/model/actions/skeletontracing_actions";
import { findTreeByNodeId } from "oxalis/model/accessors/skeletontracing_accessor";
import type { Vector3 } from "oxalis/constants";
import type { MappingArray } from "oxalis/model/binary/mappings";
import type { NodeType, UserConfigurationType, DatasetConfigurationType } from "oxalis/store";
import { overwriteAction } from "oxalis/model/helpers/overwrite_action_middleware.js";

/**
 * All tracing related API methods.
 * @class
 */
class TracingApi {

  model: OxalisModel;
 /**
  * @private
  */
  constructor(model: OxalisModel) {
    this.model = model;
  }

 /**
  * Returns the id of the current active node.
  */
  getActiveNodeId(): ?number {
    return Store.getState().skeletonTracing.activeNodeId;
  }

 /**
  * Returns the id of the current active tree.
  */
  getActiveTreeId(): ?number {
    return Store.getState().skeletonTracing.activeTreeId;
  }

 /**
  * Sets the active node given a node id.
  */
  setActiveNode(id: number) {
    if (id == null) {
      throw new Error("Node id is missing.");
    }
    Store.dispatch(setActiveNodeAction(id));
  }

 /**
  * Returns all nodes belonging to a tracing.
  */
  getAllNodes(): Array<NodeType> {
    const { trees } = Store.getState().skeletonTracing;
    return _.flatMap(trees, tree => _.values(tree.nodes));
  }

 /**
  * Sets the comment for a node.
  *
  * @example
  * const activeNodeId = api.tracing.getActiveNodeId();<commit_msg>add deleteNode function to api<commit_after>/*
 * api.js
 * @flow strict
 */

// only relative imports are followed by documentationjs
import _ from "lodash";
import app from "app";
import { InputKeyboardNoLoop } from "libs/input";
import OxalisModel from "oxalis/model";
import Store from "oxalis/store";
import Binary from "oxalis/model/binary";
import { updateUserSettingAction, updateDatasetSettingAction } from "oxalis/model/actions/settings_actions";
import { setActiveNodeAction, createCommentAction, deleteNodeAction } from "oxalis/model/actions/skeletontracing_actions";
import { findTreeByNodeId } from "oxalis/model/accessors/skeletontracing_accessor";
import type { Vector3 } from "oxalis/constants";
import type { MappingArray } from "oxalis/model/binary/mappings";
import type { NodeType, UserConfigurationType, DatasetConfigurationType } from "oxalis/store";
import { overwriteAction } from "oxalis/model/helpers/overwrite_action_middleware.js";

/**
 * All tracing related API methods.
 * @class
 */
class TracingApi {

  model: OxalisModel;
 /**
  * @private
  */
  constructor(model: OxalisModel) {
    this.model = model;
  }

 /**
  * Returns the id of the current active node.
  */
  getActiveNodeId(): ?number {
    return Store.getState().skeletonTracing.activeNodeId;
  }

 /**
  * Returns the id of the current active tree.
  */
  getActiveTreeId(): ?number {
    return Store.getState().skeletonTracing.activeTreeId;
  }

 /**
  * Sets the active node given a node id.
  */
  setActiveNode(id: number) {
    if (id == null) {
      throw new Error("Node id is missing.");
    }
    Store.dispatch(setActiveNodeAction(id));
  }

 /**
  * Returns all nodes belonging to a tracing.
  */
  getAllNodes(): Array<NodeType> {
    const { trees } = Store.getState().skeletonTracing;
    return _.flatMap(trees, tree => _.values(tree.nodes));
  }

  /**
   * Deletes the node with nodeId in the tree with treeId
   */
  deleteNode(nodeId: number, treeId: number) {
    Store.dispatch(deleteNodeAction(nodeId, treeId));
  }

 /**
  * Sets the comment for a node.
  *
  * @example
  * const activeNodeId = api.tracing.getActiveNodeId();
{'fraction_non_alphanumeric': 0.12148618919579565, 'fraction_numerical': 0.0004888780249327792, 'mean_word_length': 3.96, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4315204', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1250, 'n_words': 328}