Skip to content

Detached legend improved interactivity#1655

Merged
swharden merged 27 commits intoScottPlot:masterfrom
BambOoxX:DetachedLegend-Improved-Interactivity
Mar 2, 2022
Merged

Detached legend improved interactivity#1655
swharden merged 27 commits intoScottPlot:masterfrom
BambOoxX:DetachedLegend-Improved-Interactivity

Conversation

@BambOoxX
Copy link
Contributor

Purpose:

  • This branch impements various improvements for the detached legend feature on winforms.
  • The detached legend hides a visible legend upon opening and restores it upon closing (fixes Detachable legend doesn't work as expected in demo #1651).
  • Additional options are provided to highlight, delete, re-style a plottable from a right-click menu.

Note :

  • The highlight process relies on a vector stored in the detached legend form. A isHighlighted property of a LegendItem would probably be better, but I wanted to propose this PR as such before changing that.
  • The removal process may conflict with the highlight process at the moment.

- Opening a detached legend now hides the initial legend in the `FormsPlot` resulting in a true *detaching* of the `Legend` (fix ScottPlot#1651).
    - This requires the addition of a `isDetached` flag to `Legend` defaulting to `false`
   - This initial visibility is stored in a new `FormsPlotLegendViewer` property `InitialLegendVisibility`
   - Upon closing of the detached Legend, the `InitialLegendVisibility`  is used to re-display the original `Legend` if relevant
- A plottable can now be highlighted, deleted or re-styled by opening a right-click menu on a `LegendItem`. This implementation is very basic though.
- Made some refactors to `GetLegendItemUnderMouse` to accomodate different location sources.
@BambOoxX
Copy link
Contributor Author

@swharden This is a very basic implementation of what is quite useful is Matlab :

image

Copy link
Member

@swharden swharden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi BambOoxX, thanks for this PR!

My biggest concern is just the switching/casting that has to be done because the interfaces aren't there to do it a better way.

I'd probably recommend using separate PRs for implementing those interfaces and extending the menu to support customization vs. a PR which specifically resolves #1651

- Opening a detached legend now hides the initial legend in the `FormsPlot` resulting in a true *detaching* of the `Legend` (fix ScottPlot#1651).
    - This requires the addition of a `isDetached` flag to `Legend` defaulting to `false`
   - This initial visibility is stored in a new `FormsPlotLegendViewer` property `InitialLegendVisibility`
   - Upon closing of the detached Legend, the `InitialLegendVisibility`  is used to re-display the original `Legend` if relevant
- A plottable can now be highlighted, deleted or re-styled by opening a right-click menu on a `LegendItem`. This implementation is very basic though.
- Made some refactors to `GetLegendItemUnderMouse` to accomodate different location sources.
…`IHasLine`, `IHasMarker`)

- Removed casting to `ScatterPlot` or `SignalPlot`, but some castings to the interfaces remain, not sure how to avoid them
- Removed useless `HighlightedPlottabes` and `ClickedIndex`
- Highlight logic now hidden in `Render` of each specific `IIsHighlightable`
- Added `GetHighlightedItems` to `Legend` to retrieve the list of `LegendItem`s associated with highlightable plottables
@BambOoxX
Copy link
Contributor Author

Here is a preview of the extended functionalities

test3.mp4

@swharden swharden mentioned this pull request Feb 17, 2022
@BambOoxX
Copy link
Contributor Author

@swharden I tested this branch this morning, and I believe everything works as intended, do you think it is worth merging as such or do you see other improvements ?

@swharden
Copy link
Member

do you think it is worth merging as such or do you see other improvements?

I haven't looked at this one in detail yet. My commits so far have just been to ensure this branch keeps building successfully, and my goal is to get the lower-level Marker refactoring done before moving to this higher-level GUI-related PR, but hopefully I'll finish all these over today and tomorrow 👍

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Feb 19, 2022

@swharden Allright, just tell me if you need help on this.

@BambOoxX
Copy link
Contributor Author

Hey @swharden Do you think this is ready for a merge ? It seems last modifications in #1690 did not break anything, and I just added support for modifications of this property.

@swharden
Copy link
Member

Hi @BambOoxX, thanks for the follow-up! The short answer is that I haven't had a long enough time block for me to sit down and review this PR yet. I've had smaller bits of free time I've devoted to quicker/prioritized tasks in this and other repos (hence my recent GitHub activity, but inaction on this specific PR), but I still haven't gotten the time I need to review this yet. I don't want to short-change this work by picking it up and putting it down a bunch of times - it would be best if I can review it all in one sitting.

Complicating things is that there's been a work-related issue that has been greatly encroaching on my free time to do open-source work. I've been at the laboratory late every day and am working through this weekend there to try to resolve it, but it's likely to persist for a few more days, and after that I'll be a lot more free to work on this PR.

Thanks again for your work here and recent efforts here and on #1689, #1690, and #1692! All of these are fantastic improvements 🚀

@swharden
Copy link
Member

ready for a merge

Oh, and technically merging is blocked because the build is failing due to the autoformatter not being run 🙃

dotnet tool update -g dotnet-format
dotnet-format

@BambOoxX
Copy link
Contributor Author

Haha, the famous autoformatter. I believe I can solve that easily 😅.

I understand your position, it was just a gentle poke to see if I was going in the right direction or not.

I have a feeling this kind of interactive behavior can attract new users to this library.

I'll let you review this whenever you can, no big deal. If you see something I can improve in the meantime, don't hesitate to indicate it.

Finally, thanks for the kind words. This is really the first C# project I'm actively contributing to, so it's really nice to be able to learn whil being helpful. Cheers!

swharden added 7 commits March 1, 2022 23:08
Favored switch expressions over switch statements and removed XML docs where function names were descriptive enough to convey functionality and purpose.

Code comments were retained where code was exceptionally confusing.
@swharden
Copy link
Member

swharden commented Mar 2, 2022

Hi @BambOoxX, thanks for this PR! I was able to review it and I'll merge it in shortly. I'll share some of my thoughts here so you can learn more about my line of thinking (not as a criticism of your work), and to clarify why I was a bit slow to get to this PR and why I'm often hesitant to extend GUI-related features

I have a feeling this kind of interactive behavior can attract new users to this library

Yes... but it's also really hard to maintain as a library maintainer 😅

GUI code like this is a bit finnicky (and difficult to test), and if the Legend, LineStyle, or Marker code, etc. ever change in the future, it may also require re-testing (and possibly new code edits) in this module. I'm not super concerned about this particular PR because the GUI features are tucked away under an overridable right-click menu, but in general I try to avoid adding GUI features to this library.

Also there's a goal of achieving consistent behavior across the WinForms control, WPF control, Avalonia control, and Eto control, so technically anything we add in one means multiplying the effort across all 4 of these. Let's not worry about it for this feature, but FYI that's another reason I hesitate to add new GUI functionality.

It's pretty easy for users to write GUI code to satisfy their use cases, so I try to lean wherever possible toward making it easy for users to customize their own GUI rather than predict all their use cases and support them from this side of the library.

Finally, thanks for the kind words. This is really the first C# project I'm actively contributing to, so it's really nice to be able to learn while being helpful. Cheers!

Wow! This is a complicated project, and this PR touches some advanced topics and obscure WinForms behavior, and you're doing fantastic! 🚀 Are you a student? If you're interested in getting plugged into some more circles feel free to email me [email protected] and I can share a few resources with you that I found helpful.

Thanks again for your work on this PR!

@swharden swharden merged commit 90ef7a6 into ScottPlot:master Mar 2, 2022
@BambOoxX BambOoxX deleted the DetachedLegend-Improved-Interactivity branch March 8, 2022 10:26
@BambOoxX
Copy link
Contributor Author

BambOoxX commented Mar 8, 2022

Wow! This is a complicated project, and this PR touches some advanced topics and obscure WinForms behavior, and you're doing fantastic! 🚀 Are you a student? If you're interested in getting plugged into some more circles feel free to email me [email protected] and I can share a few resources with you that I found helpful.

Haha, no I'm not a student, but most of my work before last year was focused on low-level computational stuff. I just discovered the upper GUI layer world. What dou you mean by plugged into some circles ?

@swharden
Copy link
Member

swharden commented Mar 8, 2022

This is really the first C# project I'm actively contributing to

my work before last year was focused on low-level computational stuff ... What do you mean by plugged into some circles?

Ah okay, that makes sense. My offer sounded more cryptic than was intended! I was just going to list some some resources I found useful for getting plugged-in a little deeper to the C#/programming community. If you were looking for more projects to contribute to or wanted to get some perspectives related to entering the job market for the first time (useful information for students) they might be helpful.

I'll list some info here in case someone else following is interested:

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Mar 8, 2022

@swharden Thanks for the helpful links, I'll check them when I get some spare time. Though I'm not a student anymore, I'm learning new stuff every day, also by trying to contribute ! I'm not sure I can contribute, but whenever I get the chance I try to participate to the extent of my abilities, a way to return the favor to the persons initiating such projects I use like yourself !

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.

Detachable legend doesn't work as expected in demo

2 participants