-
Notifications
You must be signed in to change notification settings - Fork 311
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
SURAJ-SHARMA27
wants to merge
32
commits into
cBioPortal:master
Choose a base branch
from
SURAJ-SHARMA27:GSoC-2024-Single-Cell-Tab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 2417ba0
pie-chart-added
SURAJ-SHARMA27 bcfb7cf
Merge branch 'cBioPortal:master' into GSoC-2024-Single-Cell
SURAJ-SHARMA27 a9ea625
table-tooltip-added
SURAJ-SHARMA27 b414342
tooltip-enable-button-added
SURAJ-SHARMA27 464f523
downloading-options-added
SURAJ-SHARMA27 d268e97
download-functionality-enabled
SURAJ-SHARMA27 cfb9cfa
reusable-downloadUtils.ts-made
SURAJ-SHARMA27 bb6a23a
resizable-data-table
SURAJ-SHARMA27 dd69002
stacked-bar-plot-added-E2E
SURAJ-SHARMA27 6d17f27
NA-counts-@-barplot
SURAJ-SHARMA27 053e820
adjusted-code-for-newly-added-data
SURAJ-SHARMA27 9a918e4
Height,searching_issuefixed
SURAJ-SHARMA27 656f8a6
stacked-Bar-axes-tooltip-fix
SURAJ-SHARMA27 686b745
axes-labels-added,select-component-fixed
SURAJ-SHARMA27 31e99e3
patient-view-page-linked
SURAJ-SHARMA27 a1bf41c
select_sample_ID_dropdown_fixed
SURAJ-SHARMA27 25eaddb
sorting_functionality_new_features_added_&_minor_fixes
SURAJ-SHARMA27 25c6e27
enhancements-made
SURAJ-SHARMA27 0406033
svg_issue_fixed
SURAJ-SHARMA27 e8a276f
tooltip_issue_fixed
SURAJ-SHARMA27 7400e58
tooltip_issue_fixed_2
SURAJ-SHARMA27 91a4e90
stacked_bar_dropdown
SURAJ-SHARMA27 c6746a1
custom_databin_functionality_added
SURAJ-SHARMA27 de23d79
custom_Databin_decimal
SURAJ-SHARMA27 358cc4e
log-statements-removed
SURAJ-SHARMA27 60dd7cc
made-singleCellStore
SURAJ-SHARMA27 b7e7633
stacked-bar-tooltip-fixed
SURAJ-SHARMA27 9cbdc87
stacked-bar-tooltip-fixed-2
SURAJ-SHARMA27 bf3af8a
min-height-validation_added
SURAJ-SHARMA27 89807b1
generalized_download,colors_removed_logs
SURAJ-SHARMA27 7fe7bee
type-added-for-all-props
SURAJ-SHARMA27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] = []; | ||
|
||
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; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 useconst
(also for the other variables defined below)