From 625c92a9856103fb3b8aef661e6ebc148d1b30ba Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Sat, 28 May 2016 11:17:34 -0400 Subject: [PATCH] working on 0.5 changes --- src/backends/plotly.jl | 20 ++++----- src/backends/plotlyjs.jl | 6 +-- src/backends/unicodeplots.jl | 3 +- src/backends/web.jl | 12 ++++-- src/components.jl | 2 +- src/layouts.jl | 28 ++++++------ src/recipes.jl | 84 ++++++++++++++++++------------------ 7 files changed, 81 insertions(+), 74 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index cc1c8334..8687e642 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -54,7 +54,7 @@ function _initialize_backend(::PlotlyBackend; kw...) JSON._print(io::IO, state::JSON.State, dt::Union{Date,DateTime}) = print(io, '"', dt, '"') _js_path = Pkg.dir("Plots", "deps", "plotly-latest.min.js") - _js_code = open(readall, _js_path, "r") + _js_code = open(@compat(readstring), _js_path, "r") # borrowed from https://github.com/plotly/plotly.py/blob/2594076e29584ede2d09f2aa40a8a195b3f3fc66/plotly/offline/offline.py#L64-L71 c/o @spencerlyon2 _js_script = """ @@ -222,15 +222,15 @@ function plotly_domain(sp::Subplot, letter) [pcts[i1], pcts[i1]+pcts[i2]] end -# TODO: this should actually take into account labels, font sizes, etc -# sets (left, top, right, bottom) -function plotly_minpad(sp::Subplot) - (12mm, 2mm, 2mm, 8mm) -end - -function _update_min_padding!(sp::Subplot{PlotlyBackend}) - sp.minpad = plotly_minpad(sp) -end +# # TODO: this should actually take into account labels, font sizes, etc +# # sets (left, top, right, bottom) +# function plotly_minpad(sp::Subplot) +# (12mm, 2mm, 2mm, 8mm) +# end +# +# function _update_min_padding!(sp::Subplot{PlotlyBackend}) +# sp.minpad = plotly_minpad(sp) +# end # tickssym(letter) = Symbol(letter * "ticks") # limssym(letter) = Symbol(letter * "lims") diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 1c5c65c3..92bad079 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -166,9 +166,9 @@ end # ---------------------------------------------------------------- -function _update_min_padding!(sp::Subplot{PlotlyBackend}) - sp.minpad = plotly_minpad(sp) -end +# function _update_min_padding!(sp::Subplot{PlotlyBackend}) +# sp.minpad = plotly_minpad(sp) +# end # function plotlyjs_finalize(plt::Plot) # plotly_finalize(plt) diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 9131ed03..573c0fb8 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -287,7 +287,8 @@ function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString) println("\n\n\n\n\n\n") gui(plt) - @osx_only begin + # @osx_only begin + @compat @static if is_apple() # BEGIN HACK # wait while the plot gets drawn diff --git a/src/backends/web.jl b/src/backends/web.jl index 2920ba68..4681316b 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -20,9 +20,15 @@ function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr end function open_browser_window(filename::AbstractString) - @osx_only return run(`open $(filename)`) - @linux_only return run(`xdg-open $(filename)`) - @windows_only return run(`$(ENV["COMSPEC"]) /c start $(filename)`) + @compat @static if is_apple() + return run(`open $(filename)`) + end + @compat @static if is_linux() + return run(`xdg-open $(filename)`) + end + @compat @static if is_windows() + return run(`$(ENV["COMSPEC"]) /c start $(filename)`) + end warn("Unknown OS... cannot open browser window.") end diff --git a/src/components.jl b/src/components.jl index 358bc1cd..f6d21a3a 100644 --- a/src/components.jl +++ b/src/components.jl @@ -436,7 +436,7 @@ type BezierCurve{T <: FixedSizeArrays.Vec} control_points::Vector{T} end -function Base.call(bc::BezierCurve, t::Real) +@compat function (bc::BezierCurve)(t::Real) p = zero(P2) n = length(bc.control_points)-1 for i in 0:n diff --git a/src/layouts.jl b/src/layouts.jl index b2116b62..79b25698 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -7,10 +7,10 @@ const pct = Length{:pct, Float64}(1.0) const _cbar_width = 5mm -Base.(:.*)(m::Measure, n::Number) = m * n -Base.(:.*)(n::Number, m::Measure) = m * n -Base.(:-)(m::Measure, a::AbstractArray) = map(ai -> m - ai, a) -Base.(:-)(a::AbstractArray, m::Measure) = map(ai -> ai - m, a) +@compat Base.:.*(m::Measure, n::Number) = m * n +@compat Base.:.*(n::Number, m::Measure) = m * n +@compat Base.:-(m::Measure, a::AbstractArray) = map(ai -> m - ai, a) +@compat Base.:-(a::AbstractArray, m::Measure) = map(ai -> ai - m, a) Base.zero(::Type{typeof(mm)}) = 0mm Base.one(::Type{typeof(mm)}) = 1mm Base.typemin(::typeof(mm)) = -Inf*mm @@ -18,15 +18,15 @@ Base.typemax(::typeof(mm)) = Inf*mm Base.convert{F<:AbstractFloat}(::Type{F}, l::AbsoluteLength) = convert(F, l.value) # TODO: these are unintuitive and may cause tricky bugs -# Base.(:+)(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 + m2.value)) -# Base.(:+)(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * (1 + m1.value)) -# Base.(:-)(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 - m2.value)) -# Base.(:-)(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * (m1.value - 1)) +# @compat Base.:+(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 + m2.value)) +# @compat Base.:+(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * (1 + m1.value)) +# @compat Base.:-(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 - m2.value)) +# @compat Base.:-(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * (m1.value - 1)) -Base.(:*)(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * m2.value) -Base.(:*)(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * m1.value) -Base.(:/)(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value / m2.value) -Base.(:/)(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value / m1.value) +@compat Base.:*(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * m2.value) +@compat Base.:*(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * m1.value) +@compat Base.:/(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value / m2.value) +@compat Base.:/(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value / m1.value) Base.zero(::Type{typeof(pct)}) = 0pct @@ -42,11 +42,11 @@ right(bbox::BoundingBox) = left(bbox) + width(bbox) bottom(bbox::BoundingBox) = top(bbox) + height(bbox) Base.size(bbox::BoundingBox) = (width(bbox), height(bbox)) -# Base.(:*){T,N}(m1::Length{T,N}, m2::Length{T,N}) = Length{T,N}(m1.value * m2.value) +# @compat Base.:*{T,N}(m1::Length{T,N}, m2::Length{T,N}) = Length{T,N}(m1.value * m2.value) ispositive(m::Measure) = m.value > 0 # union together bounding boxes -function Base.(:+)(bb1::BoundingBox, bb2::BoundingBox) +@compat function Base.:+(bb1::BoundingBox, bb2::BoundingBox) # empty boxes don't change the union ispositive(width(bb1)) || return bb2 ispositive(height(bb1)) || return bb2 diff --git a/src/recipes.jl b/src/recipes.jl index 7b002e59..2858372b 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -675,48 +675,48 @@ end # --------------------------------------------------------------------------- # --------------------------------------------------------------------------- -function rotate(x::Real, y::Real, θ::Real; center = (0,0)) - cx = x - center[1] - cy = y - center[2] - xrot = cx * cos(θ) - cy * sin(θ) - yrot = cy * cos(θ) + cx * sin(θ) - xrot + center[1], yrot + center[2] -end - -# --------------------------------------------------------------------------- - -type EllipseRecipe <: PlotRecipe - w::Float64 - h::Float64 - x::Float64 - y::Float64 - θ::Float64 -end -EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0) - -# return x,y coords of a rotated ellipse, centered at the origin -function rotatedEllipse(w, h, x, y, θ, rotθ) - # # coord before rotation - xpre = w * cos(θ) - ypre = h * sin(θ) - - # rotate and translate - r = rotate(xpre, ypre, rotθ) - x + r[1], y + r[2] -end - -function getRecipeXY(ep::EllipseRecipe) - x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)]) - top = rotate(0, ep.h, ep.θ) - right = rotate(ep.w, 0, ep.θ) - linex = Float64[top[1], 0, right[1]] + ep.x - liney = Float64[top[2], 0, right[2]] + ep.y - Any[x, linex], Any[y, liney] -end - -function getRecipeArgs(ep::EllipseRecipe) - [(:line, (3, [:dot :solid], [:red :blue], :path))] -end +# function rotate(x::Real, y::Real, θ::Real; center = (0,0)) +# cx = x - center[1] +# cy = y - center[2] +# xrot = cx * cos(θ) - cy * sin(θ) +# yrot = cy * cos(θ) + cx * sin(θ) +# xrot + center[1], yrot + center[2] +# end +# +# # --------------------------------------------------------------------------- +# +# type EllipseRecipe <: PlotRecipe +# w::Float64 +# h::Float64 +# x::Float64 +# y::Float64 +# θ::Float64 +# end +# EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0) +# +# # return x,y coords of a rotated ellipse, centered at the origin +# function rotatedEllipse(w, h, x, y, θ, rotθ) +# # # coord before rotation +# xpre = w * cos(θ) +# ypre = h * sin(θ) +# +# # rotate and translate +# r = rotate(xpre, ypre, rotθ) +# x + r[1], y + r[2] +# end +# +# function getRecipeXY(ep::EllipseRecipe) +# x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)]) +# top = rotate(0, ep.h, ep.θ) +# right = rotate(ep.w, 0, ep.θ) +# linex = Float64[top[1], 0, right[1]] + ep.x +# liney = Float64[top[2], 0, right[2]] + ep.y +# Any[x, linex], Any[y, liney] +# end +# +# function getRecipeArgs(ep::EllipseRecipe) +# [(:line, (3, [:dot :solid], [:red :blue], :path))] +# end # -------------------------------------------------