@@ -2,7 +2,7 @@ import SwiftPlot
2
2
import Foundation
3
3
4
4
extension LineChartTests {
5
-
5
+
6
6
func testLineChart_positiveYOrigin( ) throws {
7
7
let x : [ Float ] = [ 0 , 1 , 2 , 3 ]
8
8
let y : [ Float ] = [ 70 , 80 , 95 , 100 ]
@@ -16,7 +16,7 @@ extension LineChartTests {
16
16
17
17
try renderAndVerify ( lineGraph, size: Size ( width: 300 , height: 300 ) )
18
18
}
19
-
19
+
20
20
func testLineChart_positiveYOrigin_secondary( ) throws {
21
21
let x : [ Float ] = [ 0 , 1 , 2 , 3 ]
22
22
let y : [ Float ] = [ 70 , 80 , 95 , 100 ]
@@ -32,10 +32,10 @@ extension LineChartTests {
32
32
lineGraph. plotLineThickness = 3.0
33
33
lineGraph. enablePrimaryAxisGrid = true
34
34
lineGraph. enableSecondaryAxisGrid = true
35
-
35
+
36
36
try renderAndVerify ( lineGraph, size: Size ( width: 400 , height: 400 ) )
37
37
}
38
-
38
+
39
39
func testLineChart_negativeYOrigin( ) throws {
40
40
let x : [ Float ] = [ 0 , 1 , 2 , 3 ]
41
41
let y : [ Float ] = [ - 70 , - 80 , - 95 , - 100 ]
@@ -49,7 +49,7 @@ extension LineChartTests {
49
49
50
50
try renderAndVerify ( lineGraph, size: Size ( width: 300 , height: 300 ) )
51
51
}
52
-
52
+
53
53
func testLineChart_positiveXOrigin( ) throws {
54
54
let x : [ Float ] = [ 5 , 6 , 7 , 8 ]
55
55
let y : [ Float ] = [ 70 , 80 , 95 , 100 ]
@@ -63,7 +63,7 @@ extension LineChartTests {
63
63
64
64
try renderAndVerify ( lineGraph, size: Size ( width: 300 , height: 300 ) )
65
65
}
66
-
66
+
67
67
func testLineChart_negativeXOrigin( ) throws {
68
68
let x : [ Float ] = [ - 5 , - 6 , - 7 , - 8 ]
69
69
let y : [ Float ] = [ - 70 , - 80 , - 95 , - 100 ]
@@ -77,7 +77,7 @@ extension LineChartTests {
77
77
78
78
try renderAndVerify ( lineGraph, size: Size ( width: 300 , height: 300 ) )
79
79
}
80
-
80
+
81
81
func testLineChart_positiveXOrigin_secondary( ) throws {
82
82
let x : [ Float ] = [ 0 , 1 , 2 , 3 ]
83
83
let y : [ Float ] = [ 70 , 80 , 95 , 100 ]
@@ -94,10 +94,10 @@ extension LineChartTests {
94
94
lineGraph. plotLineThickness = 3.0
95
95
lineGraph. enablePrimaryAxisGrid = true
96
96
lineGraph. enableSecondaryAxisGrid = true
97
-
97
+
98
98
try renderAndVerify ( lineGraph, size: Size ( width: 400 , height: 400 ) )
99
99
}
100
-
100
+
101
101
func testLineChart_negativeXOrigin_unsorted( ) throws {
102
102
let x : [ Float ] = [ - 8 , - 7 , - 6 , - 5 ]
103
103
let y : [ Float ] = [ 70 , 80 , 95 , 100 ]
@@ -111,7 +111,7 @@ extension LineChartTests {
111
111
112
112
try renderAndVerify ( lineGraph, size: Size ( width: 300 , height: 300 ) )
113
113
}
114
-
114
+
115
115
func testLineChart_crossX( ) throws {
116
116
func someFunction( _ x: Float ) -> Float { ( x * x) + 10 }
117
117
var lineGraph_func = LineGraph < Float , Float > ( enablePrimaryAxisGrid: true )
@@ -126,7 +126,7 @@ extension LineChartTests {
126
126
lineGraph_func. plotLabel. yLabel = " Y-AXIS "
127
127
try renderAndVerify ( lineGraph_func, size: Size ( width: 400 , height: 400 ) )
128
128
}
129
-
129
+
130
130
func testLineChart_crossY( ) throws {
131
131
func someFunction( _ x: Float ) -> Float { 5 * cos( 2 * x * x) / x }
132
132
var lineGraph_func = LineGraph < Float , Float > ( enablePrimaryAxisGrid: true )
@@ -141,22 +141,22 @@ extension LineChartTests {
141
141
lineGraph_func. plotLabel. yLabel = " Y-AXIS "
142
142
try renderAndVerify ( lineGraph_func, size: Size ( width: 400 , height: 400 ) )
143
143
}
144
-
144
+
145
145
func testLineChart_crossBothAxes( ) throws {
146
146
var lineGraph = LineGraph < Float , Float > ( enablePrimaryAxisGrid: true ,
147
147
enableSecondaryAxisGrid: false )
148
148
let clamp : ClosedRange < Float > ? = - 150 ... 150
149
- lineGraph. addFunction ( { pow ( $0 , 2 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 2 " , color: . lightBlue)
150
- lineGraph. addFunction ( { pow ( $0 , 3 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 3 " , color: . orange)
151
- lineGraph. addFunction ( { pow ( $0 , 4 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 4 " , color: . red)
152
- lineGraph. addFunction ( { pow ( $0 , 5 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 5 " , color: . brown)
153
- lineGraph. addFunction ( { pow ( $0 , 6 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 6 " , color: . purple)
154
- lineGraph. addFunction ( { pow ( $0 , 7 ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 7 " , color: . green)
149
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 2 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 2 " , color: . lightBlue)
150
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 3 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 3 " , color: . orange)
151
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 4 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 4 " , color: . red)
152
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 5 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 5 " , color: . brown)
153
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 6 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 6 " , color: . purple)
154
+ lineGraph. addFunction ( { Float ( truncating : pow ( Decimal ( Double ( $0 ) ) , Int ( 7 ) ) as NSNumber ) } , minX: - 5 , maxX: 5 , clampY: clamp, label: " 7 " , color: . green)
155
155
lineGraph. plotTitle. title = " y = x^n "
156
156
lineGraph. plotLabel. xLabel = " x "
157
157
lineGraph. plotLabel. yLabel = " y "
158
158
lineGraph. backgroundColor = . transparent
159
-
159
+
160
160
try renderAndVerify ( lineGraph, size: Size ( width: 800 , height: 400 ) )
161
161
}
162
162
}
0 commit comments