profun/app/Plot.hs

24 lines
866 B
Haskell
Raw Normal View History

module Plot where
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Diagrams
import System.Process (callCommand)
2024-05-26 19:08:56 +02:00
formatData :: Float -> Float -> Float -> [(Int, Float)]
formatData yday tday tmrw = [(0, yday), (1, tday), (2, tmrw)]
2024-05-26 19:08:56 +02:00
generatePlot :: Float -> Float -> Float -> IO ()
generatePlot yday tday tmrw = toFile def "plot/weather.svg" $ do
layout_title .= "Yesterday, Today, and Tomorrow's Temperatures"
layout_margin .= 30
2024-05-26 12:52:54 +02:00
layout_y_axis . laxis_generate .= scaledAxis def (-10, 40)
layout_x_axis . laxis_generate .= autoIndexAxis ["Yesterday", "Today", "Tomorrow"]
plot $ line "Degrees Celsius" [formatData yday tday tmrw]
openPlot :: IO ()
openPlot = callCommand "start plot/weather.svg"
-- start plot/weather.svg -- Windows
-- xdg-open plot/weather.svg -- Linux
-- open plot/weather.svg -- macOS