Why is event PreUpdate and PostUpdate not triggered in ChartContainer?

16 次查看(过去 30 天)
Hi all,
I’ve created a ChartContainer in MATLAB R2024b and need to track when its update routine finishes so I can restore an internal property to its original value. During setup, I added listeners for the PreUpdate and PostUpdate events of the ChartContainer.
However, when I change a property, the update method runs, but neither the PreUpdate nor PostUpdate events seem to fire.
Below I share the class implementation:
classdef TestComponent < matlab.graphics.chartcontainer.ChartContainer
%% Properties
properties (AbortSet)
% Internal use. Indicates update is required, triggered by external
% property.
TriggerUpdate (1,1) logical = false;
end %properties
properties (Transient, NonCopyable, Hidden, SetAccess = protected, UsedInUpdate = false)
% Event listener array
EventListeners (1,:) event.listener
end
%% Protected Methods
methods (Access = protected)
function setup(obj)
% Setup routine
% Show setup routine is executed
disp('setup')
% Setup listeners to all events in the class
metaClass = meta.class.fromName(class(obj));
eventList = {metaClass.EventList.Name};
listenAcces = {metaClass.EventList.ListenAccess};
% Initialize listener to post-update event
for idx = 1:numel(eventList)
if ~strcmpi(listenAcces{idx}, {'public', 'protected'})
continue
end
obj.EventListeners(end+1) = listener(obj, ...
eventList{idx}, @(s,e) obj.showEvent(e));
end
end %function
function update(obj)
% Update routine
% Show update routine is executed
disp('update')
end %function
end %methods
methods
function showEvent(obj, e)
disp(e)
end %function
end %methods
end
Does anyone know why these events aren’t triggered? For ComponentContainer, the events work as expected.

采纳的回答

Aditya
Aditya about 23 hours 前
Hi Jacob,
You have observed correctly: PreUpdate and PostUpdate events are available and documented for ComponentContainer (UI components), but not for ChartContainer (axes-based charts).Why aren't PreUpdate/PostUpdate firing in ChartContainer?
  • ChartContainer does not define or fire PreUpdate/PostUpdate events.
  • The MATLAB documentation for ComponentContainer explicitly lists these events, but the ChartContainer documentation does not.
  • This is by design: ChartContainer update cycle is not evented in the same way as ComponentContainer.
You can try the following steps:
  • Override the update method and place your logic before and after calling the superclass update, if needed.
  • If you need to execute code after every update, do it at the end of your update method.
  • If you have code that should run before an update, do it at the beginning of update.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Developing Chart Classes 的更多信息

产品


版本

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by