Skip to content

IDraggable: DragSnap#2022

Merged
swharden merged 19 commits intoScottPlot:mainfrom
Agorath:ISnap_#2017
Aug 7, 2022
Merged

IDraggable: DragSnap#2022
swharden merged 19 commits intoScottPlot:mainfrom
Agorath:ISnap_#2017

Conversation

@Agorath
Copy link
Contributor

@Agorath Agorath commented Aug 7, 2022

Purpose:
Implemented the new ISnap-interface proposed in #2017.

Added the new ISnap interface as well as the default implementation Smooth, NearestInteger, NearestPosition.
Modified the signature of DragSnapX/Y in IDraggable and adjusted all derived classes.
Furthermore modified all relevant usages of these adjusted classes.
Added a new cookbook recipe for axis lines that shows the usage of the custom position axis snap (NearestPosition).

2022-08-07.20-22-58.mp4

Usage of the default NearestInteger and NearestPosition snap implementations:

plt.AddSignal(DataGen.Sin(51, mult: 5));
plt.AddSignal(DataGen.Cos(51, mult: 5));

var hLine = plt.AddHorizontalLine(2);
hLine.DragEnabled = true;
hLine.DragSnapY = new ScottPlot.SnapLogic.NearestInteger();

var vLine = plt.AddVerticalLine(30);
vLine.DragEnabled = true;
var snapPositions = DataGen.Consecutive(11, 5D);
vLine.DragSnapX = new ScottPlot.SnapLogic.NearestPosition(snapPositions);

Usage of a custom snap implementation:

// class CustomSnap : ISnap
// {
//     // Snap to nearest integer divisible by 3
//     public double Snap(double value)
//     {
//         var rounded = (int)Math.Round(value);
//         var distanceToDivisibleBy3 = rounded % 3;
//         return distanceToDivisibleBy3 switch
//         {
//             0 => rounded,
//             1 => rounded - 1,
//             _ => rounded + 1
//         };
//     }
// }

plt.AddSignal(DataGen.Sin(51, mult: 5));
plt.AddSignal(DataGen.Cos(51, mult: 5));

var hLine = plt.AddHorizontalLine(2);
hLine.DragEnabled = true;
hLine.DragSnapY = new NearestInteger();

var vLine = plt.AddVerticalLine(30);
vLine.DragEnabled = true;
vLine.DragSnapX = new CustomSnap();

Sebastian Schäfer added 3 commits August 7, 2022 20:13
…derived classes.

Furthermore modified all relevant usages of these adjusted classes.
Added a new cook book recipe for axis lines that shows the usage of the custom position axis snap (NearestPosition).
@Agorath Agorath changed the title I snap #2017 ISnap interface implemented Aug 7, 2022
@swharden swharden changed the title ISnap interface implemented IDraggableSnap 1D and 2D Aug 7, 2022
@swharden swharden enabled auto-merge August 7, 2022 21:10
@swharden swharden linked an issue Aug 7, 2022 that may be closed by this pull request
@swharden swharden disabled auto-merge August 7, 2022 21:13
this logic object allows separate 1D snap logic objects to be combined into a 2D snap system
IDraggable now requires a single 2D snap system. It can be replaced with a custom one if desired.
@swharden swharden changed the title IDraggableSnap 1D and 2D IDraggable: add DragSnap object Aug 7, 2022
@swharden swharden enabled auto-merge August 7, 2022 21:33
@swharden swharden changed the title IDraggable: add DragSnap object IDraggable: DragSnap Aug 7, 2022
@swharden swharden disabled auto-merge August 7, 2022 21:52
@swharden swharden enabled auto-merge August 7, 2022 23:09
@swharden swharden merged commit 672d2af into ScottPlot:main Aug 7, 2022
@Agorath Agorath deleted the ISnap_#2017 branch August 8, 2022 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ISnap

3 participants