24 lines
873 B
Haskell
24 lines
873 B
Haskell
module Plot where
|
|
import Graphics.Rendering.Chart.Easy
|
|
import Graphics.Rendering.Chart.Backend.Diagrams
|
|
import System.Process (callCommand)
|
|
|
|
|
|
formatData :: Double -> Double -> Double -> [(Int, Double)]
|
|
formatData yday tday tmrw = [(0, yday), (1, tday), (2, tmrw)]
|
|
|
|
|
|
generatePlot :: Double -> Double -> Double -> IO ()
|
|
generatePlot yday tday tmrw = toFile def "plot/weather.svg" $ do
|
|
layout_title .= "Yesterday, Today, and Tomorrow's Temperatures"
|
|
layout_margin .= 30
|
|
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 |