Skip to content

Commit

Permalink
feat!: initial change for plotting individual figures
Browse files Browse the repository at this point in the history
BREAKING: not all individual figures are supported
  • Loading branch information
mfacchinelli committed Sep 3, 2024
1 parent 1397cd1 commit 14555e6
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/+mag/+app/+control/Control.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
classdef (Abstract) Control < matlab.mixin.Heterogeneous & mag.mixin.SetGet
% CONTROL Abstract base class for view-controllers.

properties (SetAccess = immutable)
% PARENT Parent of view-controller.
Parent (1, 1) matlab.ui.container.Panel
% RESULTS Results to plot.
Results (1, 1) mag.Instrument
end

methods

function this = Control(parent, results)

this.Parent = parent;
this.Results = results;
end
end

methods (Abstract)

% INSTANTIATE Populate view-control elements.
instantiate(this)

% VISUALIZE Plot all figures.
figures = visualize(this)
end

methods (Access = protected)

function results = cropResults(this, startTime, endTime)

arguments
this
startTime (1, 1) datetime
endTime (1, 1) datetime
end

if ismissing(startTime)
startTime = datetime("-Inf", TimeZone = "UTC");
end

if ismissing(endTime)
endTime = datetime("Inf", TimeZone = "UTC");
end

period = timerange(startTime, endTime, "closed");

results = this.Results.copy();
results.crop(period);
end
end
end
80 changes: 80 additions & 0 deletions app/+mag/+app/+control/Field.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
classdef Field < mag.app.control.Control
% FIELD View-controller for generating "mag.graphics.view.Field".

properties (Access = private)
% LAYOUT Grid layout of view-controller.
Layout matlab.ui.container.GridLayout
% STARTDATEPICKER Start date picker for cropping.
StartDatePicker matlab.ui.control.DatePicker
% STARTTIMEPICKER Start time edit field for cropping.
StartTimeField matlab.ui.control.EditField
% ENDDATEPICKER End date picker for cropping.
EndDatePicker matlab.ui.control.DatePicker
% ENDTIMEPICKER End time edit field for cropping.
EndTimeField matlab.ui.control.EditField
% EVENTSTREE Events checkbox tree.
EventsTree matlab.ui.container.CheckBoxTree
end

methods

function instantiate(this)

this.Layout = uigridlayout(this.Parent, [3, 3], RowHeight = ["1x", "1x", "2x"], ColumnWidth = ["fit", "1x", "1x"]);

% Start date.
startLabel = uilabel(this.Layout, Text = "Start date/time:");
startLabel.Layout.Row = 1;
startLabel.Layout.Column = 1;

this.StartDatePicker = uidatepicker(this.Layout);
this.StartDatePicker.Layout.Row = 1;
this.StartDatePicker.Layout.Column = 2;

this.StartTimeField = uieditfield(this.Layout, Placeholder = "HH:mm:ss.SSS");
this.StartTimeField.Layout.Row = 1;
this.StartTimeField.Layout.Column = 3;

% End date.
endLabel = uilabel(this.Layout, Text = "End date/time:");
endLabel.Layout.Row = 2;
endLabel.Layout.Column = 1;

this.EndDatePicker = uidatepicker(this.Layout);
this.EndDatePicker.Layout.Row = 2;
this.EndDatePicker.Layout.Column = 2;

this.EndTimeField = uieditfield(this.Layout, Placeholder = "HH:mm:ss.SSS");
this.EndTimeField.Layout.Row = 2;
this.EndTimeField.Layout.Column = 3;

% Events.
eventsLabel = uilabel(this.Layout, Text = "Events:");
eventsLabel.Layout.Row = 3;
eventsLabel.Layout.Column = 1;

this.EventsTree = uitree(this.Layout, "checkbox");
this.EventsTree.Layout.Row = 3;
this.EventsTree.Layout.Column = [2, 3];

for e = ["Compression", "Mode", "Range"]
uitreenode(this.EventsTree, Text = e);
end
end

function figures = visualize(this)

startTime = mag.app.internal.combineDateAndTime(this.StartDatePicker.Value, this.StartTimeField.Value);
endTime = mag.app.internal.combineDateAndTime(this.EndDatePicker.Value, this.EndTimeField.Value);

if isempty(this.EventsTree.CheckedNodes)
events = string.empty();
else
events = {this.EventsTree.CheckedNodes.Text};
end

results = this.cropResults(startTime, endTime);
figures = mag.graphics.view.Field(results, Events = events).visualizeAll();
end
end
end
44 changes: 44 additions & 0 deletions app/+mag/+app/+internal/combineDateAndTime.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function dateTime = combineDateAndTime(date, time)
% COMBINEDATEANDTIME Combine a datetime and an optional time string as a
% datetime.

arguments (Input)
date (1, 1) datetime
time string {mustBeScalarOrEmpty}
end

arguments (Output)
dateTime (1, 1) datetime
end

dateTime = date;

if ~isempty(time)
dateTime = dateTime + decodeTime(time);
end

dateTime.Format = mag.time.Constant.Format;
dateTime.TimeZone = mag.time.Constant.TimeZone;
end

function time = decodeTime(time)

formats = ["hh:mm", "hh:mm:ss", "hh:mm:ss.SSS"];
conversion = @(f) duration(time, InputFormat = f);

for f = formats

try

time = conversion(f);
return;
catch exception

if ~isequal(exception.identifier, "MATLAB:duration:DataMismatchedFormat")
exception.rethrow();
end
end
end

error("Unable to parse '%s' using the formats %s.", time, join(compose("'%s'", formats), ", "));
end
Binary file modified app/DataVisualization.mlapp
Binary file not shown.
4 changes: 4 additions & 0 deletions resources/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# App

- Add option to select individual figures to plot

# Software

## Graphics
Expand Down

0 comments on commit 14555e6

Please sign in to comment.