Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from JuliaPlots/sd/07
Browse files Browse the repository at this point in the history
fixes for 0.7
  • Loading branch information
SimonDanisch authored Aug 30, 2018
2 parents 85207a2 + 2529621 commit fd30412
Show file tree
Hide file tree
Showing 29 changed files with 211 additions and 191 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7

Reactive
StaticArrays
Expand Down
9 changes: 4 additions & 5 deletions src/AbstractPlotting.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__precompile__()
module AbstractPlotting

using Reactive, GeometryTypes, StaticArrays, ColorTypes, Colors, IntervalSets
Expand All @@ -8,15 +7,15 @@ using ColorBrewer
using Packing
using SignedDistanceFields
using FreeType, FreeTypeAbstraction, UnicodeFun
using LinearAlgebra, Statistics


using Base: RefValue
using Base.Iterators: repeated, drop
import Base: getindex, setindex!, push!, append!, parent, scale!, get, get!, delete!, haskey

import Base: getindex, setindex!, push!, append!, parent, get, get!, delete!, haskey

include("utilities/quaternions.jl")
include("types.jl")
include("utilities/compat.jl")
include("utilities/utilities.jl")
include("utilities/logging.jl")
include("utilities/texture_atlas.jl")
Expand Down Expand Up @@ -63,7 +62,7 @@ export AbstractScene, SceneLike, Scene, AbstractScreen
export AbstractPlot, Combined, Atomic, Axis

# Theming, working with Plots
export Attributes, Theme, attributes, arguments, default_theme, theme
export Attributes, Theme, attributes, default_theme, theme

# Node/Signal related
export Node, node, lift, map_once
Expand Down
40 changes: 21 additions & 19 deletions src/basic_recipes/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
grid_color = RGBAf0(0.5, 0.5, 0.5, 0.4)
darktext = RGB(0.4, 0.4, 0.4)
grid_thickness = 1
gridthickness = ntuple(x-> 1f0, 3)
gridthickness = ntuple(x-> 1f0, Val(3))
tsize = 5 # in percent
Theme(
showticks = (true, true, true),
Expand Down Expand Up @@ -142,7 +142,7 @@ default_ticks(limits::Tuple{Number, Number}, ticks, scale_func = identity) = def
function default_ticks(lmin::Number, lmax::Number, ticks::AbstractVector{<: Number}, scale_func = identity)
scale_func.((filter(t -> lmin <= t <= lmax, ticks)))
end
function default_ticks(lmin::Number, lmax::Number, ::Void, scale_func = identity)
function default_ticks(lmin::Number, lmax::Number, ::Nothing, scale_func = identity)
# scale the limits
scaled_ticks, mini, maxi = optimize_ticks(
scale_func(lmin),
Expand Down Expand Up @@ -209,7 +209,7 @@ function draw_ticks(
textcolor, textsize, rotation, align, font
)
for (tick, str) in ticks
pos = ntuple(i-> i != dim ? origin[i] : tick, Val{2})
pos = ntuple(i-> i != dim ? origin[i] : tick, Val(2))
push!(
textbuffer,
str, pos,
Expand All @@ -225,7 +225,7 @@ function draw_grid(
) where N
dirf0 = Pointf0{N}(dir)
for (tick, str) in ticks
tup = ntuple(i-> i != dim ? origin[i] : tick, Val{N})
tup = ntuple(i-> i != dim ? origin[i] : tick, Val(N))
posf0 = Pointf0{N}(tup)
append!(
linebuffer,
Expand Down Expand Up @@ -273,7 +273,7 @@ function draw_frame(
if !(from == origin && axis_position == :origin)
for otherside in 1:2
for dim in 1:N
p = ntuple(i-> i == dim ? limits[i][otherside] : limits[i][side], Val{N})
p = ntuple(i-> i == dim ? limits[i][otherside] : limits[i][side], Val(N))
to = Point{N, Float32}(p)
append!(
linebuffer, [from, to],
Expand Down Expand Up @@ -312,18 +312,20 @@ function draw_titles(
posy = (title_start[1], half_width[2])
positions = (posx, posy)
for i = 1:2
push!(
textbuffer, axis_labels[i], positions[i],
textsize = textsize[i], align = align[i], rotation = rotation[i],
color = textcolor[i], font = font[i]
)
if !isempty(axis_labels[i])
push!(
textbuffer, axis_labels[i], positions[i],
textsize = textsize[i], align = align[i], rotation = rotation[i],
color = textcolor[i], font = font[i]
)
end
end

end


function ticks_and_labels(x)
r = linspace(extrema(x)..., 5)
st, s = extrema(x)
r = range(st, stop=s, length=4)
zip(r, string.(round.(r, 4)))
end

Expand All @@ -334,7 +336,7 @@ end
un_transform(model::Mat4, x) = transform(inv(model), x)


to2tuple(x) = ntuple(i-> x, Val{2})
to2tuple(x) = ntuple(i-> x, Val(2))
to2tuple(x::Tuple{<:Any, <: Any}) = x

function draw_axis(
Expand Down Expand Up @@ -415,10 +417,10 @@ function plot!(scene::SceneLike, ::Type{<: Axis2D}, attributes::Attributes, args
)
ti_keys = (:axisnames, :textcolor, :textsize, :rotation, :align, :font)

g_args = getindex.(cplot[:grid], g_keys)
f_args = getindex.(cplot[:frame], f_keys)
t_args = getindex.(cplot[:ticks], t_keys)
ti_args = getindex.(cplot[:names], ti_keys)
g_args = getindex.(Ref(cplot[:grid]), g_keys)
f_args = getindex.(Ref(cplot[:frame]), f_keys)
t_args = getindex.(Ref(cplot[:ticks]), t_keys)
ti_args = getindex.(Ref(cplot[:names]), ti_keys)

textbuffer = TextBuffer(cplot, Point{2})
linebuffer = LinesegmentBuffer(cplot, Point{2})
Expand All @@ -441,7 +443,7 @@ function labelposition(ranges, dim, dir, tgap, origin::StaticVector{N}) where N
end


function GeometryTypes.widths(x::Range)
function GeometryTypes.widths(x::AbstractRange)
mini, maxi = Float32.(extrema(x))
maxi - mini
end
Expand All @@ -451,7 +453,7 @@ _widths(x::Tuple{<: Number, <: Number}) = x[2] - x[1]
_widths(x) = Float32(maximum(x) - minimum(x))

to3tuple(x::Tuple{Any, Any, Any}) = x
to3tuple(x) = ntuple(i-> x, Val{3})
to3tuple(x) = ntuple(i-> x, Val(3))

function draw_axis(textbuffer, linebuffer, limits, ranges, labels, args...)
# make sure we extend all args to 3D
Expand Down
19 changes: 10 additions & 9 deletions src/basic_recipes/basic_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ end


xvector(x::AbstractVector, len) = x
xvector(x::ClosedInterval, len) = linspace(minimum(x), maximum(x), len)
xvector(x::ClosedInterval, len) = range(minimum(x), stop=maximum(x), length=len)
xvector(x::AbstractMatrix, len) = x

yvector(x, len) = xvector(x, len)'
Expand Down Expand Up @@ -232,7 +232,7 @@ function plot!(sub::Series)
cmap = to_colormap(colors)
if size(A, 2) > length(cmap)
@info("Colormap doesn't have enough distinctive values. Please consider using another value for seriescolors")
cmap = interpolated_getindex.((cmap,), linspace(0, 1, M))
cmap = interpolated_getindex.((cmap,), range(0, stop=1, length=M))
end
cmap
end
Expand Down Expand Up @@ -275,7 +275,7 @@ function plot!(plot::Annotations)
sargs = (
plot[:model], plot[:font],
plot[1], position,
getindex.(plot, (:color, :textsize, :align, :rotation))...,
getindex.(Ref(plot), (:color, :textsize, :align, :rotation))...,
)
N = value(position) |> eltype |> length
tp = map(sargs...) do model, font, args...
Expand Down Expand Up @@ -312,7 +312,7 @@ function plot!(plot::Annotations)
t_attributes[:font] = map(x-> x[5], tp)
t_attributes[:rotation] = map(x-> x[6], tp)
t_attributes[:align] = Vec2f0(0)
t_attributes[:model] = eye(Mat4f0)
t_attributes[:model] = Mat4f0(I)
t_attributes[:raw] = true
text!(plot, t_attributes, map(x-> x[1], tp))
plot
Expand All @@ -333,19 +333,20 @@ function plot!(scene::SceneLike, subscene::AbstractPlot, attributes::Attributes)
center = true,
axis = Attributes(),
legend = Attributes(),
camera = :automatic,
limits = :automatic,
camera = automatic,
limits = automatic,
padding = Vec3f0(0.1),
raw = false
)
end
if plot_attributes[:raw][] == false
s_limits = limits(scene)
map_once(plot_attributes[:limits], plot_attributes[:padding]) do limit, padd
if limit == :automatic
if limit == automatic
@info("calculating limits")
@log_performance "calculating limits" begin
x = data_limits(scene)
# for when scene is empty
dlimits = if x == FRect3D(Vec3f0(0), Vec3f0(0))
data_limits(subscene)
else
Expand Down Expand Up @@ -391,7 +392,7 @@ function plot!(scene::SceneLike, subscene::AbstractPlot, attributes::Attributes)
# legend_attributes = plot_attributes[:legend][]
# colorlegend(scene, p.attributes[:colormap], p.attributes[:colorrange], legend_attributes)
# end
if plot_attributes[:camera][] == :automatic
if plot_attributes[:camera][] == automatic
cam = cameracontrols(scene)
if cam == EmptyCamera()
if is2d(scene)
Expand Down Expand Up @@ -419,7 +420,7 @@ end
function plot!(p::Arc)
args = getindex.(p, (:origin, :radius, :start_angle, :stop_angle, :resolution))
positions = lift(args...) do origin, radius, start_angle, stop_angle, resolution
map(linspace(start_angle, stop_angle, resolution)) do angle
map(range(start_angle, stop=stop_angle, length=resolution)) do angle
origin .+ (Point2f0(sin(angle), cos(angle)) .* radius)
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/camera/camera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function disconnect!(nodes::Vector)
empty!(nodes)
return
end

"""
When mapping over nodes for the camera, we store them in the steering_node vector,
to make it easier to disconnect the camera steering signals later!
"""

function Base.map(f, c::Camera, nodes::Node...)
node = map(f, nodes...)
push!(c.steering_nodes, node)
Expand All @@ -32,9 +32,9 @@ end

function Camera(px_area)
Camera(
Node(eye(Mat4f0)),
Node(eye(Mat4f0)),
Node(eye(Mat4f0)),
Node(Mat4f0(I)),
Node(Mat4f0(I)),
Node(Mat4f0(I)),
map(a-> Vec2f0(widths(a)), px_area),
Node(Vec3f0(1)),
Node[]
Expand Down
2 changes: 1 addition & 1 deletion src/camera/camera2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ end

struct PixelCamera <: AbstractCamera end
function campixel!(scene)
camera(scene).view[] = eye(Mat4f0)
camera(scene).view[] = Mat4f0(I)
map(camera(scene), pixelarea(scene)) do window_size
nearclip = -10_000f0
farclip = 10_000f0
Expand Down
8 changes: 4 additions & 4 deletions src/camera/camera3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ function cam3d!(scene; kw_args...)
camera
end

function projection_switch{T <: Real}(
function projection_switch(
wh::Rect2D,
fov::T, near::T, far::T,
projection::ProjectionEnum, zoom::T
)
) where T <: Real
aspect = T((/)(widths(wh)...))
h = T(tan(fov / 360.0 * pi) * near)
w = T(h * aspect)
Expand All @@ -60,10 +60,10 @@ function projection_switch{T <: Real}(
orthographicprojection(-w, w, -h, h, near, far)
end

function rotate_cam{T}(
function rotate_cam(
theta::Vec{3, T},
cam_right::Vec{3, T}, cam_up::Vec{3, T}, cam_dir::Vec{3, T}
)
) where T
rotation = Quaternion{T}(0, 0, 0, 1)
# first the rotation around up axis, since the other rotation should be relative to that rotation
if theta[1] != 0
Expand Down
4 changes: 2 additions & 2 deletions src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end
View frustum matrix (4x4).
"""
function frustum(left::T, right::T, bottom::T, top::T, znear::T, zfar::T) where T
(right == left || bottom == top || znear == zfar) && return eye(Mat{4,4,T})
(right == left || bottom == top || znear == zfar) && return Mat{4,4,T}(I)
T0, T1, T2 = zero(T), one(T), T(2)
return Mat{4}(
T2 * znear / (right - left), T0, T0, T0,
Expand Down Expand Up @@ -155,7 +155,7 @@ function orthographicprojection(
bottom::T, top ::T,
znear ::T, zfar ::T
) where T
(right==left || bottom==top || znear==zfar) && return eye(Mat{4,4,T})
(right==left || bottom==top || znear==zfar) && return Mat{4,4,T}(I)
T0, T1, T2 = zero(T), one(T), T(2)
Mat{4}(
T2/(right-left), T0, T0, T0,
Expand Down
Loading

0 comments on commit fd30412

Please sign in to comment.