Skip to content

Commit

Permalink
Add invert and gridlines options. Closes #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunetos committed May 26, 2014
1 parent e57ed23 commit 7f57fff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ end
function plot(data::PlotInputs, start::Real=-10, stop::Real=10;
border::Bool=true, labels::Bool=true, title::Bool=true,
cols::Int=60, rows::Int=16, margin::Int=9,
invert::Bool=false, gridlines::Bool=false,
scalefunc::Function=identity)
grid = fill(char(0x2800), cols, rows)

grid = fill(char(gridlines ? 0x2812 : 0x2800), cols, rows)
left, right = sides = ((0, 1, 2, 6), (3, 4, 5, 7))
function showdot(x, y) # Assumes x & y are already scaled to the grid.
invy = (rows - y)*0.9999
Expand Down Expand Up @@ -102,6 +104,8 @@ function plot(data::PlotInputs, start::Real=-10, stop::Real=10;
end
end

invert && (grid = map(c -> char(c $ 0xFF), grid))

lines = String[]
padding = labels ? repeat(" ", margin) : ""
prefix, suffix = border ? (padding * "", "") : (padding * "", "")
Expand Down
6 changes: 6 additions & 0 deletions test/plot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO: Make tests that vary the parameters and validate the output.


plot(exp, 0, 30)
plot(sinpi, -2, 2)
plot(rand(15))
Expand All @@ -22,3 +23,8 @@ plot(exp, 0.1:20)
logplot(exp, 0.1:20)
plot(x -> exp(-x/5), 0.01:20)
logplot(x -> exp(-x/5), 0.01:20)

plot(sinpi, -2, 2, invert=false, gridlines=false)
plot(sinpi, -2, 2, invert=true, gridlines=false)
plot(sinpi, -2, 2, invert=false, gridlines=true)
plot(sinpi, -2, 2, invert=true, gridlines=true)

0 comments on commit 7f57fff

Please sign in to comment.