Conversation
|
Hi @StendProg, I really like the direction of this PR! Having decorators like these that we can place on plottable data variables, combined with methods which can check them for validity, is an excellent combination. This will indeed make it easier for users to troubleshoot plots that fail due to bad data.
Actually, it may be best to delete these demos since they throw exceptions which crash the cookbook and demo application. I'm not sure of the best way to communicate that this feature exists though. I wonder if it would be a good idea to put This would make it easier to see for new users creating console applications, but unfortunately it would not be seen by people using the user control. I will continue to think about this problem! |
|
Hi Scott (@swharden ),
The sole purpose of these demos is to let the user know about this mode, I think you will find a beautiful solution without them.
Demo can use second variant, and replace demo description with error detail on event. But I think most users will be satisfied with getting an exception to diagnose and fix the problem... |
src/ScottPlot/Diagnostic/CheckFiledsOrderedAccendingDecorator.cs
Outdated
Show resolved
Hide resolved
|
To make sure the user knows that diagnostic mode is not intended to be used for non-debugging purposes for performance reasons, it may make sense to log a warning when it is enabled? |
|
I like the idea... Maybe something like Debug.WriteLine("WARNING: diagnostic mode is enabled, reducing performance") Perhaps with some logic so the message is only shown once? |
|
@Benny121221 pointed to the thing I missed. There is a What can be left of all this is clever universal checks through reflection on attributes. This will greatly reduce code cohesion and eliminate duplication. The only drawback is the visual pollution of the code with attributes. |
I agree this is clever code, but I'm not totally convinced yet that decorators are the best way to solve this problem. A It might be nicer to put all validation information for a plottable inside a public bool AssertValidityBeforeRender = false; // diagnostic mode if true
public void AssertValidity(){
Assert.NotNull(Xs, "Xs cannot be null");
Assert.NotNull(Ys, "Ys cannot be null");
Assert.EqualLength(Xs, Ys, "Xs and Ys have different lengths");
Assert.AllReal(Xs, "Xs cannot contain infinity or NaN");
Assert.AllReal(Ys, "Ys cannot contain infinity or NaN");
Assert.Ascending(Xs, "Xs cannot contain any descending values");
}I will continue to think about this! These are all interesting ideas. |
We can mark
Decorators, in my terms, are the objects that wrapped the plottable, I have already abandoned them, at least as long as But mark proprtyes with attributes is another concept. The only thing that keeps this PR from closing. A significant drawback of attribute-based checks is that you will have to request properties through reflection, which is tens of times slower than the usual approach. But since these checks are only for special mode, where performance is not significant, this does not matter much. |
Add FiniteNumberAttribute which run NotNAN and NotInfinity checks
… with ValidateData only.
… with ValidateData only.
|
I think it's finished. |
|
Thank you for your hard work on this @StendProg! As I work toward refactoring the constructors for all plottables (#573) I'll review their public properties and continue to build upon this work. |
excellent code and logic introduced in #553 has now been moved inside individual plottables

Purpose:
Sometimes users provide incorrect data and blame library for incorrect results #546.
This PR allow user to enable
Diagnostic modeat init of their project.As a result, multiple data checks are enabled before each render, and detailed exceptions are thrown if the data is not in the correct format.
With diagnostic mode turned off, there are absolutely no negative performance impacts compared to the existing code.
Added a stub for
IValidatableData. If some plottable implements it, instead of attribute checks simple callIValidatableData.ValidateData()PR contains 3
Diagnostic modedemo.It needs a good names and descriptions. My bad English won't let me do it myself.
Also feel free to change any namings in this PR.
Expansion of this PR
To enable existing types of check on new plottable fields, just mark it with existing attribute:
this field will start to automaticaly be checked for NAN value in
Diagnostic modeTo make new Type of check:
Attributediscribing this check. A short name is very preferred because attributes create a lot of visual noise inPlottables.FieldsCheckerderived fromFieldsCheckerBase.DiagnosticDataChecker.Checks.Plottablefields with newAttributeNew functionality (code):