diff --git a/client/plots/barchart.events.js b/client/plots/barchart.events.js index 5a7bc249d..fb40195a9 100644 --- a/client/plots/barchart.events.js +++ b/client/plots/barchart.events.js @@ -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 @@ -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 @@ -496,11 +496,30 @@ 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({ @@ -508,7 +527,6 @@ async function listSamples(event, self, seriesId, dataId, chartId) { columns, div, showLines: true, - maxWidth: '27vw', maxHeight: '40vh', resize: true }) @@ -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)] } diff --git a/server/src/termdb.filter.js b/server/src/termdb.filter.js index fe619258b..97f7bad0c 100644 --- a/server/src/termdb.filter.js +++ b/server/src/termdb.filter.js @@ -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 } diff --git a/shared/utils/src/terms.js b/shared/utils/src/terms.js index 14458c3c1..c145b951a 100644 --- a/shared/utils/src/terms.js +++ b/shared/utils/src/terms.js @@ -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]