11import React from "react"
22import range from "lodash/range"
33import { styled } from "@material-ui/core/styles"
4- import moment from "moment"
54import useColors from "../../hooks/use-colors"
65import TimeStamp from "../TimeStamp"
76
7+ import { formatTime } from "../../utils/format-time"
8+
89const Container = styled ( "div" ) ( ( { width, themeColors } ) => ( {
910 width,
1011 overflow : "hidden" ,
@@ -14,7 +15,7 @@ const Container = styled("div")(({ width, themeColors }) => ({
1415 color : themeColors . fg ,
1516} ) )
1617
17- const TimeText = styled ( "div" ) ( ( { x } ) => ( {
18+ const TimeText = styled ( "div" ) ( ( { x, faded } ) => ( {
1819 display : "inline-block" ,
1920 width : 80 ,
2021 fontSize : 12 ,
@@ -24,6 +25,7 @@ const TimeText = styled("div")(({ x }) => ({
2425 borderLeft : "1px solid rgba(255,255,255,0.5)" ,
2526 paddingLeft : 4 ,
2627 whiteSpace : "wrap" ,
28+ opacity : faded ? 0.5 : 1 ,
2729} ) )
2830
2931const Svg = styled ( "svg" ) ( {
@@ -32,25 +34,6 @@ const Svg = styled("svg")({
3234 bottom : 0 ,
3335} )
3436
35- export const formatTime = ( time , format , visibleDuration ) => {
36- const lessThan3DaysShown = visibleDuration < 1000 * 60 * 60 * 24 * 3
37- if ( format === "none" ) return time
38- if ( format === "dates" ) {
39- return (
40- moment ( time ) . format ( "L" ) +
41- ( ! lessThan3DaysShown ? "" : "\n" + moment ( time ) . format ( "h:mm:ss a" ) )
42- )
43- }
44- if ( time < 0 ) return ""
45- const deciSecs = Math . floor ( ( time % 1000 ) / 10 )
46- const secs = Math . floor ( ( time / 1000 ) % 60 )
47- const mins = Math . floor ( ( time / 60000 ) % 60 )
48- const hours = Math . floor ( time / ( 60000 * 60 ) )
49- return [ hours , mins , secs , deciSecs ]
50- . map ( ( t ) => t . toString ( ) . padStart ( 2 , "0" ) )
51- . join ( ":" )
52- }
53-
5437export const Timeline = ( {
5538 timeFormat,
5639 visibleTimeStart,
@@ -81,6 +64,7 @@ export const Timeline = ({
8164 < TimeText
8265 key = { timeTextIndex }
8366 x = { ( timeTextIndex / timeTextCount ) * width }
67+ faded = { timeTextTimes [ timeTextIndex ] < 0 }
8468 >
8569 { formatTime (
8670 timeTextTimes [ timeTextIndex ] ,
0 commit comments