This document provides a technical overview of the NcDashboard architecture, designed to help developers (and AI agents) understand how the components interact.
NcDashboard follows a decoupled Model-View-Controller pattern:
- Model: Located in
model/. Orchestrates data loading (viaxarray) and manages the hierarchical representation of figures (FigureNodetree). - View/Controller:
- Panel:
ncdashboard.py(Primary) - Dash:
controller.py(Secondary/Experimental)
- Panel:
The dashboard state is managed by a tree of FigureNode objects.
FigureNode(Base Class inmodel/FigureNode.py)TwoDNode: 2D Map plots (lat/lon).ThreeDNode: 3D plots (Adds a third dimension like Time or Depth with navigation).FourDNode: 4D plots (Handles both Time and Depth).
AnimationNode: Specialized node for animated plots.ProfileNode: 1D plots (e.g., vertical profiles from a map click).
id: Unique identifier (e.g.,water_temp_1).parent: Reference to the parent node (rootis a special ID).children: List of child nodes.background_color: Assigned to root-level nodes and inherited by children for visual grouping.maximized: Boolean flag for "full screen" state.
- Selection: User selects variables in the sidebar.
- Creation:
Dashboard.create_default_figureis called. - Instantiation: The appropriate
FigureNodesubclass is instantiated. - UI Wrapping: The
Dashboardwraps the node's HoloViews/Plotly object into a UI container (PanelColumnor Dashhtml.Div). - Event Linking:
marker_stream(hv.streams.Tap): Handles map clicks to triggercreate_profiles.range_stream(hv.streams.RangeXY): Tracks viewport (zoom/pan) for state persistence.
State logic is encapsulated in model/state.py and model/dashboard.py.
get_state_from_dashboard: Walks theFigureNodetree (depth-first)._serialize_node: Converts a node into a dictionary.- Includes: Colormaps, normalization (
cnorm), coordinates (time_idx,depth_idx), viewport ranges (x_range,y_range), and visual flags (maximized,background_color).
apply_state:- Sorts serialized figures by parent-child depth.
- Recreates root nodes first.
- Recreates child nodes (profiles, animations) using
_restore_figure. - Re-links viewport streams to the new UI containers.
- Sidebar: Defined in
ncdashboard.py:init_menu. Action buttons (Close All, Save/Load) are at the top, followed by variable-specific buttons for one-click plotting. - Main Area: Static
FlexBoxorColumnwhere figure containers are appended.
- Create a new subclass of
FigureNodeinmodel/. - Implement
create_figure(). - Update
Dashboard.create_default_figureto instantiate your new class. - Update
_serialize_nodeinstate.pyif the new node has unique attributes.
- Most nodes assume the last two dimensions are spatial (Lat/Lon).
- 3D/4D nodes expect Z/T dimensions at specific indices. See
model_utils.pyfor selection helpers.
- Resolutions Enum: Values are currently swapped (
HIGH="low",LOW="high") inmodel_utils.pydue to internal logic dependencies; do not "fix" without refactoringAnimationNode. - Viewport Streams: Range streams must be linked after the figure is wrapped in a Panel/Dash component for correct synchronization.