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

Commit

Permalink
Browse files Browse the repository at this point in the history
…ng.jl into master
  • Loading branch information
SimonDanisch committed Apr 27, 2021
2 parents 261378a + b1bb986 commit 6239983
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
26 changes: 22 additions & 4 deletions docs/src/makielayout/axis.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CairoMakie.activate!(type = "png")
## Creating an Axis

The `Axis` is a 2D axis that works well with automatic layouts.
Here's how you create one
Here's how you create one

```@example laxis
using CairoMakie
Expand Down Expand Up @@ -571,7 +571,7 @@ You can check which interactions are currently active by calling `interactions(a
Often, you don't want to remove an interaction entirely but only disable it for a moment, then reenable it again.
You can use the functions `activate_interaction!(ax, name::Symbol)` and `deactivate_interaction!(ax, name::Symbol)` for that.

#### `Function` Interaction
#### `Function` Interaction
If `interaction` is a `Function`, it should accept two arguments, which correspond to an event and the axis.
This function will then be called whenever the axis generates an event.

Expand All @@ -595,7 +595,7 @@ The function option is most suitable for interactions that don't involve much st
A more verbose but flexible option is available.
For this, you define a new type which typically holds all the state variables you're interested in.

Whenever the axis generates an event, it calls `process_interaction(interaction, event, axis)` on all
Whenever the axis generates an event, it calls `process_interaction(interaction, event, axis)` on all
stored interactions.
By defining `process_interaction` for specific types of interaction and event, you can create more complex interaction patterns.

Expand Down Expand Up @@ -659,9 +659,27 @@ hlines!(ax2, [1, 2, 3, 4], xmax = [0.25, 0.5, 0.75, 1], color = :blue)
scene
```

### abline!

abline works similar to v/hlines!:

```@docs
abline!
```

```@setup 1
using CairoMakie
CairoMakie.activate!(type = "png")
```

```@example 1
fig, ax, pl = scatter(1:4)
abline!(ax, 0, 1)
abline!(ax, 0, 1.5, color = :red, linestyle=:dash, linewidth=2)
fig
```

```@eval
using GLMakie
GLMakie.activate!()
```

2 changes: 1 addition & 1 deletion src/makielayout/MakieLayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export labelslider!, labelslidergrid!
export addmouseevents!
export interactions, register_interaction!, deregister_interaction!, activate_interaction!, deactivate_interaction!
export MouseEventTypes, MouseEvent, ScrollEvent, KeysEvent
export hlines!, vlines!
export hlines!, vlines!, abline!


# from GridLayoutBase
Expand Down
22 changes: 18 additions & 4 deletions src/makielayout/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ function labelslidergrid!(scene, labels, ranges; formats = [string],
sliders = map(x -> x.slider, elements)
labels = map(x -> x.label, elements)
valuelabels = map(x -> x.valuelabel, elements)

layout = grid!(hcat(labels, sliders, valuelabels); layoutkw...)

(sliders = sliders, labels = labels, valuelabels = valuelabels, layout = layout)
end

Expand Down Expand Up @@ -448,5 +448,19 @@ Create vertical lines across `ax` at `xs` in data coordinates and `ymin` to `yma
in axis coordinates (0 to 1). All three of these can have single or multiple values because
they are broadcast to calculate the final line segments.
"""
vlines!(ax::Axis, xs; ymin = 0.0, ymax = 1.0, attrs...) =
hvlines!(ax, 2, xs, ymin, ymax; attrs...)
vlines!(ax::Axis, xs; ymin = 0.0, ymax = 1.0, attrs...) =
hvlines!(ax, 2, xs, ymin, ymax; attrs...)

"""
abline!(axis::Axis, a::Number, b::Number; line_kw_args...)
Adds a line defined by `f(x) = x * b + a` to the axis.
kwargs are the same as for a `line` plot and are passed directly to the line attributess.
"""
function abline!(axis::Axis, a::Number, b::Number; kwargs...)
f(x) = x * b + a
line = map(axis.finallimits) do limits
xmin, xmax = first.(extrema(limits))
return [Point2f0(xmin, f(xmin)), Point2f0(xmax, f(xmax))]
end
return linesegments!(axis, line; xautolimits=false, yautolimits=false, kwargs...)
end

0 comments on commit 6239983

Please sign in to comment.