Skip to content

Commit

Permalink
conf: Move examples to become tests (#42)
Browse files Browse the repository at this point in the history
* Add initial CoreGraphics Renderer code

* chor: Update Examples

* feat: Add patterns to QuartzRenderer and fix offset bug in QuartzRenderer and SVG Renderer

* rfac: Add code for iOS

* rfac: Update Package.swift to build in Linux

* Add .swiftpm directory to gitignore

* Move examples to a single, executable product

* Actually, let's just straight-up move these to be tests

* - Turn the examples in to actual test-cases (although they do not yet compare with the reference images, so always pass)
- Clean up warnings (mostly turning 'var's in to 'let's)
- Ensure output directory is created by the test-case setup function

* Add test target to linux, fix casing for test target

* Move CFreeType system dependency in to the package itself

* Update README
  • Loading branch information
karwa authored and KarthikRIyer committed Nov 27, 2019
1 parent a0fe255 commit 852f4b3
Show file tree
Hide file tree
Showing 146 changed files with 1,927 additions and 757 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ playground.xcworkspace
# Package.pins
# Package.resolved
.build/
.swiftpm/

# CocoaPods
#
Expand Down Expand Up @@ -68,3 +69,4 @@ fastlane/screenshots/**/*.png
fastlane/test_output

Notebooks/.ipynb_checkpoints/
**/.DS_Store
16 changes: 0 additions & 16 deletions Package.resolved

This file was deleted.

243 changes: 101 additions & 142 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,149 +3,108 @@

import PackageDescription

#if os(Linux)
let platformTargets: [Target] = [
.systemLibrary(
name: "CFreeType",
path: "framework/CFreeType",
pkgConfig: "freetype2",
providers: [.brew(["freetype2"]), .apt(["libfreetype6-dev"])]),
.target(
name: "AGG",
dependencies: ["CFreeType"],
path: "framework/AGG"),
.target(
name: "lodepng",
dependencies: [],
path: "framework/lodepng"),
.target(
name: "CPPAGGRenderer",
dependencies: ["AGG","lodepng"],
path: "framework/AGGRenderer/CPPAGGRenderer"),
.target(
name: "CAGGRenderer",
dependencies: ["CPPAGGRenderer"],
path: "framework/AGGRenderer/CAGGRenderer"),
.target(
name: "SwiftPlot",
dependencies: [],
path: "framework/SwiftPlot"),
.target(
name: "AGGRenderer",
dependencies: ["CAGGRenderer","SwiftPlot"],
path: "framework/AGGRenderer/AGGRenderer"),
.target(
name: "SVGRenderer",
dependencies: ["SwiftPlot"],
path: "framework/SVGRenderer"),

.testTarget(
name: "SwiftPlotTests",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"])
]
let platformProducts: [Product] = [
.library(
name: "SwiftPlot",
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer"]
),
]

#elseif os(iOS) || os(macOS)
let platformTargets: [Target] = [
.systemLibrary(
name: "CFreeType",
path: "framework/CFreeType",
pkgConfig: "freetype2",
providers: [.brew(["freetype2"]), .apt(["libfreetype6-dev"])]),
.target(
name: "AGG",
dependencies: ["CFreeType"],
path: "framework/AGG"),
.target(
name: "lodepng",
dependencies: [],
path: "framework/lodepng"),
.target(
name: "CPPAGGRenderer",
dependencies: ["AGG","lodepng"],
path: "framework/AGGRenderer/CPPAGGRenderer"),
.target(
name: "CAGGRenderer",
dependencies: ["CPPAGGRenderer"],
path: "framework/AGGRenderer/CAGGRenderer"),
.target(
name: "SwiftPlot",
dependencies: [],
path: "framework/SwiftPlot"),
.target(
name: "QuartzRenderer",
dependencies: ["SwiftPlot"],
path: "framework/QuartzRenderer"),
.target(
name: "AGGRenderer",
dependencies: ["CAGGRenderer","SwiftPlot"],
path: "framework/AGGRenderer/AGGRenderer"),
.target(
name: "SVGRenderer",
dependencies: ["SwiftPlot"],
path: "framework/SVGRenderer"),

.testTarget(
name: "SwiftPlotTests",
dependencies: ["AGGRenderer", "SVGRenderer", "QuartzRenderer", "SwiftPlot"])
]
let platformProducts: [Product] = [
.library(
name: "SwiftPlot",
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer", "QuartzRenderer"]
),
]
#endif

let package = Package(
name: "SwiftPlot",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftPlot",
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url:"https://github.com/KarthikRIyer/CFreeType.git", .branch("master")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "AGG",
dependencies: [],
path: "framework/AGG"),
.target(
name: "lodepng",
dependencies: [],
path: "framework/lodepng"),
.target(
name: "CPPAGGRenderer",
dependencies: ["AGG","lodepng"],
path: "framework/AGGRenderer/CPPAGGRenderer"),
.target(
name: "CAGGRenderer",
dependencies: ["CPPAGGRenderer"],
path: "framework/AGGRenderer/CAGGRenderer"),
.target(
name: "SwiftPlot",
dependencies: [],
path: "framework/SwiftPlot"),
.target(
name: "AGGRenderer",
dependencies: ["CAGGRenderer","SwiftPlot"],
path: "framework/AGGRenderer/AGGRenderer"),
.target(
name: "SVGRenderer",
dependencies: ["SwiftPlot"],
path: "framework/SVGRenderer"),
.target(
name: "LineChartSingleSeriesExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartSingleSeries"),
.target(
name: "LineChartMultipleSeriesExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartMultipleSeries"),
.target(
name: "LineChartSubPlotHorizontallyStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartSubPlotHorizontallyStacked"),
.target(
name: "LineChartSubPlotVerticallyStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartSubPlotVerticallyStacked"),
.target(
name: "LineChartSubPlotGridStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartSubPlotGridStacked"),
.target(
name: "LineChartFunctionPlotExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartFunctionPlot"),
.target(
name: "LineChartSecondaryAxisExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/LineChartSecondaryAxis"),
.target(
name: "BarChartExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChart"),
.target(
name: "BarChartForwardSlashHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartForwardSlashHatched"),
.target(
name: "BarChartBackwardSlashHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartBackwardSlashHatched"),
.target(
name: "BarChartVerticalHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartVerticalHatched"),
.target(
name: "BarChartHorizontalHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartHorizontalHatched"),
.target(
name: "BarChartGridHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartGridHatched"),
.target(
name: "BarChartCrossHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartCrossHatched"),
.target(
name: "BarChartHollowCircleHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartHollowCircleHatched"),
.target(
name: "BarChartFilledCircleHatchedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartFilledCircleHatched"),
.target(
name: "BarChartOrientationHorizontalExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartOrientationHorizontal"),
.target(
name: "BarChartVerticalStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartVerticalStacked"),
.target(
name: "BarChartHorizontalStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/BarChartHorizontalStacked"),
.target(
name: "ScatterPlotExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/ScatterPlot"),
.target(
name: "HistogramExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/Histogram"),
.target(
name: "HistogramStepExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/HistogramStep"),
.target(
name: "HistogramStackedExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/HistogramStacked"),
.target(
name: "HistogramStackedStepExample",
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
path: "examples/HistogramStackedStep"),
//.testTarget(
// name: "swiftplotTests",
// dependencies: ["swiftplot"]),
],
products: platformProducts,
targets: platformTargets,
cxxLanguageStandard: .cxx11
)
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ To encode the plots as PNG images it uses the [lodepng](https://github.com/lvand
SwiftPlot can also be used in Jupyter Notebooks.
</br>

Examples, demonstrating all the features, have been included with the repository under the `examples` directory.
To run the examples, clone the repository, and run the run_examples.sh script as shown below.
Examples, demonstrating all the features, have been included with the repository under the `Tests/SwiftPlotTests` directory. To run the examples, clone the repository, and run the `swift test` command from the package directory.

```console
run_examples.sh
```
Jupyter Notebook examples are under the `Notebooks` directory.

The resultant images are stored in the `examples/Reference` directory. The images rendered by each of the backends are stored their respective directories: [agg](https://github.com/KarthikRIyer/swiftplot/tree/master/examples/Reference/agg) and [svg](https://github.com/KarthikRIyer/swiftplot/tree/master/examples/Reference/svg).
The resultant images are stored in a directory named `output`. The `Tests` folder includes a collection of reference images in the `Reference` directory.


## License
Expand Down
5 changes: 3 additions & 2 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import XCTest

import swiftplotTests
import SwiftPlotTests

var tests = [XCTestCaseEntry]()
tests += swiftplotTests.allTests()
tests += SwiftPlotTests.__allTests()

XCTMain(tests)
37 changes: 37 additions & 0 deletions Tests/SwiftPlotTests/BarChart/barchart-hatched-backwardslash.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import SwiftPlot
import AGGRenderer
import SVGRenderer
#if canImport(QuartzRenderer)
import QuartzRenderer
#endif

extension BarchartTests {

func testBarchartHatchedBackslash() {

let fileName = "_11_bar_chart_backward_slash_hatched"

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

let agg_renderer = AGGRenderer()
let svg_renderer = SVGRenderer()
#if canImport(QuartzRenderer)
let quartz_renderer = QuartzRenderer()
#endif

let barGraph = BarGraph<String,Float>(enableGrid: true)
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, hatchPattern: .backwardSlash)
barGraph.plotTitle = PlotTitle("HATCHED BAR CHART")
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")

barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
renderer: agg_renderer)
barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
renderer: svg_renderer)
#if canImport(QuartzRenderer)
barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
renderer: quartz_renderer)
#endif
}
}
37 changes: 37 additions & 0 deletions Tests/SwiftPlotTests/BarChart/barchart-hatched-cross.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import SwiftPlot
import AGGRenderer
import SVGRenderer
#if canImport(QuartzRenderer)
import QuartzRenderer
#endif

extension BarchartTests {

func testBarchartHatchedCross() {

let fileName = "_15_bar_chart_cross_hatched"

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

let agg_renderer = AGGRenderer()
let svg_renderer = SVGRenderer()
#if canImport(QuartzRenderer)
let quartz_renderer = QuartzRenderer()
#endif

let barGraph = BarGraph<String,Float>(enableGrid: true)
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, hatchPattern: .cross)
barGraph.plotTitle = PlotTitle("HATCHED BAR CHART")
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")

barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
renderer: agg_renderer)
barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
renderer: svg_renderer)
#if canImport(QuartzRenderer)
barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
renderer: quartz_renderer)
#endif
}
}
Loading

0 comments on commit 852f4b3

Please sign in to comment.