Skip to content

Commit 852f4b3

Browse files
karwaKarthikRIyer
authored andcommitted
conf: Move examples to become tests (#42)
* 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
1 parent a0fe255 commit 852f4b3

File tree

146 files changed

+1927
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1927
-757
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ playground.xcworkspace
3939
# Package.pins
4040
# Package.resolved
4141
.build/
42+
.swiftpm/
4243

4344
# CocoaPods
4445
#
@@ -68,3 +69,4 @@ fastlane/screenshots/**/*.png
6869
fastlane/test_output
6970

7071
Notebooks/.ipynb_checkpoints/
72+
**/.DS_Store

Package.resolved

-16
This file was deleted.

Package.swift

+101-142
Original file line numberDiff line numberDiff line change
@@ -3,149 +3,108 @@
33

44
import PackageDescription
55

6+
#if os(Linux)
7+
let platformTargets: [Target] = [
8+
.systemLibrary(
9+
name: "CFreeType",
10+
path: "framework/CFreeType",
11+
pkgConfig: "freetype2",
12+
providers: [.brew(["freetype2"]), .apt(["libfreetype6-dev"])]),
13+
.target(
14+
name: "AGG",
15+
dependencies: ["CFreeType"],
16+
path: "framework/AGG"),
17+
.target(
18+
name: "lodepng",
19+
dependencies: [],
20+
path: "framework/lodepng"),
21+
.target(
22+
name: "CPPAGGRenderer",
23+
dependencies: ["AGG","lodepng"],
24+
path: "framework/AGGRenderer/CPPAGGRenderer"),
25+
.target(
26+
name: "CAGGRenderer",
27+
dependencies: ["CPPAGGRenderer"],
28+
path: "framework/AGGRenderer/CAGGRenderer"),
29+
.target(
30+
name: "SwiftPlot",
31+
dependencies: [],
32+
path: "framework/SwiftPlot"),
33+
.target(
34+
name: "AGGRenderer",
35+
dependencies: ["CAGGRenderer","SwiftPlot"],
36+
path: "framework/AGGRenderer/AGGRenderer"),
37+
.target(
38+
name: "SVGRenderer",
39+
dependencies: ["SwiftPlot"],
40+
path: "framework/SVGRenderer"),
41+
42+
.testTarget(
43+
name: "SwiftPlotTests",
44+
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"])
45+
]
46+
let platformProducts: [Product] = [
47+
.library(
48+
name: "SwiftPlot",
49+
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer"]
50+
),
51+
]
52+
53+
#elseif os(iOS) || os(macOS)
54+
let platformTargets: [Target] = [
55+
.systemLibrary(
56+
name: "CFreeType",
57+
path: "framework/CFreeType",
58+
pkgConfig: "freetype2",
59+
providers: [.brew(["freetype2"]), .apt(["libfreetype6-dev"])]),
60+
.target(
61+
name: "AGG",
62+
dependencies: ["CFreeType"],
63+
path: "framework/AGG"),
64+
.target(
65+
name: "lodepng",
66+
dependencies: [],
67+
path: "framework/lodepng"),
68+
.target(
69+
name: "CPPAGGRenderer",
70+
dependencies: ["AGG","lodepng"],
71+
path: "framework/AGGRenderer/CPPAGGRenderer"),
72+
.target(
73+
name: "CAGGRenderer",
74+
dependencies: ["CPPAGGRenderer"],
75+
path: "framework/AGGRenderer/CAGGRenderer"),
76+
.target(
77+
name: "SwiftPlot",
78+
dependencies: [],
79+
path: "framework/SwiftPlot"),
80+
.target(
81+
name: "QuartzRenderer",
82+
dependencies: ["SwiftPlot"],
83+
path: "framework/QuartzRenderer"),
84+
.target(
85+
name: "AGGRenderer",
86+
dependencies: ["CAGGRenderer","SwiftPlot"],
87+
path: "framework/AGGRenderer/AGGRenderer"),
88+
.target(
89+
name: "SVGRenderer",
90+
dependencies: ["SwiftPlot"],
91+
path: "framework/SVGRenderer"),
92+
93+
.testTarget(
94+
name: "SwiftPlotTests",
95+
dependencies: ["AGGRenderer", "SVGRenderer", "QuartzRenderer", "SwiftPlot"])
96+
]
97+
let platformProducts: [Product] = [
98+
.library(
99+
name: "SwiftPlot",
100+
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer", "QuartzRenderer"]
101+
),
102+
]
103+
#endif
104+
6105
let package = Package(
7106
name: "SwiftPlot",
8-
products: [
9-
// Products define the executables and libraries produced by a package, and make them visible to other packages.
10-
.library(
11-
name: "SwiftPlot",
12-
targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer"]),
13-
],
14-
dependencies: [
15-
// Dependencies declare other packages that this package depends on.
16-
// .package(url: /* package url */, from: "1.0.0"),
17-
.package(url:"https://github.com/KarthikRIyer/CFreeType.git", .branch("master")),
18-
],
19-
targets: [
20-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
21-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
22-
.target(
23-
name: "AGG",
24-
dependencies: [],
25-
path: "framework/AGG"),
26-
.target(
27-
name: "lodepng",
28-
dependencies: [],
29-
path: "framework/lodepng"),
30-
.target(
31-
name: "CPPAGGRenderer",
32-
dependencies: ["AGG","lodepng"],
33-
path: "framework/AGGRenderer/CPPAGGRenderer"),
34-
.target(
35-
name: "CAGGRenderer",
36-
dependencies: ["CPPAGGRenderer"],
37-
path: "framework/AGGRenderer/CAGGRenderer"),
38-
.target(
39-
name: "SwiftPlot",
40-
dependencies: [],
41-
path: "framework/SwiftPlot"),
42-
.target(
43-
name: "AGGRenderer",
44-
dependencies: ["CAGGRenderer","SwiftPlot"],
45-
path: "framework/AGGRenderer/AGGRenderer"),
46-
.target(
47-
name: "SVGRenderer",
48-
dependencies: ["SwiftPlot"],
49-
path: "framework/SVGRenderer"),
50-
.target(
51-
name: "LineChartSingleSeriesExample",
52-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
53-
path: "examples/LineChartSingleSeries"),
54-
.target(
55-
name: "LineChartMultipleSeriesExample",
56-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
57-
path: "examples/LineChartMultipleSeries"),
58-
.target(
59-
name: "LineChartSubPlotHorizontallyStackedExample",
60-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
61-
path: "examples/LineChartSubPlotHorizontallyStacked"),
62-
.target(
63-
name: "LineChartSubPlotVerticallyStackedExample",
64-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
65-
path: "examples/LineChartSubPlotVerticallyStacked"),
66-
.target(
67-
name: "LineChartSubPlotGridStackedExample",
68-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
69-
path: "examples/LineChartSubPlotGridStacked"),
70-
.target(
71-
name: "LineChartFunctionPlotExample",
72-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
73-
path: "examples/LineChartFunctionPlot"),
74-
.target(
75-
name: "LineChartSecondaryAxisExample",
76-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
77-
path: "examples/LineChartSecondaryAxis"),
78-
.target(
79-
name: "BarChartExample",
80-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
81-
path: "examples/BarChart"),
82-
.target(
83-
name: "BarChartForwardSlashHatchedExample",
84-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
85-
path: "examples/BarChartForwardSlashHatched"),
86-
.target(
87-
name: "BarChartBackwardSlashHatchedExample",
88-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
89-
path: "examples/BarChartBackwardSlashHatched"),
90-
.target(
91-
name: "BarChartVerticalHatchedExample",
92-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
93-
path: "examples/BarChartVerticalHatched"),
94-
.target(
95-
name: "BarChartHorizontalHatchedExample",
96-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
97-
path: "examples/BarChartHorizontalHatched"),
98-
.target(
99-
name: "BarChartGridHatchedExample",
100-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
101-
path: "examples/BarChartGridHatched"),
102-
.target(
103-
name: "BarChartCrossHatchedExample",
104-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
105-
path: "examples/BarChartCrossHatched"),
106-
.target(
107-
name: "BarChartHollowCircleHatchedExample",
108-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
109-
path: "examples/BarChartHollowCircleHatched"),
110-
.target(
111-
name: "BarChartFilledCircleHatchedExample",
112-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
113-
path: "examples/BarChartFilledCircleHatched"),
114-
.target(
115-
name: "BarChartOrientationHorizontalExample",
116-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
117-
path: "examples/BarChartOrientationHorizontal"),
118-
.target(
119-
name: "BarChartVerticalStackedExample",
120-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
121-
path: "examples/BarChartVerticalStacked"),
122-
.target(
123-
name: "BarChartHorizontalStackedExample",
124-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
125-
path: "examples/BarChartHorizontalStacked"),
126-
.target(
127-
name: "ScatterPlotExample",
128-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
129-
path: "examples/ScatterPlot"),
130-
.target(
131-
name: "HistogramExample",
132-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
133-
path: "examples/Histogram"),
134-
.target(
135-
name: "HistogramStepExample",
136-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
137-
path: "examples/HistogramStep"),
138-
.target(
139-
name: "HistogramStackedExample",
140-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
141-
path: "examples/HistogramStacked"),
142-
.target(
143-
name: "HistogramStackedStepExample",
144-
dependencies: ["AGGRenderer", "SVGRenderer", "SwiftPlot"],
145-
path: "examples/HistogramStackedStep"),
146-
//.testTarget(
147-
// name: "swiftplotTests",
148-
// dependencies: ["swiftplot"]),
149-
],
107+
products: platformProducts,
108+
targets: platformTargets,
150109
cxxLanguageStandard: .cxx11
151110
)

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,11 @@ To encode the plots as PNG images it uses the [lodepng](https://github.com/lvand
3838
SwiftPlot can also be used in Jupyter Notebooks.
3939
</br>
4040

41-
Examples, demonstrating all the features, have been included with the repository under the `examples` directory.
42-
To run the examples, clone the repository, and run the run_examples.sh script as shown below.
41+
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.
4342

44-
```console
45-
run_examples.sh
46-
```
4743
Jupyter Notebook examples are under the `Notebooks` directory.
4844

49-
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).
45+
The resultant images are stored in a directory named `output`. The `Tests` folder includes a collection of reference images in the `Reference` directory.
5046

5147

5248
## License

Tests/LinuxMain.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import XCTest
22

3-
import swiftplotTests
3+
import SwiftPlotTests
44

55
var tests = [XCTestCaseEntry]()
6-
tests += swiftplotTests.allTests()
6+
tests += SwiftPlotTests.__allTests()
7+
78
XCTMain(tests)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import SwiftPlot
2+
import AGGRenderer
3+
import SVGRenderer
4+
#if canImport(QuartzRenderer)
5+
import QuartzRenderer
6+
#endif
7+
8+
extension BarchartTests {
9+
10+
func testBarchartHatchedBackslash() {
11+
12+
let fileName = "_11_bar_chart_backward_slash_hatched"
13+
14+
let x:[String] = ["2008","2009","2010","2011"]
15+
let y:[Float] = [320,-100,420,500]
16+
17+
let agg_renderer = AGGRenderer()
18+
let svg_renderer = SVGRenderer()
19+
#if canImport(QuartzRenderer)
20+
let quartz_renderer = QuartzRenderer()
21+
#endif
22+
23+
let barGraph = BarGraph<String,Float>(enableGrid: true)
24+
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, hatchPattern: .backwardSlash)
25+
barGraph.plotTitle = PlotTitle("HATCHED BAR CHART")
26+
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
27+
28+
barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
29+
renderer: agg_renderer)
30+
barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
31+
renderer: svg_renderer)
32+
#if canImport(QuartzRenderer)
33+
barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
34+
renderer: quartz_renderer)
35+
#endif
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import SwiftPlot
2+
import AGGRenderer
3+
import SVGRenderer
4+
#if canImport(QuartzRenderer)
5+
import QuartzRenderer
6+
#endif
7+
8+
extension BarchartTests {
9+
10+
func testBarchartHatchedCross() {
11+
12+
let fileName = "_15_bar_chart_cross_hatched"
13+
14+
let x:[String] = ["2008","2009","2010","2011"]
15+
let y:[Float] = [320,-100,420,500]
16+
17+
let agg_renderer = AGGRenderer()
18+
let svg_renderer = SVGRenderer()
19+
#if canImport(QuartzRenderer)
20+
let quartz_renderer = QuartzRenderer()
21+
#endif
22+
23+
let barGraph = BarGraph<String,Float>(enableGrid: true)
24+
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, hatchPattern: .cross)
25+
barGraph.plotTitle = PlotTitle("HATCHED BAR CHART")
26+
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
27+
28+
barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
29+
renderer: agg_renderer)
30+
barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
31+
renderer: svg_renderer)
32+
#if canImport(QuartzRenderer)
33+
barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
34+
renderer: quartz_renderer)
35+
#endif
36+
}
37+
}

0 commit comments

Comments
 (0)