    module System.Taffybar.Widget.NetworkGraph where

    import qualified GI.Gtk
    import System.Taffybar.Context
    import System.Taffybar.Hooks
    import System.Taffybar.Information.Network
    import System.Taffybar.Widget.Generic.ChannelGraph
    import System.Taffybar.Widget.Generic.Graph

    logScale :: Double -> Double -> Double -> Double
    logScale :: Double -> Double -> Double -> Double
    logScale base :: Double
    base maxValue :: Double
    maxValue value :: Double
    value =
      Double -> Double -> Double
    forall a. Floating a => a -> a -> a
    logBase Double
    base (Double -> Double -> Double
    forall a. Ord a => a -> a -> a
    min Double
    value Double
    maxValue) Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / Double
    actualMax
        where actualMax :: Double
    actualMax = Double -> Double -> Double
    forall a. Floating a => a -> a -> a
    logBase Double
    base Double
    maxValue

    networkGraphNew :: GraphConfig -> Maybe [String] -> TaffyIO GI.Gtk.Widget
    networkGraphNew :: GraphConfig -> Maybe [String] -> TaffyIO Widget
    networkGraphNew config :: GraphConfig
    config interfaces :: Maybe [String]
    interfaces = do
      NetworkInfoChan chan :: BroadcastChan In [(String, (Rational, Rational))]
    chan <- TaffyIO NetworkInfoChan
    getNetworkChan
      let filterFn :: String -> Bool
    filterFn = (String -> Bool)
    -> ([String] -> String -> Bool) -> Maybe [String] -> String -> Bool
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (Bool -> String -> Bool
    forall a b. a -> b -> a
    const Bool
    True) ((String -> [String] -> Bool) -> [String] -> String -> Bool
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip String -> [String] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    elem) Maybe [String]
    interfaces
          getUpDown :: [(String, (Rational, Rational))] -> (Rational, Rational)
    getUpDown = [(Rational, Rational)] -> (Rational, Rational)
    sumSpeeds ([(Rational, Rational)] -> (Rational, Rational))
    -> ([(String, (Rational, Rational))] -> [(Rational, Rational)])
    -> [(String, (Rational, Rational))]
    -> (Rational, Rational)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((String, (Rational, Rational)) -> (Rational, Rational))
    -> [(String, (Rational, Rational))] -> [(Rational, Rational)]
    forall a b. (a -> b) -> [a] -> [b]
    map (String, (Rational, Rational)) -> (Rational, Rational)
    forall a b. (a, b) -> b
    snd ([(String, (Rational, Rational))] -> [(Rational, Rational)])
    -> ([(String, (Rational, Rational))]
        -> [(String, (Rational, Rational))])
    -> [(String, (Rational, Rational))]
    -> [(Rational, Rational)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((String, (Rational, Rational)) -> Bool)
    -> [(String, (Rational, Rational))]
    -> [(String, (Rational, Rational))]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (String -> Bool
    filterFn (String -> Bool)
    -> ((String, (Rational, Rational)) -> String)
    -> (String, (Rational, Rational))
    -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (String, (Rational, Rational)) -> String
    forall a b. (a, b) -> a
    fst)
          toLogScale :: Double -> Double
    toLogScale = Double -> Double -> Double -> Double
    logScale 2 (2 Double -> Double -> Double
    forall a. Floating a => a -> a -> a
    ** 32)
          toSample :: (Rational, Rational) -> [Double]
    toSample (up :: Rational
    up, down :: Rational
    down) = (Rational -> Double) -> [Rational] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map (Double -> Double
    toLogScale (Double -> Double) -> (Rational -> Double) -> Rational -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Rational -> Double
    forall a. Fractional a => Rational -> a
    fromRational) [Rational
    up, Rational
    down]
          sampleBuilder :: [(String, (Rational, Rational))] -> IO [Double]
    sampleBuilder = [Double] -> IO [Double]
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Double] -> IO [Double])
    -> ([(String, (Rational, Rational))] -> [Double])
    -> [(String, (Rational, Rational))]
    -> IO [Double]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Rational, Rational) -> [Double]
    toSample ((Rational, Rational) -> [Double])
    -> ([(String, (Rational, Rational))] -> (Rational, Rational))
    -> [(String, (Rational, Rational))]
    -> [Double]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [(String, (Rational, Rational))] -> (Rational, Rational)
    getUpDown
      GraphConfig
    -> BroadcastChan In [(String, (Rational, Rational))]
    -> ([(String, (Rational, Rational))] -> IO [Double])
    -> TaffyIO Widget
    forall (m :: * -> *) a.
    MonadIO m =>
    GraphConfig -> BroadcastChan In a -> (a -> IO [Double]) -> m Widget
    channelGraphNew GraphConfig
    config BroadcastChan In [(String, (Rational, Rational))]
    chan [(String, (Rational, Rational))] -> IO [Double]
    sampleBuilder