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 { |
| 127 | let ymin = try number("ymin"), ymax = try number("ymax") |
127 | let ymin = try number("ymin"), ymax = try number("ymax") |
| 128 | let ticks: Int |
128 | let ticks: Int |
| 129 | if let given = try number("ticks") { |
129 | if let given = try number("ticks") { |
| 130 | // gnuplot can't draw fewer than none, and the web has a ring for each. |
130 | // gnuplot can't draw fewer than none. |
| 131 | guard given >= 0, given <= 1000 else { throw Failure(description: "ticks: must be from 0 to 1000") } |
131 | guard given >= 0, given < 0x1p63 else { throw Failure(description: "ticks: is out of range") } |
| 132 | ticks = Int(given) |
132 | ticks = Int(given) |
| 133 | } else if let sensible = sensibleTicks(rows, hardMin: ymin, hardMax: ymax) { |
133 | } else if let sensible = sensibleTicks(rows, hardMin: ymin, hardMax: ymax) { |
| 134 | ticks = sensible |
134 | ticks = sensible |
| 135 | } else { |
135 | } else { |
| 136 | throw Failure(description: "Org can't choose this radar plot's ticks; give ticks:") |
136 | throw Failure(description: "Org can't choose this radar plot's ticks; give ticks:") |
| 137 | } |
137 | } |
| 138 | let axes = rows.map { row -> Radar.Axis in |
138 | let axes = try rows.map { row -> Radar.Axis in |
| 139 | let nums = row.dropFirst().map(lispNumber) |
139 | let nums = row.dropFirst().map(lispNumber) |
| 140 | let s = stats(nums) |
140 | 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 | } |
| 141 | return Radar.Axis(label: row[0], fields: Array(row.dropFirst()), values: nums.map(\.value), |
145 | return Radar.Axis(label: row[0], fields: Array(row.dropFirst()), values: nums.map(\.value), |
| 142 | low: ymin ?? s.niceMin.value, high: ymax ?? s.niceMax.value, |
146 | low: ymin ?? s.niceMin.value, high: ymax ?? s.niceMax.value, |
| 143 | lowText: plot.options["ymin"]?.description ?? (s.niceMin.integer ? integerText(row[1]) : printed(s.niceMin)), |
147 | 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 { |
| 214 | #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ymax:0\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) } |
214 | #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ymax:0\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) } |
| 215 | #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ticks:-1\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) } |
215 | #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ticks:-1\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) } |
| 216 | #expect(throws: TablePlot.Failure.self) { try TablePlot.plot("#+PLOT: type:radar ticks:99999999999999999999\n| x | 1 | 5 |\n| y | 2 | 3 |\n", at: 0) } |
216 | #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 | } |
| 217 | // Emacs prints a bignum as it is. |
224 | // Emacs prints a bignum as it is. |
| 218 | let big = try TablePlot.radarSetup(TablePlot.plot("#+PLOT: type:radar ticks:3\n| x | 100000000000000000000 | 100000000000000000000 |\n| y | -007 | -007 |\n", at: 0)) |
225 | let big = try TablePlot.radarSetup(TablePlot.plot("#+PLOT: type:radar ticks:3\n| x | 100000000000000000000 | 100000000000000000000 |\n| y | -007 | -007 |\n", at: 0)) |
| 219 | #expect(big.contains("\"x\" 100000000000000000000 100000000000000000000 3\n\"y\" -7 -7 3\n"), "\(big)") |
226 | #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 |
| 796 | highest values rounded outward (120 to 340 becomes 100 to 400), or from =ymin= to =ymax=. Org |
796 | highest values rounded outward (120 to 340 becomes 100 to 400), or from =ymin= to =ymax=. Org |
| 797 | works out the number of rings from the values; where Org can't (it signals an error, as for a |
797 | works out the number of rings from the values; where Org can't (it signals an error, as for a |
| 798 | =ymin= above a row's values, or never finishes, as for a row whose values are all the same), |
798 | =ymin= above a row's values, or never finishes, as for a row whose values are all the same), |
| 799 | orgstar reports it and asks for =ticks:=. =ticks:= takes 0 to 1000. |
799 | orgstar reports it and asks for =ticks:=. =ticks:= can't be below 0, and without gnuplot it |
| |
800 | takes at most 1000. A row whose values or their range overflow a double is refused, as Emacs signals an |
| |
801 | error for it. |
| 800 | |
802 | |
| 801 | On the Mac, when gnuplot is installed (orgstar looks on the same =PATH= as code blocks), the |
803 | On the Mac, when gnuplot is installed (orgstar looks on the same =PATH= as code blocks), the |
| 802 | table goes to gnuplot as Emacs sends it: the same data file and script, so every option and |
804 | table goes to gnuplot as Emacs sends it: the same data file and script, so every option and |