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

In the barchart show term2 value in list samples if there is overlay #2364

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 24 additions & 6 deletions client/plots/barchart.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { newpane, export_data } from '../src/client'
import { filterJoin, getFilterItemByTag, getNormalRoot, findItemByTermId, normalizeProps } from '#filter'
import { rgb } from 'd3-color'
import { roundValueAuto } from '#shared/roundValue.js'

import { isNumericTerm } from '#shared/terms.js'
export default function getHandlers(self) {
const tip = new Menu({ padding: '5px' })
self.dom.tip = tip
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function getHandlers(self) {

//mouse-over p-value and 2x2 table
if (t2) {
const pvalue = d.groupPvalues.term2tests.find(x => x.term2id === d.dataId).pvalue
const pvalue = d.groupPvalues?.term2tests?.find(x => x.term2id === d.dataId).pvalue
const term1Label = d.groupPvalues.term1Label
const term2Label = d.groupPvalues.term2tests.find(x => x.term2id === d.dataId).term2Label
const tableValues = d.groupPvalues.term2tests.find(x => x.term2id === d.dataId).tableValues
Expand Down Expand Up @@ -496,19 +496,37 @@ async function listSamples(event, self, seriesId, dataId, chartId) {
}
const data = await self.app.vocabApi.getAnnotatedSampleData(opts)
const rows = []
const termIsNumeric = isNumericTerm(self.config.term.term)
const term2isNumeric = self.config.term2 ? isNumericTerm(self.config.term2.term) : false

for (const sample of data.lst) {
const value = data.refs.bySampleId[Number(sample.sample)].label
rows.push([{ value }])
const sampleName = data.refs.bySampleId[Number(sample.sample)].label
const row = [{ value: sampleName }]
if (termIsNumeric) {
const value = sample[self.config.term.$id]?.value
row.push({ value: roundValueAuto(value) })
}
if (self.config.term2) {
let value = sample[self.config.term2.$id]
if (!value) row.push({ value: '' })
else {
const label = self.config.term2.term.values?.[value.key]?.label
value = term2isNumeric ? roundValueAuto(value.value) : label || value.value
row.push({ value })
}
}
rows.push(row)
}
const columns = [{ label: 'Sample' }]
if (termIsNumeric) columns.push({ label: self.config.term.term.name })
if (self.config.term2) columns.push({ label: self.config.term2.term.name })
const menu = new Menu({ padding: '5px' })
const div = menu.d.append('div')
renderTable({
rows,
columns,
div,
showLines: true,
maxWidth: '27vw',
maxHeight: '40vh',
resize: true
})
Expand All @@ -523,7 +541,7 @@ async function listSamples(event, self, seriesId, dataId, chartId) {
values: [{ key: value }]
}
}
if (term.term.type == 'integer' || term.term.type == 'float') {
if (isNumericTerm(term.term)) {
const bins = self.bins[termIndex]
tvs.tvs.ranges = [bins.find(bin => bin.label == value)]
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/termdb.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function getFilterSampleTypes(filter, ds, sampleTypes) {

const term_id = item.tvs.term
const sample_type = getSampleType(term_id, ds)
sampleTypes.add(sample_type)
if (sample_type != null) sampleTypes.add(sample_type)
}
return sampleTypes
}
Expand Down
1 change: 1 addition & 0 deletions shared/utils/src/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export function getBin(lst, value) {

export function getSampleType(term, ds) {
if (!term) return null
if (term.type && isNonDictionaryType(term.type)) return DEFAULT_SAMPLE_TYPE
if (term.id) return ds.cohort.termdb.term2SampleType.get(term.id)
if (term.type == 'samplelst') {
const key = Object.keys(term.values)[0]
Expand Down
Loading