Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
language: cpp
compiler:
- gcc
language: julia
os:
- linux
- osx
julia:
- release
- nightly
notifications:
email: false
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/julianightlies -y
- sudo apt-get update -qq -y
- sudo apt-get install git libpcre3-dev julia -y
- git config --global user.name "Travis User"
- git config --global user.email "[email protected]"
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
email: false
script:
- julia --code-coverage ./test/runtests.jl
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("$pkg"); Pkg.test("$pkg"; coverage=true)
after_success:
- julia -e 'cd(Pkg.dir("TextPlots")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- if [[ $JULIAVERSION = "juliareleases" && `uname` = "Linux" ]]; then julia -e 'cd(Pkg.dir("TextPlots")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; fi
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.3-
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the - is no longer necessary, that's for prereleases of 0.3

Compat
22 changes: 13 additions & 9 deletions src/plot.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Compat

# Currently Julia gives false for isa([1,2,3], Vector{Real}), so doing manually.
typealias RealVector Union(Vector{Int}, Vector{Float64})
typealias RealMatrix Union(Matrix{Int}, Matrix{Float64})
typealias PlotInputs Union(Vector{Function}, (RealVector, RealMatrix))
typealias PlotInputs Union(Vector{Function}, @compat Tuple{RealVector, RealMatrix})

SUPER = utf16("\u2070\u00b9\u00b2\u00b3\u2074\u2075\u2076\u2077\u2078\u2079")

# Find magnitude of difference between 2 nums, as digits before/after decimal.
function magnitude(num1::Real, num2::Real)
-iround(log10(abs(num2 - num1)))
-round(Integer,log10(abs(num2 - num1)))
end

# See if this float happens to match common uses of constants like n*pi.
Expand All @@ -16,9 +18,9 @@ function findsymbolic(num::Real)

# Format strings for minus sign, superscript, multiples, and exponents.
dash(x, super=false) = x >= 0 ? "" : super ? "⁻" : "-"
sup(x) = dash(x, true) * join([SUPER[d + 1] for d in reverse(digits(iround(abs(x))))])
multiple(x) = iround(x) == 0 ? "0" : iround(x) == 1 ? "" : "$(iround(x))"
topower(n, x) = iround(x) == 0 ? "1" : iround(x) == 1 ? n : "$n$(sup(x))"
sup(x) = dash(x, true) * join([SUPER[d + 1] for d in reverse(digits(round(Integer,abs(x))))])
multiple(x) = round(Integer,x) == 0 ? "0" : round(Integer,x) == 1 ? "" : "$(round(Integer,x))"
topower(n, x) = round(Integer,x) == 0 ? "1" : round(Integer,x) == 1 ? n : "$n$(sup(x))"

# Split number between the absolute value and the minus sign, if any
anum, sgn = abs(num), dash(num)
Expand Down Expand Up @@ -87,14 +89,16 @@ function plot(data::PlotInputs, start::Real=-10, stop::Real=10;

# The unicode braille chars are conveniently structured to support bitwise
# manipulation, so we can just OR specific bits to set that dot to filled.
grid = fill(char(gridlines ? 0x2812 : 0x2800), cols, rows)
grid = fill((@compat 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
col, col2 = ifloor(x), ifloor(x*2)
row, row4 = ifloor(invy), ifloor(invy*4)
col, col2 = floor(Integer,x), floor(Integer,x*2)
row, row4 = floor(Integer,invy), floor(Integer,invy*4)
# This does the bitwise OR to fill in a single dot out of the 8.
grid[col + 1, row + 1] |= 1 << sides[1 + (col2 & 1)][1 + (row4 & 3)]
grid[col + 1, row + 1] = @compat Char(
(@compat Int(grid[col + 1, row + 1])) |
(1 << sides[1 + (col2 & 1)][1 + (row4 & 3)]))
end

# If input is a function, sample it at each row & col to fill xvals & yvals.
Expand Down