tawasuyu

tawasuyu/brahman

Rust 582TOML 222Markdown 83JSON 198635 Sutichaykuna

gioser-graph-web: fix web-sys feature casing and compilation

- SvgSvgElement → SvgsvgElement
- Add Response feature
- Make color owned String for closure lifetime

7a53fea13c673882d5419fecbe9f7d2605fd5fe9 · ruwaq Sergio · (5 killa ñawpaq) · tayta cb5d83b1f · kay commitpi sach'ata qhaway

Semántico sayk'uy · 3

crates/modules/gioser/gioser-graph-web/src/lib.rs

2 qillqakuna · +15 −8

diff --git a/crates/modules/gioser/gioser-graph-web/Cargo.toml b/crates/modules/gioser/gioser-graph-web/Cargo.toml
index ae905f6..081899e 100644
--- a/crates/modules/gioser/gioser-graph-web/Cargo.toml
+++ b/crates/modules/gioser/gioser-graph-web/Cargo.toml
@@ -21,13 +21,14 @@ features = [
     "Element",
     "HtmlElement",
     "SvgElement",
-    "SvgSvgElement",
+    "SvgsvgElement",
     "SvgCircleElement",
     "SvgLineElement",
     "SvgTextElement",
     "SvgTextContentElement",
     "SvgGraphicsElement",
     "Node",
+    "Response",
     "CssStyleDeclaration",
     "DomRect",
     "Event",
diff --git a/crates/modules/gioser/gioser-graph-web/src/lib.rs b/crates/modules/gioser/gioser-graph-web/src/lib.rs
index db0f1d4..36adf9c 100644
--- a/crates/modules/gioser/gioser-graph-web/src/lib.rs
+++ b/crates/modules/gioser/gioser-graph-web/src/lib.rs
@@ -34,10 +34,16 @@ use wasm_bindgen::prelude::*;
 use wasm_bindgen::JsCast;
 use wasm_bindgen_futures::JsFuture;
 use web_sys::{
-    Document, Element, HtmlElement, MouseEvent, SvgCircleElement, SvgElement, SvgLineElement,
-    SvgSvgElement, SvgTextElement, Window,
+    Document, HtmlElement, MouseEvent, Response, SvgCircleElement, SvgLineElement,
+    SvgsvgElement, SvgTextElement,
 };
 
+/// Helper para obtener el document desde web-sys. Se llama desde los métodos
+/// de GraphWidget sin depender de la referencia pasada (aunque la tenemos).
+pub(crate) fn document() -> Option<Document> {
+    web_sys::window().and_then(|w| w.document())
+}
+
 // ─── Tipos de respuesta de `/graph` ──────────────────────────────
 
 #[derive(Deserialize, Debug, Clone)]
@@ -116,7 +122,7 @@ fn camino_color(camino: &str) -> &str {
 pub struct GraphWidget {
     container: HtmlElement,
     api_url: String,
-    svg: Option<SvgSvgElement>,
+    svg: Option<SvgsvgElement>,
     nodes: Vec<NodeData>,
     edges: Vec<EdgeData>,
     on_navigate: NavCallback,
@@ -195,7 +201,7 @@ impl GraphWidget {
         let positions = force_layout(&self.nodes, &self.edges, CANVAS_W, CANVAS_H);
 
         let ns = "http://www.w3.org/2000/svg";
-        let svg: SvgSvgElement = self
+        let svg: SvgsvgElement = self
             .document
             .create_element_ns(Some(ns), "svg")
             .unwrap()
@@ -255,7 +261,7 @@ impl GraphWidget {
         let on_nav = self.on_navigate.clone();
         for (i, node) in self.nodes.iter().enumerate() {
             let (x, y) = positions.get(i).map(|(_, p)| *p).unwrap_or((100.0, 100.0));
-            let color = camino_color(&node.camino);
+            let color = camino_color(&node.camino).to_string();
 
             // Círculo
             let circle: SvgCircleElement = self
@@ -267,9 +273,9 @@ impl GraphWidget {
             circle.set_attribute("cx", &format!("{:.1}", x)).ok();
             circle.set_attribute("cy", &format!("{:.1}", y)).ok();
             circle.set_attribute("r", &format!("{:.1}", NODE_RADIUS)).ok();
-            circle.set_attribute("fill", color).ok();
+            circle.set_attribute("fill", &color).ok();
             circle.set_attribute("fill-opacity", "0.35").ok();
-            circle.set_attribute("stroke", color).ok();
+            circle.set_attribute("stroke", &color).ok();
             circle.set_attribute("stroke-width", "2").ok();
             circle.set_attribute("cursor", "pointer").ok();