Commit fb82a26f74

fb82a26f74911aa752fba2a1748bc85f3e1fd0a2

parent: 8331782f4d

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-21 10:14 UTC

Refuse radar rows that overflow a double, and leave ticks: above 1000 to gnuplot

Layout: unified · split

Sources/OrgCore/Compute/TablePlotRadar.swift +7 −3
@@ -127,17 +127,21 @@ extension TablePlot {
127127 let ymin = try number("ymin"), ymax = try number("ymax")
128128 let ticks: Int
129129 if let given = try number("ticks") {
130 // gnuplot can't draw fewer than none, and the web has a ring for each.
131 guard given >= 0, given <= 1000 else { throw Failure(description: "ticks: must be from 0 to 1000") }
130 // gnuplot can't draw fewer than none.
131 guard given >= 0, given < 0x1p63 else { throw Failure(description: "ticks: is out of range") }
132132 ticks = Int(given)
133133 } else if let sensible = sensibleTicks(rows, hardMin: ymin, hardMax: ymax) {
134134 ticks = sensible
135135 } else {
136136 throw Failure(description: "Org can't choose this radar plot's ticks; give ticks:")
137137 }
138 let axes = rows.map { row -> Radar.Axis in
138 let axes = try rows.map { row -> Radar.Axis in
139139 let nums = row.dropFirst().map(lispNumber)
140140 let s = stats(nums)
141 // Emacs scales every row, given ticks: or not; past a double, `ceiling` signals overflow-error.
142 guard s.factor.isFinite, s.niceMin.value.isFinite, s.niceMax.value.isFinite else {
143 throw Failure(description: "Org can't scale the radar row \"\(row[0])\"")
144 }
141145 return Radar.Axis(label: row[0], fields: Array(row.dropFirst()), values: nums.map(\.value),
142146 low: ymin ?? s.niceMin.value, high: ymax ?? s.niceMax.value,
143147 lowText: plot.options["ymin"]?.description ?? (s.niceMin.integer ? integerText(row[1]) : printed(s.niceMin)),
Tests/OrgCoreTests/TablePlotTests.swift +7
@@ -214,6 +214,13 @@ struct TablePlotTests {
214214 #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ymax:0\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) }
215215 #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ticks:-1\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) }
216216 #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ticks:99999999999999999999\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) }
217 // gnuplot draws as many rings as it's given.
218 _ = try TablePlot.plot("#+PLOT: type:radar ticks:2000\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0)
219 // Emacs scales every row with or without ticks:, and signals overflow-error past a double.
220 for row in ["| x | 1e400 | 5 |", "| x | 1e400 | 1e400 |", "| x | -1e400 | 5 |", "| x | 1e308 | -1e308 |"] {
221 #expect(throws: TablePlot.Failure.self, "\(row)") { try TablePlot.plot("#+PLOT: type:radar ticks:3\n\(row)\n| y | 2 | 3 |\n", at: 0) }
222 #expect(throws: TablePlot.Failure.self, "\(row)") { try TablePlot.plot("#+PLOT: type:radar ticks:3 ymin:0 ymax:10\n\(row)\n| y | 2 | 3 |\n", at: 0) }
223 }
217224 // Emacs prints a bignum as it is.
218225 let big = try TablePlot.radarSetup(TablePlot.plot("#+PLOT: type:radar ticks:3\n| x | 100000000000000000000 | 100000000000000000000 |\n| y | -007 | -007 |\n", at: 0))
219226 #expect(big.contains("\"x\" 100000000000000000000 100000000000000000000 3\n\"y\" -7 -7 3\n"), "\(big)")
docs/manual/guide/10-tables.org +3 −1
@@ -796,7 +796,9 @@ the first as a series named by the header. Each axis is scaled from its row's lo
796796highest values rounded outward (120 to 340 becomes 100 to 400), or from =ymin= to =ymax=. Org
797797works out the number of rings from the values; where Org can't (it signals an error, as for a
798798=ymin= above a row's values, or never finishes, as for a row whose values are all the same),
799orgstar reports it and asks for =ticks:=. =ticks:= takes 0 to 1000.
799orgstar reports it and asks for =ticks:=. =ticks:= can't be below 0, and without gnuplot it
800takes at most 1000. A row whose values or their range overflow a double is refused, as Emacs signals an
801error for it.
800802
801803On the Mac, when gnuplot is installed (orgstar looks on the same =PATH= as code blocks), the
802804table goes to gnuplot as Emacs sends it: the same data file and script, so every option and