10BC0 Tag property on IPlottable by btarb24 · Pull Request #5185 · ScottPlot/ScottPlot · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@btarb24
Copy link
@btarb24 btarb24 commented Jan 1, 2026

Added a new property to IPlottable:
public object Tag {get; set;}

This Tag property is consistently available across WPF UI objects to allow consumers to add additional data objects to the UI.
wpf documentation

My specific use case was i allow the user to create trend lines on a candlestick chart and i save them to a database. The Tag property lets me add my model to the UI object for direct association. The user may have many different charts for the same symbol (1min, 2min, 5min, 15min, etc) and the trend lines need to be synchronized across all charts of that symbol. The common Tag property saves me from having to create more tedious mapping tables for each chart.

@bclehmann
Copy link
Member

I think most users would get better results by handling this themselves, it's pretty easy to create a TaggedPlottable class which implements IPlottable and exposes a tag.

And tha 7440 t way you could implement things like pub-sub or whatever your application model wants more easily. You could also get real typing, a TaggedPlottable<T> could expose a tag of type T rather than object?. I think that would be a big improvement.

My main issue though, is if ScottPlot isn't supposed to do anything with the tag, then I don't think ScottPlot should be responsible for handling it. As an example of how this could get dicey, suppose we had a Plot.Clone API. Should tags be preserved when a plot is cloned? And then what does that do to our users if their tags exist on 2 different plots? I think the correct solution there is to make our users handle it in whatever way makes sense for their app.

More generally, I think IPlottable is the wrong abstraction for users to develop appmodels around, and I think the WPF way of tags is also dubious in general.

@bclehmann
Copy link
Member

It also looks like you have some extra changes in here, I'm seeing a new InteractiveTrendline plottable?

@btarb24
Copy link
Author
btarb24 commented Jan 2, 2026

@bclehmann

BRANCHING - yea, i did the InteractiveTrendLine work first (has its own PR). I branched off that work to do the Tag obj since InteractiveTrendLine is an IPlottable. Sadly, github doesn't offer much in the way of separating those concepts. The tag code is a branch off the tip of the trendLine code.

Either branch/pr would fail to compile if the other wasn't approved. If we don't want the InteractiveTrendLine then we'd just edit this PR to remove that class.

TAGGEDPLOTTABLE - while that saves a cast for accessing properties off the object, it does have the negative compromise that you can no longer ref check .Tag with your own object.

Plot.GetPlottables().FirstOrDefault(p => p.Tag == lookup)
would become
Plot.GetPlottables().FirstOrDefault(p => p.Tag.Value == lookup)

Both the cast and the compromise for ref access are minor. I'm fine with going either way. Given you've got the yellow name i think i'll just say 'which one do ya want?' 🙂

as for naming.. i'm new to scottPlot.. is there any other area that you'd think would benefit from a Tag obj? If so then perhaps a more generic wrapper name would be better since the wrapper wouldn't expose any new members specific to Plottable objs.

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

0