Skip to content

Ability to use custom-drawn markers#386

Closed
henkburgstra wants to merge 7 commits intoScottPlot:masterfrom
henkburgstra:master
Closed

Ability to use custom-drawn markers#386
henkburgstra wants to merge 7 commits intoScottPlot:masterfrom
henkburgstra:master

Conversation

@henkburgstra
Copy link

New contributors should review CONTRIBUTING.md:
https://github.com/swharden/ScottPlot/blob/master/CONTRIBUTING.md

Purpose:
This is a non-evasive change. The existing interface remains unchanged.

I needed the ability to use custom-drawn markers. This change adds this ability. The change adds public field Settings.markerDrawer of type IMarkerDrawer. PlottableScatter.Render uses this field if present to draw markers.

New functionality (code):
Provide a code example demonstrating new functionality achieved with this pull request (if applicable)

Implementation of IMarkerDrawer (open triangle in this case) to be used in an Audiogram (https://en.wikipedia.org/wiki/Audiogram)

    public class LuchtGemaskeerdRechts : IMarkerDrawer
    {
        public void DrawMarker(Graphics gfx, PointF pixelLocation, MarkerShape shape, float size, Color color)
        {
            var c = new MarkerConfig(gfx, pixelLocation, shape, size, color);
            gfx.DrawPolygon(c.Pen, new PointF[] { 
                new PointF(pixelLocation.X, pixelLocation.Y - size / 2),
                new PointF(pixelLocation.X - size / 2, pixelLocation.Y + size / 2),
                new PointF(pixelLocation.X + size / 2, pixelLocation.Y + size / 2)
            });
        }
    }

To be used like this:

            plt.MarkerDrawer(new LuchtGemaskeerdRechts());

New functionality (image):
image
If this pull request changes how a plot is rendered, provide an image or screenshot demonstrating the new functionality:

swharden added a commit that referenced this pull request May 16, 2020
@swharden
Copy link
Member

Hi @henkburgstra, thank you for this insightful suggestion! I really like how this PR uses interfaces to let the user create a custom marker. This seems like a really useful feature that could benefit many plottable objects.

However, this PR only addresses scatter plots. Rather than merge this PR, I added this topic to the ScottPlot roadmap because I think the whole library would benefit from refactoring away from the enum-based marker system to a class-based system with interfaces like the one you implemented here.

This is a really good idea, and it pains mt to close this PR, but I'd really like to implement this idea on a much wider scale. I'll ping you when I do so you can take a look and let me know what you think!

@swharden swharden closed this May 16, 2020
@henkburgstra
Copy link
Author

Hi Scott, thank you very much for your thoughtful response!

Could I maybe help you with this? Thank you for keeping me updated, I would rather use the original ScottPlot library than my fork in our project :)

@swharden
Copy link
Member

Could I maybe help you with this? Thank you for keeping me updated, I would rather use the original ScottPlot library than my fork in our project :)

Since the current marker system is enum based, markers are hard-coded into the library. The fastest way could be for me to add your custom markers to the enum-based system so you can use them immediately, then I work toward supporting custom markers in a future release.

To add a custom marker you could just add its name to the list of current markers.

https://github.com/swharden/ScottPlot/blob/ef59756715ac87c6d778fe783c81357a593561b2/src/ScottPlot/Markers.cs#L10-L27

Then add a case for that marker in the DrawMarker function (using the arguments that are passed in for location, size, and color)

https://github.com/swharden/ScottPlot/blob/ef59756715ac87c6d778fe783c81357a593561b2/src/ScottPlot/Markers.cs#L44-L46

You could either paste that code in this issue, or change the code and make a PR, and I can incorporate it into the main library pretty quick.

@henkburgstra
Copy link
Author

henkburgstra commented Jun 9, 2020 via email

@swharden swharden mentioned this pull request Aug 14, 2020
53 tasks
@swharden swharden mentioned this pull request Dec 10, 2020
20 tasks
@swharden swharden mentioned this pull request Jan 26, 2021
48 tasks
@swharden swharden mentioned this pull request May 1, 2021
@swharden swharden mentioned this pull request May 17, 2021
82 tasks
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.

2 participants