diff --git a/Makefile b/Makefile index 73183fa..fac318a 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,33 @@ ZIRAN_INCLUDE := $(shell $(ZIRAN) pkg path ziran)/include .PHONY: run build check run build: - $(ZIRAN) tool Kryon $@ + $(ZIRAN) tool kryon $@ + +HOST := plot_widget_host +# The widget test draws through Kryon's host capabilities; its host module +# provides them. Kryon's modules are named by their import paths. +BINDS := \ + --bind kryon/font_metrics:MeasureGlyphWidth=$(HOST):MeasureGlyphWidth \ + --bind kryon/raster_text:RasterText=$(HOST):RasterText \ + --bind kryon/raster_text:RasterTextClipped=$(HOST):RasterTextClipped \ + --bind kryon/raster_shape:RasterRoundedRectangle=$(HOST):RasterRoundedRectangle \ + --bind kryon/raster_shape:RasterRoundedRectangleOutline=$(HOST):RasterRoundedRectangleOutline \ + --bind kryon/raster:RasterLine=$(HOST):RasterLine \ + --bind kryon/paint_queue:RasterImage=$(HOST):RasterImage check: - $(ZIRAN) tool Kryon check + $(ZIRAN) tool kryon check + $(ZIRAN) bundle --project $(BINDS) --entry plot_widget_behavior:main \ + -o build/plot-widget.zib tests/plot_widget_behavior.zi + test "$$($(ZIRAN) run build/plot-widget.zib)" = 0 + @if command -v go >/dev/null; then \ + rm -rf build/plot-widget-go && \ + $(ZIRAN) build --project --target=go --pkg main --exe $(BINDS) \ + --entry plot_widget_behavior:main -o build/plot-widget-go \ + tests/plot_widget_behavior.zi && \ + cd build/plot-widget-go && env -u DISPLAY -u WAYLAND_DISPLAY \ + GO111MODULE=off go run *.go ; \ + fi mkdir -p build/indicator-test-c $(ZIRAN) build --project --target=c --entry indicator_test:main \ -o build/indicator-test-c \ diff --git a/README.md b/README.md index 1c42ed4..c8f237c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Plot -`plot` is a Ziran app package that depends on the separate Kryon package. Its candle -chart draws OHLC bodies and wicks, volume, SMA 20, SMA 50, and EMA 20 over -Kryon's generic `Plot` surface. `ChartMarker` and `CandleMarkers` add dated, +`plot` is a Ziran package that depends on the separate Kryon package. It +owns `PlotWidget`, a retained Kryon widget that draws lines, bars, markers, +and axes over caller-owned values, and its candle chart draws OHLC bodies and +wicks, volume, SMA 20, SMA 50, and EMA 20 over that surface. `ChartMarker` and `CandleMarkers` add dated, clickable markers while leaving each marker's meaning to the caller. It also has a simple line chart. Both accept caller-owned values and colors; market data, networking, price formatting, @@ -19,13 +20,14 @@ charts and Kryon's public UI surface; app code can use To add Plot to another Ziran project, run: ```sh -ziran add kryonlabs/plot +ziran add https://github.com/kryonlabs/plot.git ``` -Then import its public module: +Then import its public module, or only the chart surface: ```zi -using Charts :: #import "Plot"; +using Charts :: #import "plot/Plot"; +using Surface :: #import "plot/PlotWidget"; ``` The package exports `PriceBar`, `CandleChartProps`, `CandleChart`, diff --git a/src/PlotWidget/module.zi b/src/PlotWidget/module.zi new file mode 100644 index 0000000..0357684 --- /dev/null +++ b/src/PlotWidget/module.zi @@ -0,0 +1,4 @@ +// Optional chart widget surface. Apps import this only when they use charts. +using PlotPropsModule :: #import "plot_props"; +using PlotModule :: #import "plot"; +using PlotWidgetModule :: #import "plot_widget"; diff --git a/src/candle_chart.zi b/src/candle_chart.zi index b40211f..e50042e 100644 --- a/src/candle_chart.zi +++ b/src/candle_chart.zi @@ -1,4 +1,4 @@ -using UI :: #import "Kryon"; +using UI :: #import "kryon/Kryon"; using PlotWidget :: #import "PlotWidget"; PriceBar :: struct { diff --git a/src/line_chart.zi b/src/line_chart.zi index 0601a43..fc32a8b 100644 --- a/src/line_chart.zi +++ b/src/line_chart.zi @@ -1,4 +1,4 @@ -using UI :: #import "Kryon"; +using UI :: #import "kryon/Kryon"; using PlotWidget :: #import "PlotWidget"; ChartRange :: struct { diff --git a/src/module.zi b/src/module.zi index 10b4726..4b07f4b 100644 --- a/src/module.zi +++ b/src/module.zi @@ -1,4 +1,4 @@ // Reusable chart API, independent of the demo application's entry. -using UI :: #import "Kryon"; +using UI :: #import "kryon/Kryon"; using Candle :: #import "candle_chart"; using Line :: #import "line_chart"; diff --git a/src/plot.zi b/src/plot.zi new file mode 100644 index 0000000..4047fb9 --- /dev/null +++ b/src/plot.zi @@ -0,0 +1,167 @@ +#import "kryon/control_props" +#import "kryon/drawing_props" +#import "kryon/geometry" +#import "kryon/style" + +using StyleField; + +PlotRange :: struct { + min_value: float32 + max_value: float32 + range: float32 +} + +PlotMark :: struct { + bounds: Rectangle + color: u32 +} + +PlotTextPaint :: struct { + label_bounds: Rectangle + overlay_bounds: Rectangle + text_color: u32 + show_label: bool + show_overlay: bool +} + +PlotMetric :: (fields: u32, field: u32, value: float32, + fallback: float32, scale: float32) -> float32 { + if (fields & field) == cast(u32)0 || value < 0.0 { value = fallback } + return value * scale +} + +#program_export +PlotOffset :: (count: s32, offset: s32) -> s32 { + if count <= 0 { + return 0 + } + wrapped: s32 = offset % count + if wrapped < 0 { + wrapped = wrapped + count + } + return wrapped +} + +#program_export +PlotRangeFor :: (scale_min: float32, scale_max: float32, + observed_min: float32, observed_max: float32) -> PlotRange { + result: PlotRange + result.min_value = scale_min + result.max_value = scale_max + if result.min_value >= result.max_value { + result.min_value = observed_min + result.max_value = observed_max + } + if result.min_value == result.max_value { + result.min_value = result.min_value - 0.5 + result.max_value = result.max_value + 0.5 + } + result.range = result.max_value - result.min_value + if result.range <= 0.0 { + result.range = 1.0 + } + return result +} + +#program_export +PlotNormalize :: (value: float32, plot_range: PlotRange) -> float32 { + t: float32 = (value - plot_range.min_value) / plot_range.range + if t < 0.0 { + return 0.0 + } + if t > 1.0 { + return 1.0 + } + return t +} + +#program_export +PlotHistogramBar :: (bounds: Rectangle, index: s32, count: s32, + value: float32, plot_range: PlotRange, mark_frame: StyleFrame) -> PlotMark { + mark: PlotMark + if count <= 0 { + mark.color = mark_frame.value.background + return mark + } + step: float32 = bounds.width / cast(float32)count + height: float32 = PlotNormalize(value, plot_range) * bounds.height + width: float32 = step - 2.0 + if width < 1.0 { + width = step + } + mark.bounds.x = bounds.x + cast(float32)index * step + 1.0 + mark.bounds.y = bounds.y + bounds.height - height + mark.bounds.width = width + mark.bounds.height = height + mark.color = mark_frame.value.background + return mark +} + +#program_export +PlotSingleLine :: (bounds: Rectangle, value: float32, + plot_range: PlotRange, mark_frame: StyleFrame) -> PlotMark { + mark: PlotMark + y: float32 = bounds.y + (1.0 - PlotNormalize(value, plot_range)) * bounds.height + mark.bounds.x = bounds.x + mark.bounds.y = y + mark.bounds.width = bounds.width + mark.bounds.height = 0.0 + mark.color = mark_frame.value.background + return mark +} + +#program_export +PlotLineSegment :: (bounds: Rectangle, index: s32, count: s32, + a: float32, b: float32, plot_range: PlotRange, mark_frame: StyleFrame) -> PlotMark { + mark: PlotMark + if count <= 1 { + return PlotSingleLine(bounds, b, plot_range, mark_frame) + } + x1: float32 = bounds.x + cast(float32)(index - 1) * bounds.width / cast(float32)(count - 1) + x2: float32 = bounds.x + cast(float32)index * bounds.width / cast(float32)(count - 1) + y1: float32 = bounds.y + (1.0 - PlotNormalize(a, plot_range)) * bounds.height + y2: float32 = bounds.y + (1.0 - PlotNormalize(b, plot_range)) * bounds.height + mark.bounds.x = x1 + mark.bounds.y = y1 + mark.bounds.width = x2 - x1 + mark.bounds.height = y2 - y1 + mark.color = mark_frame.value.background + return mark +} + +#program_export +PlotTextPaintFor :: (bounds: Rectangle, label_width: float32, + overlay_width: float32, scale: float32, frame: StyleFrame, + show_label: bool, show_overlay: bool) -> PlotTextPaint { + paint: PlotTextPaint + if scale <= 0.0 { + scale = 1.0 + } + pad_x: float32 = PlotMetric(frame.value.fields, cast(u32)StylePaddingX, + frame.value.padding_x, 6.0, scale) + pad_y: float32 = PlotMetric(frame.value.fields, cast(u32)StylePaddingY, + frame.value.padding_y, 4.0, scale) + text_height: float32 = PlotMetric(frame.value.fields, cast(u32)StyleFontSize, + frame.value.font_size, 18.0, scale) + if text_height <= 0.0 { text_height = 18.0 * scale } + paint.text_color = frame.value.foreground + paint.show_label = show_label + paint.show_overlay = show_overlay + paint.label_bounds.x = bounds.x + pad_x + paint.label_bounds.y = bounds.y + pad_y + paint.label_bounds.width = label_width + paint.label_bounds.height = text_height + paint.overlay_bounds.x = bounds.x + bounds.width - overlay_width - pad_x + paint.overlay_bounds.y = bounds.y + pad_y + paint.overlay_bounds.width = overlay_width + paint.overlay_bounds.height = text_height + if !show_label { + paint.label_bounds.width = 0.0 + paint.label_bounds.height = 0.0 + } + if !show_overlay { + paint.overlay_bounds.width = 0.0 + paint.overlay_bounds.height = 0.0 + } + return paint +} diff --git a/src/plot_props.zi b/src/plot_props.zi new file mode 100644 index 0000000..885551f --- /dev/null +++ b/src/plot_props.zi @@ -0,0 +1,23 @@ +#import "kryon/geometry" + +PlotMode :: enum { + PlotLines :: 0 + PlotBars :: 1 +} + +PlotProps :: struct { + key: u64 + bounds: Rectangle + id: s32 + class_name: s32 + label: string + // Accessible name without drawing text over the plot; label remains the + // visible caption when one is wanted. + semantic_label: string + overlay: string + offset: s32 + scale_min: float32 + scale_max: float32 + scale: float32 + mode: PlotMode +} diff --git a/src/plot_widget.zi b/src/plot_widget.zi new file mode 100644 index 0000000..e267dba --- /dev/null +++ b/src/plot_widget.zi @@ -0,0 +1,188 @@ +#import "kryon/session" +#import "kryon/control_props" +#import "kryon/drawing_props" +#import "kryon/font_metrics" +#import "kryon/geometry" +#import "kryon/paint_queue" +#import "plot" +#import "plot_props" +#import "kryon/style" +#import "kryon/style_sheet" +#import "kryon/surface" +#import "kryon/tree" +#import "kryon/widget_kind" + +using PlotMode; +using WidgetKind; +using ButtonTone; +using ButtonEmphasis; +using ControlSize; +using ButtonState; +using StyleField; + +PlotFaces :: struct { + plot: StyleFrame + mark: StyleFrame +} + +#program_export +DefaultPlotFaces :: () -> PlotFaces { + faces: PlotFaces + faces.plot.value.fields = cast(u32)StyleBackground | + cast(u32)StyleForeground | cast(u32)StyleBorder | + cast(u32)StyleBorderWidth | cast(u32)StyleRadius | + cast(u32)StyleFontSize | cast(u32)StylePaddingX | + cast(u32)StylePaddingY | cast(u32)StyleOpacity + faces.plot.value.background = cast(u32)0xf5f5f5ff + faces.plot.value.foreground = cast(u32)0x171717ff + faces.plot.value.border = cast(u32)0x737373ff + faces.plot.value.border_width = 1.0 + faces.plot.value.radius = 4.0 + faces.plot.value.font_size = 14.0 + faces.plot.value.padding_x = 6.0 + faces.plot.value.padding_y = 4.0 + faces.plot.value.opacity = 1.0 + faces.mark.value.fields = cast(u32)StyleBackground | + cast(u32)StyleOpacity + faces.mark.value.background = cast(u32)0x3b609bff + faces.mark.value.opacity = 1.0 + return faces +} + +#program_export +PlotFacesFor :: (props: PlotProps, + defaults: PlotFaces) -> PlotFaces { + faces: PlotFaces = defaults + plot_facts: StyleFacts = StyleControlRoleFacts(StyleKindPlot(), + props.id, props.class_name, StyleAny(), + cast(s32)ButtonToneNeutral, cast(s32)ButtonEmphasisFilled, + cast(s32)ControlSizeMedium, cast(s32)ButtonStateNormal) + mark_facts: StyleFacts = StyleControlRoleFacts(StyleKindPlotMark(), + props.id, props.class_name, StyleAny(), + cast(s32)ButtonToneAccent, cast(s32)ButtonEmphasisFilled, + cast(s32)ControlSizeMedium, cast(s32)ButtonStateNormal) + faces.plot.value = ResolveInstalledStyleRules(defaults.plot.value, + plot_facts, cast(s32)ButtonStateNormal) + faces.mark.value = ResolveInstalledStyleRules(defaults.mark.value, + mark_facts, cast(s32)ButtonStateNormal) + return faces +} + +#program_export +PlotObservedRange :: (values: []float32, + offset: s32, props: PlotProps) -> PlotRange { + offset = PlotOffset((cast(s32)values.count), offset) + observed_min: float32 = 0.0 + observed_max: float32 = 0.0 + if (cast(s32)values.count) > 0 { + observed_min = values[offset] + observed_max = observed_min + index: s32 = 1 + while index < (cast(s32)values.count) { + value: float32 = values[(offset + index) % (cast(s32)values.count)] + if value < observed_min { observed_min = value } + if value > observed_max { observed_max = value } + index += 1 + } + } + return PlotRangeFor(props.scale_min, props.scale_max, + observed_min, observed_max) +} + +// Values are borrowed for this frame. The retained node keeps only its key, +// bounds, and semantic label; the caller supplies the next frame's values. +#program_export +Plot :: (session: Session, props: PlotProps, values: []float32) -> s32 { + bounds: Rectangle = props.bounds + if bounds.width <= 0.0 || bounds.height <= 0.0 { return -1 } + key: u64 = props.key + if key == cast(u64)0 && props.id > 0 { key = cast(u64)cast(u32)props.id } + if key == cast(u64)0 { key = TreeNextKey(session) } + node: s32 = -1 + if TreeIsBuilding(session) { + node = TreeSubmitCurrent(session, key, WidgetKindPlot, bounds) + if node < 0 { return -1 } + semantic_label: string = props.label + if props.semantic_label != "" { + semantic_label = props.semantic_label + } + TreeSetLabel(session, node, semantic_label) + bounds = TreeSubmittedNodeAt(session, node).bounds + } + faces: PlotFaces = PlotFacesFor(props, + DefaultPlotFaces()) + opacity: float32 = StyleOpacityValue(faces.plot.value.fields, + faces.plot.value.opacity) + PaintRoundedFill(session, node, bounds, faces.plot.value.radius, 12, + ColorFromPacked(Opacity(faces.plot.value.background, opacity))) + if faces.plot.value.border_width > 0.0 { + PaintRoundedOutline(session, node, bounds, faces.plot.value.radius, 12, + faces.plot.value.border_width, + ColorFromPacked(Opacity(faces.plot.value.border, opacity))) + } + if (cast(s32)values.count) > 0 { + offset: s32 = PlotOffset((cast(s32)values.count), props.offset) + value_range: PlotRange = PlotObservedRange(values, offset, props) + mark_color: Color = ColorFromPacked(Opacity( + faces.mark.value.background, + StyleOpacityValue(faces.mark.value.fields, + faces.mark.value.opacity))) + index: s32 = 0 + if props.mode == cast(PlotMode)PlotBars { + while index < (cast(s32)values.count) { + mark: PlotMark = PlotHistogramBar(bounds, index, + (cast(s32)values.count), values[(offset + index) % (cast(s32)values.count)], + value_range, faces.mark) + if mark.bounds.width > 0.0 && mark.bounds.height > 0.0 { + PaintRoundedFill(session, node, mark.bounds, 0.0, 0, mark_color) + } + index += 1 + } + } else if (cast(s32)values.count) == 1 { + mark: PlotMark = PlotSingleLine(bounds, values[offset], + value_range, faces.mark) + PaintLine(session, node, mark.bounds, mark_color) + } else { + index = 1 + while index < (cast(s32)values.count) { + a: float32 = values[(offset + index - 1) % (cast(s32)values.count)] + b: float32 = values[(offset + index) % (cast(s32)values.count)] + mark: PlotMark = PlotLineSegment(bounds, index, + (cast(s32)values.count), a, b, value_range, faces.mark) + PaintLine(session, node, mark.bounds, mark_color) + index += 1 + } + } + } + if props.label != "" || props.overlay != "" { + font: s32 = ResolveFont(0, + StyleFontValue(faces.plot.value.fields, + faces.plot.value.font_size), 14) + label_width: float32 = 0.0 + overlay_width: float32 = 0.0 + if props.label != "" { + label_width = cast(float32)GlyphWidth(props.label, font, + faces.plot.value.typeface) + } + if props.overlay != "" { + overlay_width = cast(float32)GlyphWidth(props.overlay, font, + faces.plot.value.typeface) + } + paint: PlotTextPaint = PlotTextPaintFor(bounds, label_width, + overlay_width, props.scale, faces.plot, + props.label != "", props.overlay != "") + text_color: Color = ColorFromPacked(Opacity(paint.text_color, + opacity)) + if paint.show_label { + PaintClippedLabel(session, node, props.label, + cast(s32)paint.label_bounds.x, + cast(s32)paint.label_bounds.y, font, text_color, bounds) + } + if paint.show_overlay { + PaintClippedLabel(session, node, props.overlay, + cast(s32)paint.overlay_bounds.x, + cast(s32)paint.overlay_bounds.y, font, text_color, bounds) + } + } + return node +} diff --git a/tests/indicator_test.zi b/tests/indicator_test.zi index f464f60..decec65 100644 --- a/tests/indicator_test.zi +++ b/tests/indicator_test.zi @@ -1,5 +1,5 @@ #import "candle_chart" -using UI :: #import "Kryon"; +using UI :: #import "kryon/Kryon"; #program_export main :: () -> s32 { diff --git a/tests/plot_widget_behavior.zi b/tests/plot_widget_behavior.zi new file mode 100644 index 0000000..f03d7bb --- /dev/null +++ b/tests/plot_widget_behavior.zi @@ -0,0 +1,95 @@ +#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 +} diff --git a/tests/plot_widget_host.zi b/tests/plot_widget_host.zi new file mode 100644 index 0000000..9b669c0 --- /dev/null +++ b/tests/plot_widget_host.zi @@ -0,0 +1,122 @@ +#import "kryon/drawing_props" +#import "kryon/geometry" + +backgrounds: s32; +marks: s32; +outlines: s32; +lines: s32; +labels: s32; +failed: bool; + +#program_export +MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 { + if font != 14 || typeface.count != 0 { failed = true } + return cast(s32)value.count * 8 +} + +#program_export +RasterRoundedRectangle :: (bounds: Rectangle, radius: float32, + segments: s32, color: Color) { + unused segments + if bounds.x < 10.0 || bounds.y < 10.0 || + bounds.x + bounds.width > 110.0 || + bounds.y + bounds.height > 150.0 { failed = true } + if radius == 0.0 { + if color.r != cast(u8)59 || color.g != cast(u8)96 || + color.b != cast(u8)155 || color.a != cast(u8)255 { + failed = true + } + which: s32 = marks % 3 + if which == 0 && (bounds.x <= 10.9 || bounds.x >= 11.1 || + bounds.y != 120.0 || bounds.height != 30.0) { failed = true } + if which == 1 && (bounds.x <= 44.2 || bounds.x >= 44.5 || + bounds.y != 90.0 || bounds.height != 60.0) { failed = true } + if which == 2 && (bounds.x <= 77.5 || bounds.x >= 77.8 || + bounds.y != 135.0 || bounds.height != 15.0) { failed = true } + marks += 1 + } else { + if radius != 4.0 || color.r != cast(u8)245 || + color.g != cast(u8)245 || color.b != cast(u8)245 || + color.a != cast(u8)255 { failed = true } + backgrounds += 1 + } +} + +#program_export +RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32, + segments: s32, width: float32, color: Color) { + unused segments + if bounds.x != 10.0 || bounds.width != 100.0 || + bounds.height != 60.0 || + (bounds.y != 10.0 && bounds.y != 90.0) || + radius != 4.0 || width != 1.0 || + color.r != cast(u8)115 || color.g != cast(u8)115 || + color.b != cast(u8)115 || color.a != cast(u8)255 { failed = true } + outlines += 1 +} + +#program_export +RasterLine :: (line: Rectangle, color: Color) { + if line.x < 10.0 || line.x + line.width > 110.0 || + line.y < 10.0 || line.y > 70.0 || + line.y + line.height < 10.0 || line.y + line.height > 70.0 || + color.r != cast(u8)59 || color.g != cast(u8)96 || + color.b != cast(u8)155 || color.a != cast(u8)255 { failed = true } + lines += 1 +} + +#program_export +RasterText :: (value: string, x: s32, y: s32, font: s32, + color: Color) { + unused value + unused x + unused y + unused font + unused color + failed = true +} + +#program_export +RasterTextClipped :: (value: string, x: s32, y: s32, font: s32, + color: Color, clip: Rectangle) { + if value.count == 0 || x < 10 || x > 110 || y < 10 || y > 150 || + font != 14 || clip.x != 10.0 || clip.width != 100.0 || + (clip.y != 10.0 && clip.y != 90.0) || clip.height != 60.0 || + color.r != cast(u8)23 || color.g != cast(u8)23 || + color.b != cast(u8)23 || color.a != cast(u8)255 { failed = true } + labels += 1 +} + +#program_export +RasterImage :: (path: string, texture_id: u32, + source: Rectangle, destination: Rectangle, clip: Rectangle, + origin: Vector2, rotation: float32, radius: float32, tint: Color) { + unused path + unused texture_id + unused source + unused destination + unused clip + unused origin + unused rotation + unused radius + unused tint + failed = true +} + +#program_export +PlotHostFailed :: () -> bool { return failed } + +#program_export +PlotBackgrounds :: () -> s32 { return backgrounds } + +#program_export +PlotMarks :: () -> s32 { return marks } + +#program_export +PlotOutlines :: () -> s32 { return outlines } + +#program_export +PlotLineCount :: () -> s32 { return lines } + +#program_export +PlotLabels :: () -> s32 { return labels } diff --git a/ziran.lock b/ziran.lock index 4042236..da6d882 100644 --- a/ziran.lock +++ b/ziran.lock @@ -2,20 +2,29 @@ "format": 1, "packages": [ { - "commit": "c7b623317e2a4603186d38534873848888bc3331", - "dependencies": {}, - "id": "pb1eb996de20f3de6", + "commit": "42c649dab1c97213b0ffd84d673fde3ec5a4b950", + "dependencies": {"raylib": "p5a77c9c35110e925"}, + "id": "p4c79176f910b74b8", "name": "Kryon", "ref": "master", "url": "https://github.com/kryonlabs/kryon.git" + }, + { + "commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", + "dependencies": {}, + "id": "p5a77c9c35110e925", + "name": "raylib", + "ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", + "source": true, + "url": "https://github.com/raysan5/raylib.git" } ], "root": { - "dependencies": {"kryon": "pb1eb996de20f3de6"}, + "dependencies": {"kryon": "p4c79176f910b74b8"}, "name": "plot" }, "toolchain": { - "commit": "d61e47f8da3b17b7855f247624b1ade4104d45c3", + "commit": "363b2ec5461aa1ec457176b2acf77fc9b92f2175", "ref": "master", "url": "https://github.com/ziranlang/ziran.git" } diff --git a/ziran.toml b/ziran.toml index ede6c53..7f0429b 100644 --- a/ziran.toml +++ b/ziran.toml @@ -11,12 +11,13 @@ ref = "master" [dependencies.kryon] git = "https://github.com/kryonlabs/kryon.git" ref = "master" -module_aliases = { Kryon = "Kryon", PlotWidget = "PlotWidget" } [exports] # Public module is Plot; the lowercase export is retained for older imports. plot = "src/module.zi" Plot = "src/module.zi" +# The chart surface alone, for apps that draw their own series. +PlotWidget = "src/PlotWidget/module.zi" [tool.kryon] default_profile = "cairo"