File

src/app/store/tree.state.ts

Index

Methods

Methods

discrepencyId
discrepencyId(undefined: StateContext<TreeStateModel>, undefined: DiscrepencyLabel)
Decorators :
@Action(DiscrepencyId)

Updates the discrepency ids list

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
DiscrepencyLabel No
Returns : void
discrepencyLabel
discrepencyLabel(undefined: StateContext<TreeStateModel>, undefined: DiscrepencyLabel)
Decorators :
@Action(DiscrepencyLabel)

Updates the discrepency labels list

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
DiscrepencyLabel No
Returns : void
doSearch
doSearch(undefined: StateContext<TreeStateModel>, undefined: DoSearch)
Decorators :
@Action(DoSearch)

Updates the search list

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
DoSearch No
Returns : void
duplicateId
duplicateId(undefined: StateContext<TreeStateModel>, undefined: DiscrepencyLabel)
Decorators :
@Action(DuplicateId)

Updates the duplicate ids list

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
DiscrepencyLabel No
Returns : void
Static getBimodal
getBimodal(state: TreeStateModel)
Decorators :
@Selector()

Select the bimodal data. Contains the nodes, links and the bimodal config

Parameters :
Name Type Optional
state TreeStateModel No
Returns : { nodes: {}; links: {}; config: BimodalConfig; }
Static getBimodalConfig
getBimodalConfig(state: TreeStateModel)
Decorators :
@Selector()

Select the bimodal config (for sorting and sizing)

Parameters :
Name Type Optional
state TreeStateModel No
Returns : BimodalConfig
Static getBiomarkerType
getBiomarkerType(state: TreeStateModel)
Decorators :
@Selector()

Select the bimodal config (for sorting and sizing)

Parameters :
Name Type Optional
state TreeStateModel No
Returns : any
Static getBottomSheetData
getBottomSheetData(state: TreeStateModel)
Decorators :
@Selector()

Select the bottom sheet data

Parameters :
Name Type Optional
state TreeStateModel No
Returns : Record<string, never>
Static getLatestSearchStructure
getLatestSearchStructure(state: TreeStateModel)
Decorators :
@Selector()

Select the most recently chosen search option

Parameters :
Name Type Optional
state TreeStateModel No
Returns : SearchStructure
Static getLinksData
getLinksData(state: TreeStateModel)
Decorators :
@Selector()

Select the links data to show in the report

Parameters :
Name Type Optional
state TreeStateModel No
Returns : { AS_CT: number; CT_B: number; AS_AS: number; AS_CT_organWise: Record<string, number>; CT_B_organWise: Record<string, number>; AS_AS_organWise: Record<string, number>; }
Static getOmapConfig
getOmapConfig(state: TreeStateModel)
Decorators :
@Selector()

Select the config for OMAPS

Parameters :
Name Type Optional
state TreeStateModel No
Returns : OmapConfig
Static getTreeData
getTreeData(state: TreeStateModel)
Decorators :
@Selector()

Select the tree data (only anatomical structures)

Parameters :
Name Type Optional
state TreeStateModel No
Returns : {}
Static getVegaSpec
getVegaSpec(state: TreeStateModel)
Decorators :
@Selector()

Select the vega specification

Parameters :
Name Type Optional
state TreeStateModel No
Returns : Spec
Static getVegaView
getVegaView(state: TreeStateModel)
Decorators :
@Selector()

Select the Vega View to use the Vega View API

Parameters :
Name Type Optional
state TreeStateModel No
Returns : View
updateBimodal
updateBimodal(undefined: StateContext<TreeStateModel>, undefined: UpdateBimodal)
Decorators :
@Action(UpdateBimodal)

Updates the bimodal data

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateBimodal No
Returns : void
updateBimodalConfig
updateBimodalConfig(undefined: StateContext<TreeStateModel>, undefined: UpdateBimodalConfig)
Decorators :
@Action(UpdateBimodalConfig)

Updates the bimodal config

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateBimodalConfig No
Returns : void
updateBottomSheetData
updateBottomSheetData(undefined: StateContext<TreeStateModel>, undefined: UpdateBottomSheetData)
Decorators :
@Action(UpdateBottomSheetData)

Updates the bottom sheet data

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateBottomSheetData No
Returns : void
updateLinksData
updateLinksData(undefined: StateContext<TreeStateModel>, undefined: UpdateLinksData)
Decorators :
@Action(UpdateLinksData)

Updates the links data that is displayed in the report

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateLinksData No
Returns : void
updateOmapConfig
updateOmapConfig(undefined: StateContext<TreeStateModel>, undefined: UpdateOmapConfig)
Decorators :
@Action(UpdateOmapConfig)
Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateOmapConfig No
Returns : void
updateVegaSpec
updateVegaSpec(undefined: StateContext<TreeStateModel>, undefined: UpdateVegaSpec)
Decorators :
@Action(UpdateVegaSpec)

Updates te vega spec

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateVegaSpec No
Returns : void
updateVegaView
updateVegaView(undefined: StateContext<TreeStateModel>, undefined: UpdateVegaView)
Decorators :
@Action(UpdateVegaView)

Updates the vega view Updates the tree data with the anatomical structures Updates the width of the visualization

Parameters :
Name Type Optional
StateContext<TreeStateModel> No
UpdateVegaView No
Returns : void
import { Injectable } from '@angular/core';
import { Action, Selector, State, StateContext } from '@ngxs/store';
import { Spec, View } from 'vega';
import {
  DiscrepencyId,
  DiscrepencyLabel,
  DoSearch,
  DuplicateId,
  UpdateBimodal,
  UpdateBimodalConfig,
  UpdateBottomSheetData,
  UpdateLinksData,
  UpdateOmapConfig,
  UpdateVegaSpec,
  UpdateVegaView,
} from '../actions/tree.actions';
import { BMNode, BimodalConfig, Link } from '../models/bimodal.model';
import { OmapConfig } from '../models/omap.model';
import { DiscrepencyStructure, SearchStructure, TNode } from '../models/tree.model';

/** Class to keep track of all data and events related to the visualization */
export interface TreeStateModel {
  /**
   * Stores the Vega Specification
   */
  spec: Spec;
  /**
   * Store the data from the Tree
   */
  treeData: TNode[];
  /**
   * Store the Vega view object which enables us to use the Vega API
   */
  view: View;
  /**
   * Store the width of the visualization
   */
  width: number;
  /**
   * Store the height of the visualization
   */
  height: number;
  /**
   * Store bimodal data - nodes, links and config (for sorting and sizing)
   */
  bimodal: {
    nodes: BMNode[];
    links: Link[];
    config: BimodalConfig;
  };
  /**
   * Store the search data
   */
  search: SearchStructure[];
  /**
   * Store the last clicked node in the search field
   */
  lastSearch: SearchStructure;
  /**
   * Store data for the bottom sheet to display information
   */
  bottomSheetData: Record<string, never>;
  /**
   * Store data of links between nodes to show in the report
   */
  links: {
    AS_CT: number;
    CT_B: number;
    AS_AS: number;
    AS_CT_organWise: Record<string, number>;
    CT_B_organWise: Record<string, number>;
    AS_AS_organWise: Record<string, number>;
  };
  /**
   * Store the discrepency label data
   */
  discrepencyLabel: DiscrepencyStructure[];
  /**
   * Store the discrepency id data
   */
  discrepencyId: DiscrepencyStructure[];
  /**
   * Store the discrepency id data
   */
  duplicateId: DiscrepencyStructure[];
  /**
   * Store the OMAP Config
   */
  omapConfig: OmapConfig;
}

@State<TreeStateModel>({
  name: 'treeState',
  defaults: {
    spec: {},
    treeData: [],
    view: {} as View,
    width: 0,
    height: document.getElementsByTagName('body')[0].clientHeight,
    bimodal: {
      nodes: [],
      links: [],
      config: {
        BM: { sort: 'Alphabetically', size: 'None', type: 'All' },
        CT: { sort: 'Alphabetically', size: 'None' },
      },
    },
    search: [],
    lastSearch: null as unknown as SearchStructure,
    bottomSheetData: {},
    links: {
      AS_CT: 0,
      CT_B: 0,
      AS_AS: 0,
      AS_CT_organWise: {},
      CT_B_organWise: {},
      AS_AS_organWise: {},
    },
    discrepencyLabel: [],
    discrepencyId: [],
    duplicateId: [],
    omapConfig: { organsOnly: false, proteinsOnly: false },
  },
})
@Injectable()
export class TreeState {
  /**
   * Select the bimodal config (for sorting and sizing)
   */
  @Selector()
  static getBiomarkerType(state: TreeStateModel) {
    return state.bimodal.config.BM.type;
  }

  /**
   * Select the bimodal config (for sorting and sizing)
   */
  @Selector()
  static getBimodalConfig(state: TreeStateModel) {
    return state.bimodal.config;
  }

  /**
   * Select the vega specification
   */
  @Selector()
  static getVegaSpec(state: TreeStateModel) {
    return state.spec;
  }

  /**
   * Select the tree data (only anatomical structures)
   */
  @Selector()
  static getTreeData(state: TreeStateModel) {
    return state.treeData;
  }

  /**
   * Select the Vega View to use the Vega View API
   */
  @Selector()
  static getVegaView(state: TreeStateModel) {
    return state.view;
  }

  /**
   * Select the bimodal data. Contains the nodes, links and the bimodal config
   */
  @Selector()
  static getBimodal(state: TreeStateModel) {
    return state.bimodal;
  }

  /**
   * Select the bottom sheet data
   */
  @Selector()
  static getBottomSheetData(state: TreeStateModel) {
    return state.bottomSheetData;
  }

  /**
   * Select the links data to show in the report
   */
  @Selector()
  static getLinksData(state: TreeStateModel) {
    return state.links;
  }

  /**
   * Select the most recently chosen search option
   */
  @Selector()
  static getLatestSearchStructure(state: TreeStateModel) {
    return state.lastSearch;
  }

  /**
   * Select the config for OMAPS
   */
  @Selector()
  static getOmapConfig(state: TreeStateModel) {
    return state.omapConfig;
  }

  /**
   * Updates the bimodal data
   */
  @Action(UpdateBimodal)
  updateBimodal({ getState, setState }: StateContext<TreeStateModel>, { nodes, links }: UpdateBimodal) {
    const state = getState();
    setState({
      ...state,
      bimodal: { nodes, links, config: state.bimodal.config },
    });
  }

  /**
   * Updates the vega view
   * Updates the tree data with the anatomical structures
   * Updates the width of the visualization
   */
  @Action(UpdateVegaView)
  updateVegaView({ patchState }: StateContext<TreeStateModel>, { view }: UpdateVegaView) {
    patchState({
      view,
      treeData: view.data('tree'),
      width: view._viewWidth,
    });
  }

  /**
   * Updates te vega spec
   */
  @Action(UpdateVegaSpec)
  updateVegaSpec({ setState, getState }: StateContext<TreeStateModel>, { spec }: UpdateVegaSpec) {
    const state = getState();
    setState({
      ...state,
      spec,
    });
  }

  /**
   * Updates the bimodal config
   */
  @Action(UpdateBimodalConfig)
  updateBimodalConfig({ getState, setState }: StateContext<TreeStateModel>, { config }: UpdateBimodalConfig) {
    const state = getState();
    const nodes = state.bimodal.nodes;
    const links = state.bimodal.links;

    setState({
      ...state,
      bimodal: {
        nodes,
        links,
        config,
      },
    });
  }

  @Action(UpdateOmapConfig)
  updateOmapConfig({ getState, setState }: StateContext<TreeStateModel>, { config }: UpdateOmapConfig) {
    setState({
      ...getState(),
      omapConfig: config,
    });
  }

  /**
   * Updates the search list
   */
  @Action(DoSearch)
  doSearch(
    { getState, setState }: StateContext<TreeStateModel>,
    { searchStructures, lastClickedOption: lastClickedStructure }: DoSearch,
  ) {
    const state = getState();
    setState({
      ...state,
      search: searchStructures,
      lastSearch: lastClickedStructure,
    });
  }

  /**
   * Updates the discrepency labels list
   */
  @Action(DiscrepencyLabel)
  discrepencyLabel({ getState, setState }: StateContext<TreeStateModel>, { discrepencyStructures }: DiscrepencyLabel) {
    const state = getState();
    setState({
      ...state,
      discrepencyLabel: discrepencyStructures,
    });
  }

  /**
   * Updates the discrepency ids list
   */
  @Action(DiscrepencyId)
  discrepencyId({ getState, setState }: StateContext<TreeStateModel>, { discrepencyStructures }: DiscrepencyLabel) {
    const state = getState();
    setState({
      ...state,
      discrepencyId: discrepencyStructures,
    });
  }

  /**
   * Updates the duplicate ids list
   */
  @Action(DuplicateId)
  duplicateId({ getState, setState }: StateContext<TreeStateModel>, { discrepencyStructures }: DiscrepencyLabel) {
    const state = getState();
    setState({
      ...state,
      duplicateId: discrepencyStructures,
    });
  }

  /**
   * Updates the bottom sheet data
   */
  @Action(UpdateBottomSheetData)
  updateBottomSheetData({ getState, setState }: StateContext<TreeStateModel>, { data }: UpdateBottomSheetData) {
    const state = getState();
    setState({
      ...state,
      bottomSheetData: data,
    });
  }

  /**
   * Updates the links data that is displayed in the report
   */
  @Action(UpdateLinksData)
  updateLinksData(
    { getState, setState }: StateContext<TreeStateModel>,
    { AS_CT, CT_B, AS_CT_organWise, CT_B_organWise, AS_AS, AS_AS_organWise, allOrgans }: UpdateLinksData,
  ) {
    const state = getState();
    if (AS_AS) {
      setState({
        ...state,
        links: { ...state.links, AS_AS },
      });
    } else if (AS_AS_organWise) {
      setState({
        ...state,
        links: {
          ...state.links,
          AS_AS_organWise: {
            ...state.links.AS_AS_organWise,
            ...AS_AS_organWise,
          },
        },
      });
    } else {
      setState({
        ...state,
        links: {
          AS_CT: allOrgans ? state.links.AS_CT : AS_CT,
          CT_B: allOrgans ? state.links.CT_B : CT_B,
          CT_B_organWise: { ...state.links.CT_B_organWise, ...CT_B_organWise },
          AS_CT_organWise: {
            ...state.links.AS_CT_organWise,
            ...AS_CT_organWise,
          },
          AS_AS: state.links.AS_AS,
          AS_AS_organWise: state.links.AS_AS_organWise,
        },
      });
    }
  }
}

results matching ""

    No results matching ""