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

Range Circles on XYScatterPlot #457

Open
keltonhalbert opened this issue Oct 12, 2021 · 1 comment
Open

Range Circles on XYScatterPlot #457

keltonhalbert opened this issue Oct 12, 2021 · 1 comment

Comments

@keltonhalbert
Copy link

While I'm in the midst of working out the fundamentals of core-plot and possibly adding functionality, I was wondering if there might be a method for exposing some drawing primitives, such as drawing a circle, as an axis grid lines option?

I have a plot that works in X-Y space, in this case it's the components of a 2D vector. As such, a circular ring represents the magnitude of that vector. I've managed to implement this in a very naive way by calculating the points of a circle and plotting it manually, as seen in this image below.
IMG_0615

Unfortunately, either due to issues of numerical accuracy, or the curved/linear interpolation for lines, my circles are actually kind of squiggly. The other down side, is that to get more accurate circles, you have to compute more and more points, which eventually causes performance issues when using pan/zoom interactivity.

Previously when working with OpenGL, I was able to call specific drawing primitives for defining a circle, and it was much more efficient performance wise while also not having to deal with squiggles/calculating points. Obviously CPTXYAxis will need to be modified to pull anything like this off, but are there any tips or starting points that use circle drawing primitives? Or is this a bit of a pipe dream?

    func addIsotachLines(){
        print("Called!")
        for spd in self.windSpeedValues {
            // just a quarter circle right now
            for u in stride(from: spd, to: 0.0, by: -0.5) {
                self.isotachLines_u.append(Double(u))
                self.isotachLines_v.append( sqrt(pow(Double(spd), 2.0) - pow(Double(u), 2.0)) )
            }
            for u in stride(from: 1.0, to: spd+1.0, by: 1.0) {
                self.isotachLines_u.append(-1.0 * Double(u))
                self.isotachLines_v.append( sqrt(pow(Double(spd), 2.0) - pow(Double(u), 2.0)) )
            }
            for u in stride(from: -1.0*spd, to:0.0, by: 1.0) {
                self.isotachLines_u.append(Double(u))
                self.isotachLines_v.append( -1.0*sqrt(pow(Double(spd), 2.0) - pow(Double(u), 2.0)) )
            }
            for u in stride(from: 0.0, to: spd+1.0, by: 1.0) {
                self.isotachLines_u.append(Double(u))
                self.isotachLines_v.append( -1.0*sqrt(pow(Double(spd), 2.0) - pow(Double(u), 2.0)) )
            }
            self.isotachLines_u.append(nil)
            self.isotachLines_v.append(nil)
        }

        plot = CPTScatterPlot()
        let color = CPTColor(componentRed: CGFloat(50.0/255.0), green: CGFloat(50/255.0), blue: CGFloat(50.0/255.0), alpha: CGFloat(1))
        let plotLineStyle = CPTMutableLineStyle()
        plotLineStyle.lineJoin = .round
        plotLineStyle.lineCap = .round
        plotLineStyle.lineWidth = 1
        plotLineStyle.lineColor = color
        plot.dataLineStyle = plotLineStyle
        plot.curvedInterpolationOption = .catmullCustomAlpha
        plot.interpolation = .curved
        plot.identifier = "isotachs-hodo" as NSCoding & NSCopying & NSObjectProtocol
        guard let graph = hodoChart.hostedGraph else { return }
        plot.dataSource = (self as CPTPlotDataSource)
        plot.delegate = (self as CALayerDelegate)
        graph.add(plot, to: graph.defaultPlotSpace)
    }
@eskroch
Copy link
Member

eskroch commented Oct 13, 2021

We have the foundations polar plots in place, but nothing has been implemented. It would require building CPTPolarPlotSpace and some new plot types, e.g., issue #31.

All drawing in Core Plot is done using Core Graphics primitives. There are functions for drawing ellipses and arcs. You provide a bounding rectangle and some other shape parameters and the drawing system takes care of the details. We use them when drawing pie charts, for example.

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

2 participants