4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import React from 'react';
20 import './transmit-receive.scss'
21 class TransmitReceive extends React.Component {
25 // getDigits(number) {
26 // return Math.log(number) * Math.LOG10E + 1 | 0;
29 if (number < Math.pow(10,3)) {
31 } else if (number < Math.pow(10,6)) {
32 return [(number / Math.pow(10,3)), 'K'];
33 } else if (number < Math.pow(10,9)) {
34 return [(number / Math.pow(10,6)), 'M'];
35 } else if (number < Math.pow(10,12)) {
36 return [(number / Math.pow(10,9)), 'G'];
37 } else if (number < Math.pow(10,15)) {
38 return [(number / Math.pow(10,12)), 'T'];
39 } else if (number < Math.pow(10,18)) {
40 return [(number / Math.pow(10,15)), 'P'];
41 } else if (number < Math.pow(10,21)) {
42 return [(number / Math.pow(10,18)), 'E'];
43 } else if (number < Math.pow(10,24)) {
44 return [(number / Math.pow(10,21)), 'Z'];
45 } else if (number < Math.pow(10,27)) {
46 return [(number / Math.pow(10,24)), 'Z'];
48 return [(number / Math.pow(10,27)), 'Y'];
52 shouldComponentUpdate(nextProps, nextState) {
53 if (JSON.stringify(this.props.data) === JSON.stringify(nextProps.data)) {
63 <div className="transmit-receive-container">
64 <div className="transmit-container">
65 <div className="label">{this.props.data.outgoing.label}</div>
66 <div className="measure">{this.getUnits(this.props.data.outgoing.bytes)[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.outgoing.bytes)[1]}B</div>
67 <div className="measure">{this.getUnits(this.props.data.outgoing.packets)[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.outgoing.packets)[1]}P</div>
68 <div className="measure">{this.getUnits(this.props.data.outgoing['byte-rate'])[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.outgoing['byte-rate'])[1]}BPS</div>
69 <div className="measure">{this.getUnits(this.props.data.outgoing['packet-rate'])[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.outgoing['packet-rate'])[1]}PPS</div>
71 <div className="receive-container">
72 <div className="label">{this.props.data.incoming.label}</div>
73 <div className="measure">{this.getUnits(this.props.data.incoming.bytes)[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.incoming.bytes)[1]}B</div>
74 <div className="measure">{this.getUnits(this.props.data.incoming.packets)[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.incoming.packets)[1]}P</div>
75 <div className="measure">{this.getUnits(this.props.data.incoming['byte-rate'])[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.incoming['byte-rate'])[1]}BPS</div>
76 <div className="measure">{this.getUnits(this.props.data.incoming['packet-rate'])[0].toFixed(1)}</div><div className="units">{this.getUnits(this.props.data.incoming['packet-rate'])[1]}PPS</div>
85 export default TransmitReceive;