Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gsoc 2024 single cell tab- stackedBar,piechart and bar plots added #4921

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8e2c23d
Single-cell-tab-and-BarChart-added
SURAJ-SHARMA27 May 24, 2024
2417ba0
pie-chart-added
SURAJ-SHARMA27 May 25, 2024
bcfb7cf
Merge branch 'cBioPortal:master' into GSoC-2024-Single-Cell
SURAJ-SHARMA27 May 29, 2024
a9ea625
table-tooltip-added
SURAJ-SHARMA27 May 29, 2024
b414342
tooltip-enable-button-added
SURAJ-SHARMA27 May 31, 2024
464f523
downloading-options-added
SURAJ-SHARMA27 Jun 2, 2024
d268e97
download-functionality-enabled
SURAJ-SHARMA27 Jun 3, 2024
cfb9cfa
reusable-downloadUtils.ts-made
SURAJ-SHARMA27 Jun 4, 2024
bb6a23a
resizable-data-table
SURAJ-SHARMA27 Jun 4, 2024
dd69002
stacked-bar-plot-added-E2E
SURAJ-SHARMA27 Jun 11, 2024
6d17f27
NA-counts-@-barplot
SURAJ-SHARMA27 Jun 11, 2024
053e820
adjusted-code-for-newly-added-data
SURAJ-SHARMA27 Jun 15, 2024
9a918e4
Height,searching_issuefixed
SURAJ-SHARMA27 Jun 20, 2024
656f8a6
stacked-Bar-axes-tooltip-fix
SURAJ-SHARMA27 Jun 23, 2024
686b745
axes-labels-added,select-component-fixed
SURAJ-SHARMA27 Jun 24, 2024
31e99e3
patient-view-page-linked
SURAJ-SHARMA27 Jun 24, 2024
a1bf41c
select_sample_ID_dropdown_fixed
SURAJ-SHARMA27 Jun 25, 2024
25eaddb
sorting_functionality_new_features_added_&_minor_fixes
SURAJ-SHARMA27 Jun 26, 2024
25c6e27
enhancements-made
SURAJ-SHARMA27 Jun 29, 2024
0406033
svg_issue_fixed
SURAJ-SHARMA27 Jul 1, 2024
e8a276f
tooltip_issue_fixed
SURAJ-SHARMA27 Jul 1, 2024
7400e58
tooltip_issue_fixed_2
SURAJ-SHARMA27 Jul 1, 2024
91a4e90
stacked_bar_dropdown
SURAJ-SHARMA27 Jul 1, 2024
c6746a1
custom_databin_functionality_added
SURAJ-SHARMA27 Jul 3, 2024
de23d79
custom_Databin_decimal
SURAJ-SHARMA27 Jul 4, 2024
358cc4e
log-statements-removed
SURAJ-SHARMA27 Jul 17, 2024
60dd7cc
made-singleCellStore
SURAJ-SHARMA27 Jul 21, 2024
b7e7633
stacked-bar-tooltip-fixed
SURAJ-SHARMA27 Jul 22, 2024
9cbdc87
stacked-bar-tooltip-fixed-2
SURAJ-SHARMA27 Jul 22, 2024
bf3af8a
min-height-validation_added
SURAJ-SHARMA27 Jul 28, 2024
89807b1
generalized_download,colors_removed_logs
SURAJ-SHARMA27 Jul 31, 2024
7fe7bee
type-added-for-all-props
SURAJ-SHARMA27 Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
652 changes: 652 additions & 0 deletions src/pages/SingleCell/BarChart.tsx

Large diffs are not rendered by default.

1,189 changes: 1,189 additions & 0 deletions src/pages/SingleCell/HomePage.tsx

Large diffs are not rendered by default.

344 changes: 344 additions & 0 deletions src/pages/SingleCell/PieChart.tsx

Large diffs are not rendered by default.

253 changes: 253 additions & 0 deletions src/pages/SingleCell/PieToolTip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
import React, { useState, useEffect, useRef } from 'react';
import { VictoryPie, VictoryTooltip } from 'victory';
import './styles.css';
import { observer } from 'mobx-react-lite';
import singleCellStore, {
SampleOption,
colors,
PatientData,
} from './SingleCellStore';
interface VictoryEventProps {
index: number;
}

const PieToolTip: React.FC = observer(() => {
const {
pieChartData,
tooltipEnabled,
downloadSvg,
setDownloadSvg,
downloadPdf,
setDownloadPdf,
heading,
isHovered,
setIsHovered,
hoveredSliceIndex,
setHoveredSliceIndex,
} = singleCellStore;

const [tooltipVisible, setTooltipVisible] = useState<boolean>(false);
const [tooltipHovered, setTooltipHovered] = useState<boolean>(false);
const [downloadOptionsVisible, setDownloadOptionsVisible] = useState<
boolean
>(false);

const svgRef = useRef<SVGSVGElement>(null);
// Set to store unique patient IDs
let differentPatientIds: string[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid let and use const (also for the other variables defined below)


for (let i = 0; i < pieChartData.length; i++) {
let currentId = pieChartData[i].patientId;
if (!differentPatientIds.includes(currentId)) {
differentPatientIds.push(currentId);
}
}
let patientData: PatientData = {};

// Iterate over unique patient IDs
for (let i = 0; i < differentPatientIds.length; i++) {
let id = differentPatientIds[i];
patientData[id] = [];
for (let j = 0; j < pieChartData.length; j++) {
if (pieChartData[j].patientId === id) {
patientData[id].push({
stableId: pieChartData[j].stableId,
value: parseFloat(pieChartData[j].value),
});
}
}
}
useEffect(() => {
if (tooltipEnabled) {
setTooltipVisible(true);
} else {
if (isHovered || tooltipHovered) {
setTooltipVisible(true);
} else {
const timeoutId = setTimeout(
() => setTooltipVisible(false),
300
);
return () => clearTimeout(timeoutId);
}
}
}, [isHovered, tooltipHovered, tooltipEnabled]);

const uniqueIds: any = [
...new Set(pieChartData.map((item: any) => item.genericAssayStableId)),
];
const sumValues: { [key: string]: number } = {};
let totalSum = 0;
uniqueIds.forEach((id: string) => {
sumValues[id] = pieChartData.reduce((acc: number, item: any) => {
if (item.genericAssayStableId === id) {
const value = parseFloat(item.value);
totalSum += value;
return acc + value;
}
return acc;
}, 0);
});

const pieData = Object.keys(sumValues).map((key, index) => {
const color = colors[index];
return {
typeOfCell: key,
percentage: sumValues[key],
color: color,
};
});

return (
<div>
<div style={{ position: 'relative' }}>
<div
style={{
pointerEvents: 'auto',
opacity: tooltipEnabled
? tooltipVisible
? 1
: 0
: isHovered || tooltipHovered
? 1
: 0,
transition: 'opacity 0.5s ease-in-out',
transitionDelay: '0s',
backgroundColor: 'white',
width: '400px',
marginRight: '10px',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.3)',
borderRadius: '10px',
zIndex: 220,
padding: '10px',
transform: 'translateZ(0)',
position: 'relative',
}}
onMouseEnter={() => setTooltipHovered(true)}
onMouseLeave={() => setTooltipHovered(false)}
>
<div
style={{
content: '""',
position: 'absolute',
left: '-10px',
top: '50%',
transform: 'translateY(-50%)',
width: '0',
height: '0',
borderTop: '10px solid transparent',
borderBottom: '10px solid transparent',
borderRight: '10px solid rgba(0, 0, 0, 0.15)',
zIndex: 219,
}}
></div>

<div
className="custom-scrollbar"
style={{
height: tooltipEnabled ? 'max-content' : undefined,
overflowY: 'auto',
resize: 'both',
overflow: 'auto',
backgroundColor: 'white',
pointerEvents: 'auto',
borderRadius: '10px',
}}
>
<table
style={{
borderCollapse: 'collapse',
width: '100%',
textAlign: 'center',
borderRadius: '10px',
}}
>
<thead>
<tr>
<th
style={{
padding: '8px',
backgroundColor: '#f0f0f0',
borderRadius: '10px 10px 0 0',
}}
>
Color
</th>
<th
style={{
padding: '8px',
textAlign: 'center',
backgroundColor: '#f0f0f0',
}}
>
Type of Cell
</th>
<th
style={{
padding: '8px',
textAlign: 'center',
backgroundColor: '#f0f0f0',
}}
>
Frequency
</th>
</tr>
</thead>
<tbody>
{pieData.map((slice, index) => (
<tr
key={slice.typeOfCell}
style={{
backgroundColor:
hoveredSliceIndex === index
? 'rgba(0, 0, 0, 0.15)'
: 'transparent',
}}
>
<td
style={{
padding: '8px',
textAlign: 'center',
}}
>
<div
style={{
width: '23px',
height: '23px',
backgroundColor:
slice.color,
textAlign: 'center',
borderRadius: '50%',
}}
></div>
</td>
<td
style={{
padding: '8px',
}}
>
{slice.typeOfCell}
</td>
<td
style={{
padding: '8px',
}}
>
{(
(slice.percentage / totalSum) *
100
).toFixed(2)}
%
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
);
});

export default PieToolTip;
Loading
Loading