Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Apr 11, 2024
1 parent 8a29d6c commit 869b464
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 99 deletions.
14 changes: 5 additions & 9 deletions frontend/src/components/IndividualModel/ContinuousSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {observer} from "mobx-react";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";
import {ff, fractionalFormatter} from "@/utils/formatters";

@observer
Expand All @@ -27,29 +27,25 @@ class ContinuousSummary extends Component {
<tr>
<td>BMD</td>
<td>
{ff(results.bmd)}
<LongFloatPopover content={`${results.bmd}`} />
<FloatingPointHover value={results.bmd} />
</td>
</tr>
<tr>
<td>BMDL</td>
<td>
{ff(results.bmdl)}
<LongFloatPopover content={`${results.bmdl}`} />
<FloatingPointHover value={results.bmdl} />
</td>
</tr>
<tr>
<td>BMDU</td>
<td>
{ff(results.bmdu)}
<LongFloatPopover content={`${results.bmdu}`} />
<FloatingPointHover value={results.bmdu} />
</td>
</tr>
<tr>
<td>AIC</td>
<td>
{ff(results.fit.aic)}
<LongFloatPopover content={`${results.fit.aic}`} />
<FloatingPointHover value={results.fit.aic} />
</td>
</tr>
<tr>
Expand Down
14 changes: 5 additions & 9 deletions frontend/src/components/IndividualModel/DichotomousSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {observer} from "mobx-react";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";
import {ff, fourDecimalFormatter} from "@/utils/formatters";

@observer
Expand All @@ -26,29 +26,25 @@ class DichotomousSummary extends Component {
<tr>
<td>BMD</td>
<td>
{ff(results.bmd)}
<LongFloatPopover content={`${results.bmd}`} />
<FloatingPointHover value={results.bmd} />
</td>
</tr>
<tr>
<td>BMDL</td>
<td>
{ff(results.bmdl)}
<LongFloatPopover content={`${results.bmdl}`} />
<FloatingPointHover value={results.bmdl} />
</td>
</tr>
<tr>
<td>BMDU</td>
<td>
{ff(results.bmdu)}
<LongFloatPopover content={`${results.bmdu}`} />
<FloatingPointHover value={results.bmdu} />
</td>
</tr>
<tr>
<td>AIC</td>
<td>
{ff(results.fit.aic)}
<LongFloatPopover content={`${results.fit.aic}`} />
<FloatingPointHover value={results.fit.aic} />
</td>
</tr>
<tr>
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/IndividualModel/MaIndividualModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {observer} from "mobx-react";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";
import {ff} from "@/utils/formatters";

@observer
Expand Down Expand Up @@ -40,16 +40,13 @@ class MaIndividualModels extends Component {
<td>{ff(model_average.results.priors[i])}</td>
<td>{ff(model_average.results.posteriors[i])}</td>
<td>
{ff(model.results.bmdl)}
<LongFloatPopover content={`${model.results.bmdl}`} />
<FloatingPointHover value={model.results.bmdl} />
</td>
<td>
{ff(model.results.bmd)}
<LongFloatPopover content={`${model.results.bmd}`} />
<FloatingPointHover value={model.results.bmd} />
</td>
<td>
{ff(model.results.bmdu)}
<LongFloatPopover content={`${model.results.bmd}`} />
<FloatingPointHover value={model.results.bmd} />
</td>
</tr>
);
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/components/Output/BayesianResultTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {inject, observer} from "mobx-react";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";
import {maIndex, modelClasses} from "@/constants/outputConstants";
import {ff, fractionalFormatter} from "@/utils/formatters";

Expand Down Expand Up @@ -61,16 +61,13 @@ class BayesianResultTable extends Component {
{ma ? fractionalFormatter(ma.results.posteriors[index]) : "-"}
</td>
<td>
{ff(model.results.bmdl)}
<LongFloatPopover content={`${model.results.bmdl}`} />
<FloatingPointHover value={model.results.bmdl} />
</td>
<td>
{ff(model.results.bmd)}
<LongFloatPopover content={`${model.results.bmd}`} />
<FloatingPointHover value={model.results.bmd} />
</td>
<td>
{ff(model.results.bmdu)}
<LongFloatPopover content={`${model.results.bmdu}`} />
<FloatingPointHover value={model.results.bmdu} />
</td>
<td>{ff(model.results.fit.bic_equiv)}</td>
<td>{ff(model.results.gof.residual[0])}</td>
Expand All @@ -93,9 +90,9 @@ class BayesianResultTable extends Component {
</td>
<td>-</td>
<td>-</td>
<td>{ff(ma.results.bmdl)}</td>
<td>{ff(ma.results.bmd)}</td>
<td>{ff(ma.results.bmdu)}</td>
<td><FloatingPointHover value={ma.results.bmdl}/></td>

Check failure on line 93 in frontend/src/components/Output/BayesianResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={ma.results.bmdl}/>` with `⏎································<FloatingPointHover·value={ma.results.bmdl}·/>⏎····························`
<td><FloatingPointHover value={ma.results.bmd}/></td>

Check failure on line 94 in frontend/src/components/Output/BayesianResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={ma.results.bmd}/>` with `⏎································<FloatingPointHover·value={ma.results.bmd}·/>⏎····························`
<td><FloatingPointHover value={ma.results.bmdu}/></td>

Check failure on line 95 in frontend/src/components/Output/BayesianResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={ma.results.bmdu}/>` with `⏎································<FloatingPointHover·value={ma.results.bmdu}·/>⏎····························`
<td>-</td>
<td>-</td>
<td>-</td>
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/components/Output/FrequentistResultTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {BIN_LABELS} from "@/constants/logicConstants";
import {getPValue, modelClasses, priorClass} from "@/constants/outputConstants";
import {fractionalFormatter} from "@/utils/formatters";
import {ff} from "@/utils/formatters";
import FloatingPointHover from "@/components/common/FloatingPointHover";

import Button from "../common/Button";
import Popover from "../common/Popover";
Expand Down Expand Up @@ -210,11 +211,11 @@ class FrequentistRow extends Component {
rowIcon={rowIcon}
modelClasses={modelClasses}
/>
<td>{ff(results.summary.bmdl)}</td>
<td>{ff(results.summary.bmd)}</td>
<td>{ff(results.summary.bmdu)}</td>
<td><FloatingPointHover value={results.summary.bmdl}/></td>

Check failure on line 214 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.summary.bmdl}/>` with `⏎························<FloatingPointHover·value={results.summary.bmdl}·/>⏎····················`
<td><FloatingPointHover value={results.summary.bmd}/></td>

Check failure on line 215 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.summary.bmd}/>` with `⏎························<FloatingPointHover·value={results.summary.bmd}·/>⏎····················`
<td><FloatingPointHover value={results.summary.bmdu}/></td>

Check failure on line 216 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.summary.bmdu}/>` with `⏎························<FloatingPointHover·value={results.summary.bmdu}·/>⏎····················`
<td>{ff(results.combined_pvalue)}</td>
<td>{ff(results.summary.aic)}</td>
<td><FloatingPointHover value={results.summary.aic}/></td>

Check failure on line 218 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.summary.aic}/>` with `⏎························<FloatingPointHover·value={results.summary.aic}·/>⏎····················`
<td>-</td>
<td>-</td>
<RecommendationTd
Expand All @@ -237,11 +238,11 @@ class FrequentistRow extends Component {
rowIcon={rowIcon}
modelClasses={modelClasses}
/>
<td>{ff(results.bmdl)}</td>
<td>{ff(results.bmd)}</td>
<td>{ff(results.bmdu)}</td>
<td><FloatingPointHover value={results.bmdl}/></td>

Check failure on line 241 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.bmdl}/>` with `⏎····················<FloatingPointHover·value={results.bmdl}·/>⏎················`
<td><FloatingPointHover value={results.bmd}/></td>

Check failure on line 242 in frontend/src/components/Output/FrequentistResultTable.js

View workflow job for this annotation

GitHub Actions / frontend

Replace `<FloatingPointHover·value={results.bmd}/>` with `⏎····················<FloatingPointHover·value={results.bmd}·/>⏎················`
<td><FloatingPointHover value={results.bmdu}/></td>
<td>{fractionalFormatter(getPValue(dataset.dtype, results))}</td>
<td>{ff(results.fit.aic)}</td>
<td><FloatingPointHover value={results.fit.aic}/></td>
<td>{ff(results.gof.residual[0])}</td>
<td>{ff(results.gof.roi)}</td>
<RecommendationTd
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Output/Multitumor/MsCombo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MsComboSummary extends Component {
["BMD", ff(results.bmd), results.bmd],
["BMDL", ff(results.bmdl), results.bmdl],
["BMDU", ff(results.bmdu), results.bmdu],
["Slope Factor", ff(results.slope_factor)],
["Slope Factor", ff(results.slope_factor), results.slope_factor],
["Combined Log-Likelihood", ff(results.ll)],
["Combined Log-Likelihood Constant", ff(results.ll_constant)],
];
Expand Down
29 changes: 12 additions & 17 deletions frontend/src/components/Output/Multitumor/ResultTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {inject, observer} from "mobx-react";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";
import {getNameFromDegrees} from "@/constants/modelConstants";
import {ff} from "@/utils/formatters";

Expand Down Expand Up @@ -62,18 +62,15 @@ class ResultTable extends Component {
</td>
<td>-</td>
<td>
{ff(results.bmdl)}
<LongFloatPopover content={`${results.bmdl}`} />
<FloatingPointHover value={results.bmdl} />
</td>
<td>
{ff(results.bmd)}
<LongFloatPopover content={`${results.bmd}`} />
<FloatingPointHover value={results.bmd} />
</td>
<td>
{ff(results.bmdu)}
<LongFloatPopover content={`${results.bmdu}`} />
<FloatingPointHover value={results.bmdu} />
</td>
<td>{ff(results.slope_factor)}</td>
<td><FloatingPointHover value={results.slope_factor} /></td>
<td>-</td>
<td>-</td>
<td>-</td>
Expand Down Expand Up @@ -106,22 +103,20 @@ class ResultTable extends Component {
</td>
<td>{dataset.metadata.name}</td>
<td>
{ff(model.bmdl)}
<LongFloatPopover content={`${results.bmdl}`} />
<FloatingPointHover value={results.bmdl} />
</td>
<td>
{ff(model.bmd)}
<LongFloatPopover content={`${model.bmd}`} />
<FloatingPointHover value={model.bmd} />
</td>
<td>
{ff(model.bmdu)}
<LongFloatPopover content={`${model.bmdu}`} />
<FloatingPointHover value={model.bmdu} />
</td>
<td>
<FloatingPointHover value={model.slope_factor} />
</td>
<td>{ff(model.slope_factor)}</td>
<td>{ff(model.gof.p_value)}</td>
<td>
{ff(model.fit.aic)}
<LongFloatPopover content={`${model.bmdl}`} />
<FloatingPointHover value={model.bmdl} />
</td>
<td>{ff(model.gof.residual[0])}</td>
<td>{ff(model.gof.roi)}</td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Output/Multitumor/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Summary extends Component {
["BMD", ff(model.bmd), model.bmd],
["BMDL", ff(model.bmdl), model.bmdl],
["BMDU", ff(model.bmdu), model.bmdu],
["Slope Factor", ff(model.slope_factor)],
["Slope Factor", ff(model.slope_factor), model.slope_factor],
["AIC", ff(model.fit.aic), model.fit.aic],
[
<span key="0">
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/common/FloatingPointHover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PropTypes from "prop-types";
import React, {Component} from "react";

import {ff} from "@/utils/formatters";

import Popover from "./Popover";

class FloatingPointHover extends Component {
render() {
const {value} = this.props;
return (
<Popover element={"span"} content={value} title="Floating-Point Value">
{ff(value)}
</Popover>
);
}
}
FloatingPointHover.propTypes = {
value: PropTypes.number.isRequired,
};

export default FloatingPointHover;
26 changes: 0 additions & 26 deletions frontend/src/components/common/LongFloatPopover.js

This file was deleted.

17 changes: 6 additions & 11 deletions frontend/src/components/common/TwoColumnTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import _ from "lodash";
import PropTypes from "prop-types";
import React, {Component} from "react";

import LongFloatPopover from "@/components/common/LongFloatPopover";
import FloatingPointHover from "@/components/common/FloatingPointHover";

class TwoColumnTable extends Component {
render() {
const {id, data, label, colwidths} = this.props,
widths = colwidths.map(d => `${d}%`);
const formatPopover = function(value) {
let ff_val = value[1];
let raw_value = value[2];
if (ff_val !== "-" && raw_value) {
return <LongFloatPopover content={`${raw_value}`} />;
}
};
widths = colwidths.map(d => `${d}%`),
formatPopover = function(value, raw_value) {
return _.isFinite(raw_value)? <FloatingPointHover value={raw_value} /> :<span>{value}</span>;
};
return (
<table id={id} className="table table-sm table-bordered">
<colgroup>
Expand All @@ -31,8 +27,7 @@ class TwoColumnTable extends Component {
<tr key={i}>
<td>{item[0]}</td>
<td>
{item[1]}
{formatPopover(item)}
{formatPopover(item[1], item[2])}
</td>
</tr>
))}
Expand Down

0 comments on commit 869b464

Please sign in to comment.