The plot surface moves here from Kryon, which no longer ships it. Plot exports PlotWidget for apps that draw their own series next to the Plot charts, and every Kryon import names its package (kryon/Kryon, kryon/session, ...). The widget's behavior test runs as a portable bundle and in Go, binding Kryon's host capabilities by import path.
96 lines
3.0 KiB
Ziran
96 lines
3.0 KiB
Ziran
#import "kryon/session"
|
|
test_session: Session;
|
|
TestSession :: () -> Session {
|
|
if !SessionValid(test_session) { test_session = SessionOpen() }
|
|
return test_session
|
|
}
|
|
|
|
#import "kryon/geometry"
|
|
#import "kryon/paint_queue"
|
|
#import "plot"
|
|
#import "plot_props"
|
|
#import "plot_widget"
|
|
#import "kryon/tree"
|
|
#import "kryon/widget_kind"
|
|
|
|
using PlotMode;
|
|
using WidgetKind;
|
|
|
|
phase: s32;
|
|
|
|
#program_export
|
|
Frame :: () -> s32 {
|
|
lines: [3]float32
|
|
lines[0] = 0.0
|
|
lines[1] = 0.5
|
|
lines[2] = 1.0
|
|
bars: [3]float32
|
|
bars[0] = 0.25
|
|
bars[1] = 0.5
|
|
bars[2] = 1.0
|
|
automatic: PlotProps
|
|
observed: PlotRange = PlotObservedRange(bars[0:3], -1,
|
|
automatic)
|
|
if observed.min_value != 0.25 ||
|
|
observed.max_value != 1.0 ||
|
|
observed.range != 0.75 { return -2 }
|
|
if PlotOffset(0, 5) != 0 || PlotOffset(4, 6) != 2 ||
|
|
PlotOffset(4, -1) != 3 || PlotOffset(4, -6) != 2 ||
|
|
PlotOffset(1, 99) != 0 { return -3 }
|
|
fixed: PlotRange = PlotRangeFor(0.0, 10.0, -1.0, 20.0)
|
|
if fixed.min_value != 0.0 || fixed.max_value != 10.0 ||
|
|
fixed.range != 10.0 || PlotNormalize(5.0, fixed) != 0.5 ||
|
|
PlotNormalize(-5.0, fixed) != 0.0 ||
|
|
PlotNormalize(50.0, fixed) != 1.0 { return -4 }
|
|
singleton: PlotRange = PlotRangeFor(10.0, 5.0, 3.0, 3.0)
|
|
if singleton.min_value != 2.5 ||
|
|
singleton.max_value != 3.5 ||
|
|
singleton.range != 1.0 { return -5 }
|
|
line_props: PlotProps
|
|
line_props.key = cast(u64)11
|
|
line_props.bounds = Rectangle.{10.0, 10.0, 100.0, 60.0}
|
|
line_props.label = "Trend"
|
|
line_props.semantic_label = "XMR price trend"
|
|
line_props.overlay = "Now"
|
|
line_props.scale_min = 0.0
|
|
line_props.scale_max = 1.0
|
|
bar_props: PlotProps
|
|
bar_props.key = cast(u64)12
|
|
bar_props.bounds = Rectangle.{10.0, 90.0, 100.0, 60.0}
|
|
bar_props.label = "Bars"
|
|
bar_props.overlay = "Peak"
|
|
bar_props.offset = 1
|
|
bar_props.scale_min = 0.0
|
|
bar_props.scale_max = 1.0
|
|
bar_props.mode = cast(PlotMode)PlotBars
|
|
TreeStart(TestSession(), cast(u64)1, Rectangle.{0.0, 0.0, 140.0, 180.0})
|
|
if Plot(TestSession(), line_props, lines[0:3]) != 1 ||
|
|
Plot(TestSession(), bar_props, bars[0:3]) != 2 ||
|
|
!TreeFinish(TestSession()) || TreeCount(TestSession()) != 3 ||
|
|
TreeNodeAt(TestSession(), 1).kind != WidgetKindPlot ||
|
|
TreeNodeAt(TestSession(), 2).kind != WidgetKindPlot ||
|
|
TreeNodeAt(TestSession(), 1).semantic_label != "XMR price trend" ||
|
|
TreeNodeAt(TestSession(), 2).semantic_label != "Bars" { return -1 }
|
|
PaintFlush(TestSession())
|
|
old: s32 = phase
|
|
phase += 1
|
|
return old
|
|
}
|
|
|
|
#import "plot_widget_host"
|
|
|
|
#program_export
|
|
main :: () -> s32 {
|
|
index: s32 = 0
|
|
while index < 2 {
|
|
if Frame() != index || PlotHostFailed() { return 1 }
|
|
if PlotBackgrounds() != (index + 1) * 2 ||
|
|
PlotMarks() != (index + 1) * 3 ||
|
|
PlotOutlines() != (index + 1) * 2 ||
|
|
PlotLineCount() != (index + 1) * 2 ||
|
|
PlotLabels() != (index + 1) * 4 { return 2 }
|
|
index += 1
|
|
}
|
|
return 0
|
|
}
|