pub mod manager;
pub mod renderer;
pub use manager::*;
pub use renderer::*;
pub use renderer::{
ChartConfig, ChartData, ChartInstance, ChartRenderer, EdgeStyle, ForceParams, GraphEdge,
GraphInstance, GraphNode, GraphRenderer, HierarchicalParams, InteractionConfig, LayoutConfig,
LayoutEngine, LayoutType, Position, RenderStats, SeriesData, Size, Template, TemplateEngine,
TemplateFunction, WebSocketClient,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PanelConfig {
pub id: String,
pub title: String,
pub panel_type: String,
pub grid_pos: GridPos,
pub datasource: String,
pub targets: Vec<QueryTarget>,
pub field_config: FieldConfig,
pub options: PanelOptions,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GridPos {
pub x: i32,
pub y: i32,
pub w: i32,
pub h: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryTarget {
pub ref_id: String,
pub query: String,
pub interval: String,
pub legend_format: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldConfig {
pub min: Option<f64>,
pub max: Option<f64>,
pub unit: Option<String>,
pub decimals: Option<u32>,
pub thresholds: Option<ThresholdsConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThresholdsConfig {
pub steps: Vec<ThresholdStep>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThresholdStep {
pub color: String,
pub value: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PanelOptions {
pub legend: LegendConfig,
pub tooltip: TooltipConfig,
pub time: TimeRangeConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LegendConfig {
pub show: bool,
pub position: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TooltipConfig {
pub mode: String,
pub sort: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeRangeConfig {
pub from: String,
pub to: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardTags {
pub tags: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardVersion {
pub version: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefreshConfig {
pub interval: String,
pub pause: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ChartType {
LineChart,
BarChart,
PieChart,
HeatMap,
StatChart,
Table,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GraphType {
TopologyGraph,
DependencyGraph,
TraceGraph,
NetworkGraph,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemplateVariable {
pub name: String,
pub label: String,
pub query: String,
pub options: Vec<VariableOption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VariableOption {
pub text: String,
pub value: String,
pub selected: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_panel_config_creation() {
let config: _ = PanelConfig {
id: "panel-1".to_string(),
title: "CPU Usage".to_string(),
panel_type: "graph".to_string(),
grid_pos: GridPos {
x: 0,
y: 0,
w: 12,
h: 8,
},
datasource: "Prometheus".to_string(),
targets: vec![],
field_config: FieldConfig {
min: Some(0.0),
max: Some(100.0),
unit: Some("percent".to_string()),
decimals: Some(2),
thresholds: None,
},
options: PanelOptions {
legend: LegendConfig {
show: true,
position: "bottom".to_string(),
},
tooltip: TooltipConfig {
mode: "multi".to_string(),
sort: "none".to_string(),
},
time: TimeRangeConfig {
from: "now-1h".to_string(),
to: "now".to_string(),
},
},
};
assert_eq!(config.id, "panel-1");
assert_eq!(config.title, "CPU Usage");
assert_eq!(config.panel_type, "graph");
}
#[test]
fn test_grid_pos_validation() {
let pos: _ = GridPos {
x: 0,
y: 0,
w: 24,
h: 12,
};
assert!(pos.w > 0);
assert!(pos.h > 0);
}
#[test]
fn test_threshold_config() {
let thresholds: _ = ThresholdsConfig {
steps: vec![
ThresholdStep {
color: "green".to_string(),
value: None,
},
ThresholdStep {
color: "yellow".to_string(),
value: Some(50.0),
},
ThresholdStep {
color: "red".to_string(),
value: Some(80.0),
},
],
};
assert_eq!(thresholds.steps.len(), 3);
assert_eq!(thresholds.steps[1].color, "yellow");
}
}
use std::collections::{BTreeMap, HashMap};