-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(wmg): rewrite x axis using react (#3879)
* rewrite x axis as react * update * update * prettier * remove dup prop Co-authored-by: atarashansky <atarashansky@CZIMACOS3990.hsd1.ma.comcast.net>
- Loading branch information
1 parent
bf07eff
commit d37b16d
Showing
8 changed files
with
177 additions
and
279 deletions.
There are no files selected for viewing
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
96 changes: 44 additions & 52 deletions
96
frontend/src/views/WheresMyGene/components/HeatMap/components/XAxisChart/index.tsx
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 |
---|---|---|
@@ -1,75 +1,67 @@ | ||
import { init } from "echarts"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { EMPTY_OBJECT } from "src/common/constants/utils"; | ||
import { useEffect, useState } from "react"; | ||
import { useDeleteGenesAndCellTypes } from "../../hooks/useDeleteGenesAndCellTypes"; | ||
import { useUpdateXAxisChart } from "../../hooks/useUpdateXAxisChart"; | ||
import { CHART_LEFT_PADDING } from "../../style"; | ||
import { getHeatmapWidth, Y_AXIS_CHART_WIDTH_PX } from "../../utils"; | ||
import { XAxisWrapper, XAxisContainer } from "./style"; | ||
import { CHART_LEFT_PADDING, SELECTED_STYLE } from "../../style"; | ||
import { | ||
getHeatmapWidth, | ||
formatLabel, | ||
X_AXIS_CHART_HEIGHT_PX, | ||
Y_AXIS_CHART_WIDTH_PX, | ||
} from "../../utils"; | ||
import { | ||
XAxisWrapper, | ||
XAxisContainer, | ||
XAxisLabel, | ||
GeneButtonStyle, | ||
} from "./style"; | ||
|
||
interface Props { | ||
geneNames: string[]; | ||
} | ||
|
||
export default function XAxisChart({ geneNames }: Props): JSX.Element { | ||
const [isChartInitialized, setIsChartInitialized] = useState(false); | ||
const [xAxisChart, setXAxisChart] = useState<echarts.ECharts | null>(null); | ||
const [heatmapWidth, setHeatmapWidth] = useState(getHeatmapWidth(geneNames)); | ||
|
||
const { genesToDelete, handleGeneClick } = useDeleteGenesAndCellTypes(); | ||
|
||
const xAxisRef = useRef(null); | ||
|
||
// Update heatmap size | ||
useEffect(() => { | ||
setHeatmapWidth(getHeatmapWidth(geneNames)); | ||
}, [geneNames]); | ||
|
||
// Initialize charts | ||
useEffect(() => { | ||
const { current: xAxisCurrent } = xAxisRef; | ||
|
||
if (!xAxisCurrent || isChartInitialized) { | ||
return; | ||
} | ||
|
||
setIsChartInitialized(true); | ||
|
||
const xAxisChart = init(xAxisCurrent, EMPTY_OBJECT, { | ||
renderer: "svg", | ||
useDirtyRect: true, | ||
}); | ||
|
||
setXAxisChart(xAxisChart); | ||
}, [xAxisRef, isChartInitialized]); | ||
|
||
// Bind xAxisChart events | ||
useEffect(() => { | ||
xAxisChart?.on("click", function (params) { | ||
/** | ||
* `value` is set by utils.getGeneNames() | ||
*/ | ||
const { value } = params; | ||
handleGeneClick(value as string); | ||
}); | ||
}, [handleGeneClick, xAxisChart]); | ||
|
||
useUpdateXAxisChart({ | ||
geneNames, | ||
genesToDelete, | ||
heatmapWidth, | ||
xAxisChart, | ||
}); | ||
return ( | ||
<XAxisWrapper | ||
width={heatmapWidth} | ||
left={Y_AXIS_CHART_WIDTH_PX + CHART_LEFT_PADDING} | ||
> | ||
<XAxisContainer | ||
data-test-id="gene-labels" | ||
width={heatmapWidth} | ||
ref={xAxisRef} | ||
/> | ||
<XAxisContainer data-test-id="gene-labels" width={heatmapWidth}> | ||
{geneNames.map((geneName) => { | ||
const active = genesToDelete.includes(geneName); | ||
const currentFont = ` | ||
normal | ||
${active ? SELECTED_STYLE.fontWeight : "normal"} | ||
${SELECTED_STYLE.fontSize}px ${SELECTED_STYLE.fontFamily} | ||
`; | ||
const formattedLabel = formatLabel( | ||
geneName, | ||
X_AXIS_CHART_HEIGHT_PX, | ||
currentFont, | ||
0 | ||
); | ||
return ( | ||
<GeneButtonStyle | ||
key={geneName} | ||
onClick={() => handleGeneClick(geneName)} | ||
data-test-id={`gene-label-${geneName}`} | ||
> | ||
<XAxisLabel | ||
active={genesToDelete.includes(geneName)} | ||
font={currentFont} | ||
> | ||
{formattedLabel} | ||
</XAxisLabel> | ||
</GeneButtonStyle> | ||
); | ||
})} | ||
</XAxisContainer> | ||
</XAxisWrapper> | ||
); | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
frontend/src/views/WheresMyGene/components/HeatMap/components/YAxisChart/style.ts
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
66 changes: 0 additions & 66 deletions
66
frontend/src/views/WheresMyGene/components/HeatMap/hooks/useUpdateXAxisChart.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.