Improve ratio display

This commit is contained in:
Drew DeVault 2017-12-29 02:07:40 -05:00
parent b75f89ed7d
commit 40c8c73166
4 changed files with 42 additions and 8 deletions

View File

@ -188,6 +188,22 @@ fieldset .form-check-input:only-child {
} }
} }
.ratio {
& > * {
padding: 0 0.5rem;
}
}
.torrents .ratio {
display: flex;
& > * {
padding: 0;
flex: 1 1 0;
text-align: right;
}
}
.progress { .progress {
border-radius: 0; border-radius: 0;

View File

@ -33,6 +33,8 @@ export function formatBitrate(bitrate) {
places = 0; places = 0;
} else if (rate >= 10) { } else if (rate >= 10) {
places = 1; places = 1;
} else if (rate == 0) {
places = 0;
} }
return `${rate.toFixed(places)} ${unit}`; return `${rate.toFixed(places)} ${unit}`;
} }
@ -50,6 +52,8 @@ export function formatAmount(amount) {
places = 0; places = 0;
} else if (rate >= 10) { } else if (rate >= 10) {
places = 1; places = 1;
} else if (rate == 0) {
places = 0;
} }
return `${rate.toFixed(places)} ${units[unit]}`; return `${rate.toFixed(places)} ${units[unit]}`;
} }

View File

@ -5,18 +5,26 @@ import { formatAmount } from '../bitrate';
export default function Ratio({ up, down }) { export default function Ratio({ up, down }) {
const ratio = up / down; const ratio = up / down;
if (isNaN(ratio)) { if (isNaN(ratio)) {
return <span>0</span>; return <span class="ratio">
<span>0</span>
<span></span>
<span></span>
</span>;
} }
if (!isFinite(ratio)) { if (!isFinite(ratio)) {
return <span></span>; return <span class="ratio">
<strong></strong>
<span></span>
<span></span>
</span>;
} }
return ( return (
<span class="ratio">
<span> <span>
<span> {`${ratio.toFixed(2)}`}
{`${ratio.toFixed(3)} `}
</span> </span>
<span>({formatAmount(up)} <FontAwesome name="arrow-up" /></span> <span>{formatAmount(up)} <FontAwesome name="arrow-up" /></span>
<span>{` ${formatAmount(down)}`} <FontAwesome name="arrow-down" />)</span> <span>{`${formatAmount(down)}`} <FontAwesome name="arrow-down" /></span>
</span> </span>
); );
} }

View File

@ -9,7 +9,7 @@ class TorrentTable extends Component {
render() { render() {
const { selection, torrents, dispatch } = this.props; const { selection, torrents, dispatch } = this.props;
return ( return (
<table className="table"> <table className="table torrents">
<thead> <thead>
<tr> <tr>
<th style={{width: "1px"}}> <th style={{width: "1px"}}>
@ -28,7 +28,13 @@ class TorrentTable extends Component {
<th>name</th> <th>name</th>
<th>up</th> <th>up</th>
<th>down</th> <th>down</th>
<th>ratio</th> <th style={{width: "18rem"}}>
<span class="ratio">
<span>ratio</span>
<span></span>
<span></span>
</span>
</th>
<th>progress</th> <th>progress</th>
</tr> </tr>
</thead> </thead>