///|
fn esc_svg(s : String) -> String {
let sb = StringBuilder()
for ch in s {
match ch {
'&' => sb.write_string("&")
'<' => sb.write_string("<")
'>' => sb.write_string(">")
'"' => sb.write_string(""")
_ => sb.write_char(ch)
}
}
sb.to_string()
}
///|
fn stream_color(sid : UInt32, kind : String) -> String {
if kind == "GOAWAY" || kind == "RST_STREAM" {
return "#f43f5e"
}
if sid == 0U {
return "#38bdf8"
}
match sid / 2U % 5U {
0U => "#34d399"
1U => "#a78bfa"
2U => "#fbbf24"
3U => "#fb7185"
_ => "#60a5fa"
}
}
///|
/// Render an HTTP/2 connection's recorded frame exchange as a native SVG sequence timeline.
pub fn render_timeline_svg(entries : Array[FrameTraceEntry]) -> String {
let max_rows = if entries.length() > 48 { 48 } else { entries.length() }
let row_h = 30
let top_h = 68
let height = top_h + max_rows * row_h + 36
let width = 760
let left_x = 130
let right_x = 630
let sb = StringBuilder()
sb.write_string(
"")
sb.to_string()
}
///|
/// Per-request HPACK compression statistics entry for SVG visualization.
#derive(Debug, Eq, ToJson)
pub(all) struct HpackSampleStat {
request_index : Int32
raw_bytes : Int32
encoded_bytes : Int32
dynamic_entries : Int32
dynamic_bytes : Int32
}
///|
pub extend HpackSampleStat with @debug.Debug::{to_repr}
///|
pub extend HpackSampleStat with Eq::{not_equal, equal}
///|
pub extend HpackSampleStat with @json.ToJson::{to_json}
///|
/// Render HPACK compression ratio progression across consecutive requests as a native SVG chart.
pub fn render_hpack_svg(stats : Array[HpackSampleStat]) -> String {
let width = 720
let row_h = 34
let top_h = 54
let height = top_h + stats.length() * row_h + 28
let mut max_raw = 1
for st in stats {
if st.raw_bytes > max_raw {
max_raw = st.raw_bytes
}
}
let bar_max = 420
let sb = StringBuilder()
sb.write_string(
"")
sb.to_string()
}