This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |