clean up chart.zig
This commit is contained in:
parent
04882a4ff8
commit
6d99349b62
1 changed files with 12 additions and 22 deletions
|
|
@ -302,8 +302,8 @@ pub fn renderChart(
|
|||
|
||||
// ── Grid lines ────────────────────────────────────────────────────
|
||||
const grid_color = blendColor(th.text_muted, 60, bg);
|
||||
try drawHorizontalGridLines(&ctx, alloc, chart_left, chart_right, price_top, price_bottom, price_min, price_max, 5, grid_color);
|
||||
try drawHorizontalGridLines(&ctx, alloc, chart_left, chart_right, rsi_top, rsi_bottom, 0, 100, 4, grid_color);
|
||||
try drawHorizontalGridLines(&ctx, chart_left, chart_right, price_top, price_bottom, 5, grid_color);
|
||||
try drawHorizontalGridLines(&ctx, chart_left, chart_right, rsi_top, rsi_bottom, 4, grid_color);
|
||||
|
||||
// ── Volume bars (overlaid on price panel bottom 25%) ─────────────
|
||||
{
|
||||
|
|
@ -385,10 +385,10 @@ pub fn renderChart(
|
|||
// ── Bollinger Band boundary lines + SMA (on top of fills) ──────────
|
||||
{
|
||||
const band_line_color = blendColor(th.text_muted, 100, bg);
|
||||
try drawLineSeries(&ctx, alloc, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, band_line_color, 1.0, .upper);
|
||||
try drawLineSeries(&ctx, alloc, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, band_line_color, 1.0, .lower);
|
||||
try drawLineSeries(&ctx, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, band_line_color, 1.0, .upper);
|
||||
try drawLineSeries(&ctx, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, band_line_color, 1.0, .lower);
|
||||
// SMA (middle)
|
||||
try drawLineSeries(&ctx, alloc, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, blendColor(th.text_muted, 160, bg), 1.0, .middle);
|
||||
try drawLineSeries(&ctx, bb, data.len, price_min, price_max, price_top, price_bottom, chart_left, x_step, blendColor(th.text_muted, 160, bg), 1.0, .middle);
|
||||
}
|
||||
|
||||
// ── Price line (on top of everything) ─────────────────────────────
|
||||
|
|
@ -411,9 +411,9 @@ pub fn renderChart(
|
|||
// ── RSI panel ─────────────────────────────────────────────────────
|
||||
{
|
||||
const ref_color = blendColor(th.text_muted, 100, bg);
|
||||
try drawHLine(&ctx, alloc, chart_left, chart_right, mapY(70, 0, 100, rsi_top, rsi_bottom), ref_color, 1.0);
|
||||
try drawHLine(&ctx, alloc, chart_left, chart_right, mapY(30, 0, 100, rsi_top, rsi_bottom), ref_color, 1.0);
|
||||
try drawHLine(&ctx, alloc, chart_left, chart_right, mapY(50, 0, 100, rsi_top, rsi_bottom), blendColor(th.text_muted, 50, bg), 1.0);
|
||||
try drawHLine(&ctx, chart_left, chart_right, mapY(70, 0, 100, rsi_top, rsi_bottom), ref_color, 1.0);
|
||||
try drawHLine(&ctx, chart_left, chart_right, mapY(30, 0, 100, rsi_top, rsi_bottom), ref_color, 1.0);
|
||||
try drawHLine(&ctx, chart_left, chart_right, mapY(50, 0, 100, rsi_top, rsi_bottom), blendColor(th.text_muted, 50, bg), 1.0);
|
||||
|
||||
const rsi_color = blendColor(th.info, 220, bg);
|
||||
ctx.setSourceToPixel(rsi_color);
|
||||
|
|
@ -438,8 +438,8 @@ pub fn renderChart(
|
|||
// ── Panel borders ─────────────────────────────────────────────────
|
||||
{
|
||||
const border_color = blendColor(th.border, 80, bg);
|
||||
try drawRect(&ctx, alloc, chart_left, price_top, chart_right, price_bottom, border_color, 1.0);
|
||||
try drawRect(&ctx, alloc, chart_left, rsi_top, chart_right, rsi_bottom, border_color, 1.0);
|
||||
try drawRect(&ctx, chart_left, price_top, chart_right, price_bottom, border_color, 1.0);
|
||||
try drawRect(&ctx, chart_left, rsi_top, chart_right, rsi_bottom, border_color, 1.0);
|
||||
}
|
||||
|
||||
// Get latest RSI
|
||||
|
|
@ -508,7 +508,6 @@ const BandField = enum { upper, middle, lower };
|
|||
|
||||
fn drawLineSeries(
|
||||
ctx: *Context,
|
||||
alloc: std.mem.Allocator,
|
||||
bb: []const ?zfin.indicators.BollingerBand,
|
||||
len: usize,
|
||||
price_min: f64,
|
||||
|
|
@ -521,7 +520,6 @@ fn drawLineSeries(
|
|||
line_w: f64,
|
||||
field: BandField,
|
||||
) !void {
|
||||
_ = alloc;
|
||||
ctx.setSourceToPixel(col);
|
||||
ctx.setLineWidth(line_w);
|
||||
ctx.resetPath();
|
||||
|
|
@ -549,23 +547,17 @@ fn drawLineSeries(
|
|||
|
||||
fn drawHorizontalGridLines(
|
||||
ctx: *Context,
|
||||
alloc: std.mem.Allocator,
|
||||
left: f64,
|
||||
right: f64,
|
||||
top: f64,
|
||||
bottom: f64,
|
||||
min_val: f64,
|
||||
max_val: f64,
|
||||
n_lines: usize,
|
||||
col: Pixel,
|
||||
) !void {
|
||||
_ = alloc;
|
||||
ctx.setSourceToPixel(col);
|
||||
ctx.setLineWidth(0.5);
|
||||
for (1..n_lines) |i| {
|
||||
const frac = @as(f64, @floatFromInt(i)) / @as(f64, @floatFromInt(n_lines));
|
||||
_ = min_val;
|
||||
_ = max_val;
|
||||
const y = top + frac * (bottom - top);
|
||||
ctx.resetPath();
|
||||
try ctx.moveTo(left, y);
|
||||
|
|
@ -575,8 +567,7 @@ fn drawHorizontalGridLines(
|
|||
ctx.setLineWidth(2.0);
|
||||
}
|
||||
|
||||
fn drawHLine(ctx: *Context, alloc: std.mem.Allocator, x1: f64, x2: f64, y: f64, col: Pixel, w: f64) !void {
|
||||
_ = alloc;
|
||||
fn drawHLine(ctx: *Context, x1: f64, x2: f64, y: f64, col: Pixel, w: f64) !void {
|
||||
ctx.setSourceToPixel(col);
|
||||
ctx.setLineWidth(w);
|
||||
ctx.resetPath();
|
||||
|
|
@ -586,8 +577,7 @@ fn drawHLine(ctx: *Context, alloc: std.mem.Allocator, x1: f64, x2: f64, y: f64,
|
|||
ctx.setLineWidth(2.0);
|
||||
}
|
||||
|
||||
fn drawRect(ctx: *Context, alloc: std.mem.Allocator, x1: f64, y1: f64, x2: f64, y2: f64, col: Pixel, w: f64) !void {
|
||||
_ = alloc;
|
||||
fn drawRect(ctx: *Context, x1: f64, y1: f64, x2: f64, y2: f64, col: Pixel, w: f64) !void {
|
||||
ctx.setSourceToPixel(col);
|
||||
ctx.setLineWidth(w);
|
||||
ctx.resetPath();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue