forked from Bayer-Group/cellenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cross-study dot plot shows one plot per gene; add the dot plot to sin…
…gle study expression analysis
- Loading branch information
1 parent
8817507
commit 1b97a12
Showing
8 changed files
with
317 additions
and
276 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
68 changes: 68 additions & 0 deletions
68
client/src/components/ExpressionDotPlot/ExpressionDotPlot.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, {useEffect, useMemo, useState} from 'react'; | ||
import {VegaLite, View, VisualizationSpec} from "react-vega"; | ||
import {DotPlotElementFragment} from "../../generated/types"; | ||
import {ScenegraphEvent} from "vega"; | ||
|
||
|
||
function createSpec(annotationTitle: string, xAxis: "studyName" | "displaySymbol") { | ||
return { | ||
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | ||
"data": {"name": "table"}, | ||
"mark": {"type": "point", "filled": true}, | ||
"encoding": { | ||
"y": { | ||
"field": "annotationDisplayValue", | ||
"type": "ordinal", | ||
"title": annotationTitle | ||
}, | ||
"x": xAxis === "studyName" ? { | ||
"field": "studyName", "type": "nominal", "title": "Study", | ||
} : { | ||
"field": "displaySymbol", "type": "nominal", "title": "Gene", | ||
}, | ||
"size": { | ||
"field": "exprCellsFraction", | ||
"type": "quantitative", | ||
"title": "Expr. fraction" | ||
}, | ||
"color": { | ||
"field": "q3", | ||
"type": "quantitative", | ||
"scale": {"scheme": "viridis", reverse: true} | ||
} | ||
|
||
} | ||
} as VisualizationSpec; | ||
} | ||
|
||
export function ExpressionDotPlot({ | ||
data, | ||
annotationTitle, | ||
xAxis, | ||
onClick | ||
}: | ||
{ | ||
data: DotPlotElementFragment[], | ||
annotationTitle: string, | ||
xAxis: "studyName" | "displaySymbol", | ||
onClick?: (dotPlotElement: DotPlotElementFragment, event: ScenegraphEvent) => void | ||
}) { | ||
const spec = useMemo(() => createSpec(annotationTitle, xAxis), [annotationTitle, xAxis]); | ||
|
||
const setUpSelectionListener = (view: View) => { | ||
view.addEventListener("click", (event, item) => { | ||
if (item && onClick) { | ||
const dotPlotElement = item.datum as DotPlotElementFragment; | ||
onClick(dotPlotElement, event); | ||
} | ||
}); | ||
}; | ||
|
||
return <VegaLite | ||
spec={spec} | ||
onNewView={(view) => setUpSelectionListener(view)} | ||
data={{ | ||
"table": data | ||
}}/> | ||
} | ||
|
Oops, something went wrong.