Skip to content

Instantly share code, notes, and snippets.

View jkrumbiegel's full-sized avatar

Julius Krumbiegel jkrumbiegel

View GitHub Profile
@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),
@jkrumbiegel
jkrumbiegel / makie_gantt.jl
Created August 20, 2021 07:18
makie gantt bar chart
task_starts = [0, 3, 5, 10]
task_ends = [3, 6, 9, 12]
task_positions = [1, 2, 1, 2]
barplot(task_positions, task_ends, fillto = task_starts,
direction = :x)
text!("task " .* string.(1:4),
position = Point2f0.(
(task_starts .+ task_ends) ./ 2,
task_positions
@jkrumbiegel
jkrumbiegel / cleveland.jl
Created May 2, 2021 17:30
cleveland gridlayout
f = Figure()
nrows, ncols = (3, 7)
real_axes = map(Iterators.product(1:nrows, 1:ncols)) do (i, j)
ax = Axis(f[2i, j])
if i < nrows
hidexdecorations!(ax, grid = false)
end
if 1 < j < ncols
@jkrumbiegel
jkrumbiegel / subplots_fixed_size.jl
Created May 2, 2021 15:07
makielayout set figure size according to fixed width/height subplots
f = Figure()
[Axis(f[i, j], width = 300, height = 250) for i in 1:3, j in 1:3]
sz = ceil.(Int, GridLayoutBase.determinedirsize.(
Ref(f.layout),
(GridLayoutBase.Col(), GridLayoutBase.Row())))
resize!(f.scene, sz)