Skip to documentation
SLOP

tiny.zen.diagram.category

Reference tiny.zen diagram category

Defined in diagram.

API (4)

Actions

Public operations.

Values and defaults

Public values and defaults.

No direct callersNo direct callsdiagramcategory
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsprivate sourcelib.zen.src.diagram.boundscomputePreparedprivate sourcelib.zen.src.diagram.boundsincludeXValuediagram.categoryappendAssumeCapacity
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callsprivate sourcelib.zen.src.diagram.ascii.markdrawBarprivate sourcelib.zen.src.diagram.ascii.plotdrawCategoryLabelsdiagram.spacexCoordinatediagram.categorycoordinate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.zen.src.diagram.categorytest: category labels fit every finit...diagram.spacexCoordinatediagram.categorylabel
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/zen/src/diagram/category.zig

zig
const std = @import("std");const model = @import("model.zig");const root = @import("root.zig");const spec = root.spec;const Bounds = model.Bounds;pub const label_buffer_bytes: usize = 512;pub fn appendAssumeCapacity(bounds: *Bounds, label_value: []const u8) void {    for (bounds.categories.items) |item| {        if (std.mem.eql(u8, item, label_value)) return;    }    bounds.categories.appendAssumeCapacity(label_value);}pub fn label(buffer: *[label_buffer_bytes]u8, value: spec.XValue) []const u8 {    return switch (value) {        .number => |number| std.fmt.bufPrint(buffer, "{d:.3}", .{number}) catch unreachable,        .text => |text| text,    };}pub fn coordinate(label_value: []const u8, bounds: Bounds, left: f64, right: f64) f64 {    const count = @max(bounds.categories.items.len, 1);    const slot = (right - left) / @as(f64, @floatFromInt(count));    for (bounds.categories.items, 0..) |item, index| {        if (std.mem.eql(u8, item, label_value)) return left + slot * (@as(f64, @floatFromInt(index)) + 0.5);    }    return left + slot * 0.5;}test "category labels fit every finite f64 without allocation" {    var buffer: [label_buffer_bytes]u8 = undefined;    try std.testing.expect(label(&buffer, .{ .number = std.math.floatMax(f64) }).len < buffer.len);    try std.testing.expect(label(&buffer, .{ .number = -std.math.floatMax(f64) }).len < buffer.len);    try std.testing.expectEqualStrings("borrowed", label(&buffer, .{ .text = @constCast("borrowed") }));}

Source: lib/zen/src/diagram/root.zig:3

zig
pub const category = @import("category.zig");

Audit

Definitions5
Public names5
Members0
Version26.7.0
Revisiondaab053ee433