Use ILPlotCube.Limits
instead! The ILLimits
class manages the axis limits for a plotcube. It provides the Changed
event. You can use that in order to reflect changes to other plot cubes.
private void ilPanel1_Load_1(object sender, EventArgs e) {
// just some data
ILArray<float> A1 = new float[] { 1,4,3,2,5 };
// setup new plot cube
var pc1 = ilPanel1.Scene.Add(new ILPlotCube("pc1") {
ScreenRect = new RectangleF(0,0,1,.6f)
});
// 2nd plot cube
ILArray<float> A2 = new float[] { -1,-4,-3,-2,4 };
var pc2 = ilPanel1.Scene.Add(new ILPlotCube("pc2") {
ScreenRect = new RectangleF(0, .4f, 1, .6f)
});
// add line plots to the plot cubes
pc1.Add(new ILLinePlot(A1));
pc2.Add(new ILLinePlot(A2));
// Synchronize changes to the limits property
// NOTE: mouse interaction is fired on the SYNCHRONIZED COPY
// of the plot cube, which is maintained for each individual ILPanel!
pc1 = ilPanel1.SceneSyncRoot.First<ILPlotCube>("pc1");
pc2 = ilPanel1.SceneSyncRoot.First<ILPlotCube>("pc2");
pc1.Limits.Changed += (_s, _a) => { SynchXAxis(pc1.Limits, pc2.Limits); };
pc2.Limits.Changed += (_s, _a) => { SynchXAxis(pc2.Limits, pc1.Limits); };
}
private void SynchXAxis(ILLimits lim1, ILLimits lim2) {
// synch x-axis lim1 -> lim2
Vector3 min = lim2.Min;
Vector3 max = lim2.Max;
min.X = lim1.XMin; max.X = lim1.XMax;
// disable eventing to prevent from feedback loops
lim2.EventingSuspend();
lim2.Set(min, max);
lim2.EventingStart(); // discards Changed events
}

Now, when you zoom / pan with the mouse, changes to one plot cube gets transferred to the other plot cube. This acts on the X axes only. Other limits will not be affected.
Two Hints
1) Keep in mind that mouse interaction does not affect the original plot cube object you created but instead change a synchronized copy of it. The copy is maintained by the ILPanel internally and prevents from multithreading issues as well as from changes to one instance populating back to other instances which may existing in other panels. In order to get informed about those changes, you must wire up to the event handler of the synchronized copy. ILPanel.SceneSynchRoot
provides you access.
2) When transferring the changes from the Limits
of one plot cube to the other one should disable the eventing on the target limits object. Otherwise, it would trigger another Changed
event and the events would fire endlessly. The ILLimits.EventingStart()
function reenables the eventing after your changes and discards all events accumulated so far.