Multiple PlotCube Sync

Several ILPlotCubes in the same ILScene react independently of mouse interaction. Sample document here .

Each of my PlotCubes contains one LinePlot, and I need the X-Axis of both PlotCubes to be aligned. Therefore, an event is needed that notifies me when the X-Axis in one PlotCube changes due to mouse interaction.

Could not find anything in the documentation or search engines. Was there any limited testing with mouse events (complex, possible?). Found class ILAxisChangedEventArgs, but not an event.

+4
source share
1 answer

ILPlotCube.Limits ! ILLimits plotcube. Changed. , .

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
}

enter image description here

, / , . X. .

1) , , , . ILPanel , , , . , . ILPanel.SceneSynchRoot .

2) When transferring changes from Limitsone plot cube to another, you need to disable the event on the target limits object. Otherwise, it will trigger another event Changed, and the events will fire indefinitely. The function ILLimits.EventingStart()repeats the event after the changes and cancels all the events accumulated so far.

+2
source

Source: https://habr.com/ru/post/1538653/


All Articles