@samitouri / QOS-React-2 / commits / d3522f1f66

Uses FormDuration and FormTime to format times that are 0 into something more readable

Subhan committed May 8, 2019 at 23:18 UTC d3522f1f66bc55ba5f1e227aea1d6b9d953a4f45
4 files changed +9 -16
src/devtools/views/Profiler/FlamegraphChartBuilder.js
+3 -3
@@ -1,6 +1,6 @@
1 // @flow
2
3 -import { calculateSelfDuration, fineTune } from './utils';
3 +import { calculateSelfDuration, formatDuration } from './utils';
4
5 import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
@@ -68,8 +68,8 @@ export function getChartData({
68
69 let label = `${name}${maybeKey}`;
70 if (didRender) {
71 - label += ` (${fineTune(selfDuration.toFixed(1))}ms of ${fineTune(
72 - actualDuration.toFixed(1)
71 + label += ` (${formatDuration(selfDuration)}ms of ${formatDuration(
72 + actualDuration
73 )}ms)`;
74 }
75
src/devtools/views/Profiler/RankedChartBuilder.js
+2 -2
@@ -1,6 +1,6 @@
1 // @flow
2
3 -import { calculateSelfDuration, fineTune } from './utils';
3 +import { calculateSelfDuration, formatDuration } from './utils';
4
5 import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
@@ -54,7 +54,7 @@ export function getChartData({
54
55 const name = node.displayName || 'Unknown';
56 const maybeKey = node.key !== null ? ` key="${node.key}"` : '';
57 - const label = `${name}${maybeKey} (${fineTune(selfDuration.toFixed(1))}ms)`;
57 + const label = `${name}${maybeKey} (${formatDuration(selfDuration)}ms)`;
58 chartNodes.push({
59 id,
60 label,
src/devtools/views/Profiler/SidebarSelectedFiberInfo.js
+2 -2
@@ -2,7 +2,7 @@
2
3 import React, { Fragment, useContext } from 'react';
4 import { ProfilerContext } from './ProfilerContext';
5 -import { formatDuration, formatTime, fineTune } from './utils';
5 +import { formatDuration, formatTime } from './utils';
6 import { StoreContext } from '../context';
7 import Button from '../Button';
8 import ButtonIcon from '../ButtonIcon';
@@ -50,7 +50,7 @@ export default function SidebarSelectedFiberInfo(_: Props) {
50 }
51 onClick={() => selectCommitIndex(commitIndex)}
52 >
53 - {fineTune(formatTime(time))}s for {fineTune(formatDuration(duration))}ms
53 + {formatTime(time)}s for {formatDuration(duration)}ms
54 </button>
55 );
56 }
src/devtools/views/Profiler/utils.js
+2 -9
@@ -57,11 +57,11 @@ export const getGradientColor = (value: number) => {
57 };
58
59 export const formatDuration = (duration: number) =>
60 - Math.round(duration * 10) / 10;
60 + Math.round(duration * 10) / 10 || '<0.1';
61 export const formatPercentage = (percentage: number) =>
62 Math.round(percentage * 100);
63 export const formatTime = (timestamp: number) =>
64 - Math.round(Math.round(timestamp) / 100) / 10;
64 + Math.round(Math.round(timestamp) / 100) / 10 || '<0.1';
65
66 export const scale = (
67 minValue: number,
@@ -72,10 +72,3 @@ export const scale = (
72 maxValue - minValue === 0
73 ? fallbackValue
74 : ((value - minValue) / (maxValue - minValue)) * (maxRange - minRange);
75 -
76 -export const fineTune = (duration: number | string): string => {
77 - if (Number(duration) === 0) {
78 - return '<0.1';
79 - }
80 - return `${duration}`;
81 -};