Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data-driven multi-colored lines for ScatterPlot #458

Open
keltonhalbert opened this issue Nov 2, 2021 · 1 comment
Open

Data-driven multi-colored lines for ScatterPlot #458

keltonhalbert opened this issue Nov 2, 2021 · 1 comment

Comments

@keltonhalbert
Copy link

I'm interested in being able to color line segments based on the values within a third array. That is to say, if X and Y are the graph positions that represent a line, then the color of the line along the path is represented by some array Z along that path.

In its simplest form, I want to achieve what's in the screenshot below. The X/Y values are components of a wind speed vector (X being the U or zonal component, and Y being the V or meridional component) and the lines are colored based on the altitude of those wind measurements. Wind speeds below 3 km altitude are colored red, 3-6km colored green, 6-9km colored cyan, and so on. However - I also envision the ability to color each segment of an array (rather than all just one color) based on the Z array. This would be analogous to the gradient or fill options, but not being dependent on the XY representation of a gradient.

Screen Shot 2021-11-02 at 9 52 03 AM

Right now, the only way I can to do this in CorePlot is to have individual arrays for 0-3km, 3-6km, 6-9km, etc and creating new instances of CPTScatterPlot for each line segment, and then changing the line style for each instance of ScatterPlot. I'm worried about this approach's possible performance hit by having to create multiple CPTScatterPlots to achieve this functionality, especially as more segments require more instances of the object. I think it would be ideal to be able to style a path without having to create new CPTScatterPlot instances.

I see that the line positions appear to be handled by CPTScatterPlot::newDataLinePathForViewPoints, and that line color is set by CPTLineStyle::setLineStyleInContext. From doing some research into drawing with CoreGraphics, it looks like the stroke would have to be updated along each segment of the line as it is being added. Creating an array that holds the colors of each line segment would be trivial, the question becomes how does one integrate this into the current drawing system well? If you have any pointers for how integrating this functionality might be possible, I would be happy to work on it myself.

@keltonhalbert
Copy link
Author

An alternative to pre-computing the colors for the Z array and setting the line color that way could be to make it part of the delegate, and allow the user to code how the color is selected via the delegate method. But again, not entirely sure how that would need to be implemented.

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

No branches or pull requests

1 participant