-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathTest2.hs
More file actions
63 lines (51 loc) · 2.39 KB
/
Test2.hs
File metadata and controls
63 lines (51 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Test2 where
import Graphics.Rendering.Chart
import Data.Time.LocalTime
import Data.Colour
import Data.Colour.Names
import Data.Colour.SRGB
import Control.Lens
import Data.Default.Class
import Prices(prices2)
import Utils
chart :: [(LocalTime,Double,Double)] -> Bool -> Double -> Renderable (LayoutPick LocalTime Double Double)
chart prices showMinMax lwidth = layoutLRToRenderable $ chartLR prices showMinMax lwidth
chartLR :: [(LocalTime,Double,Double)] -> Bool -> Double -> LayoutLR LocalTime Double Double
chartLR prices showMinMax lwidth = layout
where
lineStyle c = line_width .~ 3 * lwidth
$ line_color .~ c
$ def ^. plot_lines_style
limitLineStyle c = line_width .~ lwidth
$ line_color .~ opaque c
$ line_dashes .~ [5,10]
$ def ^. plot_lines_style
price1 = plot_lines_style .~ lineStyle (opaque blue)
$ plot_lines_values .~ [[ (d, v) | (d,v,_) <- prices]]
$ plot_lines_title .~ "price 1"
$ def
price2 = plot_lines_style .~ lineStyle (opaque green)
$ plot_lines_values .~ [[ (d, v) | (d,_,v) <- prices]]
$ plot_lines_title .~ "price 2"
$ def
(min1,max1) = (minimum [v | (_,v,_) <- prices],maximum [v | (_,v,_) <- prices])
(min2,max2) = (minimum [v | (_,_,v) <- prices],maximum [v | (_,_,v) <- prices])
limits | showMinMax = [ Left $ hlinePlot "min/max" (limitLineStyle blue) min1,
Left $ hlinePlot "" (limitLineStyle blue) max1,
Right $ hlinePlot "min/max" (limitLineStyle green) min2,
Right $ hlinePlot "" (limitLineStyle green) max2 ]
| otherwise = []
bg = opaque $ sRGB 0 0 0.25
fg = opaque white
fg1 = opaque $ sRGB 0.0 0.0 0.15
layout = layoutlr_title .~"Price History"
$ layoutlr_background .~ solidFillStyle bg
$ layoutlr_axes_styles %~ (axis_grid_style .~ solidLine 1 fg1)
$ layoutlr_left_axis . laxis_override .~ axisGridHide
$ layoutlr_right_axis . laxis_override .~ axisGridHide
$ layoutlr_x_axis . laxis_override .~ axisGridHide
$ layoutlr_plots .~ ([Left (toPlot price1), Right (toPlot price2)] ++ limits)
$ layoutlr_grid_last .~ False
$ layoutlr_foreground .~ fg
$ def
-- main = main' "test2" (chart prices2 True 0.25)