Skip to content

Commit 6166303

Browse files
committed
New options for X axis
1 parent f7ca912 commit 6166303

1 file changed

Lines changed: 64 additions & 11 deletions

File tree

src/components/tlois/ConfidencePlot.tsx

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Box, FormControl, FormControlLabel, FormLabel, MenuItem, Radio, RadioGroup, Select, Skeleton } from "@mui/material";
2-
import { Goal, RunBinding, TriggeredLineOfInquiry, Workflow, WorkflowRun } from "DISK/interfaces";
1+
import { Box, FormControl, FormControlLabel, FormLabel, InputLabel, MenuItem, Radio, RadioGroup, Select, SelectChangeEvent, Skeleton } from "@mui/material";
2+
import { RunBinding, TriggeredLineOfInquiry } from "DISK/interfaces";
33
import { useEffect, useState } from "react";
44
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title,
55
Tooltip, Legend, ChartData, ChartOptions, Chart, TooltipModel, LogarithmicScale } from 'chart.js';
@@ -24,6 +24,8 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
2424

2525
const [files, setFiles] = useState<{ [key: string]: RunBinding }>({});
2626
const [selectedFile, setSelectedFile] = useState<string>("");
27+
const [xAxis, setXAxis] = useState<'default'|'extra'>('default');
28+
const [extraActive, setExtraActive] = useState<boolean>(false);
2729

2830
const [idToLabel, setIdToLabel] = useState<{[id:string]: string}>({});
2931
const [contentType, setContentType] = useState<string>("");
@@ -43,7 +45,7 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
4345
//Sets output types, and create data for plot.
4446
useEffect(() => {
4547
let outputs: { [name: string]: RunBinding } = {};
46-
let pValues: { [label: string]: number } = {};
48+
let pValues: { [x: number]: number } = {};
4749
let labelDic: { [uri: string]: string } = {};
4850
let labels: string[] = [];
4951

@@ -58,19 +60,26 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
5860
if (nInputs < db.binding.length)
5961
nInputs = db.binding.length;
6062
});
61-
let label = String(nInputs);
63+
if (xAxis === 'extra') {
64+
for (let b of exec.result.extras) {
65+
if (b.variable === 'X') {
66+
nInputs = Number(b.binding[0]);
67+
}
68+
}
69+
}
70+
let label = (xAxis === 'default' ? "Number of Cohorts = " : "Sample Size = ") + String(nInputs)
6271
labels.push(label);
6372
labelDic[tloi.id] = label;
64-
pValues[label] = exec.result.confidenceValue;
73+
pValues[nInputs] = exec.result.confidenceValue;
6574
break;
6675
}
6776
}
6877
}
6978
});
7079

7180
let d : {x:number, y:number}[] = Object.keys(pValues).map((key)=>({
72-
x: Number(key),
73-
y: -Math.log10(pValues[key]),
81+
x: key as unknown as number,
82+
y: -Math.log10(pValues[key as unknown as number]),
7483
}));
7584

7685
setData({
@@ -82,14 +91,14 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
8291
backgroundColor: 'rgba(255, 99, 132, 0.5)',
8392
pointRadius: 8,
8493
pointHoverRadius: 10
85-
}]
94+
}],
8695
});
8796

8897
setFiles(outputs);
8998
setIdToLabel(labelDic);
9099
//TODO: add a image selector for tooltip and a date option for labels.
91100
setSelectedFile(Object.keys(outputs).length > 0 ? Object.keys(outputs)[0] : "");
92-
}, [visibleTLOIs])
101+
}, [visibleTLOIs, xAxis])
93102

94103
useEffect(() => {
95104
if (visibleTLOIs && visibleTLOIs.length > 0 && selectedFile) {
@@ -259,9 +268,17 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
259268
scales: {
260269
y: {
261270
type: "linear",
271+
title: {
272+
display: true,
273+
text: '-log(p-value)'
274+
},
262275
},
263276
x: {
264-
type: "linear"
277+
type: "linear",
278+
title: {
279+
display: true,
280+
text: xAxis === 'default' ? 'Number of Cohorts' : 'Sample Size',
281+
},
265282
}
266283
},
267284
aspectRatio: 4,
@@ -272,7 +289,7 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
272289
},
273290
title: {
274291
display: true,
275-
text: '[Number of Inputs] vs [-log(p-value)]',
292+
text: '[' + (xAxis === 'default' ? 'Number of Cohorts' : 'Accumulative Sample Size') + "] vs [-log(p-value)]",
276293
},
277294
tooltip: {
278295
enabled: false,
@@ -296,8 +313,44 @@ export const ConfidencePlot = ({ goalId, loiId }: ConfidencePlotProps) => {
296313
}
297314
}
298315

316+
const handleXAxis = (event: SelectChangeEvent<"default" | "extra">) => {
317+
if (event.target.value === 'default') {
318+
setXAxis('default');
319+
} else {
320+
setXAxis('extra');
321+
}
322+
}
323+
299324
return <Box>
300325
<Box>
326+
<FormControl style={{ marginTop: '10px', minWidth: '300px' }} size="small">
327+
<InputLabel id="demo-select-small-label">X Axis:</InputLabel>
328+
<Select
329+
fullWidth
330+
labelId="demo-select-small-label"
331+
id="demo-select-small"
332+
value={xAxis}
333+
label="X Axis"
334+
onChange={handleXAxis}
335+
>
336+
<MenuItem value={'default'}>Number of Cohorts</MenuItem>
337+
<MenuItem value={'extra'}>Accumulative Sample Size</MenuItem>
338+
</Select>
339+
</FormControl>
340+
341+
<FormControl style={{ marginTop: '10px', minWidth: '300px' }} size="small">
342+
<InputLabel id="demo2-select-small-label">Y Axis:</InputLabel>
343+
<Select
344+
fullWidth
345+
labelId="demo2-select-small-label"
346+
id="demo2-select-small"
347+
value={'p-value'}
348+
label="Y Axis"
349+
>
350+
<MenuItem value={'p-value'}>-log( p-value )</MenuItem>
351+
</Select>
352+
</FormControl>
353+
301354
{x.image !== undefined && Object.keys(x.image || {}).length === 1 && <Box>
302355
Showing {Object.keys(x.image)[0]} file on previews.
303356
</Box>}

0 commit comments

Comments
 (0)