Plot-ho-matic 0.5.0.2 → 0.5.0.3
raw patch · 3 files changed
+35/−21 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Plot-ho-matic.cabal +5/−2
- README.md +1/−1
- src/PlotHo.hs +29/−18
Plot-ho-matic.cabal view
@@ -1,5 +1,5 @@ name: Plot-ho-matic-version: 0.5.0.2+version: 0.5.0.3 synopsis: Real-time line plotter for protobuf-like data license: BSD3 license-file: LICENSE@@ -15,7 +15,10 @@ CHANGELOG.md README.md description: {-Plot-ho-matic provides real-time plotting of time-series data with a simple interface.+Plot-ho-matic provides real-time plotting of time-series data with a simple interface ('addHistoryChannel').+There is also a more general interface to plot arbitrary data ('addChannel').+.+See the example on <http://www.github.com/ghorn/Plot-ho-matic> to help get started. } library
README.md view
@@ -1,7 +1,7 @@ Plot-ho-matic == -[](https://travis-ci.org/ghorn/Plot-ho-matic)+[](https://hackage.haskell.org/package/Plot-ho-matic) [](https://travis-ci.org/ghorn/Plot-ho-matic) See the example in the examples folder for usage.
src/PlotHo.hs view
@@ -4,11 +4,12 @@ module PlotHo ( Plotter+ , runPlotter , XAxisType(..)- , Lookup- , addChannel , addHistoryChannel- , runPlotter+ , addChannel+ -- * re-exported for convenience+ , Lookup ) where import qualified GHC.Stats@@ -36,7 +37,7 @@ import PlotHo.PlotTypes ( Channel(..) ) import PlotHo.GraphWidget ( newGraph ) -+-- | add channels to this, then run it with 'runPlotter' newtype Plotter a = Plotter { unPlotter :: IO (a, [ChannelStuff]) } deriving Functor instance Applicative Plotter where@@ -71,10 +72,14 @@ , csMkChanEntry :: CC.MVar [Gtk.Window] -> IO Gtk.VBox } -+-- | Simplified time-series channel which passes a "send message" function to a worker and forks it using 'forkIO'.+-- The plotter will plot a time series of messages sent by the worker.+-- The worker should pass True to reset the message history, so sending True the first message and False subsequent messages is a good starting place. addHistoryChannel :: Lookup a- => String -> XAxisType -> ((a -> Bool -> IO ()) -> IO ())+ => String -- ^ channel name+ -> XAxisType -- ^ what to use for the X axis+ -> ((a -> Bool -> IO ()) -> IO ()) -- ^ worker which is passed a "new message" function, this will be forked with 'forkIO' -> Plotter () addHistoryChannel name xaxisType action = do (chan, newMessage) <- liftIO $ newHistoryChannel name xaxisType@@ -83,12 +88,16 @@ , csMkChanEntry = newChannelWidget chan } -+-- | This is the general interface to plot whatever you want.+-- Use this when you want to give the whole time series in one go, rather than one at a time+-- such as with 'addHistoryChannel'.+-- Using types or data, you must encode the signal tree with the message so that+-- the plotter can build you the nice message toggle tree. addChannel ::- String- -> (a -> a -> Bool)- -> (a -> [Tree (String, String, Maybe (a -> [[(Double, Double)]]))])- -> ((a -> IO ()) -> IO ())+ String -- ^ channel name+ -> (a -> a -> Bool) -- ^ Is the signal tree the same? This is used for instance if signals have changed and the plotter needs to rebuild the signal tree. This lets you keep the plotter running and change other programs which send messages to the plotter.+ -> (a -> [Tree (String, String, Maybe (a -> [[(Double, Double)]]))]) -- ^ how to build the signal tree+ -> ((a -> IO ()) -> IO ()) -- ^ worker which is passed a "new message" function, this will be forked with 'forkIO' -> Plotter () addChannel name sameSignalTree toSignalTree action = do (chan, newMessage) <- liftIO $ newChannel name sameSignalTree toSignalTree@@ -132,10 +141,10 @@ type SignalTree a = Tree.Forest (String, String, Maybe (History a -> [[(Double, Double)]])) data XAxisType =- XAxisTime- | XAxisCount- | XAxisTime0- | XAxisCount0+ XAxisTime -- ^ time since the first message+ | XAxisTime0 -- ^ time since the first message, normalized to 0 (to reduce plot jitter)+ | XAxisCount -- ^ message index+ | XAxisCount0 -- ^ message index, normalized to 0 (to reduce plot jitter) sameHistorySignalTree :: Lookup a => XAxisType -> a -> a -> Bool sameHistorySignalTree xaxisType x y = hx == hy@@ -241,7 +250,7 @@ return (retChan, newMessage) -+-- | fire up the the GUI runPlotter :: Plotter () -> IO () runPlotter plotterMonad = do statsEnabled <- GHC.Stats.getGCStatsEnabled@@ -261,8 +270,10 @@ msg <- if statsEnabled then do stats <- GHC.Stats.getGCStats- return $ printf "The current memory usage is %.2f MB"- ((realToFrac (GHC.Stats.currentBytesUsed stats) :: Double) /(1024*1024))+ return $ init $ unlines+ [ printf "The current memory usage is %.2f MB"+ ((realToFrac (GHC.Stats.currentBytesUsed stats) :: Double) /(1024*1024))+ ] else return "(enable GHC statistics with +RTS -T)" Gtk.postGUISync $ Gtk.labelSetText statsLabel ("Welcome to Plot-ho-matic!\n" ++ msg) statsWorker