Skip to content

Commit

Permalink
runic -i src/
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Nov 4, 2024
1 parent 743a443 commit 2c3d6db
Show file tree
Hide file tree
Showing 132 changed files with 5,960 additions and 4,947 deletions.
24 changes: 12 additions & 12 deletions src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ using MakieCore: Pixel, px, Unit, Billboard
using MakieCore: NoShading, FastShading, MultiLightShading
using MakieCore: not_implemented_for
import MakieCore: plot, plot!, theme, plotfunc, plottype, merge_attributes!, calculated_attributes!,
get_attribute, plotsym, plotkey, attributes, used_attributes
get_attribute, plotsym, plotkey, attributes, used_attributes
import MakieCore: create_axis_like, create_axis_like!, figurelike_return, figurelike_return!
import MakieCore: arrows, heatmap, image, lines, linesegments, mesh, meshscatter, poly, scatter, surface, text, volume, voxels
import MakieCore: arrows!, heatmap!, image!, lines!, linesegments!, mesh!, meshscatter!, poly!, scatter!, surface!, text!, volume!, voxels!
Expand Down Expand Up @@ -287,7 +287,7 @@ export mouseover, onpick, pick, Events, Keyboard, Mouse, is_mouseinside
export ispressed, Exclusively
export connect_screen
export window_area, window_open, mouse_buttons, mouse_position, mouseposition_px,
scroll, keyboard_buttons, unicode_input, dropped_files, hasfocus, entered_window
scroll, keyboard_buttons, unicode_input, dropped_files, hasfocus, entered_window
export disconnect!
export DataInspector
export Consume
Expand Down Expand Up @@ -335,12 +335,12 @@ export assetpath
function icon()
path = assetpath("icons")
imgs = FileIO.load.(joinpath.(path, readdir(path)))
icons = map(img-> RGBA{Colors.N0f8}.(img), imgs)
return reinterpret.(NTuple{4,UInt8}, icons)
icons = map(img -> RGBA{Colors.N0f8}.(img), imgs)
return reinterpret.(NTuple{4, UInt8}, icons)
end

function logo()
FileIO.load(assetpath("logo.png"))
return FileIO.load(assetpath("logo.png"))
end

# populated by __init__()
Expand All @@ -351,20 +351,20 @@ function __init__()
# This mutates module-level state so it could mess up other libraries using
# GridLayoutBase at the same time as Makie, which is unlikely, though
GridLayoutBase.DEFAULT_COLGAP_GETTER[] = function()
return convert(Float64, to_value(Makie.theme(:colgap; default=GridLayoutBase.DEFAULT_COLGAP[])))
return convert(Float64, to_value(Makie.theme(:colgap; default = GridLayoutBase.DEFAULT_COLGAP[])))
end
GridLayoutBase.DEFAULT_ROWGAP_GETTER[] = function()
return convert(Float64, to_value(Makie.theme(:rowgap; default=GridLayoutBase.DEFAULT_ROWGAP[])))
return convert(Float64, to_value(Makie.theme(:rowgap; default = GridLayoutBase.DEFAULT_ROWGAP[])))
end
# fonts aren't cacheable by precompilation, so we need to empty it on load!
empty!(FONT_CACHE)
cfg_path = joinpath(homedir(), ".config", "makie", "theme.jl")
if isfile(cfg_path)
@warn "The global configuration file is no longer supported." *
"Please include the file manually with `include(\"$cfg_path\")` before plotting."
"Please include the file manually with `include(\"$cfg_path\")` before plotting."
end

global makie_cache_dir = @get_scratch!("makie")
return global makie_cache_dir = @get_scratch!("makie")
end

include("figures.jl")
Expand All @@ -378,9 +378,9 @@ include("basic_recipes/text.jl")
include("basic_recipes/raincloud.jl")
include("deprecated.jl")

export Arrows , Heatmap , Image , Lines , LineSegments , Mesh , MeshScatter , Poly , Scatter , Surface , Text , Volume , Wireframe, Voxels
export arrows , heatmap , image , lines , linesegments , mesh , meshscatter , poly , scatter , surface , text , volume , wireframe, voxels
export arrows! , heatmap! , image! , lines! , linesegments! , mesh! , meshscatter! , poly! , scatter! , surface! , text! , volume! , wireframe!, voxels!
export Arrows, Heatmap, Image, Lines, LineSegments, Mesh, MeshScatter, Poly, Scatter, Surface, Text, Volume, Wireframe, Voxels
export arrows, heatmap, image, lines, linesegments, mesh, meshscatter, poly, scatter, surface, text, volume, wireframe, voxels
export arrows!, heatmap!, image!, lines!, linesegments!, mesh!, meshscatter!, poly!, scatter!, surface!, text!, volume!, wireframe!, voxels!

export AmbientLight, PointLight, DirectionalLight, SpotLight, EnvironmentLight, RectLight, SSAO
export FastPixel
Expand Down
6 changes: 3 additions & 3 deletions src/basic_recipes/ablines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function Makie.plot!(p::ABLines)
notify(p[1])

linesegments!(p, points; p.attributes...)
p
return p
end

data_limits(::ABLines) = Rect3f(Point3f(NaN), Vec3f(NaN))
boundingbox(::ABLines, space::Symbol = :data) = Rect3f(Point3f(NaN), Vec3f(NaN))

function abline!(args...; kwargs...)
Base.depwarn("abline! is deprecated and will be removed in the future. Use ablines / ablines! instead." , :abline!, force = true)
ablines!(args...; kwargs...)
Base.depwarn("abline! is deprecated and will be removed in the future. Use ablines / ablines! instead.", :abline!, force = true)
return ablines!(args...; kwargs...)
end
18 changes: 11 additions & 7 deletions src/basic_recipes/annotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ Plots an array of texts at each position in `positions`.
MakieCore.documented_attributes(Text)...
end

function convert_arguments(::Type{<: Annotations},
strings::AbstractVector{<: AbstractString},
text_positions::AbstractVector{<: Point{N, T}}) where {N, T}
return (map(strings, text_positions) do str, pos
(String(str), Point{N, float_type(T)}(pos))
end,)
function convert_arguments(
::Type{<:Annotations},
strings::AbstractVector{<:AbstractString},
text_positions::AbstractVector{<:Point{N, T}}
) where {N, T}
return (
map(strings, text_positions) do str, pos
(String(str), Point{N, float_type(T)}(pos))
end,
)
end

function plot!(plot::Annotations)
# annotations are not necessary anymore with the different text behavior
text!(plot, plot[1]; plot.attributes...)
plot
return plot
end
4 changes: 2 additions & 2 deletions src/basic_recipes/arc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ end
function plot!(p::Arc)
args = getindex.(p, (:origin, :radius, :start_angle, :stop_angle, :resolution))
positions = lift(p, args...) do origin, radius, start_angle, stop_angle, resolution
return map(range(start_angle, stop=stop_angle, length=resolution)) do angle
return map(range(start_angle, stop = stop_angle, length = resolution)) do angle
return origin .+ Point2f((cos(angle), sin(angle)) .* radius)
end
end
attr = Attributes(p)
delete!(attr, :resolution)
lines!(p, attr, positions)
return lines!(p, attr, positions)
end
78 changes: 41 additions & 37 deletions src/basic_recipes/arrows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ function arrow_head(N, marker::Automatic, quality)
if N == 2
return :utriangle
else
merge([
_circle(Point3f(0), 0.5f0, Vec3f(0,0,-1), quality),
_mantle(Point3f(0), Point3f(0,0,1), 0.5f0, 0f0, quality)
])
merge(
[
_circle(Point3f(0), 0.5f0, Vec3f(0, 0, -1), quality),
_mantle(Point3f(0), Point3f(0, 0, 1), 0.5f0, 0.0f0, quality),
]
)
end
end

arrow_tail(N, marker, quality) = marker
function arrow_tail(N, marker::Automatic, quality)
if N == 2
return if N == 2
nothing
else
merge([
_circle(Point3f(0,0,-1), 0.5f0, Vec3f(0,0,-1), quality),
_mantle(Point3f(0,0,-1), Point3f(0), 0.5f0, 0.5f0, quality)
])
merge(
[
_circle(Point3f(0, 0, -1), 0.5f0, Vec3f(0, 0, -1), quality),
_mantle(Point3f(0, 0, -1), Point3f(0), 0.5f0, 0.5f0, quality),
]
)
end
end

Expand All @@ -34,69 +38,69 @@ function _mantle(origin, extremity, r1, r2, N)
# Equivalent to
# xy = cos(atan(temp))
# z = sin(atan(temp))
temp = -(r2-r1) / norm(extremity .- origin)
temp = -(r2 - r1) / norm(extremity .- origin)
xy = 1.0 / sqrt(temp^2 + 1)
z = temp / sqrt(temp^2 + 1)

coords = Vector{Point3f}(undef, 2N)
normals = Vector{Vec3f}(undef, 2N)
faces = Vector{GLTriangleFace}(undef, 2N)

for (i, phi) in enumerate(0:dphi:2pi-0.5dphi)
for (i, phi) in enumerate(0:dphi:(2pi - 0.5dphi))
coords[2i - 1] = origin .+ r1 * Vec3f(cos(phi), sin(phi), 0)
coords[2i] = extremity .+ r2 * Vec3f(cos(phi), sin(phi), 0)
normals[2i - 1] = Vec3f(xy*cos(phi), xy*sin(phi), z)
normals[2i] = Vec3f(xy*cos(phi), xy*sin(phi), z)
faces[2i - 1] = GLTriangleFace(2i-1, mod1(2i+1, 2N), 2i)
faces[2i] = GLTriangleFace(mod1(2i+1, 2N), mod1(2i+2, 2N), 2i)
normals[2i - 1] = Vec3f(xy * cos(phi), xy * sin(phi), z)
normals[2i] = Vec3f(xy * cos(phi), xy * sin(phi), z)
faces[2i - 1] = GLTriangleFace(2i - 1, mod1(2i + 1, 2N), 2i)
faces[2i] = GLTriangleFace(mod1(2i + 1, 2N), mod1(2i + 2, 2N), 2i)
end

GeometryBasics.Mesh(meta(coords; normals=normals), faces)
return GeometryBasics.Mesh(meta(coords; normals = normals), faces)
end

# GeometryBasics.Circle doesn't work with Point3f...
function _circle(origin, r, normal, N)
dphi = 2pi / N

coords = Vector{Point3f}(undef, N+1)
normals = fill(normal, N+1)
coords = Vector{Point3f}(undef, N + 1)
normals = fill(normal, N + 1)
faces = Vector{GLTriangleFace}(undef, N)

for (i, phi) in enumerate(0:dphi:2pi-0.5dphi)
for (i, phi) in enumerate(0:dphi:(2pi - 0.5dphi))
coords[i] = origin .+ r * Vec3f(cos(phi), sin(phi), 0)
faces[i] = GLTriangleFace(N+1, mod1(i+1, N), i)
faces[i] = GLTriangleFace(N + 1, mod1(i + 1, N), i)
end
coords[N+1] = origin
coords[N + 1] = origin

GeometryBasics.Mesh(meta(coords; normals=normals), faces)
return GeometryBasics.Mesh(meta(coords; normals = normals), faces)
end

function convert_arguments(::Type{<: Arrows}, x, y, u, v)
function convert_arguments(::Type{<:Arrows}, x, y, u, v)
return (Point2{float_type(x, y)}.(x, y), Vec2{float_type(u, v)}.(u, v))
end
function convert_arguments(::Type{<: Arrows}, x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix)
function convert_arguments(::Type{<:Arrows}, x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix)
return (vec(Point2{float_type(x, y)}.(x, y')), vec(Vec2{float_type(u, v)}.(u, v)))
end
function convert_arguments(::Type{<: Arrows}, x, y, z, u, v, w)
function convert_arguments(::Type{<:Arrows}, x, y, z, u, v, w)
return (Point3{float_type(x, y, z)}.(x, y, z), Vec3{float_type(u, v, w)}.(u, v, w))
end

function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N}}, V}}) where {N, V}
function plot!(arrowplot::Arrows{<:Tuple{AbstractVector{<:Point{N}}, V}}) where {N, V}
@extract arrowplot (
points, directions, colormap, colorscale, normalize, align,
arrowtail, color, linecolor, linestyle, linewidth, lengthscale,
arrowhead, arrowsize, arrowcolor, quality,
# passthrough
diffuse, specular, shininess, shading,
fxaa, ssao, transparency, visible, inspectable
fxaa, ssao, transparency, visible, inspectable,
)

line_c = lift((a, c)-> a === automatic ? c : a , arrowplot, linecolor, color)
arrow_c = lift((a, c)-> a === automatic ? c : a , arrowplot, arrowcolor, color)
line_c = lift((a, c) -> a === automatic ? c : a, arrowplot, linecolor, color)
arrow_c = lift((a, c) -> a === automatic ? c : a, arrowplot, arrowcolor, color)
fxaa_bool = lift(fxaa -> fxaa == automatic ? N == 3 : fxaa, arrowplot, fxaa) # automatic == fxaa for 3D

marker_head = lift((ah, q) -> arrow_head(N, ah, q), arrowplot, arrowhead, quality)
if N == 2
return if N == 2
headstart = lift(arrowplot, points, directions, normalize, align, lengthscale) do points, dirs, n, align, s
map(points, dirs) do p1, dir
dir = n ? LinearAlgebra.normalize(dir) : dir
Expand Down Expand Up @@ -134,19 +138,19 @@ function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N}}, V}}) wher

linesegments!(
arrowplot, headstart,
color=line_c, colormap=colormap, colorscale=colorscale, linestyle=linestyle,
colorrange=arrowplot.colorrange,
linewidth=lift(lw -> lw === automatic ? 1.0f0 : lw, arrowplot, linewidth),
color = line_c, colormap = colormap, colorscale = colorscale, linestyle = linestyle,
colorrange = arrowplot.colorrange,
linewidth = lift(lw -> lw === automatic ? 1.0f0 : lw, arrowplot, linewidth),
fxaa = fxaa_bool, inspectable = inspectable,
transparency = transparency, visible = visible,
)
scatter!(
arrowplot,
lift(x-> last.(x), arrowplot, headstart),
marker=marker_head,
markersize = lift(as-> as === automatic ? theme(scene, :markersize)[] : as, arrowplot, arrowsize),
lift(x -> last.(x), arrowplot, headstart),
marker = marker_head,
markersize = lift(as -> as === automatic ? theme(scene, :markersize)[] : as, arrowplot, arrowsize),
color = arrow_c, rotation = rotations, strokewidth = 0.0,
colormap=colormap, markerspace=arrowplot.markerspace, colorrange=arrowplot.colorrange,
colormap = colormap, markerspace = arrowplot.markerspace, colorrange = arrowplot.colorrange,
fxaa = fxaa_bool, inspectable = inspectable,
transparency = transparency, visible = visible
)
Expand Down
Loading

0 comments on commit 2c3d6db

Please sign in to comment.