From 8a6d5d5b9df6c18a31cc4a7cd586348d827f76ca Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 7 Feb 2024 13:59:44 -0600 Subject: [PATCH] dev: generation of a graph with no data for graph --- src/routes.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/routes.rs b/src/routes.rs index bc003b4..c679430 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -58,11 +58,17 @@ pub fn mk_api_routes(config: Arc>) -> Router { ) } -pub fn graph_component(graph: &Graph) -> Markup { +// TODO(jwall): This should probably be encapsulated in a web component? +pub fn graph_component(dash_idx: usize, graph_idx: usize, graph: &Graph) -> Markup { + let graph_id = format!("graph-{}-{}", dash_idx, graph_idx); + let script = format!("var data = []; Plotly.newPlot('{}', data, {{ width: 500, height: 500 }});", graph_id); html!( div { h2 { (graph.title) } - div { "data/graph goes here" } + script { + (script) + } + div id=(graph_id) { } } ) } @@ -77,23 +83,24 @@ pub async fn graph_ui( .graphs .get(graph_idx) .expect("No such graph"); - graph_component(graph) + graph_component(dash_idx, graph_idx, graph) } -pub async fn dash_ui(State(config): State, Path(idx): Path) -> Markup { +pub async fn dash_ui(State(config): State, Path(dash_idx): Path) -> Markup { // TODO(zaphar): Should do better http error reporting here. - let dash = config.get(idx).expect("No such dashboard"); + let dash = config.get(dash_idx).expect("No such dashboard"); + let graph_iter = dash.graphs.iter().enumerate().collect::>(); html!( h1 { (dash.title) } - @for graph in &dash.graphs { - (graph_component(graph)) + @for (idx, graph) in &graph_iter { + (graph_component(dash_idx, *idx, *graph)) } ) } pub fn mk_ui_routes(config: Arc>) -> Router { Router::new() - .route("/dash/:idx", get(dash_ui).with_state(State(config.clone()))) + .route("/dash/:dash_idx", get(dash_ui).with_state(State(config.clone()))) .route( "/dash/:dash_idx/graph/:graph_idx", get(graph_ui).with_state(State(config)),