Skip to main content

scirs2_cluster/native_plotting/
types.rs

1//! Data types for native plotting — structs, enums, and their Default impls.
2
3use scirs2_core::ndarray::Array2;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Configuration for native plotting
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct NativePlotConfig {
10    /// Canvas width in pixels
11    pub width: usize,
12    /// Canvas height in pixels
13    pub height: usize,
14    /// Enable interactive features
15    pub enable_interactivity: bool,
16    /// Enable animations
17    pub enable_animations: bool,
18    /// Animation frame rate (FPS)
19    pub animation_fps: f64,
20    /// Color scheme
21    pub color_scheme: PlotColorScheme,
22    /// Export quality
23    pub export_quality: ExportQuality,
24}
25
26/// Color schemes for native plotting
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub enum PlotColorScheme {
29    /// Quantum theme (blue-cyan-purple)
30    Quantum,
31    /// Neuromorphic theme (green-yellow-red)
32    Neuromorphic,
33    /// AI theme (gold-orange-red)
34    AI,
35    /// Scientific theme (grayscale with highlights)
36    Scientific,
37    /// Custom color palette
38    Custom(Vec<[u8; 3]>),
39}
40
41/// Export quality settings
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub enum ExportQuality {
44    /// Draft quality (fast rendering)
45    Draft,
46    /// Standard quality
47    Standard,
48    /// High quality (detailed rendering)
49    High,
50    /// Publication quality (maximum detail)
51    Publication,
52}
53
54/// SVG canvas for native rendering
55#[derive(Debug)]
56pub struct SvgCanvas {
57    /// Canvas dimensions
58    pub(crate) width: usize,
59    pub(crate) height: usize,
60    /// SVG elements
61    pub(crate) elements: Vec<SvgElement>,
62    /// Style definitions
63    pub(crate) styles: HashMap<String, String>,
64}
65
66/// SVG element types
67#[derive(Debug, Clone)]
68pub enum SvgElement {
69    /// Circle element
70    Circle {
71        cx: f64,
72        cy: f64,
73        r: f64,
74        fill: String,
75        stroke: String,
76        stroke_width: f64,
77        opacity: f64,
78    },
79    /// Line element
80    Line {
81        x1: f64,
82        y1: f64,
83        x2: f64,
84        y2: f64,
85        stroke: String,
86        stroke_width: f64,
87        opacity: f64,
88    },
89    /// Path element (for complex shapes)
90    Path {
91        d: String,
92        fill: String,
93        stroke: String,
94        stroke_width: f64,
95        opacity: f64,
96    },
97    /// Text element
98    Text {
99        x: f64,
100        y: f64,
101        content: String,
102        font_size: f64,
103        fill: String,
104        text_anchor: String,
105    },
106    /// Group element (for hierarchical organization)
107    Group {
108        id: String,
109        elements: Vec<SvgElement>,
110        transform: String,
111    },
112}
113
114/// Animation engine for dynamic visualizations
115#[derive(Debug)]
116pub struct AnimationEngine {
117    /// Animation frames
118    pub(crate) frames: Vec<AnimationFrame>,
119    /// Current frame index
120    pub(crate) current_frame: usize,
121    /// Frame duration in milliseconds
122    pub(crate) frame_duration: f64,
123    /// Total animation duration
124    pub(crate) total_duration: f64,
125}
126
127/// Animation frame data
128#[derive(Debug, Clone)]
129pub struct AnimationFrame {
130    /// Frame timestamp
131    pub timestamp: f64,
132    /// Frame elements
133    pub elements: Vec<SvgElement>,
134    /// Frame-specific transformations
135    pub transformations: Vec<Transformation>,
136}
137
138/// Animation transformations
139#[derive(Debug, Clone)]
140pub enum Transformation {
141    /// Translation
142    Translate { dx: f64, dy: f64 },
143    /// Rotation
144    Rotate { angle: f64, cx: f64, cy: f64 },
145    /// Scale
146    Scale { sx: f64, sy: f64 },
147    /// Opacity fade
148    Fade { from: f64, to: f64 },
149    /// Color transition
150    ColorTransition { from: String, to: String },
151}
152
153/// Interactive controller for user interaction
154#[derive(Debug)]
155pub struct InteractiveController {
156    /// Zoom level
157    pub(crate) zoom_level: f64,
158    /// Pan offset
159    pub(crate) pan_offset: (f64, f64),
160    /// Selected elements
161    pub(crate) selected_elements: Vec<String>,
162    /// Hover state
163    pub(crate) hover_element: Option<String>,
164}
165
166/// Native dendrogram plot
167#[derive(Debug, Serialize, Deserialize)]
168pub struct NativeDendrogramPlot {
169    /// Dendrogram tree structure
170    pub tree: DendrogramTree,
171    /// Node positions
172    pub node_positions: HashMap<String, (f64, f64)>,
173    /// Branch lengths
174    pub branch_lengths: HashMap<String, f64>,
175    /// Quantum enhancement data
176    pub quantum_enhancements: HashMap<String, f64>,
177    /// Interactive features
178    pub interactive_features: Vec<InteractiveFeature>,
179}
180
181/// Dendrogram tree structure
182#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct DendrogramTree {
184    /// Root node
185    pub root: DendrogramNode,
186    /// Total height
187    pub height: f64,
188    /// Leaf count
189    pub leaf_count: usize,
190}
191
192/// Dendrogram node
193#[derive(Debug, Clone, Serialize, Deserialize)]
194pub struct DendrogramNode {
195    /// Node ID
196    pub id: String,
197    /// Node height
198    pub height: f64,
199    /// Child nodes
200    pub children: Vec<DendrogramNode>,
201    /// Data point indices (for leaf nodes)
202    pub data_indices: Vec<usize>,
203    /// Quantum coherence at this node
204    pub quantum_coherence: f64,
205    /// Neuromorphic activity
206    pub neuromorphic_activity: f64,
207}
208
209/// Interactive features for plots
210#[derive(Debug, Clone, Serialize, Deserialize)]
211pub enum InteractiveFeature {
212    /// Zoom and pan
213    ZoomPan,
214    /// Node selection
215    NodeSelection,
216    /// Tooltip on hover
217    Tooltip,
218    /// Real-time filtering
219    RealTimeFilter,
220    /// Animation controls
221    AnimationControls,
222    /// Export options
223    ExportOptions,
224}
225
226/// 3D cluster plot for high-dimensional visualization
227#[derive(Debug, Serialize, Deserialize)]
228pub struct Native3DClusterPlot {
229    /// 3D data points
230    pub points_3d: Array2<f64>,
231    /// Point colors based on clustering
232    pub point_colors: Vec<[u8; 3]>,
233    /// 3D centroids
234    pub centroids_3d: Array2<f64>,
235    /// Camera position
236    pub camera: Camera3D,
237    /// Lighting setup
238    pub lighting: Lighting3D,
239    /// Quantum field visualization
240    pub quantum_field: QuantumField3D,
241}
242
243/// 3D camera configuration
244#[derive(Debug, Clone, Serialize, Deserialize)]
245pub struct Camera3D {
246    /// Camera position
247    pub position: [f64; 3],
248    /// Look-at target
249    pub target: [f64; 3],
250    /// Up vector
251    pub up: [f64; 3],
252    /// Field of view
253    pub fov: f64,
254    /// Near and far clipping planes
255    pub near: f64,
256    pub far: f64,
257}
258
259/// 3D lighting configuration
260#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct Lighting3D {
262    /// Ambient light intensity
263    pub ambient: f64,
264    /// Directional lights
265    pub directional_lights: Vec<DirectionalLight>,
266    /// Point lights
267    pub point_lights: Vec<PointLight>,
268}
269
270/// Directional light
271#[derive(Debug, Clone, Serialize, Deserialize)]
272pub struct DirectionalLight {
273    /// Light direction
274    pub direction: [f64; 3],
275    /// Light intensity
276    pub intensity: f64,
277    /// Light color
278    pub color: [f64; 3],
279}
280
281/// Point light
282#[derive(Debug, Clone, Serialize, Deserialize)]
283pub struct PointLight {
284    /// Light position
285    pub position: [f64; 3],
286    /// Light intensity
287    pub intensity: f64,
288    /// Light color
289    pub color: [f64; 3],
290    /// Attenuation
291    pub attenuation: f64,
292}
293
294/// 3D quantum field visualization
295#[derive(Debug, Clone, Serialize, Deserialize)]
296pub struct QuantumField3D {
297    /// Field strength at grid points
298    pub field_strength: Array2<f64>,
299    /// Field coherence
300    pub coherence: Array2<f64>,
301    /// Phase information
302    pub phase: Array2<f64>,
303    /// Entanglement connections
304    pub entanglement_lines: Vec<([f64; 3], [f64; 3], f64)>,
305}
306
307// Supporting output data structures
308
309/// Native cluster plot output
310#[derive(Debug)]
311pub struct NativeClusterPlot {
312    /// Plot data
313    pub data: Array2<f64>,
314    /// Point elements
315    pub point_elements: Vec<SvgElement>,
316    /// Centroid elements
317    pub centroid_elements: Vec<SvgElement>,
318    /// Quantum enhancements per point
319    pub quantum_enhancements: Vec<f64>,
320    /// Plot bounds
321    pub bounds: (f64, f64, f64, f64),
322    /// Scale factors
323    pub scale: (f64, f64),
324}
325
326/// Complete native visualization output
327#[derive(Debug)]
328pub struct NativeVisualizationOutput {
329    /// Main cluster plot
330    pub cluster_plot: NativeClusterPlot,
331    /// Dendrogram (if applicable)
332    pub dendrogram: Option<NativeDendrogramPlot>,
333    /// 3D plot (if applicable)
334    pub plot_3d: Option<Native3DClusterPlot>,
335    /// Quantum coherence animation
336    pub quantum_animation: Option<QuantumCoherenceAnimation>,
337    /// Neuromorphic activity plot
338    pub neuromorphic_plot: NeuromorphicActivityPlot,
339    /// Interactive performance dashboard
340    pub performance_dashboard: InteractivePerformanceDashboard,
341    /// SVG content as string
342    pub svg_content: String,
343    /// Interactive JavaScript
344    pub interactive_script: String,
345}
346
347/// Quantum coherence animation data
348#[derive(Debug)]
349pub struct QuantumCoherenceAnimation {
350    /// Animation frames
351    pub frames: Vec<QuantumCoherenceFrame>,
352    /// Total duration in seconds
353    pub duration: f64,
354    /// Frames per second
355    pub fps: f64,
356}
357
358/// Single quantum coherence frame
359#[derive(Debug, Clone)]
360pub struct QuantumCoherenceFrame {
361    /// Frame timestamp
362    pub timestamp: f64,
363    /// Coherence visualization elements
364    pub elements: Vec<SvgElement>,
365    /// Quantum field strength
366    pub field_strength: Array2<f64>,
367}
368
369/// Neuromorphic activity plot
370#[derive(Debug)]
371pub struct NeuromorphicActivityPlot {
372    /// Activity matrix (time x neurons)
373    pub activity_matrix: Array2<f64>,
374    /// Spike trains
375    pub spike_trains: Array2<f64>,
376    /// Plasticity changes
377    pub plasticity_changes: Array2<f64>,
378    /// Time resolution
379    pub time_resolution: f64,
380}
381
382/// Interactive performance dashboard
383#[derive(Debug)]
384pub struct InteractivePerformanceDashboard {
385    /// Performance metrics
386    pub performance_metrics: HashMap<String, f64>,
387    /// Improvement factors
388    pub improvements: HashMap<String, f64>,
389    /// Metrics timeline
390    pub metrics_timeline: Vec<MetricTimelinePoint>,
391    /// Execution summary
392    pub execution_summary: ExecutionSummary,
393}
394
395/// Timeline point for metrics
396#[derive(Debug, Clone)]
397pub struct MetricTimelinePoint {
398    /// Timestamp
399    pub timestamp: f64,
400    /// Quantum coherence at this time
401    pub quantum_coherence: f64,
402    /// Neural adaptation rate
403    pub neural_adaptation: f64,
404    /// AI confidence
405    pub ai_confidence: f64,
406}
407
408/// Execution summary
409#[derive(Debug, Clone)]
410pub struct ExecutionSummary {
411    /// Total execution time
412    pub total_time: f64,
413    /// Memory usage
414    pub memory_usage: f64,
415    /// Number of iterations
416    pub iterations: usize,
417    /// Selected algorithm
418    pub algorithm: String,
419    /// Final confidence
420    pub confidence: f64,
421}
422
423impl Default for NativePlotConfig {
424    fn default() -> Self {
425        Self {
426            width: 1200,
427            height: 800,
428            enable_interactivity: true,
429            enable_animations: true,
430            animation_fps: 30.0,
431            color_scheme: PlotColorScheme::Quantum,
432            export_quality: ExportQuality::High,
433        }
434    }
435}