From 061b34334f0e7dbd02e4c0bc7ad0fd957a95820b Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sat, 18 Jan 2020 12:01:08 -0500 Subject: [PATCH 01/79] Add a list of built-in colors --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 19179772..8a7cb397 100644 --- a/README.md +++ b/README.md @@ -414,6 +414,28 @@ In order to display the plots in Jupyter notebook, we encode the image(which is |---------------------------------------------------| |cgColor: CGColor (return the corresponding CGColor)| +|Built-In Colors | +|-----------------| +|transparent | +|black | +|white | +|transluscentWhite| +|purple | +|lightBlue | +|blue | +|darkBlue | +|green | +|darkGreen | +|yellow | +|gold | +|orange | +|red | +|darkRed | +|brown | +|pink | +|gray | +|darkGray | + ### PlotLabel From 8aefb3de05cb72f1c06a0a05b80cdf5a6f6d290f Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 11:04:21 -0500 Subject: [PATCH 02/79] Create PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 419 +++++++++++++++++++++++++++++ 1 file changed, 419 insertions(+) create mode 100644 Sources/SwiftPlot/PolarChart.swift diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift new file mode 100644 index 00000000..134a0b74 --- /dev/null +++ b/Sources/SwiftPlot/PolarChart.swift @@ -0,0 +1,419 @@ +import Foundation + +fileprivate let MAX_DIV: Float = 50 + +// class defining a lineGraph and all its logic +public struct PolarGraph: Plot { + + public var layout = GraphLayout() + // Data. + var primaryAxis = Axis() + var secondaryAxis: Axis? = nil + // Linegraph layout properties. + public var plotLineThickness: Float = 1.5 + + public init(enablePrimaryAxisGrid: Bool = false, + enableSecondaryAxisGrid: Bool = false){ + self.enablePrimaryAxisGrid = enablePrimaryAxisGrid + self.enableSecondaryAxisGrid = enableSecondaryAxisGrid + } + + public init(points : [Pair], + enablePrimaryAxisGrid: Bool = false, + enableSecondaryAxisGrid: Bool = false){ + self.init(enablePrimaryAxisGrid: enablePrimaryAxisGrid, enableSecondaryAxisGrid: enableSecondaryAxisGrid) + primaryAxis.series.append(Series(values: points, label: "Plot")) + } +} + +// Setting data. +extension PolarGraph { + + // functions to add series + public mutating func addSeries(_ s: Series, + axisType: Axis.Location = .primaryAxis){ + switch axisType { + case .primaryAxis: + primaryAxis.series.append(s) + case .secondaryAxis: + if secondaryAxis == nil { + secondaryAxis = Axis() + } + secondaryAxis!.series.append(s) + } + } + public mutating func addSeries(points : [Pair], + label: String, color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis){ + let s = Series(values: points,label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addSeries(_ y: [U], + label: String, + color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis){ + var points = [Pair]() + for i in 0..(T(i), y[i])) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addSeries(_ x: [T], + _ y: [U], + label: String, + color: Color = .lightBlue, + axisType: Axis.Location = .primaryAxis){ + var points = [Pair]() + for i in 0..(x[i], y[i])) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addFunction(_ function: (T)->U, + minX: T, + maxX: T, + numberOfSamples: Int = 400, + clampY: ClosedRange? = nil, + label: String, + color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis) { + + let step = Float(maxX - minX)/Float(numberOfSamples) + let points = stride(from: Float(minX), through: Float(maxX), by: step).compactMap { i -> Pair? in + let result = function(T(i)) + guard Float(result).isFinite else { return nil } + if let clampY = clampY, !clampY.contains(result) { + return nil + } + return Pair(T(i), result) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } +} + +// Layout properties. +extension PolarGraph { + + public var enablePrimaryAxisGrid: Bool { + get { layout.enablePrimaryAxisGrid } + set { layout.enablePrimaryAxisGrid = newValue } + } + + public var enableSecondaryAxisGrid: Bool { + get { layout.enableSecondaryAxisGrid } + set { layout.enableSecondaryAxisGrid = newValue } + } +} + +// Layout and drawing of data. +extension PolarGraph: HasGraphLayout { + + public var legendLabels: [(String, LegendIcon)] { + var allSeries: [Series] = primaryAxis.series + if (secondaryAxis != nil) { + allSeries = allSeries + secondaryAxis!.series + } + return allSeries.map { ($0.label, .square($0.color)) } + } + + public struct DrawingData { + var primaryAxisInfo: AxisLayoutInfo? + var secondaryAxisInfo: AxisLayoutInfo? + } + + // functions implementing plotting logic + public func layoutData(size: Size, renderer: Renderer) -> (DrawingData, PlotMarkers?) { + var results = DrawingData() + var markers = PlotMarkers() + guard !primaryAxis.series.isEmpty, !primaryAxis.series[0].values.isEmpty else { return (results, markers) } + + results.primaryAxisInfo = AxisLayoutInfo(series: primaryAxis.series, size: size) + results.secondaryAxisInfo = secondaryAxis.map { + var info = AxisLayoutInfo(series: $0.series, size: size) + info.mergeXAxis(with: &results.primaryAxisInfo!) + return info + } + + (markers.xMarkers, markers.xMarkersText, markers.yMarkers, markers.yMarkersText) = + results.primaryAxisInfo!.calculateMarkers() + if let secondaryAxisInfo = results.secondaryAxisInfo { + (_, _, markers.y2Markers, markers.y2MarkersText) = secondaryAxisInfo.calculateMarkers() + } + + return (results, markers) + } + + //functions to draw the plot + public func drawData(_ data: DrawingData, size: Size, renderer: Renderer) { + if let axisInfo = data.primaryAxisInfo { + for dataset in primaryAxis.series { + let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } + renderer.drawPlotLines(points: points, + strokeWidth: plotLineThickness, + strokeColor: dataset.color, + isDashed: false) + } + } + if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { + for dataset in secondaryAxis.series { + let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } + renderer.drawPlotLines(points: points, + strokeWidth: plotLineThickness, + strokeColor: dataset.color, + isDashed: true) + } + } + } +} + +extension PolarGraph { + + struct AxisLayoutInfo { + let size: Size + let rightMargin: Float + let topMargin: Float + var bounds: (x: ClosedRange, y: ClosedRange) + + var scaleX: Float = 1 + var scaleY: Float = 1 + // The "origin" is just a known value at a known location, + // used for calculating where other points are located. + var origin: Point = zeroPoint + var originValue = Pair(T(0), U(0)) + + init(series: [Series], size: Size) { + self.size = size + rightMargin = size.width * 0.05 + topMargin = size.height * 0.05 + bounds = AxisLayoutInfo.getBounds(series) + boundsDidChange() + } + + private static func getBounds(_ series: [Series]) -> (x: ClosedRange, y: ClosedRange) { + var maximumX: T = maxX(points: series[0].values) + var minimumX: T = minX(points: series[0].values) + var maximumY: U = maxY(points: series[0].values) + var minimumY: U = minY(points: series[0].values) + for s in series { + var x: T = maxX(points: s.values) + var y: U = maxY(points: s.values) + maximumX = max(x, maximumX) + maximumY = max(y, maximumY) + x = minX(points: s.values) + y = minY(points: s.values) + minimumX = min(x, minimumX) + minimumY = min(y, minimumY) + } + return (x: minimumX...maximumX, y: minimumY...maximumY) + } + + private mutating func boundsDidChange() { + let availableWidth = size.width - (2 * rightMargin) + let availableHeight = size.height - (2 * topMargin) + let xRange_primary = Float(bounds.x.upperBound - bounds.x.lowerBound) + let yRange_primary = Float(bounds.y.upperBound - bounds.y.lowerBound) + + scaleX = xRange_primary / availableWidth + scaleY = yRange_primary / availableHeight + calculateOrigin() + } + + private mutating func calculateOrigin() { + let originLocX: Float + let originLocY: Float + if Float(bounds.x.lowerBound) >= 0, Float(bounds.x.upperBound) >= 0 { + // All points on positive X axis. + originLocX = rightMargin + originValue.x = bounds.x.lowerBound + } else if Float(bounds.x.lowerBound) < 0, Float(bounds.x.upperBound) < 0 { + // All points on negative X axis. + originLocX = size.width - rightMargin + originValue.x = bounds.x.upperBound + } else { + // Both sides of X axis. + originLocX = (Float(bounds.x.lowerBound).magnitude / scaleX) + rightMargin + originValue.x = T(0) + } + + if Float(bounds.y.lowerBound) >= 0, Float(bounds.y.upperBound) >= 0 { + // All points on positive Y axis. + originLocY = topMargin + originValue.y = bounds.y.lowerBound + } else if Float(bounds.y.lowerBound) < 0, Float(bounds.y.upperBound) < 0 { + // All points on negative Y axis. + originLocY = size.height - topMargin + originValue.y = bounds.y.upperBound + } else { + // Both sides of Y axis. + originLocY = (Float(bounds.y.lowerBound).magnitude / scaleY) + topMargin + originValue.y = U(0) + } + origin = Pair(originLocX, originLocY) + + // If the zero-coordinate is already in view, snap the origin to it. + let zeroLocation = convertCoordinate(fromData: Pair(T(0), U(0))) + if (0...size.width).contains(zeroLocation.x) { + origin.x = zeroLocation.x + originValue.x = T(0) + } + if (0...size.height).contains(zeroLocation.y) { + origin.y = zeroLocation.y + originValue.y = U(0) + } + } + + func calculateMarkers() -> (x: [Float], xLabels: [String], y: [Float], yLabels: [String]) { + var yIncrement: Float = -1 + var xIncrement: Float = -1 + var xIncRound: Int = 1 + var yIncRound: Int = 1 + let xRange = Float(bounds.x.upperBound - bounds.x.lowerBound) + let yRange = Float(bounds.y.upperBound - bounds.y.lowerBound) + + if yRange <= 2.0, yRange >= 1.0 { + let differenceY = yRange + yIncrement = 0.5*(1.0/differenceY) + var c = 0 + while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + yIncrement = yIncrement/scaleY + yIncRound = c+1 + } else if yRange < 1.0 { + let differenceY = yRange + yIncrement = differenceY/10.0 + var c = 0 + while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + yIncrement = yIncrement/scaleY + yIncRound = c+1 + } + + if xRange <= 2.0, xRange >= 1.0 { + let differenceX = xRange + xIncrement = 0.5*(1.0/differenceX) + var c = 0 + while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + xIncrement = yIncrement/scaleX + xIncRound = c+1 + } else if xRange < 1.0 { + let differenceX = xRange + xIncrement = differenceX/10 + var c = 0 + while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + xIncrement = yIncrement/scaleX + xIncRound = c+1 + } + + let nD1: Int = max(getNumberOfDigits(Float(bounds.y.upperBound)), getNumberOfDigits(Float(bounds.y.lowerBound))) + var v1: Float + if (nD1 > 1 && bounds.y.upperBound <= U(pow(Float(10), Float(nD1 - 1)))) { + v1 = Float(pow(Float(10), Float(nD1 - 2))) + } else if (nD1 > 1) { + v1 = Float(pow(Float(10), Float(nD1 - 1))) + } else { + v1 = Float(pow(Float(10), Float(0))) + } + let nY: Float = v1/scaleY + if(yIncrement == -1) { + yIncrement = nY + if(size.height/nY > MAX_DIV){ + yIncrement = (size.height/nY)*yIncrement/MAX_DIV + } + } + + let nD2: Int = max(getNumberOfDigits(Float(bounds.x.upperBound)), getNumberOfDigits(Float(bounds.x.lowerBound))) + var v2: Float + if (nD2 > 1 && bounds.x.upperBound <= T(pow(Float(10), Float(nD2 - 1)))) { + v2 = Float(pow(Float(10), Float(nD2 - 2))) + } else if (nD2 > 1) { + v2 = Float(pow(Float(10), Float(nD2 - 1))) + } else { + v2 = Float(pow(Float(10), Float(0))) + } + + let nX: Float = v2/scaleX + if(xIncrement == -1) { + xIncrement = nX + var noXD: Float = size.width/nX + if(noXD > MAX_DIV){ + xIncrement = (size.width/nX)*xIncrement/MAX_DIV + noXD = MAX_DIV + } + } + + var xMarkerLocations = [Float]() + var xM = origin.x + if size.width > 0 { + while xM<=size.width { + if(xM+xIncrement<0.0 || xM<0.0) { + xM = xM+xIncrement + continue + } + xMarkerLocations.append(xM) + xM = xM + xIncrement + } + + xM = origin.x - xIncrement + while xM>0.0 { + if (xM > size.width) { + xM = xM - xIncrement + continue + } + xMarkerLocations.append(xM) + xM = xM - xIncrement + } + } + let xMarkerLabels = xMarkerLocations.map { offset -> String in + let offsetValue = scaleX * (offset - origin.x) + return "\(roundToN(offsetValue + Float(originValue.x), xIncRound))" + } + + var yMarkerLocations = [Float]() + var yM = origin.y + if size.height > 0 { + while yM<=size.height { + if(yM+yIncrement<0.0 || yM<0.0){ + yM = yM + yIncrement + continue + } + yMarkerLocations.append(yM) + yM = yM + yIncrement + } + yM = origin.y - yIncrement + while yM>0.0 { + yMarkerLocations.append(yM) + yM = yM - yIncrement + } + } + let yMarkerLabels = yMarkerLocations.map { offset -> String in + let offsetValue = scaleY * (offset - origin.y) + return "\(roundToN(offsetValue + Float(originValue.y), yIncRound))" + } + + return (x: xMarkerLocations, xLabels: xMarkerLabels, + y: yMarkerLocations, yLabels: yMarkerLabels) + } + + func convertCoordinate(fromData value: Pair) -> Point { + return Point(Float(((value.x - originValue.x) / T(scaleX)) + T(origin.x)), + Float(((value.y - originValue.y) / U(scaleY)) + U(origin.y))) + } + + mutating func mergeXAxis(with other: inout AxisLayoutInfo) { + bounds.x = + min(bounds.x.lowerBound, other.bounds.x.lowerBound)...max(bounds.x.upperBound, other.bounds.x.upperBound) + other.bounds.x = self.bounds.x + boundsDidChange() + other.boundsDidChange() + } + } +} From 9576045413c573202698efddc3f006e20d3aaab3 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 12:05:08 -0500 Subject: [PATCH 03/79] Delete PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 419 ----------------------------- 1 file changed, 419 deletions(-) delete mode 100644 Sources/SwiftPlot/PolarChart.swift diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift deleted file mode 100644 index 134a0b74..00000000 --- a/Sources/SwiftPlot/PolarChart.swift +++ /dev/null @@ -1,419 +0,0 @@ -import Foundation - -fileprivate let MAX_DIV: Float = 50 - -// class defining a lineGraph and all its logic -public struct PolarGraph: Plot { - - public var layout = GraphLayout() - // Data. - var primaryAxis = Axis() - var secondaryAxis: Axis? = nil - // Linegraph layout properties. - public var plotLineThickness: Float = 1.5 - - public init(enablePrimaryAxisGrid: Bool = false, - enableSecondaryAxisGrid: Bool = false){ - self.enablePrimaryAxisGrid = enablePrimaryAxisGrid - self.enableSecondaryAxisGrid = enableSecondaryAxisGrid - } - - public init(points : [Pair], - enablePrimaryAxisGrid: Bool = false, - enableSecondaryAxisGrid: Bool = false){ - self.init(enablePrimaryAxisGrid: enablePrimaryAxisGrid, enableSecondaryAxisGrid: enableSecondaryAxisGrid) - primaryAxis.series.append(Series(values: points, label: "Plot")) - } -} - -// Setting data. -extension PolarGraph { - - // functions to add series - public mutating func addSeries(_ s: Series, - axisType: Axis.Location = .primaryAxis){ - switch axisType { - case .primaryAxis: - primaryAxis.series.append(s) - case .secondaryAxis: - if secondaryAxis == nil { - secondaryAxis = Axis() - } - secondaryAxis!.series.append(s) - } - } - public mutating func addSeries(points : [Pair], - label: String, color: Color = Color.lightBlue, - axisType: Axis.Location = .primaryAxis){ - let s = Series(values: points,label: label, color: color) - addSeries(s, axisType: axisType) - } - public mutating func addSeries(_ y: [U], - label: String, - color: Color = Color.lightBlue, - axisType: Axis.Location = .primaryAxis){ - var points = [Pair]() - for i in 0..(T(i), y[i])) - } - let s = Series(values: points, label: label, color: color) - addSeries(s, axisType: axisType) - } - public mutating func addSeries(_ x: [T], - _ y: [U], - label: String, - color: Color = .lightBlue, - axisType: Axis.Location = .primaryAxis){ - var points = [Pair]() - for i in 0..(x[i], y[i])) - } - let s = Series(values: points, label: label, color: color) - addSeries(s, axisType: axisType) - } - public mutating func addFunction(_ function: (T)->U, - minX: T, - maxX: T, - numberOfSamples: Int = 400, - clampY: ClosedRange? = nil, - label: String, - color: Color = Color.lightBlue, - axisType: Axis.Location = .primaryAxis) { - - let step = Float(maxX - minX)/Float(numberOfSamples) - let points = stride(from: Float(minX), through: Float(maxX), by: step).compactMap { i -> Pair? in - let result = function(T(i)) - guard Float(result).isFinite else { return nil } - if let clampY = clampY, !clampY.contains(result) { - return nil - } - return Pair(T(i), result) - } - let s = Series(values: points, label: label, color: color) - addSeries(s, axisType: axisType) - } -} - -// Layout properties. -extension PolarGraph { - - public var enablePrimaryAxisGrid: Bool { - get { layout.enablePrimaryAxisGrid } - set { layout.enablePrimaryAxisGrid = newValue } - } - - public var enableSecondaryAxisGrid: Bool { - get { layout.enableSecondaryAxisGrid } - set { layout.enableSecondaryAxisGrid = newValue } - } -} - -// Layout and drawing of data. -extension PolarGraph: HasGraphLayout { - - public var legendLabels: [(String, LegendIcon)] { - var allSeries: [Series] = primaryAxis.series - if (secondaryAxis != nil) { - allSeries = allSeries + secondaryAxis!.series - } - return allSeries.map { ($0.label, .square($0.color)) } - } - - public struct DrawingData { - var primaryAxisInfo: AxisLayoutInfo? - var secondaryAxisInfo: AxisLayoutInfo? - } - - // functions implementing plotting logic - public func layoutData(size: Size, renderer: Renderer) -> (DrawingData, PlotMarkers?) { - var results = DrawingData() - var markers = PlotMarkers() - guard !primaryAxis.series.isEmpty, !primaryAxis.series[0].values.isEmpty else { return (results, markers) } - - results.primaryAxisInfo = AxisLayoutInfo(series: primaryAxis.series, size: size) - results.secondaryAxisInfo = secondaryAxis.map { - var info = AxisLayoutInfo(series: $0.series, size: size) - info.mergeXAxis(with: &results.primaryAxisInfo!) - return info - } - - (markers.xMarkers, markers.xMarkersText, markers.yMarkers, markers.yMarkersText) = - results.primaryAxisInfo!.calculateMarkers() - if let secondaryAxisInfo = results.secondaryAxisInfo { - (_, _, markers.y2Markers, markers.y2MarkersText) = secondaryAxisInfo.calculateMarkers() - } - - return (results, markers) - } - - //functions to draw the plot - public func drawData(_ data: DrawingData, size: Size, renderer: Renderer) { - if let axisInfo = data.primaryAxisInfo { - for dataset in primaryAxis.series { - let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } - renderer.drawPlotLines(points: points, - strokeWidth: plotLineThickness, - strokeColor: dataset.color, - isDashed: false) - } - } - if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { - for dataset in secondaryAxis.series { - let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } - renderer.drawPlotLines(points: points, - strokeWidth: plotLineThickness, - strokeColor: dataset.color, - isDashed: true) - } - } - } -} - -extension PolarGraph { - - struct AxisLayoutInfo { - let size: Size - let rightMargin: Float - let topMargin: Float - var bounds: (x: ClosedRange, y: ClosedRange) - - var scaleX: Float = 1 - var scaleY: Float = 1 - // The "origin" is just a known value at a known location, - // used for calculating where other points are located. - var origin: Point = zeroPoint - var originValue = Pair(T(0), U(0)) - - init(series: [Series], size: Size) { - self.size = size - rightMargin = size.width * 0.05 - topMargin = size.height * 0.05 - bounds = AxisLayoutInfo.getBounds(series) - boundsDidChange() - } - - private static func getBounds(_ series: [Series]) -> (x: ClosedRange, y: ClosedRange) { - var maximumX: T = maxX(points: series[0].values) - var minimumX: T = minX(points: series[0].values) - var maximumY: U = maxY(points: series[0].values) - var minimumY: U = minY(points: series[0].values) - for s in series { - var x: T = maxX(points: s.values) - var y: U = maxY(points: s.values) - maximumX = max(x, maximumX) - maximumY = max(y, maximumY) - x = minX(points: s.values) - y = minY(points: s.values) - minimumX = min(x, minimumX) - minimumY = min(y, minimumY) - } - return (x: minimumX...maximumX, y: minimumY...maximumY) - } - - private mutating func boundsDidChange() { - let availableWidth = size.width - (2 * rightMargin) - let availableHeight = size.height - (2 * topMargin) - let xRange_primary = Float(bounds.x.upperBound - bounds.x.lowerBound) - let yRange_primary = Float(bounds.y.upperBound - bounds.y.lowerBound) - - scaleX = xRange_primary / availableWidth - scaleY = yRange_primary / availableHeight - calculateOrigin() - } - - private mutating func calculateOrigin() { - let originLocX: Float - let originLocY: Float - if Float(bounds.x.lowerBound) >= 0, Float(bounds.x.upperBound) >= 0 { - // All points on positive X axis. - originLocX = rightMargin - originValue.x = bounds.x.lowerBound - } else if Float(bounds.x.lowerBound) < 0, Float(bounds.x.upperBound) < 0 { - // All points on negative X axis. - originLocX = size.width - rightMargin - originValue.x = bounds.x.upperBound - } else { - // Both sides of X axis. - originLocX = (Float(bounds.x.lowerBound).magnitude / scaleX) + rightMargin - originValue.x = T(0) - } - - if Float(bounds.y.lowerBound) >= 0, Float(bounds.y.upperBound) >= 0 { - // All points on positive Y axis. - originLocY = topMargin - originValue.y = bounds.y.lowerBound - } else if Float(bounds.y.lowerBound) < 0, Float(bounds.y.upperBound) < 0 { - // All points on negative Y axis. - originLocY = size.height - topMargin - originValue.y = bounds.y.upperBound - } else { - // Both sides of Y axis. - originLocY = (Float(bounds.y.lowerBound).magnitude / scaleY) + topMargin - originValue.y = U(0) - } - origin = Pair(originLocX, originLocY) - - // If the zero-coordinate is already in view, snap the origin to it. - let zeroLocation = convertCoordinate(fromData: Pair(T(0), U(0))) - if (0...size.width).contains(zeroLocation.x) { - origin.x = zeroLocation.x - originValue.x = T(0) - } - if (0...size.height).contains(zeroLocation.y) { - origin.y = zeroLocation.y - originValue.y = U(0) - } - } - - func calculateMarkers() -> (x: [Float], xLabels: [String], y: [Float], yLabels: [String]) { - var yIncrement: Float = -1 - var xIncrement: Float = -1 - var xIncRound: Int = 1 - var yIncRound: Int = 1 - let xRange = Float(bounds.x.upperBound - bounds.x.lowerBound) - let yRange = Float(bounds.y.upperBound - bounds.y.lowerBound) - - if yRange <= 2.0, yRange >= 1.0 { - let differenceY = yRange - yIncrement = 0.5*(1.0/differenceY) - var c = 0 - while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { - c+=1 - } - yIncrement = yIncrement/scaleY - yIncRound = c+1 - } else if yRange < 1.0 { - let differenceY = yRange - yIncrement = differenceY/10.0 - var c = 0 - while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { - c+=1 - } - yIncrement = yIncrement/scaleY - yIncRound = c+1 - } - - if xRange <= 2.0, xRange >= 1.0 { - let differenceX = xRange - xIncrement = 0.5*(1.0/differenceX) - var c = 0 - while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { - c+=1 - } - xIncrement = yIncrement/scaleX - xIncRound = c+1 - } else if xRange < 1.0 { - let differenceX = xRange - xIncrement = differenceX/10 - var c = 0 - while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { - c+=1 - } - xIncrement = yIncrement/scaleX - xIncRound = c+1 - } - - let nD1: Int = max(getNumberOfDigits(Float(bounds.y.upperBound)), getNumberOfDigits(Float(bounds.y.lowerBound))) - var v1: Float - if (nD1 > 1 && bounds.y.upperBound <= U(pow(Float(10), Float(nD1 - 1)))) { - v1 = Float(pow(Float(10), Float(nD1 - 2))) - } else if (nD1 > 1) { - v1 = Float(pow(Float(10), Float(nD1 - 1))) - } else { - v1 = Float(pow(Float(10), Float(0))) - } - let nY: Float = v1/scaleY - if(yIncrement == -1) { - yIncrement = nY - if(size.height/nY > MAX_DIV){ - yIncrement = (size.height/nY)*yIncrement/MAX_DIV - } - } - - let nD2: Int = max(getNumberOfDigits(Float(bounds.x.upperBound)), getNumberOfDigits(Float(bounds.x.lowerBound))) - var v2: Float - if (nD2 > 1 && bounds.x.upperBound <= T(pow(Float(10), Float(nD2 - 1)))) { - v2 = Float(pow(Float(10), Float(nD2 - 2))) - } else if (nD2 > 1) { - v2 = Float(pow(Float(10), Float(nD2 - 1))) - } else { - v2 = Float(pow(Float(10), Float(0))) - } - - let nX: Float = v2/scaleX - if(xIncrement == -1) { - xIncrement = nX - var noXD: Float = size.width/nX - if(noXD > MAX_DIV){ - xIncrement = (size.width/nX)*xIncrement/MAX_DIV - noXD = MAX_DIV - } - } - - var xMarkerLocations = [Float]() - var xM = origin.x - if size.width > 0 { - while xM<=size.width { - if(xM+xIncrement<0.0 || xM<0.0) { - xM = xM+xIncrement - continue - } - xMarkerLocations.append(xM) - xM = xM + xIncrement - } - - xM = origin.x - xIncrement - while xM>0.0 { - if (xM > size.width) { - xM = xM - xIncrement - continue - } - xMarkerLocations.append(xM) - xM = xM - xIncrement - } - } - let xMarkerLabels = xMarkerLocations.map { offset -> String in - let offsetValue = scaleX * (offset - origin.x) - return "\(roundToN(offsetValue + Float(originValue.x), xIncRound))" - } - - var yMarkerLocations = [Float]() - var yM = origin.y - if size.height > 0 { - while yM<=size.height { - if(yM+yIncrement<0.0 || yM<0.0){ - yM = yM + yIncrement - continue - } - yMarkerLocations.append(yM) - yM = yM + yIncrement - } - yM = origin.y - yIncrement - while yM>0.0 { - yMarkerLocations.append(yM) - yM = yM - yIncrement - } - } - let yMarkerLabels = yMarkerLocations.map { offset -> String in - let offsetValue = scaleY * (offset - origin.y) - return "\(roundToN(offsetValue + Float(originValue.y), yIncRound))" - } - - return (x: xMarkerLocations, xLabels: xMarkerLabels, - y: yMarkerLocations, yLabels: yMarkerLabels) - } - - func convertCoordinate(fromData value: Pair) -> Point { - return Point(Float(((value.x - originValue.x) / T(scaleX)) + T(origin.x)), - Float(((value.y - originValue.y) / U(scaleY)) + U(origin.y))) - } - - mutating func mergeXAxis(with other: inout AxisLayoutInfo) { - bounds.x = - min(bounds.x.lowerBound, other.bounds.x.lowerBound)...max(bounds.x.upperBound, other.bounds.x.upperBound) - other.bounds.x = self.bounds.x - boundsDidChange() - other.boundsDidChange() - } - } -} From dfcd57f7dcfbaa09613b2080806bc3037753822e Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 14:42:51 -0500 Subject: [PATCH 04/79] Update README.md --- README.md | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/README.md b/README.md index 8a7cb397..22d39a4a 100644 --- a/README.md +++ b/README.md @@ -414,27 +414,7 @@ In order to display the plots in Jupyter notebook, we encode the image(which is |---------------------------------------------------| |cgColor: CGColor (return the corresponding CGColor)| -|Built-In Colors | -|-----------------| -|transparent | -|black | -|white | -|transluscentWhite| -|purple | -|lightBlue | -|blue | -|darkBlue | -|green | -|darkGreen | -|yellow | -|gold | -|orange | -|red | -|darkRed | -|brown | -|pink | -|gray | -|darkGray | +Built-in Colors can be found [here](https://github.com/Qwerty71/swiftplot/blob/master/Sources/SwiftPlot/Color.swift). ### PlotLabel From 64e508440eee373dc406f69721d29bcf2beb3ab5 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 14:43:34 -0500 Subject: [PATCH 05/79] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22d39a4a..7d2c04eb 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,7 @@ In order to display the plots in Jupyter notebook, we encode the image(which is |---------------------------------------------------| |cgColor: CGColor (return the corresponding CGColor)| -Built-in Colors can be found [here](https://github.com/Qwerty71/swiftplot/blob/master/Sources/SwiftPlot/Color.swift). +Built-in Colors can be found [here](https://github.com/KarthikRIyer/swiftplot/blob/master/Sources/SwiftPlot/Color.swift). ### PlotLabel From 1bc8502210779c974a77c6fdf48a3e8483066ce6 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 16:51:37 -0500 Subject: [PATCH 06/79] Create PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 433 +++++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) create mode 100644 Sources/SwiftPlot/PolarChart.swift diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift new file mode 100644 index 00000000..578ab777 --- /dev/null +++ b/Sources/SwiftPlot/PolarChart.swift @@ -0,0 +1,433 @@ +import Foundation + +fileprivate let MAX_DIV: Float = 50 + +// class defining a lineGraph and all its logic +public struct PolarGraph: Plot { + + public var layout = GraphLayout() + // Data. + var primaryAxis = Axis() + var secondaryAxis: Axis? = nil + // Linegraph layout properties. + public var plotLineThickness: Float = 1.5 + + public init(enablePrimaryAxisGrid: Bool = false, + enableSecondaryAxisGrid: Bool = false){ + self.enablePrimaryAxisGrid = enablePrimaryAxisGrid + self.enableSecondaryAxisGrid = enableSecondaryAxisGrid + } + + public init(points : [Pair], + enablePrimaryAxisGrid: Bool = false, + enableSecondaryAxisGrid: Bool = false){ + self.init(enablePrimaryAxisGrid: enablePrimaryAxisGrid, enableSecondaryAxisGrid: enableSecondaryAxisGrid) + primaryAxis.series.append(Series(values: points, label: "Plot")) + } +} + +// Setting data. +extension PolarGraph { + + public mutating func linspace(start: Float, end: Float, num: Int) -> Array{ + var increment = (end - start) / Float((num - 1)) + var current = start + var outputs = [Float]() + for i in 1...num { + outputs.append(current) + current += increment + } + outputs[outputs.count-1] = end + return outputs + } + + // functions to add series + public mutating func addSeries(_ s: Series, + axisType: Axis.Location = .primaryAxis){ + switch axisType { + case .primaryAxis: + primaryAxis.series.append(s) + case .secondaryAxis: + if secondaryAxis == nil { + secondaryAxis = Axis() + } + secondaryAxis!.series.append(s) + } + } + public mutating func addSeries(points : [Pair], + label: String, color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis){ + let s = Series(values: points,label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addSeries(_ y: [U], + label: String, + color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis){ + var points = [Pair]() + for i in 0..(T(i), y[i])) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addSeries(_ r: [T], + _ theta: [U], + label: String, + color: Color = .lightBlue, + axisType: Axis.Location = .primaryAxis){ + var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} + var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} + var points = [Pair]() + for i in 0..(T(x[i]), U(y[i]))) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } + public mutating func addFunction(_ function: (T)->U, + minX: T, + maxX: T, + numberOfSamples: Int = 400, + clampY: ClosedRange? = nil, + label: String, + color: Color = Color.lightBlue, + axisType: Axis.Location = .primaryAxis) { + + let step = Float(maxX - minX)/Float(numberOfSamples) + let points = stride(from: Float(minX), through: Float(maxX), by: step).compactMap { i -> Pair? in + let result = function(T(i)) + guard Float(result).isFinite else { return nil } + if let clampY = clampY, !clampY.contains(result) { + return nil + } + return Pair(T(i), result) + } + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: axisType) + } +} + +// Layout properties. +extension PolarGraph { + + public var enablePrimaryAxisGrid: Bool { + get { layout.enablePrimaryAxisGrid } + set { layout.enablePrimaryAxisGrid = newValue } + } + + public var enableSecondaryAxisGrid: Bool { + get { layout.enableSecondaryAxisGrid } + set { layout.enableSecondaryAxisGrid = newValue } + } +} + +// Layout and drawing of data. +extension PolarGraph: HasGraphLayout { + + public var legendLabels: [(String, LegendIcon)] { + var allSeries: [Series] = primaryAxis.series + if (secondaryAxis != nil) { + allSeries = allSeries + secondaryAxis!.series + } + return allSeries.map { ($0.label, .square($0.color)) } + } + + public struct DrawingData { + var primaryAxisInfo: AxisLayoutInfo? + var secondaryAxisInfo: AxisLayoutInfo? + } + + // functions implementing plotting logic + public func layoutData(size: Size, renderer: Renderer) -> (DrawingData, PlotMarkers?) { + var results = DrawingData() + var markers = PlotMarkers() + guard !primaryAxis.series.isEmpty, !primaryAxis.series[0].values.isEmpty else { return (results, markers) } + + results.primaryAxisInfo = AxisLayoutInfo(series: primaryAxis.series, size: size) + results.secondaryAxisInfo = secondaryAxis.map { + var info = AxisLayoutInfo(series: $0.series, size: size) + info.mergeXAxis(with: &results.primaryAxisInfo!) + return info + } + + (markers.xMarkers, markers.xMarkersText, markers.yMarkers, markers.yMarkersText) = + results.primaryAxisInfo!.calculateMarkers() + if let secondaryAxisInfo = results.secondaryAxisInfo { + (_, _, markers.y2Markers, markers.y2MarkersText) = secondaryAxisInfo.calculateMarkers() + } + + return (results, markers) + } + + //functions to draw the plot + public func drawData(_ data: DrawingData, size: Size, renderer: Renderer) { + if let axisInfo = data.primaryAxisInfo { + for dataset in primaryAxis.series { + let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } + renderer.drawPlotLines(points: points, + strokeWidth: plotLineThickness, + strokeColor: dataset.color, + isDashed: false) + } + } + if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { + for dataset in secondaryAxis.series { + let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } + renderer.drawPlotLines(points: points, + strokeWidth: plotLineThickness, + strokeColor: dataset.color, + isDashed: true) + } + } + } +} + +extension PolarGraph { + + struct AxisLayoutInfo { + let size: Size + let rightMargin: Float + let topMargin: Float + var bounds: (x: ClosedRange, y: ClosedRange) + + var scaleX: Float = 1 + var scaleY: Float = 1 + // The "origin" is just a known value at a known location, + // used for calculating where other points are located. + var origin: Point = zeroPoint + var originValue = Pair(T(0), U(0)) + + init(series: [Series], size: Size) { + self.size = size + rightMargin = size.width * 0.05 + topMargin = size.height * 0.05 + bounds = AxisLayoutInfo.getBounds(series) + boundsDidChange() + } + + private static func getBounds(_ series: [Series]) -> (x: ClosedRange, y: ClosedRange) { + var maximumX: T = maxX(points: series[0].values) + var minimumX: T = minX(points: series[0].values) + var maximumY: U = maxY(points: series[0].values) + var minimumY: U = minY(points: series[0].values) + for s in series { + var x: T = maxX(points: s.values) + var y: U = maxY(points: s.values) + maximumX = max(x, maximumX) + maximumY = max(y, maximumY) + x = minX(points: s.values) + y = minY(points: s.values) + minimumX = min(x, minimumX) + minimumY = min(y, minimumY) + } + return (x: minimumX...maximumX, y: minimumY...maximumY) + } + + private mutating func boundsDidChange() { + let availableWidth = size.width - (2 * rightMargin) + let availableHeight = size.height - (2 * topMargin) + let xRange_primary = Float(bounds.x.upperBound - bounds.x.lowerBound) + let yRange_primary = Float(bounds.y.upperBound - bounds.y.lowerBound) + + scaleX = xRange_primary / availableWidth + scaleY = yRange_primary / availableHeight + calculateOrigin() + } + + private mutating func calculateOrigin() { + let originLocX: Float + let originLocY: Float + if Float(bounds.x.lowerBound) >= 0, Float(bounds.x.upperBound) >= 0 { + // All points on positive X axis. + originLocX = rightMargin + originValue.x = bounds.x.lowerBound + } else if Float(bounds.x.lowerBound) < 0, Float(bounds.x.upperBound) < 0 { + // All points on negative X axis. + originLocX = size.width - rightMargin + originValue.x = bounds.x.upperBound + } else { + // Both sides of X axis. + originLocX = (Float(bounds.x.lowerBound).magnitude / scaleX) + rightMargin + originValue.x = T(0) + } + + if Float(bounds.y.lowerBound) >= 0, Float(bounds.y.upperBound) >= 0 { + // All points on positive Y axis. + originLocY = topMargin + originValue.y = bounds.y.lowerBound + } else if Float(bounds.y.lowerBound) < 0, Float(bounds.y.upperBound) < 0 { + // All points on negative Y axis. + originLocY = size.height - topMargin + originValue.y = bounds.y.upperBound + } else { + // Both sides of Y axis. + originLocY = (Float(bounds.y.lowerBound).magnitude / scaleY) + topMargin + originValue.y = U(0) + } + origin = Pair(originLocX, originLocY) + + // If the zero-coordinate is already in view, snap the origin to it. + let zeroLocation = convertCoordinate(fromData: Pair(T(0), U(0))) + if (0...size.width).contains(zeroLocation.x) { + origin.x = zeroLocation.x + originValue.x = T(0) + } + if (0...size.height).contains(zeroLocation.y) { + origin.y = zeroLocation.y + originValue.y = U(0) + } + } + + func calculateMarkers() -> (x: [Float], xLabels: [String], y: [Float], yLabels: [String]) { + var yIncrement: Float = -1 + var xIncrement: Float = -1 + var xIncRound: Int = 1 + var yIncRound: Int = 1 + let xRange = Float(bounds.x.upperBound - bounds.x.lowerBound) + let yRange = Float(bounds.y.upperBound - bounds.y.lowerBound) + + if yRange <= 2.0, yRange >= 1.0 { + let differenceY = yRange + yIncrement = 0.5*(1.0/differenceY) + var c = 0 + while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + yIncrement = yIncrement/scaleY + yIncRound = c+1 + } else if yRange < 1.0 { + let differenceY = yRange + yIncrement = differenceY/10.0 + var c = 0 + while(abs(yIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + yIncrement = yIncrement/scaleY + yIncRound = c+1 + } + + if xRange <= 2.0, xRange >= 1.0 { + let differenceX = xRange + xIncrement = 0.5*(1.0/differenceX) + var c = 0 + while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + xIncrement = yIncrement/scaleX + xIncRound = c+1 + } else if xRange < 1.0 { + let differenceX = xRange + xIncrement = differenceX/10 + var c = 0 + while(abs(xIncrement)*pow(10.0,Float(c))<1.0) { + c+=1 + } + xIncrement = yIncrement/scaleX + xIncRound = c+1 + } + + let nD1: Int = max(getNumberOfDigits(Float(bounds.y.upperBound)), getNumberOfDigits(Float(bounds.y.lowerBound))) + var v1: Float + if (nD1 > 1 && bounds.y.upperBound <= U(pow(Float(10), Float(nD1 - 1)))) { + v1 = Float(pow(Float(10), Float(nD1 - 2))) + } else if (nD1 > 1) { + v1 = Float(pow(Float(10), Float(nD1 - 1))) + } else { + v1 = Float(pow(Float(10), Float(0))) + } + let nY: Float = v1/scaleY + if(yIncrement == -1) { + yIncrement = nY + if(size.height/nY > MAX_DIV){ + yIncrement = (size.height/nY)*yIncrement/MAX_DIV + } + } + + let nD2: Int = max(getNumberOfDigits(Float(bounds.x.upperBound)), getNumberOfDigits(Float(bounds.x.lowerBound))) + var v2: Float + if (nD2 > 1 && bounds.x.upperBound <= T(pow(Float(10), Float(nD2 - 1)))) { + v2 = Float(pow(Float(10), Float(nD2 - 2))) + } else if (nD2 > 1) { + v2 = Float(pow(Float(10), Float(nD2 - 1))) + } else { + v2 = Float(pow(Float(10), Float(0))) + } + + let nX: Float = v2/scaleX + if(xIncrement == -1) { + xIncrement = nX + var noXD: Float = size.width/nX + if(noXD > MAX_DIV){ + xIncrement = (size.width/nX)*xIncrement/MAX_DIV + noXD = MAX_DIV + } + } + + var xMarkerLocations = [Float]() + var xM = origin.x + if size.width > 0 { + while xM<=size.width { + if(xM+xIncrement<0.0 || xM<0.0) { + xM = xM+xIncrement + continue + } + xMarkerLocations.append(xM) + xM = xM + xIncrement + } + + xM = origin.x - xIncrement + while xM>0.0 { + if (xM > size.width) { + xM = xM - xIncrement + continue + } + xMarkerLocations.append(xM) + xM = xM - xIncrement + } + } + let xMarkerLabels = xMarkerLocations.map { offset -> String in + let offsetValue = scaleX * (offset - origin.x) + return "\(roundToN(offsetValue + Float(originValue.x), xIncRound))" + } + + var yMarkerLocations = [Float]() + var yM = origin.y + if size.height > 0 { + while yM<=size.height { + if(yM+yIncrement<0.0 || yM<0.0){ + yM = yM + yIncrement + continue + } + yMarkerLocations.append(yM) + yM = yM + yIncrement + } + yM = origin.y - yIncrement + while yM>0.0 { + yMarkerLocations.append(yM) + yM = yM - yIncrement + } + } + let yMarkerLabels = yMarkerLocations.map { offset -> String in + let offsetValue = scaleY * (offset - origin.y) + return "\(roundToN(offsetValue + Float(originValue.y), yIncRound))" + } + + return (x: xMarkerLocations, xLabels: xMarkerLabels, + y: yMarkerLocations, yLabels: yMarkerLabels) + } + + func convertCoordinate(fromData value: Pair) -> Point { + return Point(Float(((value.x - originValue.x) / T(scaleX)) + T(origin.x)), + Float(((value.y - originValue.y) / U(scaleY)) + U(origin.y))) + } + + mutating func mergeXAxis(with other: inout AxisLayoutInfo) { + bounds.x = + min(bounds.x.lowerBound, other.bounds.x.lowerBound)...max(bounds.x.upperBound, other.bounds.x.upperBound) + other.bounds.x = self.bounds.x + boundsDidChange() + other.boundsDidChange() + } + } +} From fdf91a76f6278ca518a9740070ff54ed4b89c8ac Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 16:57:48 -0500 Subject: [PATCH 07/79] Adding .addFunction capability, small change --- Sources/SwiftPlot/PolarChart.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 578ab777..0f237c51 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -86,8 +86,8 @@ extension PolarGraph { addSeries(s, axisType: axisType) } public mutating func addFunction(_ function: (T)->U, - minX: T, - maxX: T, + minX: T = T(0), + maxX: T = T(2*Float.pi), numberOfSamples: Int = 400, clampY: ClosedRange? = nil, label: String, From e84d1d00512d21e11c38e31674fda3e9ec2c28ce Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:03:57 -0500 Subject: [PATCH 08/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 0f237c51..8c899bb2 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -94,15 +94,16 @@ extension PolarGraph { color: Color = Color.lightBlue, axisType: Axis.Location = .primaryAxis) { - let step = Float(maxX - minX)/Float(numberOfSamples) - let points = stride(from: Float(minX), through: Float(maxX), by: step).compactMap { i -> Pair? in - let result = function(T(i)) - guard Float(result).isFinite else { return nil } - if let clampY = clampY, !clampY.contains(result) { - return nil - } - return Pair(T(i), result) + let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) + let r = theta.map{val in function(x: val)} + + var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} + var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} + + for i in 0..(T(x[i]), U(y[i]))) } + let s = Series(values: points, label: label, color: color) addSeries(s, axisType: axisType) } From 32224a88424855c3001c62e15bc75f4d9128a76e Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:07:35 -0500 Subject: [PATCH 09/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 8c899bb2..a28ec292 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -95,7 +95,7 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis) { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) - let r = theta.map{val in function(x: val)} + let r = theta.map{val in function(T(val))} var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} From fa3d49278b47f071437c07a48a334d59d70bb108 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:18:37 -0500 Subject: [PATCH 10/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index a28ec292..ea6ae87e 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -97,6 +97,8 @@ extension PolarGraph { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) let r = theta.map{val in function(T(val))} + var points = [Pair]() + var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} From ef016bfb2aa97d008822738b9956251baff156a8 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:37:49 -0500 Subject: [PATCH 11/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index ea6ae87e..d3c9e826 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -1,15 +1,17 @@ import Foundation +// This code is identical to LineChart.swift, with a few minor adjustments. + fileprivate let MAX_DIV: Float = 50 -// class defining a lineGraph and all its logic +// class defining a polarGraph and all its logic public struct PolarGraph: Plot { public var layout = GraphLayout() // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil - // Linegraph layout properties. + // Polargraph layout properties. public var plotLineThickness: Float = 1.5 public init(enablePrimaryAxisGrid: Bool = false, From dbee6c4d9f721560d28d7160be081bf4bb30b092 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:50:12 -0500 Subject: [PATCH 12/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index da0ae2c3..cd5ef502 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -145,6 +145,13 @@ public class SVGRenderer: Renderer{ let circle: String = #""# lines.append(circle) } + + public func drawEmptyCircle(center c: Point, + radius r: Float) { + let c = convertToSVGCoordinates(c) + let circle: String = #""# + lines.append(circle) + } public func drawSolidTriangle(point1: Point, point2: Point, From 400729809807ccef60d447567fe3f898d06af1f3 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:54:04 -0500 Subject: [PATCH 13/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index d3c9e826..ba0548d9 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -8,6 +8,7 @@ fileprivate let MAX_DIV: Float = 50 public struct PolarGraph: Plot { public var layout = GraphLayout() + self.maximum = Float(0.0) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -80,6 +81,7 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} + self.maximum = max(r.max()!, self.maximum) var points = [Pair]() for i in 0..(T(x[i]), U(y[i]))) @@ -99,6 +101,8 @@ extension PolarGraph { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) let r = theta.map{val in function(T(val))} + self.maximum = max(r.max()!, self.maximum) + var points = [Pair]() var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} From bfb1cc427c3bb70d0d066f01655f4ebc5d037d00 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:55:27 -0500 Subject: [PATCH 14/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index ba0548d9..831c4525 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -8,7 +8,7 @@ fileprivate let MAX_DIV: Float = 50 public struct PolarGraph: Plot { public var layout = GraphLayout() - self.maximum = Float(0.0) + public var self.maximum = Float(0.0) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil From c7618ca3bdd586baf2d0951935973b819b2b1ccc Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:56:53 -0500 Subject: [PATCH 15/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 831c4525..a37c493b 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -8,7 +8,7 @@ fileprivate let MAX_DIV: Float = 50 public struct PolarGraph: Plot { public var layout = GraphLayout() - public var self.maximum = Float(0.0) + public var maximum = Float(0.0) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -81,7 +81,7 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} - self.maximum = max(r.max()!, self.maximum) + maximum = max(r.max()!, maximum) var points = [Pair]() for i in 0..(T(x[i]), U(y[i]))) @@ -101,7 +101,7 @@ extension PolarGraph { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) let r = theta.map{val in function(T(val))} - self.maximum = max(r.max()!, self.maximum) + maximum = max(r.max()!, maximum) var points = [Pair]() From 444d101754746f29731268440518c835d7934d75 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:02:59 -0500 Subject: [PATCH 16/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index a37c493b..ee8c1846 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -81,7 +81,7 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} - maximum = max(r.max()!, maximum) + maximum = max(r.max().toFloat()!, maximum) var points = [Pair]() for i in 0..(T(x[i]), U(y[i]))) @@ -101,7 +101,7 @@ extension PolarGraph { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) let r = theta.map{val in function(T(val))} - maximum = max(r.max()!, maximum) + maximum = max(r.max().toFloat()!, maximum) var points = [Pair]() From be423dda611707c0d9a00fbb3df8a6a9243d6a35 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:17:20 -0500 Subject: [PATCH 17/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index ee8c1846..87ead354 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -81,7 +81,7 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} - maximum = max(r.max().toFloat()!, maximum) + var points = [Pair]() for i in 0..(T(x[i]), U(y[i]))) @@ -101,8 +101,6 @@ extension PolarGraph { let theta = linspace(start: minX.toFloat(), end: maxX.toFloat(), num: numberOfSamples) let r = theta.map{val in function(T(val))} - maximum = max(r.max().toFloat()!, maximum) - var points = [Pair]() var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} @@ -178,6 +176,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) + renderer.drawEmptyCircle(c: Pair(T(0.0), U(0.0)), r: Float(2.0)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From d3eb4eb464dcc309d83faf2a5c0457a3b719f5c4 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:21:04 -0500 Subject: [PATCH 18/79] Update Renderer.swift --- Sources/SwiftPlot/Renderer.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/SwiftPlot/Renderer.swift b/Sources/SwiftPlot/Renderer.swift index c1028271..3212d396 100644 --- a/Sources/SwiftPlot/Renderer.swift +++ b/Sources/SwiftPlot/Renderer.swift @@ -127,6 +127,17 @@ public protocol Renderer: AnyObject{ func drawSolidCircle(center c: Point, radius r: Float, fillColor: Color) + + /*drawEmptyCircle() + *params: center c: Point, + * radius r: Float + *description: Draws a circle with specified fill color, center and radius + * This function can operate in both coordinate systems with and + * without shifted origin. + * This is decided by the boolean parameter isOriginShifted. + */ + func drawEmptyCircle(center c: Point, + radius r: Float) /*drawSolidTriangle() *params: point1: Point, From c367f01c367937a2e48411b16c755589a9c8c042 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:25:34 -0500 Subject: [PATCH 19/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 87ead354..c7cf9c12 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -9,6 +9,7 @@ public struct PolarGraph: Plot { public var layout = GraphLayout() public var maximum = Float(0.0) + public var origin = Pair(T(0.0), U(0.0)) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -176,7 +177,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(c: Pair(T(0.0), U(0.0)), r: Float(2.0)) + renderer.drawEmptyCircle(c: origin, r: Float(2.0)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From da6fb93df5085a2e8375b03523cb32b37f2f3269 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:36:50 -0500 Subject: [PATCH 20/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index c7cf9c12..c1922223 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -9,7 +9,7 @@ public struct PolarGraph: Plot { public var layout = GraphLayout() public var maximum = Float(0.0) - public var origin = Pair(T(0.0), U(0.0)) + public var origin = Pair(Float(0.0), Float(0.0)) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil From 8048cea207779d08a4045c24a2705bd59b43c3c3 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 16:40:00 -0500 Subject: [PATCH 21/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index c1922223..87d7b009 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -177,7 +177,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(c: origin, r: Float(2.0)) + renderer.drawEmptyCircle(center: origin, radius: Float(2.0)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From d70cb2b4f34812f5deedae612454974df82a5484 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 17:23:57 -0500 Subject: [PATCH 22/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index cd5ef502..2d8fe815 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -149,7 +149,8 @@ public class SVGRenderer: Renderer{ public func drawEmptyCircle(center c: Point, radius r: Float) { let c = convertToSVGCoordinates(c) - let circle: String = #""# + let color = "grey" + let circle: String = #""# lines.append(circle) } From 3a32d794a2f802b3ef70a40b9db53aa1fdb82e29 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 17:52:02 -0500 Subject: [PATCH 23/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index 2d8fe815..050a6e67 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -149,7 +149,7 @@ public class SVGRenderer: Renderer{ public func drawEmptyCircle(center c: Point, radius r: Float) { let c = convertToSVGCoordinates(c) - let color = "grey" + let color = "red" let circle: String = #""# lines.append(circle) } From e205f7963072f61382fd07c6b80e0005979d3f4e Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:12:51 -0500 Subject: [PATCH 24/79] Update CPPAGGRenderer.cpp --- .../AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 19455c7d..88ecc157 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -293,6 +293,21 @@ namespace CPPAGGRenderer{ ren_aa.color(c); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } + + void draw_empty_circle(float cx, float cy, float radius) { + agg::rendering_buffer rbuf = agg::rendering_buffer(buffer, frame_width, frame_height, -frame_width*3); + pixfmt pixf = pixfmt(rbuf); + renderer_base rb = renderer_base(pixf); + ren_aa = renderer_aa(rb); + agg::ellipse circle(cx, cy, radius, radius, 100); + Color c(Float(255), Float(255), Float(255), Float(0.0)); + agg::trans_affine matrix; + matrix *= agg::trans_affine_translation(0, 0); + agg::conv_transform trans(circle, matrix); + m_ras.add_path(trans); + ren_aa.color(c); + agg::render_scanlines(m_ras, m_sl_p8, ren_aa); + } void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a) { agg::rendering_buffer rbuf = agg::rendering_buffer(buffer, frame_width, frame_height, -frame_width*3); From 0cfd296a7884f26a81b31551cd59ecc207ebc5d2 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:14:06 -0500 Subject: [PATCH 25/79] Update AGGRenderer.swift --- Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift b/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift index d01de4bd..37f29c70 100644 --- a/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift +++ b/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift @@ -125,6 +125,14 @@ public class AGGRenderer: Renderer{ fillColor.a, agg_object) } + + public func drawEmptyCircle(center c: Point, + radius r: Float) { + draw_empty_circle(c.x + xOffset, + c.y + yOffset, + r, + agg_object) + } public func drawSolidTriangle(point1: Point, point2: Point, From 1c190b1644190371406fac3aea28d17cce39fedb Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:14:43 -0500 Subject: [PATCH 26/79] Update CAGGRenderer.cpp --- Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp index 13f20f53..8a4f0e41 100644 --- a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp +++ b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp @@ -22,6 +22,10 @@ void draw_solid_circle(float cx, float cy, float radius, float r, float g, float CPPAGGRenderer::draw_solid_circle(cx, cy, radius, r, g, b, a, object); } +void draw_solid_circle(float cx, float cy, float radius, const void *object){ + CPPAGGRenderer::draw_empty_circle(cx, cy, radius, object); +} + void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){ CPPAGGRenderer::draw_solid_triangle(x1, x2, x3, y1, y2, y3, r, g, b, a, object); } From d2aff296e5f16c1d56d420c1347939d418097c93 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:14:55 -0500 Subject: [PATCH 27/79] Update CAGGRenderer.cpp --- Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp index 8a4f0e41..b52dc293 100644 --- a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp +++ b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp @@ -22,7 +22,7 @@ void draw_solid_circle(float cx, float cy, float radius, float r, float g, float CPPAGGRenderer::draw_solid_circle(cx, cy, radius, r, g, b, a, object); } -void draw_solid_circle(float cx, float cy, float radius, const void *object){ +void draw_empty_circle(float cx, float cy, float radius, const void *object){ CPPAGGRenderer::draw_empty_circle(cx, cy, radius, object); } From 616e2fee962a385d649c58aea8a9d8ae0b4f2bd1 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:15:25 -0500 Subject: [PATCH 28/79] Update CAGGRenderer.h --- Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h b/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h index 439d9e26..86969c92 100644 --- a/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h +++ b/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h @@ -13,6 +13,8 @@ void draw_rect(const float *x, const float *y, float thickness, float r, float g void draw_solid_rect(const float *x, const float *y, float r, float g, float b, float a, int hatch_pattern, const void *object); void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object); + +void draw_empty_circle(float cx, float cy, float radius, const void *object); void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object); From 6922c06fd37bc5462a2cb39cfbcacf7673c9c5e9 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:16:14 -0500 Subject: [PATCH 29/79] Update CPPAGGRenderer.h --- Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h b/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h index 69de6f94..b7f8c62e 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h +++ b/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h @@ -11,6 +11,8 @@ namespace CPPAGGRenderer{ void draw_solid_rect(const float *x, const float *y, float r, float g, float b, float a, int hatch_pattern, const void *object); void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object); + + void draw_empty_circle(float cx, float cy, float radius, const void *object); void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object); From 3d3fb06c552ed9f43b44b7211d1c45fc84f68dcc Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:20:27 -0500 Subject: [PATCH 30/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 88ecc157..7e8b2da8 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -86,6 +86,10 @@ namespace CPPAGGRenderer{ int font_weight = 0; int font_height = 0; int font_width = 0; + float r_empty = 255.0; + float g_empty = 255.0; + float b_empty = 255.0; + float a_empty = 0.0; bool font_hinting = false; bool font_kerning = true; string fontPath = ""; @@ -300,7 +304,7 @@ namespace CPPAGGRenderer{ renderer_base rb = renderer_base(pixf); ren_aa = renderer_aa(rb); agg::ellipse circle(cx, cy, radius, radius, 100); - Color c(Float(255), Float(255), Float(255), Float(0.0)); + Color c(r_empty, g_empty, b_empty, a_empty); agg::trans_affine matrix; matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); From cb1aeda95c9f0aa83067cc8c32bd42bf57a0cf07 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:35:22 -0500 Subject: [PATCH 31/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 7e8b2da8..d941d52a 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -86,10 +86,6 @@ namespace CPPAGGRenderer{ int font_weight = 0; int font_height = 0; int font_width = 0; - float r_empty = 255.0; - float g_empty = 255.0; - float b_empty = 255.0; - float a_empty = 0.0; bool font_hinting = false; bool font_kerning = true; string fontPath = ""; @@ -304,12 +300,11 @@ namespace CPPAGGRenderer{ renderer_base rb = renderer_base(pixf); ren_aa = renderer_aa(rb); agg::ellipse circle(cx, cy, radius, radius, 100); - Color c(r_empty, g_empty, b_empty, a_empty); agg::trans_affine matrix; matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); m_ras.add_path(trans); - ren_aa.color(c); + ren_aa.color(white_transluscent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 45d8e03ca56643e9fd8c59a24a75288599b61a58 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 20 Jan 2020 20:38:34 -0500 Subject: [PATCH 32/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index d941d52a..298352c7 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -304,7 +304,7 @@ namespace CPPAGGRenderer{ matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); m_ras.add_path(trans); - ren_aa.color(white_transluscent); + ren_aa.color(white_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 2d56bc1e4def37663db4e69d342ab7763c969812 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 05:59:51 -0500 Subject: [PATCH 33/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 298352c7..ca30c16b 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -517,6 +517,11 @@ namespace CPPAGGRenderer{ Plot *plot = (Plot *)object; plot -> draw_solid_circle(cx, cy, radius, r, g, b, a); } + + void draw_solid_circle(float cx, float cy, float radius, const void *object){ + Plot *plot = (Plot *)object; + plot -> draw_empty_circle(cx, cy, radius); + } void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){ Plot *plot = (Plot *)object; From c759a989f2f86c86eb84c4893203f4f2c83b1580 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:02:34 -0500 Subject: [PATCH 34/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index ca30c16b..d9652f06 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -518,7 +518,7 @@ namespace CPPAGGRenderer{ plot -> draw_solid_circle(cx, cy, radius, r, g, b, a); } - void draw_solid_circle(float cx, float cy, float radius, const void *object){ + void draw_empty_circle(float cx, float cy, float radius, const void *object){ Plot *plot = (Plot *)object; plot -> draw_empty_circle(cx, cy, radius); } From d6150128bafbc99fe8f85bf056931428ca0f7f33 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:10:16 -0500 Subject: [PATCH 35/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 87d7b009..640ce6b7 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -173,6 +173,7 @@ extension PolarGraph: HasGraphLayout { if let axisInfo = data.primaryAxisInfo { for dataset in primaryAxis.series { let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } + var point = axisInfo.convertCoordinate(fromData: origin) renderer.drawPlotLines(points: points, strokeWidth: plotLineThickness, strokeColor: dataset.color, From eadf9984facdc7fc082ede1a0f2cbaa18ce4b037 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:13:01 -0500 Subject: [PATCH 36/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 640ce6b7..f8e4f5a8 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -10,6 +10,7 @@ public struct PolarGraph: Plot { public var layout = GraphLayout() public var maximum = Float(0.0) public var origin = Pair(Float(0.0), Float(0.0)) + public var reference = Pair(Float(0.0), Float(1.0)) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -173,12 +174,13 @@ extension PolarGraph: HasGraphLayout { if let axisInfo = data.primaryAxisInfo { for dataset in primaryAxis.series { let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } - var point = axisInfo.convertCoordinate(fromData: origin) + var pointOrigin = axisInfo.convertCoordinate(fromData: origin) + var referenceRadius = axisInfo.convertCoordinate(fromData: reference) renderer.drawPlotLines(points: points, strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(center: origin, radius: Float(2.0)) + renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*referenceRadius.y) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From 89118051e7ffe600adc1bca8c3c8e12e86a97be3 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:20:58 -0500 Subject: [PATCH 37/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index d9652f06..9f0a5e74 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -303,6 +303,9 @@ namespace CPPAGGRenderer{ agg::trans_affine matrix; matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); + agg::conv_curve> curve(trans); + agg::conv_stroke>> stroke(curve); + stroke.width(1) m_ras.add_path(trans); ren_aa.color(white_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From c2a63de210f12130b1443d5391c6c92a13084452 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:21:45 -0500 Subject: [PATCH 38/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 9f0a5e74..64c9b3da 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -305,7 +305,7 @@ namespace CPPAGGRenderer{ agg::conv_transform trans(circle, matrix); agg::conv_curve> curve(trans); agg::conv_stroke>> stroke(curve); - stroke.width(1) + stroke.width(1); m_ras.add_path(trans); ren_aa.color(white_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From d66c9004a5c74777d8ac71c34e0385c6923149fd Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:26:32 -0500 Subject: [PATCH 39/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 64c9b3da..86e1c46b 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -303,8 +303,8 @@ namespace CPPAGGRenderer{ agg::trans_affine matrix; matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); - agg::conv_curve> curve(trans); - agg::conv_stroke>> stroke(curve); + agg::conv_curve> curve(trans); + agg::conv_stroke>> stroke(curve); stroke.width(1); m_ras.add_path(trans); ren_aa.color(white_translucent); From 98119dc41273b95cab4668e8c683b33246c800bd Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:29:59 -0500 Subject: [PATCH 40/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index f8e4f5a8..7461dbc9 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -9,8 +9,8 @@ public struct PolarGraph: Plot { public var layout = GraphLayout() public var maximum = Float(0.0) - public var origin = Pair(Float(0.0), Float(0.0)) - public var reference = Pair(Float(0.0), Float(1.0)) + public var origin = Pair(T(Float(0.0)), U(Float(0.0))) + public var reference = Pair(T(Float(0.0)), U(Float(1.0))) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*referenceRadius.y) + renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*Float(referenceRadius.y)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From 292a5f14d4116cd5712670e292b2bcc2c6b5476d Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 06:37:19 -0500 Subject: [PATCH 41/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 86e1c46b..ec88158e 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -44,7 +44,7 @@ typedef agg::rgba Color; const Color black(0.0,0.0,0.0,1.0); const Color blue_light(0.529,0.808,0.922,1.0); const Color white(1.0,1.0,1.0,1.0); -const Color white_translucent(1.0,1.0,1.0,0.8); +const Color gray_translucent(0.66,0.66,0.66,0.2); namespace CPPAGGRenderer{ @@ -307,7 +307,7 @@ namespace CPPAGGRenderer{ agg::conv_stroke>> stroke(curve); stroke.width(1); m_ras.add_path(trans); - ren_aa.color(white_translucent); + ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From ad196fc2219c5d11eee025a7a36ae6c237691e65 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:04:23 -0500 Subject: [PATCH 42/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index ec88158e..a8e2b547 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -305,7 +305,7 @@ namespace CPPAGGRenderer{ agg::conv_transform trans(circle, matrix); agg::conv_curve> curve(trans); agg::conv_stroke>> stroke(curve); - stroke.width(1); + stroke.width(3); m_ras.add_path(trans); ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From 267e38f748b0cb17d0e68c78ad4022a3792b67fb Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:05:13 -0500 Subject: [PATCH 43/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 7461dbc9..124ebf10 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*Float(referenceRadius.y)) + renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*Float(referenceRadius.y-pointOrigin.y)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From 9e181bde67029859f17b2520f128bd981349853a Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:08:21 -0500 Subject: [PATCH 44/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 124ebf10..b040fb49 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -10,7 +10,7 @@ public struct PolarGraph: Plot { public var layout = GraphLayout() public var maximum = Float(0.0) public var origin = Pair(T(Float(0.0)), U(Float(0.0))) - public var reference = Pair(T(Float(0.0)), U(Float(1.0))) + public var reference = Pair(T(Float(1.0)), U(Float(1.0))) // Data. var primaryAxis = Axis() var secondaryAxis: Axis? = nil @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*Float(referenceRadius.y-pointOrigin.y)) + renderer.drawEmptyCircle(center: pointOrigin, rx: Float(2.0)*Float(referenceRadius.x-pointOrigin.x), ry: Float(2.0)*Float(referenceRadius.y-pointOrigin.y)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From 6a0d6d181f3b15e5cb90e9abb743aadf5a23ab5f Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:08:49 -0500 Subject: [PATCH 45/79] Update CPPAGGRenderer.h --- Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h b/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h index b7f8c62e..59cdce5c 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h +++ b/Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h @@ -12,7 +12,7 @@ namespace CPPAGGRenderer{ void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object); - void draw_empty_circle(float cx, float cy, float radius, const void *object); + void draw_empty_circle(float cx, float cy, float rx, float ry, const void *object); void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object); From be8a365f87cce60f79cabb02e04432ef3fd9a2ff Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:09:29 -0500 Subject: [PATCH 46/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index a8e2b547..ced4cf9b 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -294,7 +294,7 @@ namespace CPPAGGRenderer{ agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } - void draw_empty_circle(float cx, float cy, float radius) { + void draw_empty_circle(float cx, float cy, float rx, float ry) { agg::rendering_buffer rbuf = agg::rendering_buffer(buffer, frame_width, frame_height, -frame_width*3); pixfmt pixf = pixfmt(rbuf); renderer_base rb = renderer_base(pixf); @@ -521,7 +521,7 @@ namespace CPPAGGRenderer{ plot -> draw_solid_circle(cx, cy, radius, r, g, b, a); } - void draw_empty_circle(float cx, float cy, float radius, const void *object){ + void draw_empty_circle(float cx, float cy, float rx, float ry, const void *object){ Plot *plot = (Plot *)object; plot -> draw_empty_circle(cx, cy, radius); } From 3eadc8d1d2c0e076c9d3bf843f5952bb57f8ace8 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:09:48 -0500 Subject: [PATCH 47/79] Update CAGGRenderer.h --- Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h b/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h index 86969c92..e5cf2bc0 100644 --- a/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h +++ b/Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h @@ -14,7 +14,7 @@ void draw_solid_rect(const float *x, const float *y, float r, float g, float b, void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object); -void draw_empty_circle(float cx, float cy, float radius, const void *object); +void draw_empty_circle(float cx, float cy, float rx, float ry, const void *object); void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object); From a0fd600c3e5173efa010e4c77c20049a72d19d43 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:10:08 -0500 Subject: [PATCH 48/79] Update CAGGRenderer.cpp --- Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp index b52dc293..39cc0b8c 100644 --- a/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp +++ b/Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp @@ -22,8 +22,8 @@ void draw_solid_circle(float cx, float cy, float radius, float r, float g, float CPPAGGRenderer::draw_solid_circle(cx, cy, radius, r, g, b, a, object); } -void draw_empty_circle(float cx, float cy, float radius, const void *object){ - CPPAGGRenderer::draw_empty_circle(cx, cy, radius, object); +void draw_empty_circle(float cx, float cy, float rx, float ry, const void *object){ + CPPAGGRenderer::draw_empty_circle(cx, cy, rx, ry, object); } void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){ From d4d25469999ec202d73451e9eb350a316101e54a Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:11:02 -0500 Subject: [PATCH 49/79] Update AGGRenderer.swift --- Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift b/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift index 37f29c70..16f2d440 100644 --- a/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift +++ b/Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift @@ -127,10 +127,12 @@ public class AGGRenderer: Renderer{ } public func drawEmptyCircle(center c: Point, - radius r: Float) { + radius rx: Float, + radius2 ry: Float) { draw_empty_circle(c.x + xOffset, c.y + yOffset, - r, + rx, + ry, agg_object) } From 1d22cd4c5f58a85d1f3242d5fa0f5f37584f215d Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:13:09 -0500 Subject: [PATCH 50/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index ced4cf9b..52e20e4a 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -299,7 +299,7 @@ namespace CPPAGGRenderer{ pixfmt pixf = pixfmt(rbuf); renderer_base rb = renderer_base(pixf); ren_aa = renderer_aa(rb); - agg::ellipse circle(cx, cy, radius, radius, 100); + agg::ellipse circle(cx, cy, rx, ry, 100); agg::trans_affine matrix; matrix *= agg::trans_affine_translation(0, 0); agg::conv_transform trans(circle, matrix); @@ -523,7 +523,7 @@ namespace CPPAGGRenderer{ void draw_empty_circle(float cx, float cy, float rx, float ry, const void *object){ Plot *plot = (Plot *)object; - plot -> draw_empty_circle(cx, cy, radius); + plot -> draw_empty_circle(cx, cy, rx, ry); } void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){ From 8225643e8f09aabbe5670a9a4b03523569635d21 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:15:03 -0500 Subject: [PATCH 51/79] Update Renderer.swift --- Sources/SwiftPlot/Renderer.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/Renderer.swift b/Sources/SwiftPlot/Renderer.swift index 3212d396..21e662ef 100644 --- a/Sources/SwiftPlot/Renderer.swift +++ b/Sources/SwiftPlot/Renderer.swift @@ -137,7 +137,8 @@ public protocol Renderer: AnyObject{ * This is decided by the boolean parameter isOriginShifted. */ func drawEmptyCircle(center c: Point, - radius r: Float) + radius rx: Float, + radius2 ry: Float) /*drawSolidTriangle() *params: point1: Point, From a53a52f1184477f212b7ef2bc33aa3e070add4e7 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:16:47 -0500 Subject: [PATCH 52/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index b040fb49..6c53f2ab 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - renderer.drawEmptyCircle(center: pointOrigin, rx: Float(2.0)*Float(referenceRadius.x-pointOrigin.x), ry: Float(2.0)*Float(referenceRadius.y-pointOrigin.y)) + renderer.drawEmptyCircle(center: pointOrigin, radius: Float(2.0)*Float(referenceRadius.x-pointOrigin.x), radius2: Float(2.0)*Float(referenceRadius.y-pointOrigin.y)) } } if let secondaryAxis = secondaryAxis, let axisInfo = data.secondaryAxisInfo { From 18a474b0faa182b713327dfa916802e3413ae30a Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:20:13 -0500 Subject: [PATCH 53/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 52e20e4a..8c98a3ce 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -307,6 +307,7 @@ namespace CPPAGGRenderer{ agg::conv_stroke>> stroke(curve); stroke.width(3); m_ras.add_path(trans); + m_ras.add_path(stroke); ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 92220a23f5a0340de4290c8d9199d97aaeaf3523 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:22:54 -0500 Subject: [PATCH 54/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 8c98a3ce..40f5fa49 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -305,8 +305,7 @@ namespace CPPAGGRenderer{ agg::conv_transform trans(circle, matrix); agg::conv_curve> curve(trans); agg::conv_stroke>> stroke(curve); - stroke.width(3); - m_ras.add_path(trans); + stroke.width(2); m_ras.add_path(stroke); ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From 6a51e7bbe47949a750fadeb41c4cc7276b3beeb1 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:25:03 -0500 Subject: [PATCH 55/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 40f5fa49..7c92570a 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -305,7 +305,7 @@ namespace CPPAGGRenderer{ agg::conv_transform trans(circle, matrix); agg::conv_curve> curve(trans); agg::conv_stroke>> stroke(curve); - stroke.width(2); + stroke.width(0.5); m_ras.add_path(stroke); ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From 7036f0fe316535a770f482bdcc1b444c94713a63 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:46:51 -0500 Subject: [PATCH 56/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 6c53f2ab..c18b85b8 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -83,6 +83,8 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} + + var maximum = max(maximum, r.max()!) var points = [Pair]() for i in 0.. Date: Thu, 23 Jan 2020 10:50:15 -0500 Subject: [PATCH 57/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index c18b85b8..612a448e 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -8,7 +8,7 @@ fileprivate let MAX_DIV: Float = 50 public struct PolarGraph: Plot { public var layout = GraphLayout() - public var maximum = Float(0.0) + public var maxRadii = Float(0.0) public var origin = Pair(T(Float(0.0)), U(Float(0.0))) public var reference = Pair(T(Float(1.0)), U(Float(1.0))) // Data. @@ -83,8 +83,6 @@ extension PolarGraph { axisType: Axis.Location = .primaryAxis){ var x = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * cos(angle.toFloat())} var y = theta.map{angle in r[theta.firstIndex(of: angle)!].toFloat() * sin(angle.toFloat())} - - var maximum = max(maximum, r.max()!) var points = [Pair]() for i in 0.. Date: Thu, 23 Jan 2020 10:51:51 -0500 Subject: [PATCH 58/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 612a448e..bb31e343 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - let maxRadii = points.values.map{pair in pair.x}.max()! + let maxRadii = points.map{pair in pair.x}.max()! for i in 1...Int(maxRadii){ renderer.drawEmptyCircle(center: pointOrigin, radius: Float(i)*Float(referenceRadius.x-pointOrigin.x), radius2: Float(i)*Float(referenceRadius.y-pointOrigin.y)) } From 700ca7f8cf39bb941802cdde36afe1b6633f57ca Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:56:05 -0500 Subject: [PATCH 59/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index bb31e343..eeba9092 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -180,7 +180,7 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - let maxRadii = points.map{pair in pair.x}.max()! + let maxRadii = dataset.values.map{pair in pair.x}.max()! for i in 1...Int(maxRadii){ renderer.drawEmptyCircle(center: pointOrigin, radius: Float(i)*Float(referenceRadius.x-pointOrigin.x), radius2: Float(i)*Float(referenceRadius.y-pointOrigin.y)) } From f5b55e260f2cbb13fce7e1277fac625d2e059235 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 11:15:02 -0500 Subject: [PATCH 60/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index eeba9092..0f5b2b82 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -181,7 +181,7 @@ extension PolarGraph: HasGraphLayout { strokeColor: dataset.color, isDashed: false) let maxRadii = dataset.values.map{pair in pair.x}.max()! - for i in 1...Int(maxRadii){ + for i in 1...maxRadii.toInt(){ renderer.drawEmptyCircle(center: pointOrigin, radius: Float(i)*Float(referenceRadius.x-pointOrigin.x), radius2: Float(i)*Float(referenceRadius.y-pointOrigin.y)) } } From 7dadb2452f7328091eb8ba1046b6c5351a50661f Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 11:18:46 -0500 Subject: [PATCH 61/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 7c92570a..67bef9d4 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -305,7 +305,7 @@ namespace CPPAGGRenderer{ agg::conv_transform trans(circle, matrix); agg::conv_curve> curve(trans); agg::conv_stroke>> stroke(curve); - stroke.width(0.5); + stroke.width(1); m_ras.add_path(stroke); ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); From b4cf27344f057dc1666308de4f2d2e7f266067a8 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 11:25:27 -0500 Subject: [PATCH 62/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index 050a6e67..dad8d932 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -147,10 +147,11 @@ public class SVGRenderer: Renderer{ } public func drawEmptyCircle(center c: Point, - radius r: Float) { + radius rx: Float, + radius2 ry: Float) { let c = convertToSVGCoordinates(c) - let color = "red" - let circle: String = #""# + let color = "gray" + let circle: String = #""# lines.append(circle) } From 00661e3b26c4afb1f32d6ed248db0e4859845ac8 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 11:29:55 -0500 Subject: [PATCH 63/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index dad8d932..e0966d42 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -151,7 +151,7 @@ public class SVGRenderer: Renderer{ radius2 ry: Float) { let c = convertToSVGCoordinates(c) let color = "gray" - let circle: String = #""# + let circle: String = #""# lines.append(circle) } From cf3eb45287c8c73122cd3abc29786d2531f8eb62 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:12:13 -0500 Subject: [PATCH 64/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index e0966d42..a4c64521 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -151,7 +151,7 @@ public class SVGRenderer: Renderer{ radius2 ry: Float) { let c = convertToSVGCoordinates(c) let color = "gray" - let circle: String = #""# + let circle: String = #""# lines.append(circle) } From dd0c0ff35df9bb3d0b4cf4f4ce4e01d1a5e59836 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:14:33 -0500 Subject: [PATCH 65/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index a4c64521..51b7f0ad 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -151,7 +151,7 @@ public class SVGRenderer: Renderer{ radius2 ry: Float) { let c = convertToSVGCoordinates(c) let color = "gray" - let circle: String = #""# + let circle: String = #""# lines.append(circle) } From 7a5a7e2469fc9064ee28185cc0b702b79c7fab78 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:19:44 -0500 Subject: [PATCH 66/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index 51b7f0ad..f4f896a3 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -151,7 +151,7 @@ public class SVGRenderer: Renderer{ radius2 ry: Float) { let c = convertToSVGCoordinates(c) let color = "gray" - let circle: String = #""# + let circle: String = #""# lines.append(circle) } From 656065d77049e978add86a7b4c4de72119632ce6 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:23:01 -0500 Subject: [PATCH 67/79] Update SVGRenderer.swift --- Sources/SVGRenderer/SVGRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SVGRenderer/SVGRenderer.swift b/Sources/SVGRenderer/SVGRenderer.swift index f4f896a3..e1e72ab3 100644 --- a/Sources/SVGRenderer/SVGRenderer.swift +++ b/Sources/SVGRenderer/SVGRenderer.swift @@ -151,7 +151,7 @@ public class SVGRenderer: Renderer{ radius2 ry: Float) { let c = convertToSVGCoordinates(c) let color = "gray" - let circle: String = #""# + let circle: String = #""# lines.append(circle) } From 6e39440326490e89164e796215f92130531b0666 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:48:35 -0500 Subject: [PATCH 68/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 0f5b2b82..6b89f8cc 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -427,6 +427,9 @@ extension PolarGraph { let offsetValue = scaleY * (offset - origin.y) return "\(roundToN(offsetValue + Float(originValue.y), yIncRound))" } + + print(xMarkerLocations.count) + print(yMarkerLocations.count) return (x: xMarkerLocations, xLabels: xMarkerLabels, y: yMarkerLocations, yLabels: yMarkerLabels) From 82c65f4cfd138bdc980b9cd76a8d28730cc2bd6f Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 23 Jan 2020 22:02:27 -0500 Subject: [PATCH 69/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 6b89f8cc..9ddd2680 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -429,7 +429,9 @@ extension PolarGraph { } print(xMarkerLocations.count) + print(xMarkerLocations) print(yMarkerLocations.count) + print(yMarkerLocations) return (x: xMarkerLocations, xLabels: xMarkerLabels, y: yMarkerLocations, yLabels: yMarkerLabels) From f3154d33f8e253267b3559fc3d68079da714dd9e Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Wed, 19 Feb 2020 10:57:31 -0500 Subject: [PATCH 70/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 67bef9d4..3d21a857 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -307,7 +307,7 @@ namespace CPPAGGRenderer{ agg::conv_stroke>> stroke(curve); stroke.width(1); m_ras.add_path(stroke); - ren_aa.color(gray_translucent); + ren_aa.color(black); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 27168c48db8110395d0ed34de306ddd4b45887e1 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Wed, 19 Feb 2020 11:00:10 -0500 Subject: [PATCH 71/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 3d21a857..7f553818 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -307,7 +307,7 @@ namespace CPPAGGRenderer{ agg::conv_stroke>> stroke(curve); stroke.width(1); m_ras.add_path(stroke); - ren_aa.color(black); + ren_aa.color(gray_transluscent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 94b83be42dcf72764be55c87c14378e71655df4e Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Fri, 21 Feb 2020 11:39:29 -0500 Subject: [PATCH 72/79] Update GraphLayout.swift --- Sources/SwiftPlot/GraphLayout.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/GraphLayout.swift b/Sources/SwiftPlot/GraphLayout.swift index 39712bd7..4fb3794d 100644 --- a/Sources/SwiftPlot/GraphLayout.swift +++ b/Sources/SwiftPlot/GraphLayout.swift @@ -469,7 +469,7 @@ extension Plot where Self: HasGraphLayout { let tup = layoutData(size: size, renderer: renderer) return (tup.0, tup.1, self.legendLabels) } - layout.drawBackground(results: results, renderer: renderer) + // layout.drawBackground(results: results, renderer: renderer) renderer.withAdditionalOffset(results.plotBorderRect.origin) { renderer in drawData(drawingData, size: results.plotBorderRect.size, renderer: renderer) } From 74838d198cc2144b3540f20f0cc62805defa9a55 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Fri, 21 Feb 2020 11:40:32 -0500 Subject: [PATCH 73/79] Update CPPAGGRenderer.cpp --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 7f553818..67bef9d4 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -307,7 +307,7 @@ namespace CPPAGGRenderer{ agg::conv_stroke>> stroke(curve); stroke.width(1); m_ras.add_path(stroke); - ren_aa.color(gray_transluscent); + ren_aa.color(gray_translucent); agg::render_scanlines(m_ras, m_sl_p8, ren_aa); } From 5ded19456aac46d2acab0c53ef7c415be1b2a7ca Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Fri, 21 Feb 2020 11:56:33 -0500 Subject: [PATCH 74/79] add transparent color we could just add a transparent limacon to expand the radius? makes it a 1:1 ratio --- Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp index 67bef9d4..69ce39aa 100644 --- a/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp +++ b/Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp @@ -45,6 +45,7 @@ const Color black(0.0,0.0,0.0,1.0); const Color blue_light(0.529,0.808,0.922,1.0); const Color white(1.0,1.0,1.0,1.0); const Color gray_translucent(0.66,0.66,0.66,0.2); +const Color transparent(1.0, 1.0, 1.0, 0.0); namespace CPPAGGRenderer{ From 977a609557b362d0fd1916af0d6a25999a775adc Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 2 Mar 2020 11:48:33 -0500 Subject: [PATCH 75/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 9ddd2680..49d51590 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -173,6 +173,15 @@ extension PolarGraph: HasGraphLayout { public func drawData(_ data: DrawingData, size: Size, renderer: Renderer) { if let axisInfo = data.primaryAxisInfo { for dataset in primaryAxis.series { + var angles = [0, 0.25, 0.5, 0.75]; + var angles2 = angles.map{val in 1+val} + angles += angles2 + angles = angles.map{angle in angle*Double.pi} + + let maxRadii = dataset.values.map{pair in pair.x}.max()! + + + let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } var pointOrigin = axisInfo.convertCoordinate(fromData: origin) var referenceRadius = axisInfo.convertCoordinate(fromData: reference) @@ -180,7 +189,6 @@ extension PolarGraph: HasGraphLayout { strokeWidth: plotLineThickness, strokeColor: dataset.color, isDashed: false) - let maxRadii = dataset.values.map{pair in pair.x}.max()! for i in 1...maxRadii.toInt(){ renderer.drawEmptyCircle(center: pointOrigin, radius: Float(i)*Float(referenceRadius.x-pointOrigin.x), radius2: Float(i)*Float(referenceRadius.y-pointOrigin.y)) } From 7852a2ab7490c9591a3f78845a7664f4e29f626b Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 2 Mar 2020 11:55:24 -0500 Subject: [PATCH 76/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 49d51590..cb92d095 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -176,11 +176,20 @@ extension PolarGraph: HasGraphLayout { var angles = [0, 0.25, 0.5, 0.75]; var angles2 = angles.map{val in 1+val} angles += angles2 - angles = angles.map{angle in angle*Double.pi} + theta = angles.map{angle in angle*Double.pi} let maxRadii = dataset.values.map{pair in pair.x}.max()! - + var x = theta.map{angle in maxRadii.toFloat() * cos(angle.toFloat())} + var y = theta.map{angle in maxRadii.toFloat() * sin(angle.toFloat())} + + for i in 0..]() + points.append(Pair(T(0), U(0))) + points.append(Pair(T(maxRadii.toFloat() * cos(angles[i].toFloat())), U(maxRadii.toFloat() * sin(angles[i].toFloat())))) + let s = Series(values: points, label: label, color: color) + addSeries(s, axisType: .primaryAxis) + } let points = dataset.values.map { axisInfo.convertCoordinate(fromData: $0) } var pointOrigin = axisInfo.convertCoordinate(fromData: origin) From dacbe1185fec52634ed668b07bfac623f557750a Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 2 Mar 2020 11:57:42 -0500 Subject: [PATCH 77/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index cb92d095..3743ceef 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -187,7 +187,7 @@ extension PolarGraph: HasGraphLayout { var points = [Pair]() points.append(Pair(T(0), U(0))) points.append(Pair(T(maxRadii.toFloat() * cos(angles[i].toFloat())), U(maxRadii.toFloat() * sin(angles[i].toFloat())))) - let s = Series(values: points, label: label, color: color) + let s = Series(values: points, label: "Boi", color: .lightBlue) addSeries(s, axisType: .primaryAxis) } From fdd752a3b5860294d3230a352c28109358651ac7 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Mon, 2 Mar 2020 11:59:49 -0500 Subject: [PATCH 78/79] Update PolarChart.swift --- Sources/SwiftPlot/PolarChart.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftPlot/PolarChart.swift b/Sources/SwiftPlot/PolarChart.swift index 3743ceef..a66fbc85 100644 --- a/Sources/SwiftPlot/PolarChart.swift +++ b/Sources/SwiftPlot/PolarChart.swift @@ -176,7 +176,7 @@ extension PolarGraph: HasGraphLayout { var angles = [0, 0.25, 0.5, 0.75]; var angles2 = angles.map{val in 1+val} angles += angles2 - theta = angles.map{angle in angle*Double.pi} + var theta = angles.map{angle in angle*Double.pi} let maxRadii = dataset.values.map{pair in pair.x}.max()! From 1e87449be4b1c82efa47d93255cab2242e7388c2 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Sat, 18 Apr 2020 18:56:43 -0400 Subject: [PATCH 79/79] Update agg_blur.h --- Sources/AGG/include/agg_blur.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AGG/include/agg_blur.h b/Sources/AGG/include/agg_blur.h index fd38e942..1f934a87 100644 --- a/Sources/AGG/include/agg_blur.h +++ b/Sources/AGG/include/agg_blur.h @@ -1487,13 +1487,13 @@ namespace agg } template - void apply_slight_blur(renderer_base& img, const rect_i& bounds, double r = 1) + void apply_slight_blur(blender_base& img, const rect_i& bounds, double r = 1) { if (r > 0) slight_blur(r).blur(img.ren(), bounds); } template - void apply_slight_blur(renderer_base& img, double r = 1) + void apply_slight_blur(blender_base& img, double r = 1) { if (r > 0) slight_blur(r).blur(img.ren(), img.clip_box()); }