File

src/app/components/organ-version/organ-version.component.ts

Description

Displays 2D FTU's according to the selected version

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(router: Router, route: ActivatedRoute, dataService: TableDataService)

Creates instance of Router, ActivatedRoute, TableDataService

Parameters :
Name Type Optional
router Router No
route ActivatedRoute No
dataService TableDataService No

Inputs

headerInfo
Type : HeaderData[]
Default value : []

Details of column definitions and headers

isMultiRow
Type : boolean
Default value : false

Flag to view tissue details in multiple rows

organInfo
Type : VersionOrgans[]
Default value : []

Deatils of version and organ data

tableRequired
Type : boolean
Default value : false

Flag to view/hide organ ftu table

versionData
Type : ChooseVersion[]
Default value : []

Deatils of the release and version

Methods

iCaseEquals
iCaseEquals(str1: string, str2: string)

Checks if both the strings are equal

Parameters :
Name Type Optional
str1 string No
str2 string No
Returns : boolean
setFtu
setFtu(organName)

Sets the ftu table data with necessary columns

Parameters :
Name Optional
organName No
Returns : void
setOrgan
setOrgan(organ: string)

Sets organ data according to the selected organ

Parameters :
Name Type Optional
organ string No
Returns : void
setVersion
setVersion(version: string, organ?: string)

Sets version data according to the selected version and organ

Parameters :
Name Type Optional
version string No
organ string Yes
Returns : void
updateQueryParams
updateQueryParams(params: Params)

Updates the query parameters

Parameters :
Name Type Optional
params Params No
Returns : void

Properties

cardTitle
Type : string
Default value : ''

Tile of the card

columns
Type : Observable<string[]>
Default value : EMPTY

Columns to display in the FTU table

displayedColumnsData
Type : string[]
Default value : []

Column definitons of the columns to be displayed

filterImages
Type : OrganData[]
Default value : []

Images of the organs to be displayed in the tabs

info
Type : VersionOrgans

Current selected version and it's organ data

organData
Type : OrganData[]
Default value : []

Organ data of current selected organ

tableData
Type : Observable<TableData[]>
Default value : EMPTY

Data for the FTU table

tableTitle
Type : string
Default value : ''

Title for the FTU Table

version
Type : ChooseVersion

Selected version from the version data

import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { EMPTY, Observable, map } from 'rxjs';
import { TableDataService } from '../../services/table-data/tabledata.service';
import { ChooseVersion } from '../choose-version/choose-version';
import { HeaderData } from '../table/header';
import { TableData } from '../table/table';
import { OrganData, VersionOrgans } from '../two-dim-image/two-dim-image';

/** Displays 2D FTU's according to the selected version */
@Component({
  selector: 'ccf-organ-version',
  templateUrl: './organ-version.component.html',
  styleUrls: ['./organ-version.component.scss'],
})
export class OrganVersionComponent implements OnInit {
  /** Deatils of the release and version */
  @Input() versionData: ChooseVersion[] = [];

  /** Deatils of version and organ data */
  @Input() organInfo: VersionOrgans[] = [];

  /** Flag to view/hide organ ftu table */
  @Input() tableRequired = false;

  /** Details of column definitions and headers */
  @Input() headerInfo: HeaderData[] = [];

  /** Flag to view tissue details in multiple rows */
  @Input() isMultiRow = false;

  /** Current selected version and it's organ data */
  info!: VersionOrgans;

  /** Organ data of current selected organ */
  organData: OrganData[] = [];

  /** Tile of the card */
  cardTitle = '';

  /** Data for the FTU table */
  tableData: Observable<TableData[]> = EMPTY;

  /** Columns to display in the FTU table */
  columns: Observable<string[]> = EMPTY;

  /** Title for the FTU Table */
  tableTitle = '';

  /** Images of the organs to be displayed in the tabs */
  filterImages: OrganData[] = [];

  /** Selected version from the version data */
  version!: ChooseVersion;

  /** Column definitons of the columns to be displayed */
  displayedColumnsData: string[] = [];

  /** Creates instance of Router, ActivatedRoute, TableDataService */
  constructor(
    private readonly router: Router,
    private readonly route: ActivatedRoute,
    private readonly dataService: TableDataService,
  ) {}

  /** Checks if both the strings are equal */
  iCaseEquals(str1: string, str2: string): boolean {
    return str1.toLowerCase() === str2.toLowerCase();
  }

  /** Sets version and ftu data */
  ngOnInit(): void {
    const [
      {
        version: defaultVersion,
        organData: [{ name: defaultOrgan }],
      },
    ] = this.organInfo;
    const { version = defaultVersion, organ = defaultOrgan } = this.route.snapshot.queryParams;
    if (this.headerInfo?.length > 0) {
      this.headerInfo = this.headerInfo.map((data) => ({
        ...data,
        cell: new Function('element', `return ${data.cell}`) as HeaderData['cell'],
      }));
      this.displayedColumnsData = this.headerInfo.map((h) => h.columnDef);
      this.setVersion(`${version}`, `${organ}`);
      this.setFtu(this.organData[0].name);
    } else {
      this.setVersion(`${version}`, `${organ}`);
    }
  }

  /** Sets version data according to the selected version and organ */
  setVersion(version: string, organ?: string): void {
    const info = this.organInfo.find((item) => this.iCaseEquals(item.version, version)) ?? this.organInfo[0];
    const choose = this.versionData.find((item) => item.version === info.version);
    if (choose) {
      this.info = info;
      this.version = choose;
      this.filterImages = info.organData;
      this.setOrgan(organ ?? info.organData[0].name);
    }
  }

  /** Sets organ data according to the selected organ */
  setOrgan(organ: string): void {
    const {
      info: { organData, version },
    } = this;
    const data = organData.filter((item) => this.iCaseEquals(item.name, organ));

    if (data.length === 0) {
      this.setOrgan(organData[0].name);
    } else {
      this.organData = data;
      if (this.headerInfo?.length > 0) {
        this.cardTitle = data[0].name + ' Functional Tissue Units';
      } else {
        this.cardTitle = data[0].name;
      }
      this.updateQueryParams({ version, organ });
    }
  }

  /** Updates the query parameters */
  updateQueryParams(params: Params): void {
    this.router.navigate([], {
      relativeTo: this.route,
      queryParams: params,
      queryParamsHandling: 'merge',
    });
  }

  /** Sets the ftu table data with necessary columns */
  setFtu(organName: OrganData['name']): void {
    const data = this.dataService.getData('ftu-cell-count-5th-release.csv', this.displayedColumnsData);
    this.tableData = data.pipe(
      map((result) => result.data),
      map((data) => data.filter((record) => this.iCaseEquals(record['Organ'] as string, organName))),
    );
    this.columns = data.pipe(map((result) => result.columns));
    this.tableTitle = organName + ' Functional Tissue Units: Anatomical Structures & Cell Types';
  }
}
<ccf-choose-version
  [releaseDate]="versionData"
  [selectedDate]="version"
  (selectedVersion)="setVersion($event.version)"
  class="mb-2r"
></ccf-choose-version>
<ccf-organ-tabs
  [tabs]="filterImages"
  [currentOrgan]="organData[0].name"
  (organName)="setOrgan($event)"
  (organName)="setFtu($event)"
  [panelClass]="'panelClass'"
></ccf-organ-tabs>
<ccf-two-dim-image [cardTitle]="cardTitle" [tissueData]="organData" [isMultirow]="isMultiRow"></ccf-two-dim-image>
<div class="table-heading-container" *ngIf="tableRequired">
  <div class="content-title">{{ tableTitle }}</div>
  <a mat-raised-button href="assets/table-data/ftu-cell-count-5th-release.csv" class="download-btn">
    <span class="material-symbols-outlined">download</span>Download CSV</a
  >
</div>
<ccf-table
  *ngIf="tableRequired"
  [typeCount]="(tableData | async) ?? []"
  [displayedColumns]="(columns | async) ?? []"
  [columns]="headerInfo"
  [isTotal]="true"
  class="description"
></ccf-table>

./organ-version.component.scss

:host {
  .table-heading-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
    line-height: 2rem;

    .download-btn:hover {
      background: rgba(103, 80, 164, 0.08);
    }

    .download-btn:focus,
    .download-btn:active {
      background: rgba(103, 80, 164, 0.12);
    }

    .download-btn:disabled {
      background: rgba(29, 27, 32, 0.12);
    }

    .download-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 500;
      font-size: 0.875rem;
      padding: 0rem 1.5rem;
      margin-left: 1px;
      min-width: 124px;
      color: #444c65;
      border-radius: 6.25rem;
      height: 40px;
      background-color: #f7f2fa;
      box-shadow:
        0px 1px 2px rgba(0, 0, 0, 0.3),
        0px 1px 3px 1px rgba(0, 0, 0, 0.15);
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""