feat(lapaloma): backend GPUI + LapalomaChartElement + app demo
Cadena end-to-end DataBuffer → LineSeries → Canvas → gpui::Window funcionando. cargo run -p lapaloma-demo abre una ventana con sin(x) sobre 1024 muestras y una sola paint_path por frame. - lapaloma-render: feature `gpui` opcional. WindowCanvas adapter traduce el trait Canvas a paint_quad/paint_path de gpui 0.2. Conversión RGB→HSL para integrar con el sistema de colores Hsla del resto del codebase yahweh. 3 tests de conversión. - lapaloma-cartesian: feature `gpui` (default). element::LapalomaChartElement con impl Element + IntoElement. Arma WindowCanvas en paint() y delega a LineSeries — un solo paint_path por chart. - crates/apps/lapaloma-demo registrado en workspace. Limitaciones conocidas v0.1: clip stack, triangle strips y draw_text no implementados (los necesitan phosphor / Sankey / axes; se agregan en sus fases). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
//! `lapaloma-demo` — demo visual mínimo de Lapaloma sobre yahweh.
|
||||
//!
|
||||
//! Levanta una ventana de 900×560 con un único chart cartesiano
|
||||
//! pre-llenado con `sin(x · 0.04)` sobre 1024 muestras. Sirve
|
||||
//! como smoke test de la cadena completa:
|
||||
//!
|
||||
//! ```text
|
||||
//! DataBuffer (lapaloma-core)
|
||||
//! ↓ LTTB cuando densidad > 3× ancho del plot
|
||||
//! CoordinateSystem (lapaloma-cartesian)
|
||||
//! ↓ project_buffer dominio → pixel, zero-alloc
|
||||
//! LineSeries (lapaloma-cartesian)
|
||||
//! ↓ canvas.stroke_polyline (una sola draw call)
|
||||
//! WindowCanvas (lapaloma-render::gpui_backend)
|
||||
//! ↓ paint_path
|
||||
//! gpui::Window
|
||||
//! ```
|
||||
//!
|
||||
//! Correr con `cargo run -p lapaloma-demo`. Requiere DISPLAY/WAYLAND.
|
||||
|
||||
use gpui::{div, prelude::*, px, Context, IntoElement, Render, Window};
|
||||
|
||||
use lapaloma_cartesian::{lapaloma_chart, ChartViewport};
|
||||
use lapaloma_core::buffer::DataBuffer;
|
||||
use lapaloma_render::{Color, StrokeStyle};
|
||||
use yahweh_launcher::launch_app;
|
||||
use yahweh_theme::Theme;
|
||||
|
||||
const N_SAMPLES: usize = 1024;
|
||||
const FREQ: f32 = 0.04;
|
||||
|
||||
fn main() {
|
||||
launch_app("Lapaloma — sin(x) demo", (900., 560.), Demo::new);
|
||||
}
|
||||
|
||||
struct Demo {
|
||||
data: DataBuffer,
|
||||
}
|
||||
|
||||
impl Demo {
|
||||
fn new(_cx: &mut Context<Self>) -> Self {
|
||||
// Buffer canónico interleaved: x va 0..N-1, y = sin(x · FREQ).
|
||||
let mut data = DataBuffer::with_capacity(N_SAMPLES);
|
||||
for i in 0..N_SAMPLES {
|
||||
let x = i as f32;
|
||||
let y = (x * FREQ).sin();
|
||||
data.push(x, y);
|
||||
}
|
||||
Self { data }
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Demo {
|
||||
fn render(&mut self, _w: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = Theme::global(cx).clone();
|
||||
|
||||
// Viewport: ve toda la X, Y con un poco de margen.
|
||||
let viewport = ChartViewport::new(0.0, (N_SAMPLES - 1) as f64, -1.1, 1.1);
|
||||
|
||||
// Estilo: stroke nórdico azul claro sobre fondo del theme.
|
||||
let stroke = StrokeStyle::new(2.0, Color::from_hex(0x88c0d0));
|
||||
let plot_bg = Color::rgba(0.10, 0.12, 0.16, 1.0);
|
||||
|
||||
// DataBuffer es `Clone`; el Element toma ownership del clone
|
||||
// por frame. Para datasets enormes el siguiente paso es
|
||||
// pasar a `Arc<DataBuffer>`; con 1k samples es trivial.
|
||||
let chart = lapaloma_chart(self.data.clone(), viewport, stroke).background(plot_bg);
|
||||
|
||||
div()
|
||||
.size_full()
|
||||
.bg(theme.bg_app.clone())
|
||||
.p(px(16.))
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap(px(12.))
|
||||
.child(
|
||||
div()
|
||||
.text_color(theme.fg_text)
|
||||
.text_size(px(18.))
|
||||
.child("Lapaloma — demo cartesian"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_color(theme.fg_muted)
|
||||
.text_size(px(12.))
|
||||
.child(format!(
|
||||
"{} muestras de sin(x · {}). LineSeries · LTTB-on-density · 1 draw call.",
|
||||
N_SAMPLES, FREQ
|
||||
)),
|
||||
)
|
||||
.child(div().w_full().flex_grow().child(chart))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user