-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilledLinePlots.nim
74 lines (68 loc) · 2.22 KB
/
FilledLinePlots.nim
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
64
65
66
67
68
69
70
71
72
73
74
import std/[random]
import imgui
import implot
import utils
#------------------------
# demo_FilledLinePlots()
#------------------------
proc demo_FilledLinePlots*() =
var
xs1{.global.}: array[101, double]
ys1{.global.}: array[101, double]
ys2{.global.}: array[101, double]
ys3{.global.}: array[101, double]
randomize(0) # srand(0) : C++
for i in 0..<101:
xs1[i] = (float)i
ys1[i] = RandomRange(400.0, 450.0)
ys2[i] = RandomRange(275.0, 350.0)
ys3[i] = RandomRange(150.0, 225.0)
var
show_lines{.global.} = true
show_fills{.global.} = true
fill_ref{.global.} = 0.float32
shade_mode{.global.} = 0
flags{.global.} = 0.ImPlotShadedFlags
igCheckbox("Lines", addr show_lines)
igSameLine()
igCheckbox("Fills", addr show_fills)
if show_fills:
igSameLine()
if igRadioButton("To -INF", shade_mode == 0): shade_mode = 0
igSameLine()
if igRadioButton("To +INF", shade_mode == 1): shade_mode = 1
igSameLine()
if igRadioButton("To Ref", shade_mode == 2): shade_mode = 2
if shade_mode == 2:
igSameLine()
igSetNextItemWidth(100)
igDragFloat("##Ref", addr fill_ref, 1, -100, 500)
if ipBeginPlot("Stock Prices"):
ipSetupAxes("Days", "Price")
ipSetupAxesLimits(0, 100, 0, 500)
if show_fills:
ipPushStyleVar(ImPlotStyleVar.FillAlpha, 0.25f)
ipPlotShaded("Stock 1", xs1.ptz, ys1.ptz, 101
, if shade_mode == 0: -Inf
else:
if shade_mode == 1: Inf
else: fill_ref
, flags)
ipPlotShaded("Stock 2", xs1.ptz, ys2.ptz, 101
, if shade_mode == 0: -Inf
else:
if shade_mode == 1: Inf
else: fill_ref
, flags)
ipPlotShaded("Stock 3", xs1.ptz, ys3.ptz, 101
, if shade_mode == 0: -Inf
else:
if shade_mode == 1: Inf
else: fill_ref
, flags)
ipPopStyleVar()
if show_lines:
ipPlotLine("Stock 1", xs1.ptz, ys1.ptz, 101)
ipPlotLine("Stock 2", xs1.ptz, ys2.ptz, 101)
ipPlotLine("Stock 3", xs1.ptz, ys3.ptz, 101)
ipEndPlot()