Skip to content

Instantly share code, notes, and snippets.

View jkrumbiegel's full-sized avatar

Julius Krumbiegel jkrumbiegel

View GitHub Profile
@jkrumbiegel
jkrumbiegel / makie_3d_barplot.jl
Created May 21, 2022 10:54
Makie 3D Barplot
@recipe(Barplot3D) do scene
Attributes(
color = theme(scene, :markercolor),
colormap = theme(scene, :colormap),
)
end
Makie.conversion_trait(::Type{<:Barplot3D}) = Makie.DiscreteSurface()
function Makie.plot!(p::Barplot3D)
@jkrumbiegel
jkrumbiegel / align_ylabels.jl
Created May 6, 2022 11:12
Makie align y labels
function align_ylabels!(axs...)
max_extent = maximum(axs) do ax
tight_yticklabel_spacing!(ax)
ax.yticklabelspace[]
end
for ax in axs
ax.yticklabelspace = max_extent
end
return
end
@jkrumbiegel
jkrumbiegel / gridlayout_boxes_with_padding.jl
Created May 4, 2022 10:45
GridLayout Boxes with padding
f = Figure()
b = Box(f[1, 1], color = :tomato)
translate!(b.elements[:rect], 0, 0, -100)
gl = f[1, 1] = GridLayout(alignmode = Outside(30))
for i in 1:2, j in 1:2
ax = Axis(gl[i, j])
end
@jkrumbiegel
jkrumbiegel / makie_sankey.jl
Created March 12, 2022 13:25
sankey makie
function sankey!(target, x1, x2, bend, start_min, start_max, stop_min, stop_max, color_start, color_stop)
bezier(t, p1, p2, p3, p4) = (1 - t)^3 * p1 + 3(1 - t)^2 * t * p2 + 3 * (1 - t) * t^2 * p3 + t^3 * p4
b(t, start, stop) = begin
p_start = Point2f(x1, start)
p_stop = Point2f(x2, stop)
c1 = Point2f(x1 + bend * (x2-x1), start)
c2 = Point2f(x2 - bend * (x2-x1), stop)
bezier(t, p_start, c1, c2, p_stop)
end
using Markdown
Docs.getdoc(s::typeof(scatter)) = plot_func_docs(s)
Docs.getdoc(h::typeof(heatmap)) = plot_func_docs(h)
function plot_func_docs(plotfunc)
T = Combined{plotfunc}
io = IOBuffer()
@jkrumbiegel
jkrumbiegel / valign_legends.jl
Created January 28, 2022 17:04
one legend per line with valign
f = Figure()
ax = Axis(f[1, 1])
ls = map(0:3) do i
lines!(ax, 1:10, (1:10) .* i)
end
for (i, l) in zip(0:3, ls)
Legend(f[1, 2], [l], ["$i"], framevisible = false, padding = (0, 0, 0, 0),
valign = i / 3)
@jkrumbiegel
jkrumbiegel / tagged_unions.jl
Last active February 1, 2022 14:59
playing around with tagged unions
function struct_reinterpret(::Type{T}, x)::T where T
ref = Base.RefValue(x)
GC.@preserve ref unsafe_load(Ptr{T}(pointer_from_objref(ref)))
end
struct TaggedUnion
type::UInt8
bytes::NTuple{8, UInt8} # would be the max size of all types used, determined automatically
end
@jkrumbiegel
jkrumbiegel / portaudio.jl
Last active December 5, 2021 20:37
basic portaudio
using Pkg
pkg"activate @portaudio"
using PortAudio.LibPortAudio
mutable struct Audio
ptr::Ptr{Float32}
buffer::Vector{Float32} # vector reference so no problems with garbage collection
len::Int
@jkrumbiegel
jkrumbiegel / multi_archimedes_spiral_makie.jl
Created September 19, 2021 08:20
multiple archimedes spiral makie
using CairoMakie
##
s = Scene(resolution = (500, 500), camera = campixel!, show_axis = false)
o = Point2f(250, 250)
n = 5
linewidth = 10
center_offset = 0
rotation_gain = 1.5
@jkrumbiegel
jkrumbiegel / makie_axis_bracket.jl
Created September 9, 2021 08:12
makie axis bracket
function bracketlabel!(ax, label, mi, ma, axoffset, bracketwidth, labeloffset)
bracketpoints = lift(ax.finallimits, ax.scene.px_area) do lims, px_area
x = minimum(lims)[1]
pmin = Makie.project(ax.scene, Point2f(x, mi))
pmax = Makie.project(ax.scene, Point2f(x, ma))
ps = Point2f[
pmin,
pmin - Point2f(bracketwidth, 0),