Skip to content

Commit

Permalink
feat: Implement horizontal bar chart feature
Browse files Browse the repository at this point in the history
  • Loading branch information
KarthikRIyer committed Jun 6, 2019
1 parent 920fc7e commit ad66f55
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 85 deletions.
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ let package = Package(
name: "BarChartFilledCircleHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartFilledCircleHatched"),
.target(
name: "BarChartOrientationHorizontalExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartOrientationHorizontal"),
//.testTarget(
// name: "swiftplotTests",
// dependencies: ["swiftplot"]),
Expand Down
22 changes: 22 additions & 0 deletions examples/BarChartOrientationHorizontal/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SwiftPlot
import AGGRenderer
import SVGRenderer

var filePath = "examples/Reference/"
let fileName = "_08_bar_chart"

let x:[String] = ["2008","2009","2010","2011"]
let y:[Float] = [320,-100,420,500]

var agg_renderer: AGGRenderer = AGGRenderer()
var svg_renderer: SVGRenderer = SVGRenderer()

var plotTitle: PlotTitle = PlotTitle()

var barGraph: BarGraph = BarGraph()
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, graphOrientation: .horizontal)
plotTitle.title = "BAR CHART"
barGraph.plotTitle = plotTitle

barGraph.drawGraphAndOutput(fileName: filePath+"agg/"+fileName, renderer: agg_renderer)
barGraph.drawGraphAndOutput(fileName: filePath+"svg/"+fileName, renderer: svg_renderer)
2 changes: 1 addition & 1 deletion framework/SVGRenderer/SVGRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SVGRenderer: Renderer{
let h: Float = abs(p2.y - p3.y)
var y = max(p1.y,p2.y,p3.y,p4.y) + (0.1*plotDimensions.subHeight) - yOffset
y = plotDimensions.subHeight - y
let x = p1.x + xOffset + (0.1*plotDimensions.subWidth)
let x = min(p1.x, p2.x, p3.x, p4.x) + xOffset + (0.1*plotDimensions.subWidth)
let rect: String = "<rect x=\"\(x)\" y=\"\(y)\" width=\"\(w)\" height=\"\(h)\" style=\"fill:rgb(\(fillColor.r*255.0),\(fillColor.g*255.0),\(fillColor.b*255.0));stroke-width:0;stroke:rgb(0,0,0);opacity:\(fillColor.a)\" />"
image = image + "\n" + rect
drawHatchingRect(x: x, y: y, width: w, height: h, hatchPattern: hatchPattern)
Expand Down
Loading

0 comments on commit ad66f55

Please sign in to comment.