Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace d by plotattributes #48

Merged
merged 2 commits into from
Sep 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type MyType end
linecolor --> :blue
seriestype := :path
markershape --> (add_marker ? :circle : :none)
delete!(d, :add_marker)
delete!(plotattributes, :add_marker)
rand(n)
end
```
Expand All @@ -51,12 +51,12 @@ We create a new type `MyType`, which is empty, and used purely for dispatch. Ou

There are a few important things to know, after which recipes boil down to updating an attribute dictionary and returning input data:

- A recipe signature `f(args...; kw...)` is converted into a definition of `apply_recipe(d::KW, args...)` where:
- `d` is an attribute dictionary of type `typealias KW Dict{Symbol,Any}`
- A recipe signature `f(args...; kw...)` is converted into a definition of `apply_recipe(plotattributes::KW, args...)` where:
- `plotattributes` is an attribute dictionary of type `typealias KW Dict{Symbol,Any}`
- Your `args` must be distinct enough that dispatch will call your definition (and without masking an existing definition). Using a custom data type will ensure proper dispatch.
- The function `f` is unused/meaningless... call it whatever you want.
- The special operator `-->` turns `linecolor --> :blue` into `get!(d, :linecolor, :blue)`, setting the attribute only when it doesn't already exist. (Tip: Wrap the right hand side in parentheses for complex expressions.)
- The special operator `:=` turns `seriestype := :path` into `d[:seriestype] = :path`, forcing that attribute value. (Tip: Wrap the right hand side in parentheses for complex expressions.)
- The special operator `-->` turns `linecolor --> :blue` into `get!(plotattributes, :linecolor, :blue)`, setting the attribute only when it doesn't already exist. (Tip: Wrap the right hand side in parentheses for complex expressions.)
- The special operator `:=` turns `seriestype := :path` into `plotattributes[:seriestype] = :path`, forcing that attribute value. (Tip: Wrap the right hand side in parentheses for complex expressions.)
- The return value of the recipe is the `args` of a `RecipeData` object, which also has a reference to the attribute dictionary.
- A recipe returns a Vector{RecipeData}. We'll see how to add to this list later with the `@series` macro.

Expand Down Expand Up @@ -148,9 +148,9 @@ This is where the magic happens. You can create your own custom visualizations

```julia
@recipe function f(::Type{Val{:histogram}}, x, y, z)
edges, counts = my_hist(y, d[:bins],
normed = d[:normalize],
weights = d[:weights])
edges, counts = my_hist(y, plotattributes[:bins],
normed = plotattributes[:normalize],
weights = plotattributes[:weights])
x := edges
y := counts
seriestype := :bar
Expand All @@ -162,9 +162,9 @@ while a 2D histogram is really a heatmap:

```julia
@recipe function f(::Type{Val{:histogram2d}}, x, y, z)
xedges, yedges, counts = my_hist_2d(x, y, d[:bins],
normed = d[:normalize],
weights = d[:weights])
xedges, yedges, counts = my_hist_2d(x, y, plotattributes[:bins],
normed = plotattributes[:normalize],
weights = plotattributes[:weights])
x := centers(xedges)
y := centers(yedges)
z := Surface(counts)
Expand Down Expand Up @@ -295,7 +295,7 @@ Next we build the subplot layout and define some attributes. A few things to no
hist2d{0.9w,0.9h} righthist]
```

Define the series of the main plot. The `@series` macro makes a local copy of the attribute dictionary `d` using a "let block". The copied dictionary and the returned args are added to the `Vector{RecipeData}` which is returned from the recipe. This block is similar to calling `histogram2d!(x, y; subplot = 2, d...)` (but you wouldn't actually want to do that).
Define the series of the main plot. The `@series` macro makes a local copy of the attribute dictionary `plotattributes` using a "let block". The copied dictionary and the returned args are added to the `Vector{RecipeData}` which is returned from the recipe. This block is similar to calling `histogram2d!(x, y; subplot = 2, plotattributes...)` (but you wouldn't actually want to do that).

Note: this `@series` block gets a "snapshot" of the attributes, so it contains anything that was set before this block, but nothing from after it. `@series` blocks can be standalone, as these are, or they can be in a loop.

Expand Down
13 changes: 6 additions & 7 deletions site/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="/assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="/assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="/assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="/assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="/assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="/assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -87,11 +86,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -587,7 +586,7 @@ <h1>404 - Not found</h1>

</div>

<script src="/assets/javascripts/application-07b0fbb49b.js"></script>
<script src="/assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:""}})</script>
Expand Down
13 changes: 6 additions & 7 deletions site/animations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="../assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="../assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="../assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="../assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="../assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="../assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -93,11 +92,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -775,7 +774,7 @@ <h3 id="custom-iterators">Custom Iterators</h3>

</div>

<script src="../assets/javascripts/application-07b0fbb49b.js"></script>
<script src="../assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:".."}})</script>
Expand Down
1 change: 0 additions & 1 deletion site/assets/javascripts/application-07b0fbb49b.js

This file was deleted.

4 changes: 4 additions & 0 deletions site/assets/javascripts/application-b30566c560.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion site/assets/stylesheets/application-02c2a4388f.palette.css

This file was deleted.

1 change: 0 additions & 1 deletion site/assets/stylesheets/application-769c285a91.css

This file was deleted.

1 change: 1 addition & 0 deletions site/assets/stylesheets/application-8817cfa535.palette.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions site/assets/stylesheets/application-acc56dad49.css

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions site/attributes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="../assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="../assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="../assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="../assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="../assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="../assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -93,11 +92,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -948,7 +947,7 @@ <h3 id="axis">Axis</h3>

</div>

<script src="../assets/javascripts/application-07b0fbb49b.js"></script>
<script src="../assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:".."}})</script>
Expand Down
13 changes: 6 additions & 7 deletions site/backends/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="../assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="../assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="../assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="../assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="../assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="../assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -93,11 +92,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -897,7 +896,7 @@ <h3 id="winston"><a href="https://github.com/nolta/Winston.jl">Winston</a></h3>

</div>

<script src="../assets/javascripts/application-07b0fbb49b.js"></script>
<script src="../assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:".."}})</script>
Expand Down
13 changes: 6 additions & 7 deletions site/basics/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="../assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="../assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="../assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="../assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="../assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="../assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -93,11 +92,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -779,7 +778,7 @@ <h3 id="useful-tips">Useful Tips</h3>

</div>

<script src="../assets/javascripts/application-07b0fbb49b.js"></script>
<script src="../assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:".."}})</script>
Expand Down
13 changes: 6 additions & 7 deletions site/colors/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">



Expand All @@ -14,7 +13,7 @@

<link rel="shortcut icon" href="../assets/images/favicon.png">

<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.5">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.7.3">



Expand All @@ -25,9 +24,9 @@
<script src="../assets/javascripts/modernizr-1df76c4e58.js"></script>


<link rel="stylesheet" href="../assets/stylesheets/application-769c285a91.css">
<link rel="stylesheet" href="../assets/stylesheets/application-acc56dad49.css">

<link rel="stylesheet" href="../assets/stylesheets/application-02c2a4388f.palette.css">
<link rel="stylesheet" href="../assets/stylesheets/application-8817cfa535.palette.css">



Expand Down Expand Up @@ -93,11 +92,11 @@

<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

<div class="md-search" data-md-component="search" role="dialog">
<div class="md-search" data-md-component="search">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button>
</form>
Expand Down Expand Up @@ -876,7 +875,7 @@ <h4 id="misc">Misc</h4>

</div>

<script src="../assets/javascripts/application-07b0fbb49b.js"></script>
<script src="../assets/javascripts/application-b30566c560.js"></script>


<script>app.initialize({url:{base:".."}})</script>
Expand Down
Loading