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

Commit

Permalink
Merge branch 'sd/merge'
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed May 3, 2020
2 parents adf1601 + cab5672 commit 59e87e8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/basic_recipes/basic_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
end

function data_limits(x::Contour{<: Tuple{X, Y, Z}}) where {X, Y, Z}
xyz_boundingbox(transform_func(x), to_value.((x[1], x[2]))...)
return xyz_boundingbox(transform_func(x), to_value.((x[1], x[2]))...)
end

"""
Expand Down
6 changes: 6 additions & 0 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ float32type(::Type{<: Colorant}) = RGBA{Float32}
float32type(x::AbstractArray{T}) where T = float32type(T)
float32type(x::T) where T = float32type(T)
el32convert(x::AbstractArray) = elconvert(float32type(x), x)
el32convert(x::Observable) = lift(el32convert, x)
el32convert(x) = convert(float32type(x), x)

function el32convert(x::AbstractArray{T, N}) where {T<:Union{Missing, <: Number}, N}
Expand Down Expand Up @@ -551,6 +552,11 @@ end
# Attribute conversions #
################################################################################

convert_attribute(p, ::key"highclip") = to_color(p)
convert_attribute(p::Nothing, ::key"highclip") = p
convert_attribute(p, ::key"lowclip") = to_color(p)
convert_attribute(p::Nothing, ::key"lowclip") = p
convert_attribute(p, ::key"nan_color") = to_color(p)

struct Palette{N}
colors::SArray{Tuple{N},RGBA{Float32},1,N}
Expand Down
6 changes: 5 additions & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ $(ATTRIBUTES)
colormap = [:black, :white],
interpolate = true,
fxaa = false,
lowclip = nothing,
highclip = nothing,
)
end

Expand Down Expand Up @@ -120,8 +122,9 @@ $(ATTRIBUTES)
color = nothing,
colormap = :viridis,
shading = true,
interpolate = true,
fxaa = true,
lowclip = nothing,
highclip = nothing,
)
end

Expand Down Expand Up @@ -292,6 +295,7 @@ function calculated_attributes!(::Type{<: Union{Heatmap, Image}}, plot)
plot[:color] = plot[3]
color_and_colormap!(plot)
end

function calculated_attributes!(::Type{<: Surface}, plot)
colors = plot[3]
if haskey(plot, :color)
Expand Down
87 changes: 49 additions & 38 deletions test/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@ using AbstractPlotting
using GLMakie
using GeometryBasics
using Observables
using FileIO
using GeometryBasics: Pyramid
using PlotUtils
using MeshIO, FileIO

## Some helpers
data_2d = AbstractPlotting.peaks()
args_2d = (-10..10, -10..10, data_2d)

function n_times(f, n=10, interval=0.05)
obs = Observable(f(1))
@async for i in 2:n
try
obs[] = f(i)
sleep(interval)
catch e
@warn "Error!" exception=CapturedException(e, Base.catch_backtrace())
end
end
return obs
end

## Scatter
scatter(1:4, color=:red)
scatter(1:4, marker='')
scatter(1:4, marker=['', '', '', ''])
Expand All @@ -14,7 +32,7 @@ scatter(1:4, marker=rand(RGBf0, 10, 10), markersize=20px) |> display
# TODO rotation with markersize=px
scatter(1:4, marker='', markersize=0.3, rotations=LinRange(0, pi, 4)) |> display

# Meshscatter
## Meshscatter
meshscatter(1:4, color=1:4) |> display

meshscatter(1:4, color=rand(RGBAf0, 4))
Expand All @@ -23,37 +41,37 @@ meshscatter(1:4, color=:red)
meshscatter(rand(Point3f0, 10), color=rand(RGBf0, 10))
meshscatter(rand(Point3f0, 10), marker=Pyramid(Point3f0(0), 1f0, 1f0)) |> display

# Lines
## Lines
positions = Point2f0.([1:4; NaN; 1:4], [1:4; NaN; 2:5])
lines(positions)
lines(positions, linestyle=:dot)
lines(positions, linestyle=[0.0, 1.0, 2.0, 3.0, 4.0])
lines(positions, color=1:9)
lines(positions, color=rand(RGBf0, 9), linewidth=4)

# Linesegments
## Linesegments
linesegments(1:4)
linesegments(1:4, linestyle=:dot)
linesegments(1:4, linestyle=[0.0, 1.0, 2.0, 3.0, 4.0])
linesegments(1:4, color=1:4)
linesegments(1:4, color=rand(RGBf0, 4), linewidth=4)


# Surface
data = AbstractPlotting.peaks()
surface(-10..10, -10..10, data)
surface(-10..10, -10..10, data, color=rand(size(data)...)) |> display
surface(-10..10, -10..10, data, color=rand(RGBf0, size(data)...))
surface(-10..10, -10..10, data, colormap=:magma, colorrange=(0.0, 2.0))
## Surface
surface(args_2d...)
surface(args_2d..., color=rand(size(data_2d)...))
surface(args_2d..., color=rand(RGBf0, size(data_2d)...))
surface(args_2d..., colormap=:magma, colorrange=(-3.0, 4.0))
surface(args_2d..., shading=false); wireframe!(args_2d..., linewidth=0.5)

# Polygons
## Polygons
poly(decompose(Point2f0, Circle(Point2f0(0), 1f0)))

# Image like!
## Image like!
image(rand(10, 10))
heatmap(rand(10, 10))

# Volumes
## Volumes
volume(rand(4, 4, 4), isovalue=0.5, isorange=0.01, algorithm=:iso) |> display
volume(rand(4, 4, 4), algorithm=:mip)
volume(rand(4, 4, 4), algorithm=:absorption)
Expand All @@ -62,8 +80,7 @@ volume(rand(4, 4, 4), algorithm=Int32(5)) |> display
volume(rand(RGBAf0, 4, 4, 4), algorithm=:absorptionrgba)
contour(rand(4, 4, 4)) |> display

# Meshes
using MeshIO, FileIO
## Meshes
cat = load(GLMakie.assetpath("cat.obj"))
tex = load(GLMakie.assetpath("diffusemap.tga"));
scren = mesh(cat, color=tex)
Expand All @@ -74,37 +91,28 @@ m = mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue],
meshes = GeometryBasics.normal_mesh.([Sphere(Point3f0(0.5), 1), Rect(Vec3f0(1, 0, 0), Vec3f0(1))])
mesh(meshes, color=[1, 2])

# Axis
## Axis
scene = lines(IRect(Vec2f0(0), Vec2f0(1)))
axis = scene[Axis]
axis.ticks.ranges = ([0.1, 0.2, 0.9], [0.1, 0.2, 0.9])
axis.ticks.labels = (["😸", "", "𝕴"], ["β ÷ δ", "22", ""])
scene


# Text
## Text
x = text("heyllo") |> display


# Gradients
data = ((x, y) -> x^2 + y^2).(1:100, (1:100)')
heatmap(data; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true)
extrema(data)
heatmap(data; interpolate=true, colorrange=(-6.0, 7.0), highclip=:black, lowclip=:pink)
## Colormaps
cmap = cgrad(:RdYlBu; categorical=true);
heatmap(args_2d...; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true)

# Animations
function n_times(f, n=10, interval=0.05)
obs = Observable(f(1))
@async for i in 2:n
try
obs[] = f(i)
sleep(interval)
catch e
@warn "Error!" exception=CapturedException(e, Base.catch_backtrace())
end
end
return obs
end
image(args_2d...; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true)

s = heatmap(args_2d...; colorrange=(-4.0, 3.0), colormap=cmap, highclip=:green, lowclip=:pink, interpolate=true)
surface(args_2d...; colorrange=(-4.0, 3.0), highclip=:green, lowclip=:pink)

## Animations

annotations(n_times(i-> map(j-> ("$j", Point2f0(j*30, 0)), 1:i)), textsize=20, limits=FRect2D(30, 0, 320, 50))
scatter(n_times(i-> Point2f0.((1:i).*30, 0)), limits=FRect2D(30, 0, 320, 50), markersize=20px)
Expand Down Expand Up @@ -136,8 +144,7 @@ lp = map(radius, theta, phi) do r, theta, phi
end

scene = Scene()
contour!(scene, 0..1, 0..1, 0..1, rand(10, 10, 10), levels = 2;
ambient = la, diffuse = ld, specular = ls, shininess = shininess,lightposition = lp)
surface!(scene, args_2d...; ambient = la, diffuse = ld, specular = ls, shininess = shininess,lightposition = lp)
scatter!(scene, map(v -> [v], lp), color=:yellow, markersize=0.2f0)

vbox(hbox(s4, s3, s2, s1, s7, s6, s5), scene) |> display
Expand All @@ -150,8 +157,12 @@ lines!(1:4, color=rand(RGBf0, 4)) |> display


# Views

x = Point2f0[(1, 1), (2, 2), (3, 2), (4, 4)]
points = connect(x, LineFace{Int}[(1, 2), (2, 3), (3, 4)])
linesegments(points)
scatter(x)
p4 = heatmap(rand(100, 100))

# Interpolation
heatmap(data_2d, interpolate=true)
image(data_2d, interpolate=false)

0 comments on commit 59e87e8

Please sign in to comment.