generated plot file will automatically open

This commit is contained in:
K4RP4T 2024-05-26 17:28:02 +02:00
parent d2fb17df88
commit c388f4c7a5
4 changed files with 13 additions and 2 deletions

View File

@ -16,3 +16,4 @@ This project makes use of the following dependencies (specified in `profun.cabal
* bytestring (for ByteString type) * bytestring (for ByteString type)
* utf8-string (for conversion from String to ByteString) * utf8-string (for conversion from String to ByteString)
* time (for getting date) * time (for getting date)
* process (for opening svg file)

View File

@ -17,6 +17,7 @@ main = do
apiKey <- getWeatherKey apiKey <- getWeatherKey
generatePlot 20 35 25 --example generatePlot 20 35 25 --example
openPlot
putStrLn "Enter a city name: " putStrLn "Enter a city name: "
city <- getLine city <- getLine

View File

@ -1,6 +1,7 @@
module Plot where module Plot where
import Graphics.Rendering.Chart.Easy import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Diagrams import Graphics.Rendering.Chart.Backend.Diagrams
import System.Process (callCommand)
formatData :: Double -> Double -> Double -> [(Int, Double)] formatData :: Double -> Double -> Double -> [(Int, Double)]
@ -13,4 +14,11 @@ generatePlot yday tday tmrw = toFile def "plot/weather.svg" $ do
layout_margin .= 30 layout_margin .= 30
layout_y_axis . laxis_generate .= scaledAxis def (-10, 40) layout_y_axis . laxis_generate .= scaledAxis def (-10, 40)
layout_x_axis . laxis_generate .= autoIndexAxis ["Yesterday", "Today", "Tomorrow"] layout_x_axis . laxis_generate .= autoIndexAxis ["Yesterday", "Today", "Tomorrow"]
plot $ line "Degrees Celsius" [formatData yday tday tmrw] 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

View File

@ -74,7 +74,8 @@ executable profun
aeson ^>=2.2.2.0, aeson ^>=2.2.2.0,
bytestring ^>=0.12.1.0, bytestring ^>=0.12.1.0,
utf8-string ^>=1.0.2, utf8-string ^>=1.0.2,
time ^>=1.12.2 time ^>=1.12.2,
process ^>=1.6.18.0
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: app hs-source-dirs: app