Skip to content

Range Circles on XYScatterPlot #457

Open

Description

@keltonhalbert

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)
    }

Activity

  1. eskroch commented on Oct 13, 2021

    @eskroch
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions