added simple plot generator in svg format

This commit is contained in:
K4RP4T 2024-05-25 20:00:14 +02:00
parent 728dadc845
commit 0b21b7db40
4 changed files with 27 additions and 3 deletions

View File

@ -1,8 +1,12 @@
{-# LANGUAGE OverloadedStrings #-} --needed for string arguments
import Network.HTTP.Simple
import Plot
main :: IO ()
main = do
apiResponse <- httpLBS "POST http://httpbin.org/get"
putStrLn $ "Status code: " ++ show (getResponseStatusCode apiResponse)
generatePlot 20 30 25 --example

15
app/Plot.hs Normal file
View File

@ -0,0 +1,15 @@
module Plot where
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Diagrams
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_x_axis . laxis_generate .= autoIndexAxis ["Yesterday", "Today", "Tomorrow"]
plot $ line "Degrees Celsius" [formatData yday tday tmrw]

3
plot/weather.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 103 KiB

View File

@ -58,7 +58,7 @@ executable profun
main-is: Main.hs
-- Modules included in this executable, other than Main.
-- other-modules:
other-modules: Plot
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
@ -67,7 +67,9 @@ executable profun
build-depends: base ^>=4.17.2.1,
http-client ^>=0.7.17,
http-client-tls ^>=0.3.6.3,
http-conduit ^>=2.3.8.3
http-conduit ^>=2.3.8.3,
Chart ^>=1.9.5,
Chart-diagrams ^>=1.9.5
-- Directories containing source files.
hs-source-dirs: app