Skip to content

Commit

Permalink
pluto, julialogo, tidysvg
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jun 18, 2020
1 parent 1f67cb3 commit 87c3afd
Show file tree
Hide file tree
Showing 41 changed files with 57 additions and 14,455 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Changelog

## [???] - forthcoming June/July 2020
## [v.2.1.0] - 2020 June 18

### Added

- `julialogo()` centered option
- `tidysvg()` function to hack glyphnames in SVG files
(probably a temporary thing)
- support for Pluto

### Changed

- support for Pluto
- document handling code
- document handling code (cf Pluto support)
- `julialogo()` tweaks to allow :path action
- @svg rendering modified (eg no glyphname hacking done)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Luxor"
uuid = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
authors = ["cormullion <[email protected]>"]
version = "2.0.0"
version = "2.1.0"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand All @@ -24,6 +24,6 @@ julia = "1"
Cairo = "0.6, 0.7, 0.8, 1.0"
Colors = "0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 1.0"
FileIO = "^1.0"
ImageMagick = "^0.7"
ImageMagick = "0.7, 1.0"
Juno = "0.7, 0.8"
QuartzImageIO = "^0.6"
Binary file modified docs/src/assets/figures/ampersand-matrix.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 modified docs/src/assets/figures/animation-easing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/figures/animation-screengrab.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/figures/animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7,630 changes: 1 addition & 7,629 deletions docs/src/assets/figures/colors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/figures/drawing_on_images.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 modified docs/src/assets/figures/drawmacro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,102 changes: 1 addition & 4,101 deletions docs/src/assets/figures/hilbertturtle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/figures/interact.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 modified docs/src/assets/figures/isinside.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 modified docs/src/assets/figures/julia-logo-mask.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 modified docs/src/assets/figures/juno.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 modified 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 modified docs/src/assets/figures/jupyter.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 modified docs/src/assets/figures/luxorgallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,707 changes: 1 addition & 2,706 deletions docs/src/assets/figures/manyturtles.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/figures/mesh-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 modified docs/src/assets/figures/mesh1.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 modified docs/src/assets/figures/n-gon.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 modified docs/src/assets/figures/ngonside.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 modified docs/src/assets/figures/noise.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 modified docs/src/assets/figures/penrose.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 modified docs/src/assets/figures/polyarea.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 modified docs/src/assets/figures/sierpinski.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 modified docs/src/assets/figures/strange-vector.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 modified docs/src/assets/figures/test-image.png
Binary file modified docs/src/assets/figures/text-path-clipping.png
Binary file modified docs/src/assets/figures/text-spiral.png
Binary file modified docs/src/assets/figures/tiled-images.png
Binary file modified docs/src/assets/figures/transparentbackground.png
Binary file modified docs/src/assets/figures/tutorial-egg-10.png
Binary file modified docs/src/assets/figures/tutorial-egg-9.png
Binary file added docs/src/assets/figures/vscode.png
6 changes: 3 additions & 3 deletions docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ paper_sizes

To finish a drawing and close the file, use `finish()`, and, to launch an external application to view it, use `preview()`.

If you're using Jupyter (IJulia), `preview()` tries to display PNG and SVG files in the next notebook cell.
If you're using a notebook environment, such as Jupyter (IJulia) or Pluto, `preview()` tries to display PNG and SVG files in the next notebook cell.

![jupyter](assets/figures/jupyter.png)

If you're using Juno, then PNG and SVG files should appear in the Plots pane.
If you're using Juno or VS Code, then PNG and SVG files should appear in the Plots pane.

![juno](assets/figures/juno.png)

Expand Down Expand Up @@ -177,7 +177,7 @@ or (less nicely):
)
```

The `@draw` macro creates an im-memory drawing. You should see it displayed if you're working in Juno or Jupyter.
The `@draw` macro creates an in-memory drawing. You should see it displayed if you're working in a capable environment (Juno, VSCode, Jupyter, Pluto).

```@docs
@svg
Expand Down
11 changes: 8 additions & 3 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ end
```
![background](assets/figures/circle-dots.png)

The `@draw` macro is useful if you work in Juno or Jupyter and don't need to save work in files. It creates a PNG format drawing in memory, rather than saved in a file. It's displayed in the plot pane or the next cell.
The `@draw` macro is useful if you work in Juno/VS Code IDEs
or a notebook environment such as Jupyter or Pluto and
don't need to save work in files. It creates a PNG format
drawing in memory, rather than saved in a file. It's
displayed in the plot pane or the next cell.

```julia
@draw begin
Expand Down Expand Up @@ -155,11 +159,12 @@ draw(depth)

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

## Working in Jupyter and Juno
## Working in IDEs and notebooks

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.)
You can use an environment such as a Jupyter or Pluto notebook or the Juno or VS Code IDEs, 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-basic.png)
![VS Code](assets/figures/vscode.png)

## Images as matrices

Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ julia

then you're ready to start.

You can work in a Jupyter notebook, or perhaps use the Atom/Juno editor/development environment. It's also possible to work in a text editor (make sure you know how to run a file of Julia code), or, at a pinch, you could use the Julia REPL directly.
You can work in a Jupyter or Pluto notebook, or perhaps use the Atom/Juno or VSCode editor/development environment. It's also possible to work in a text editor (make sure you know how to run a file of Julia code), or, at a pinch, you could use the Julia REPL directly.

Ready? Let's begin. The goal of this tutorial is to do a bit of basic 'compass and ruler' Euclidean geometry, to introduce the basic concepts of Luxor drawings.

Expand Down
11 changes: 10 additions & 1 deletion src/Luxor.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""
The Luxor package provides a set of vector drawing functions for creating graphical documents.
```
@draw begin
circle(Point(0, 0), 100, :stroke)
text("Hello World")
end
"""
module Luxor

Expand Down Expand Up @@ -157,7 +163,10 @@ export Drawing,
# misc
layoutgraph, image_as_matrix, @imagematrix,

Style, applystyle
# experimental
Style, applystyle,

tidysvg

# basic unit conversion to Cairo/PostScript points
const inch = 72.0
Expand Down
2 changes: 1 addition & 1 deletion src/animate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ the resulting frames to build a GIF animation. This will be stored in `pathname`
`(movietitle).gif` in a temporary directory. `ffmpeg` should be installed and
available, of course, if this is to work.
In suitable environments (eg Juno), the resulting animation is displayed in the Plots window.
In suitable environments, the resulting animation is displayed in the Plots window.
### Example
Expand Down
28 changes: 23 additions & 5 deletions src/drawings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,32 @@ function Base.show(io::IO, ::MIME"text/plain", d::Drawing)
end
end

function tidysvg(m::MIME"image/svg+xml", fname)
# rename the elements to avoid display issues
"""
tidysvg(fname)
Read the SVG image in `fname` and write it to a file
`fname-tidy.svg` with modified glyph names.
SVG images use named defs for text, which cause errors
problem when used in a notebook.
[See](https://github.com/jupyter/notebook/issues/333) for example.
A kludgy workround is to rename the elements...
"""
function tidysvg(fname)
# I pinched this from Simon's RCall.jl
open(fname) do f
path, ext = splitext(fname)
if ext == ".svg"
open(fname) do f
r = string(rand(100000:999999))
d = read(f, String)
d = replace(d, "id=\"glyph" => "id=\"glyph"*r)
d = replace(d, "href=\"#glyph" => "href=\"#glyph"*r)
display(m, d)
open(path * "-tidy" * ext, "w") do out
write(out, d)
end
@info "modified SVG file copied to $(path * "-tidy" * ext)"
end
end
end

Expand Down Expand Up @@ -270,6 +287,7 @@ function finish()
Cairo.finish(current_surface())
Cairo.destroy(current_surface())


if current_filename() != ""
write(current_filename(), current_bufferdata())
end
Expand All @@ -292,7 +310,7 @@ Otherwise:
- on macOS, open the file in the default application, which is probably the Preview.app for
PNG and PDF, and Safari for SVG
- on Unix, open the file with `xdg-open`
- on Windows, pass the filename to `explorer`.
- on Windows, refer to `COMSPEC`.
"""
function preview()
@debug "preview()"
Expand Down

0 comments on commit 87c3afd

Please sign in to comment.