Stock composition version #1

Open
aniva wants to merge 5 commits from stock-composition into main
1 changed files with 52 additions and 0 deletions
Showing only changes of commit e69b55b0c7 - Show all commits

View File

@ -0,0 +1,52 @@
using Base
import Luxor as L
@kwdef struct Component
pos::Tuple{UInt, UInt}
size::Tuple{UInt, UInt}
name::String
diff::Real
end
@kwdef struct CompositionDiagram
components::Array{Component}
end
"""
Draws stock index composition chart
"""
function draw(diagram::CompositionDiagram, size=(800, 600))
L.Drawing(size[1], size[2], :png)
L.background("black")
L.sethue("white")
for component in diagram.components
pos = L.Point(component.pos)
if component.diff > 0
L.setcolor("green")
else
L.setcolor("red")
end
L.rect(pos, component.size[1], component.size[2], action = :fillstroke)
L.setcolor("white")
L.settext(
component.name,
L.Point(component.pos .+ component.size ./ 2),
halign="center",
valign="bottom",
)
L.settext(
"$(component.diff)%",
L.Point(component.pos .+ component.size ./ 2),
halign="center",
valign="top",
)
end
L.finish()
end
diagram = CompositionDiagram(
components=[
Component(pos=(0,0), size=(200,200),name="AAPL", diff=0.5),
Component(pos=(0,200), size=(200,100),name="GOOG", diff=-0.3),
],
)
draw(diagram)