Skip to content

Commit

Permalink
Add table visualisation for categorical values (#5012)
Browse files Browse the repository at this point in the history
* Create table component for category data
* Add table for categorical params to ClinicalData.tsx
- Change logic related to showing checkboxes leaving only show N/A for table

---------

Co-authored-by: alisman <lisman.aaron@gmail.com>
  • Loading branch information
pozhidaevak and alisman authored Jan 31, 2025
1 parent e02291f commit 3f3f27f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/pages/groupComparison/CategoryPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MultipleCategoryBarPlot, {
import MultipleCategoryHeatmap from 'shared/components/plots/MultipleCategoryHeatmap';
import autobind from 'autobind-decorator';
import { OncoprintJS } from 'oncoprintjs';
import { makePlotData } from 'shared/components/plots/MultipleCategoryBarPlotUtils';
import { CategoryTable } from 'pages/groupComparison/CategoryTable';

export type IMultipleCategoryPlotProps = IMultipleCategoryBarPlotProps & {
type: CategoryPlotType;
Expand All @@ -19,6 +21,7 @@ export enum CategoryPlotType {
StackedBar = 'StackedBar',
PercentageStackedBar = 'PercentageStackedBar',
Heatmap = 'Heatmap',
Table = 'Table',
}

@observer
Expand All @@ -40,8 +43,28 @@ export default class CategoryPlot extends React.Component<
}

render() {
const isHeatmap = this.props.type === CategoryPlotType.Heatmap;
return <>{isHeatmap ? this.heatmap : this.barchart}</>;
switch (this.props.type) {
case CategoryPlotType.Heatmap:
return <>{this.heatmap}</>;
case CategoryPlotType.Table:
return <>{this.table}</>;
default:
return <>{this.barchart}</>;
}
}

@computed get table() {
const plotData = makePlotData(
this.props.horzData!,
this.props.vertData!,
false
);
return (
<CategoryTable
data={plotData}
labels={this.props.horzCategoryOrder!}
/>
);
}

@computed get heatmap() {
Expand Down
36 changes: 36 additions & 0 deletions src/pages/groupComparison/CategoryTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FunctionComponent } from 'react';
import * as React from 'react';
import { IMultipleCategoryBarPlotData } from 'shared/components/plots/MultipleCategoryBarPlot';

type CategoryTableProps = {
data: IMultipleCategoryBarPlotData[];
labels: string[];
};

export const CategoryTable: FunctionComponent<CategoryTableProps> = (
props: CategoryTableProps
) => {
const headers =
props.labels.length === 1 ? (
<th colSpan={2}>{props.labels[0]}</th>
) : (
[<th />, props.labels.map(label => <th colSpan={1}>{label}</th>)]
);
return (
<table className="table table-striped" style={{ minWidth: '400px' }}>
<thead>
<tr>{headers}</tr>
</thead>
<tbody>
{props.data.map(d => (
<tr>
<td>{d.minorCategory}</td>
{d.counts.map(c => (
<td>{c.count}</td>
))}
</tr>
))}
</tbody>
</table>
);
};
18 changes: 14 additions & 4 deletions src/pages/groupComparison/ClinicalData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const categoryPlotTypeOptions = [
label: '100% stacked bar chart',
},
{ value: CategoryPlotType.Heatmap, label: 'Heatmap' },
{ value: CategoryPlotType.Table, label: 'Table' },
];

function isNumerical(datatype?: string) {
Expand Down Expand Up @@ -277,7 +278,14 @@ export default class ClinicalData extends React.Component<
}

@computed get showHorizontalBarControls() {
return !this.showLogScaleControls && !this.isHeatmap;
return (
!this.showLogScaleControls &&
!this.isHeatmap &&
!(
!this.isNumericalPlot &&
this.categoryPlotType === CategoryPlotType.Table
)
);
}

@computed get showSwapAxisControls() {
Expand All @@ -286,9 +294,11 @@ export default class ClinicalData extends React.Component<

@computed get isTable() {
return (
this.isNumericalPlot &&
this.numericalVisualisationType ===
ClinicalNumericalVisualisationType.Table
(this.isNumericalPlot &&
this.numericalVisualisationType ===
ClinicalNumericalVisualisationType.Table) ||
(!this.isNumericalPlot &&
this.categoryPlotType === CategoryPlotType.Table)
);
}

Expand Down

0 comments on commit 3f3f27f

Please sign in to comment.