Files
el/ui/vessels/el-graph/src/edge.el
T

45 lines
1.6 KiB
EmacsLisp

// edge.el Edge type definitions and visual encoding.
//
// Edges are directed (source -> target) with a weight and optional relation label.
// Edge JSON accessors
//
// Edges are passed as JSON objects: { source_id, target_id, weight, relation }
fn edge_source(e_json: String) -> String {
let s: String = json_get_string(e_json, "source_id")
if !str_eq(s, "") { return s }
json_get_string(e_json, "source")
}
fn edge_target(e_json: String) -> String {
let t: String = json_get_string(e_json, "target_id")
if !str_eq(t, "") { return t }
json_get_string(e_json, "target")
}
fn edge_weight(e_json: String) -> Float {
let w: Float = json_get_float(e_json, "weight")
if w == int_to_float(0) { return int_to_float(1) }
w
}
fn edge_relation(e_json: String) -> String {
json_get_string(e_json, "relation")
}
// Edge visual encoding
// Stroke width clamped to [1, 4] based on weight.
fn edge_stroke_width(weight: Float) -> Float {
let min_w: Float = int_to_float(1)
let max_w: Float = int_to_float(4)
let range: Float = max_w - min_w
let clamped: Float = if weight < min_w { min_w } else { if weight > max_w { max_w } else { weight } }
clamped
}
fn edge_stroke_color() -> String { "#3a4a5a" }
fn edge_stroke_color_highlight() -> String { "#5a7a9a" }