Skip to content

Commit

Permalink
fix Jupyter display
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Oct 6, 2018
1 parent 9bbcdbe commit 9d8abc3
Show file tree
Hide file tree
Showing 104 changed files with 939 additions and 596 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [v1.1.1] - 2018-10-04

### Added

### Changed

- fixed display code to work in Jupyter
- rand() in all tests is seeded in advance to produce predictable output
- internal changes to fix type stability

### Removed

### Deprecated

## [v1.1.0] - 2018-10-04

Expand Down
36 changes: 33 additions & 3 deletions benchmark/simple-benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using Luxor, BenchmarkTools
using BenchmarkTools

function bm1()
@info
Drawing(1000, 1000, "luxor-test1.pdf")
origin()
t = Tiler(1000, 1000, 10, 10, margin=10)
Expand All @@ -21,7 +20,7 @@ function bm2()
origin()
t = Tiler(1000, 1000, 10, 10, margin=10)
for (pos, n) in t
sethue("red")
setcolor"red"
setopacity(rand())
box(pos, t.tilewidth/2, t.tilewidth/2, :fill)
end
Expand All @@ -34,7 +33,7 @@ end

#=
Julia v1.0.0 Luxor v1.0.0 iMac
1: Julia v1.0.0 Luxor v1.0.0 iMac 2018-10-05 12:37:11
julia-1.0> @benchmark bm1()
BenchmarkTools.Trial:
Expand Down Expand Up @@ -62,4 +61,35 @@ BenchmarkTools.Trial:
samples: 4247
evals/sample: 1
2: Julia v1.0.0 Luxor v1.1.0 iMac 2018-10-05 12:40:11
after some type work, there's a slight improvement in allocations
julia-1.0> @benchmark bm1()
BenchmarkTools.Trial:
memory estimate: 38.94 KiB
allocs estimate: 782
--------------
minimum time: 1.950 ms (0.00% GC)
median time: 2.136 ms (0.00% GC)
mean time: 2.302 ms (1.57% GC)
maximum time: 68.908 ms (92.70% GC)
--------------
samples: 2165
evals/sample: 1
julia-1.0> @benchmark bm2()
BenchmarkTools.Trial:
memory estimate: 92.00 KiB
allocs estimate: 2285
--------------
minimum time: 663.034 μs (0.00% GC)
median time: 736.955 μs (0.00% GC)
mean time: 806.080 μs (2.46% GC)
maximum time: 49.676 ms (96.68% GC)
--------------
samples: 6164
evals/sample: 1
=#
Binary file added docs/src/assets/figures/jupyter-basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/src/assets/figures/jupyter-star.png
Binary file not shown.
36 changes: 1 addition & 35 deletions docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,6 @@ finish
preview
```

The global variable `currentdrawing` (of type Drawing) stores some parameters related to the current drawing:

```julia
julia> fieldnames(typeof(currentdrawing))
10-element Array{Symbol,1}:
:width
:height
:filename
:surface
:cr
:surfacetype
:redvalue
:greenvalue
:bluevalue
:alpha
```
## Quick drawings with macros

The `@svg`, `@png`, and `@pdf` macros are designed to let you quickly create graphics without having to provide the usual boiler-plate functions. For example, the Julia code:
Expand Down Expand Up @@ -220,25 +204,7 @@ You can choose to store the drawing in memory. The advantage to this is that in-
Drawing(width, height, surfacetype, [filename])
```

lets you supply `surfacetype` as a symbol (`:svg` or `:png`). This creates a new drawing of the given surface type and stores the image only in memory if no `filename` is supplied. In a Jupyter notebook you can use it to provide faster manipulations. For example:

```julia
using Interact

function makecircle(r)
d = Drawing(300, 300, :svg)
sethue("black")
origin()
setline(0.5)
hypotrochoid(150, 100, r, :stroke)
finish()
return d
end

@manipulate for r in 5:150
makecircle(r)
end
```
lets you supply `surfacetype` as a symbol (`:svg` or `:png`). This creates a new drawing of the given surface type and stores the image only in memory if no `filename` is supplied.

## The drawing surface

Expand Down
1 change: 0 additions & 1 deletion docs/src/clipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ nothing # hide
![simple clip](assets/figures/simpleclip.png)

```@docs
clip
clippreserve
clipreset
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/colors-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ dashes = [50.0, # ink
10.0 # skip
]
offset = -50.0
Cairo.set_dash(currentdrawing.cr, dashes, offset)
Cairo.set_dash(get_current_cr()(), dashes, offset)
```

## Blends
Expand Down
6 changes: 3 additions & 3 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ draw(depth)

The Point type is an immutable composite type containing `x` and `y` fields that specify a 2D point.

## Working interactively
## Working in Jupyter and Juno

If you want to work interactively, you can use an environment such as a Jupyter notebook or the Juno IDE, and load Luxor at the start of a session. The first drawing will take a few seconds, because the Cairo graphics engine needs to warm up. Subsequent drawings are then much quicker. (This is true of much graphics and plotting work, of course, as Julia compiles functions when they're first encountered, and calls the compiled versions thereafter.)
You can use an environment such as a Jupyter notebook or the Juno IDE, and load Luxor at the start of a session. The first drawing will take a few seconds, because the Cairo graphics engine needs to warm up. Subsequent drawings are then much quicker. (This is true of much graphics and plotting work. Julia compiles each function when it first encounters it, and then calls the compiled versions thereafter.)

![Jupyter](assets/figures/jupyter-star.png)
![Jupyter](assets/figures/jupyter-basic.png)

## More examples

Expand Down
2 changes: 1 addition & 1 deletion docs/src/moreexamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fontsize(60)
setcolor("turquoise")
fontface("Optima-ExtraBlack")
textwidth = textextents("Luxor")[5]
textcentred("Luxor", 0, currentdrawing.height/2 - 400)
textcentred("Luxor", 0, current_height()/2 - 400)
fontsize(18)
fontface("Avenir-Black")

Expand Down
6 changes: 3 additions & 3 deletions src/BoundingBox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function BoundingBox(;centered=true)
if centered
# ignore current matrix
r = BoundingBox(
Point(-currentdrawing.width/2, -currentdrawing.height/2),
Point(currentdrawing.width/2, currentdrawing.height/2))
Point(-current_width()/2, -current_height()/2),
Point(current_width()/2, current_height()/2))
else
b = getmatrix()
setmatrix([1.0, 0.0, 0.0, 1.0, 0.0, 0.0])
r = BoundingBox(Point(0, 0), Point(currentdrawing.width, currentdrawing.height))
r = BoundingBox(Point(0, 0), Point(current_width(), current_height()))
setmatrix(b)
end
return r
Expand Down
Loading

0 comments on commit 9d8abc3

Please sign in to comment.