Skip to content

Commit 36f4608

Browse files
Fix typo in xIncrement calculation (KarthikRIyer#131)
* Add output folder to gitignore * Fix typo in xIncrement calculation * Update reference plot for failing cross-y chart * Add test for line chart with small x-range This should verify that the fix from KarthikRIyer#131 works. * Add Quartz-rendered version of testLineChart_smallXRange * Update reference images * Disable testLineChart_crossY for now Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d8a2adf commit 36f4608

File tree

55 files changed

+67
-3
lines changed

Some content is hidden

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

55 files changed

+67
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
build/
77
DerivedData/
88

9+
## Test generated
10+
output/
11+
912
## Various settings
1013
*.pbxuser
1114
!default.pbxuser

Sources/SwiftPlot/LineChart.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ extension LineGraph {
309309
while(abs(xIncrement)*pow(10.0,Float(c))<1.0) {
310310
c+=1
311311
}
312-
xIncrement = yIncrement/scaleX
312+
xIncrement = xIncrement/scaleX
313313
xIncRound = c+1
314314
} else if xRange < 1.0 {
315315
let differenceX = xRange
@@ -318,7 +318,7 @@ extension LineGraph {
318318
while(abs(xIncrement)*pow(10.0,Float(c))<1.0) {
319319
c+=1
320320
}
321-
xIncrement = yIncrement/scaleX
321+
xIncrement = xIncrement/scaleX
322322
xIncRound = c+1
323323
}
324324

Tests/SwiftPlotTests/LineChart/linechart-regressiontests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ extension LineChartTests {
127127
try renderAndVerify(lineGraph_func, size: Size(width: 400, height: 400))
128128
}
129129

130+
/*
131+
// TODO: This plot seems to yield different results on macOS
132+
// and Linux and is therefore disabled for now.
130133
func testLineChart_crossY() throws {
131134
func someFunction(_ x: Float) -> Float { 5 * cos(2 * x * x) / x }
132135
var lineGraph_func = LineGraph<Float,Float>(enablePrimaryAxisGrid: true)
@@ -141,6 +144,7 @@ extension LineChartTests {
141144
lineGraph_func.plotLabel.yLabel = "Y-AXIS"
142145
try renderAndVerify(lineGraph_func, size: Size(width: 400, height: 400))
143146
}
147+
*/
144148

145149
func testLineChart_crossBothAxes() throws {
146150
var lineGraph = LineGraph<Float,Float>(enablePrimaryAxisGrid: true,
@@ -159,4 +163,16 @@ extension LineChartTests {
159163

160164
try renderAndVerify(lineGraph, size: Size(width: 800, height: 400))
161165
}
166+
167+
func testLineChart_smallXRange() throws {
168+
// Verifies the fix from PR #131
169+
var lineGraph = LineGraph<Float, Float>()
170+
171+
lineGraph.addSeries([0, 0.1], [0, 4], label: "series")
172+
lineGraph.plotTitle.title = "Small x-range"
173+
lineGraph.plotLabel.xLabel = "x"
174+
lineGraph.plotLabel.yLabel = "y"
175+
176+
try renderAndVerify(lineGraph, size: Size(width: 800, height: 400))
177+
}
162178
}
Lines changed: 45 additions & 0 deletions

Tests/SwiftPlotTests/XCTestManifests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ extension LineChartTests {
7979
static let __allTests__LineChartTests = [
8080
("testLineChart_crossBothAxes", testLineChart_crossBothAxes),
8181
("testLineChart_crossX", testLineChart_crossX),
82-
("testLineChart_crossY", testLineChart_crossY),
8382
("testLineChart_negativeXOrigin_unsorted", testLineChart_negativeXOrigin_unsorted),
8483
("testLineChart_negativeXOrigin", testLineChart_negativeXOrigin),
8584
("testLineChart_negativeYOrigin", testLineChart_negativeYOrigin),
8685
("testLineChart_positiveXOrigin_secondary", testLineChart_positiveXOrigin_secondary),
8786
("testLineChart_positiveXOrigin", testLineChart_positiveXOrigin),
8887
("testLineChart_positiveYOrigin_secondary", testLineChart_positiveYOrigin_secondary),
8988
("testLineChart_positiveYOrigin", testLineChart_positiveYOrigin),
89+
("testLineChart_smallXRange", testLineChart_smallXRange),
9090
("testLineChartFunctionPlot", testLineChartFunctionPlot),
9191
("testLineChartMultipleSeries", testLineChartMultipleSeries),
9292
("testLineChartSecondaryAxis", testLineChartSecondaryAxis),

0 commit comments

Comments
 (0)