feat: Stock composition diagram stub
This commit is contained in:
parent
bdc92baf5f
commit
e69b55b0c7
|
@ -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)
|
Loading…
Reference in New Issue