Skip to content

Commit 82bf118

Browse files
authored
Merge pull request #717 from axch/plot-patch
Add padding to plots so plots of constants functions are not degenerate.
2 parents 7ba3501 + 1f12794 commit 82bf118

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/plot.dx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ blankPlot : Plot n Unit Unit Unit = { xs = blankData
8787

8888
-- -- TODO: generalize beyond Float with a type class for auto scaling
8989
def autoScale (xs:n=>Float) : ScaledData n Float =
90-
{scale = floatScale (minimum xs) (maximum xs), dat = xs}
90+
max = maximum xs
91+
min = minimum xs
92+
-- Add 10% padding away from the plot area
93+
space = (max - min) * 0.05
94+
padding = maximum [space, max * 0.001, 0.000001]
95+
{scale = floatScale (min - padding) (max + padding), dat = xs}
9196

9297
def setXData (xs:ScaledData n new) (plot:Plot n a b c) : Plot n new b c=
9398
-- We can't use `setAt` here because we're changing the type

0 commit comments

Comments
 (0)