scirs2_metrics/visualization/advanced_interactive/
core.rs

1//! Core types and configurations for advanced interactive visualization
2//!
3//! This module provides the fundamental types, configurations, and structures
4//! that are shared across the interactive visualization system.
5
6#![allow(clippy::too_many_arguments)]
7#![allow(dead_code)]
8
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11use std::time::Duration;
12
13/// Dashboard configuration
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct DashboardConfig {
16    /// Dashboard title
17    pub title: String,
18    /// Width in pixels
19    pub width: u32,
20    /// Height in pixels
21    pub height: u32,
22    /// Theme configuration
23    pub theme: ThemeConfig,
24    /// Layout configuration
25    pub layout: LayoutConfig,
26    /// Float-time update settings
27    pub realtime_config: RealtimeConfig,
28    /// Interaction settings
29    pub interaction_config: InteractionConfig,
30    /// Export settings
31    pub export_config: ExportConfig,
32    /// Collaboration settings
33    pub collaboration_config: Option<CollaborationConfig>,
34}
35
36/// Theme configuration for the dashboard
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ThemeConfig {
39    /// Primary color scheme
40    pub primary_color: String,
41    /// Secondary color scheme
42    pub secondary_color: String,
43    /// Background color
44    pub background_color: String,
45    /// Text color
46    pub text_color: String,
47    /// Font family
48    pub font_family: String,
49    /// Font size
50    pub font_size: u32,
51    /// Border radius
52    pub border_radius: u32,
53    /// Shadow settings
54    pub shadow_enabled: bool,
55    /// Custom CSS variables
56    pub custom_variables: HashMap<String, String>,
57}
58
59/// Layout configuration
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct LayoutConfig {
62    /// Layout type
63    pub layout_type: LayoutType,
64    /// Grid configuration (if using grid layout)
65    pub grid_config: Option<GridConfig>,
66    /// Spacing configuration
67    pub spacing: SpacingConfig,
68    /// Animation configuration
69    pub animation: AnimationConfig,
70    /// Responsive breakpoints
71    pub breakpoints: HashMap<String, u32>,
72}
73
74/// Layout type enumeration
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub enum LayoutType {
77    /// Fixed layout
78    Fixed,
79    /// Responsive grid layout
80    Grid,
81    /// Flexible layout
82    Flexbox,
83    /// Masonry layout
84    Masonry,
85    /// Custom layout
86    Custom(String),
87}
88
89/// Grid configuration
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct GridConfig {
92    /// Number of columns
93    pub columns: u32,
94    /// Number of rows
95    pub rows: u32,
96    /// Column gap
97    pub column_gap: u32,
98    /// Row gap
99    pub row_gap: u32,
100    /// Auto-fit columns
101    pub auto_fit: bool,
102}
103
104/// Spacing configuration
105#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct SpacingConfig {
107    /// Margin
108    pub margin: u32,
109    /// Padding
110    pub padding: u32,
111    /// Widget spacing
112    pub widget_spacing: u32,
113    /// Container spacing
114    pub container_spacing: u32,
115}
116
117/// Animation configuration
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct AnimationConfig {
120    /// Enable animations
121    pub enabled: bool,
122    /// Animation duration
123    pub duration: Duration,
124    /// Easing function
125    pub easing: String,
126    /// Performance mode
127    pub performance_mode: bool,
128}
129
130/// Float-time configuration
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct RealtimeConfig {
133    /// Enable real-time updates
134    pub enabled: bool,
135    /// Update interval
136    pub update_interval: Duration,
137    /// Buffer size for data
138    pub buffer_size: usize,
139    /// Maximum concurrent connections
140    pub max_connections: u32,
141    /// Streaming protocol
142    pub protocol: StreamingProtocol,
143    /// Connection timeout
144    pub connection_timeout: Duration,
145    /// Retry attempts
146    pub retry_attempts: u32,
147}
148
149/// Streaming protocol enumeration
150#[derive(Debug, Clone, Serialize, Deserialize)]
151pub enum StreamingProtocol {
152    /// WebSocket protocol
153    WebSocket,
154    /// Server-Sent Events
155    SSE,
156    /// Long polling
157    LongPolling,
158    /// WebRTC
159    WebRTC,
160}
161
162/// Interaction configuration
163#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct InteractionConfig {
165    /// Enable touch interactions
166    pub touch_enabled: bool,
167    /// Enable keyboard shortcuts
168    pub keyboard_shortcuts: bool,
169    /// Enable zoom and pan
170    pub zoom_pan_enabled: bool,
171    /// Enable selection
172    pub selection_enabled: bool,
173    /// Enable drag and drop
174    pub drag_drop_enabled: bool,
175    /// Double-click threshold
176    pub double_click_threshold: Duration,
177    /// Hover delay
178    pub hover_delay: Duration,
179    /// Custom interaction handlers
180    pub custom_handlers: HashMap<String, String>,
181}
182
183/// Export configuration
184#[derive(Debug, Clone, Serialize, Deserialize)]
185pub struct ExportConfig {
186    /// Supported export formats
187    pub formats: Vec<ExportFormat>,
188    /// Default format
189    pub default_format: ExportFormat,
190    /// Quality settings
191    pub quality: u32,
192    /// Include metadata
193    pub include_metadata: bool,
194    /// Compression enabled
195    pub compression: bool,
196}
197
198/// Export format enumeration
199#[derive(Debug, Clone, Serialize, Deserialize)]
200pub enum ExportFormat {
201    /// PNG image
202    PNG,
203    /// JPEG image
204    JPEG,
205    /// SVG vector
206    SVG,
207    /// PDF document
208    PDF,
209    /// HTML file
210    HTML,
211    /// JSON data
212    JSON,
213}
214
215/// Collaboration configuration
216#[derive(Debug, Clone, Serialize, Deserialize)]
217pub struct CollaborationConfig {
218    /// Enable collaboration
219    pub enabled: bool,
220    /// Authentication configuration
221    pub auth: AuthConfig,
222    /// Sharing configuration
223    pub sharing: ShareConfig,
224    /// Synchronization configuration
225    pub sync: SyncConfig,
226    /// Maximum collaborators
227    pub max_collaborators: u32,
228}
229
230/// Authentication configuration
231#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct AuthConfig {
233    /// Authentication method
234    pub method: AuthMethod,
235    /// Session timeout
236    pub session_timeout: Duration,
237    /// Enable guest access
238    pub guest_access: bool,
239    /// Required permissions
240    pub required_permissions: Vec<String>,
241}
242
243/// Authentication method enumeration
244#[derive(Debug, Clone, Serialize, Deserialize)]
245pub enum AuthMethod {
246    /// No authentication
247    None,
248    /// Token-based authentication
249    Token,
250    /// OAuth authentication
251    OAuth,
252    /// API key authentication
253    ApiKey,
254    /// Custom authentication
255    Custom(String),
256}
257
258/// Share configuration
259#[derive(Debug, Clone, Serialize, Deserialize)]
260pub struct ShareConfig {
261    /// Enable public sharing
262    pub public_sharing: bool,
263    /// Default permission level
264    pub default_permission: PermissionLevel,
265    /// Link expiration
266    pub link_expiration: Option<Duration>,
267    /// Password protection
268    pub password_protection: bool,
269}
270
271/// Permission level enumeration
272#[derive(Debug, Clone, Serialize, Deserialize)]
273pub enum PermissionLevel {
274    /// Read-only access
275    ReadOnly,
276    /// Comment access
277    Comment,
278    /// Edit access
279    Edit,
280    /// Admin access
281    Admin,
282}
283
284/// Synchronization configuration
285#[derive(Debug, Clone, Serialize, Deserialize)]
286pub struct SyncConfig {
287    /// Sync interval
288    pub sync_interval: Duration,
289    /// Conflict resolution strategy
290    pub conflict_resolution: ConflictResolution,
291    /// Enable operational transforms
292    pub operational_transforms: bool,
293    /// History retention
294    pub history_retention: Duration,
295}
296
297/// Conflict resolution strategy enumeration
298#[derive(Debug, Clone, Serialize, Deserialize)]
299pub enum ConflictResolution {
300    /// Last writer wins
301    LastWriterWins,
302    /// First writer wins
303    FirstWriterWins,
304    /// Manual resolution
305    Manual,
306    /// Merge changes
307    Merge,
308}
309
310/// Position configuration
311#[derive(Debug, Clone, Serialize, Deserialize)]
312pub struct Position {
313    /// X coordinate
314    pub x: f64,
315    /// Y coordinate
316    pub y: f64,
317}
318
319/// Size configuration
320#[derive(Debug, Clone, Serialize, Deserialize)]
321pub struct Size {
322    /// Width
323    pub width: f64,
324    /// Height
325    pub height: f64,
326}
327
328impl Default for DashboardConfig {
329    fn default() -> Self {
330        Self {
331            title: "Interactive Dashboard".to_string(),
332            width: 1200,
333            height: 800,
334            theme: ThemeConfig::default(),
335            layout: LayoutConfig::default(),
336            realtime_config: RealtimeConfig::default(),
337            interaction_config: InteractionConfig::default(),
338            export_config: ExportConfig::default(),
339            collaboration_config: None,
340        }
341    }
342}
343
344impl Default for ThemeConfig {
345    fn default() -> Self {
346        Self {
347            primary_color: "#007bff".to_string(),
348            secondary_color: "#6c757d".to_string(),
349            background_color: "#ffffff".to_string(),
350            text_color: "#212529".to_string(),
351            font_family: "Arial, sans-serif".to_string(),
352            font_size: 14,
353            border_radius: 4,
354            shadow_enabled: true,
355            custom_variables: HashMap::new(),
356        }
357    }
358}
359
360impl Default for LayoutConfig {
361    fn default() -> Self {
362        Self {
363            layout_type: LayoutType::Grid,
364            grid_config: Some(GridConfig::default()),
365            spacing: SpacingConfig::default(),
366            animation: AnimationConfig::default(),
367            breakpoints: HashMap::new(),
368        }
369    }
370}
371
372impl Default for GridConfig {
373    fn default() -> Self {
374        Self {
375            columns: 12,
376            rows: 8,
377            column_gap: 16,
378            row_gap: 16,
379            auto_fit: true,
380        }
381    }
382}
383
384impl Default for SpacingConfig {
385    fn default() -> Self {
386        Self {
387            margin: 16,
388            padding: 16,
389            widget_spacing: 8,
390            container_spacing: 24,
391        }
392    }
393}
394
395impl Default for AnimationConfig {
396    fn default() -> Self {
397        Self {
398            enabled: true,
399            duration: Duration::from_millis(300),
400            easing: "ease-in-out".to_string(),
401            performance_mode: false,
402        }
403    }
404}
405
406impl Default for RealtimeConfig {
407    fn default() -> Self {
408        Self {
409            enabled: true,
410            update_interval: Duration::from_millis(1000),
411            buffer_size: 1000,
412            max_connections: 100,
413            protocol: StreamingProtocol::WebSocket,
414            connection_timeout: Duration::from_secs(30),
415            retry_attempts: 3,
416        }
417    }
418}
419
420impl Default for InteractionConfig {
421    fn default() -> Self {
422        Self {
423            touch_enabled: true,
424            keyboard_shortcuts: true,
425            zoom_pan_enabled: true,
426            selection_enabled: true,
427            drag_drop_enabled: true,
428            double_click_threshold: Duration::from_millis(500),
429            hover_delay: Duration::from_millis(300),
430            custom_handlers: HashMap::new(),
431        }
432    }
433}
434
435impl Default for ExportConfig {
436    fn default() -> Self {
437        Self {
438            formats: vec![ExportFormat::PNG, ExportFormat::SVG, ExportFormat::JSON],
439            default_format: ExportFormat::PNG,
440            quality: 90,
441            include_metadata: true,
442            compression: true,
443        }
444    }
445}
446
447impl Default for Position {
448    fn default() -> Self {
449        Self { x: 0.0, y: 0.0 }
450    }
451}
452
453impl Default for Size {
454    fn default() -> Self {
455        Self {
456            width: 100.0,
457            height: 100.0,
458        }
459    }
460}