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

Add basic support for svg output #233

Merged
merged 1 commit into from
Aug 24, 2016
Merged

Add basic support for svg output #233

merged 1 commit into from
Aug 24, 2016

Conversation

MichaelHatherly
Copy link
Member

Allow image/svg+xml output for at-example blocks when the object to be displayed is capable of output the format. Should help with #229, but is not yet a completely general solution.


@tlnagy could you check whether this will work at all for your needs, thanks. Should just need to do

```@example
using Gadfly
plot(x = 1:10, y = 1:10)
```

and it should display an embedded svg image. I'm not to sure how to get the interactive svg+js plots to work since I'm not familiar with Gadfly though.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

I can confirm this works on a simple case where I added

    ```@example
    using Gadfly
    plot(x = 1:10, y = 1:10)
    ``` 

to Documenter.jl. However, I'm getting an error when building the new Gadfly docs:

WARNING: both DataArrays and StatsBase export "autocor"; uses of it in module DataFrames must be qualified
WARNING: both DataArrays and StatsBase export "inverse_rle"; uses of it in module DataFrames must be qualified
WARNING: both DataArrays and StatsBase export "rle"; uses of it in module DataFrames must be qualified
Documenter: setting up build directory.
Documenter: expanding markdown templates.
ERROR: LoadError: MethodError: Cannot `convert` an object of type Float64 to an object of type Gadfly.Stat.Identity
This may have arisen from a call to the constructor Gadfly.Stat.Identity(...),
since type constructors fall back to convert methods.
 in macro expansion at ./broadcast.jl:129 [inlined]
 in macro expansion at ./simdloop.jl:73 [inlined]
 in macro expansion at ./broadcast.jl:123 [inlined]
 in _broadcast!(::Type{Gadfly.Stat.Identity}, ::Array{Int64,1}, ::Tuple{Tuple{Bool}}, ::Tuple{Tuple{Int64}}, ::Tuple{Array{Float64,1}}, ::Type{Val{1}}) at ./broadcast.jl:117
 in broadcast!(::Type{T}, ::Array{Int64,1}, ::Array{Float64,1}) at ./broadcast.jl:172
 in apply_statistic(::Gadfly.Stat.HistogramStatistic, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/tamasnagy/.julia/v0.5/Gadfly/src/statistics.jl:330
 in apply_statistics(::Array{Gadfly.StatisticElement,1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/tamasnagy/.julia/v0.5/Gadfly/src/statistics.jl:38
 in render_prepare(::Gadfly.Plot) at /Users/tamasnagy/.julia/v0.5/Gadfly/src/Gadfly.jl:740
 in render(::Gadfly.Plot) at /Users/tamasnagy/.julia/v0.5/Gadfly/src/Gadfly.jl:799
 in show at /Users/tamasnagy/.julia/v0.5/Gadfly/src/Gadfly.jl:965 [inlined]
 in verbose_show(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("image/svg+xml")}, ::Gadfly.Plot) at ./multimedia.jl:50
 in #sprint#228(::Void, ::Function, ::Int64, ::Function, ::MIME{Symbol("image/svg+xml")}, ::Vararg{Any,N}) at ./strings/io.jl:37
 in stringmime(::MIME{Symbol("image/svg+xml")}, ::Gadfly.Plot) at ./multimedia.jl:65
 in runner(::Type{Documenter.Expanders.ExampleBlocks}, ::Base.Markdown.Code, ::Documenter.Documents.Page, ::Documenter.Documents.Document) at /Users/tamasnagy/.julia/v0.5/Documenter/src/Expanders.jl:454
 in dispatch(::Type{Documenter.Expanders.ExpanderPipeline}, ::Base.Markdown.Code, ::Documenter.Documents.Page, ::Documenter.Documents.Document) at /Users/tamasnagy/.julia/v0.5/Documenter/src/Selectors.jl:164
 in expand(::Documenter.Documents.Document) at /Users/tamasnagy/.julia/v0.5/Documenter/src/Expanders.jl:29
 in dispatch(::Type{Documenter.Builder.DocumentPipeline}, ::Documenter.Documents.Document) at /Users/tamasnagy/.julia/v0.5/Documenter/src/Selectors.jl:164
 in cd(::Documenter.##2#3{Documenter.Documents.Document}, ::String) at ./file.jl:59
 in #makedocs#1(::Bool, ::Array{Any,1}, ::Function) at /Users/tamasnagy/.julia/v0.5/Documenter/src/Documenter.jl:159
 in (::Documenter.#kw##makedocs)(::Array{Any,1}, ::Documenter.#makedocs) at ./<missing>:0
 in include_from_node1(::String) at ./loading.jl:426
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
while loading /Users/tamasnagy/.julia/v0.5/Gadfly/docs/make.jl, in expression starting on line 5

and this even happens when I change make.jl to only use the index.md page.

using Documenter, Gadfly

makedocs(
    modules = [Gadfly],
    clean = true,
    format = Documenter.Formats.HTML,
    sitename = "Gadfly.jl",
    pages = Any[
        "Home" => "index.md"
    ]
)

where index.md is:

# Gadfly.jl

Gadfly is a system for plotting and visualization written in [Julia](https://julialang.org).
It is based largely on Hadley Wickhams's [ggplot2](http://ggplot2.org/) for R and Leland Wilkinson's book
[The Grammar of Graphics](http://www.cs.uic.edu/~wilkinson/TheGrammarOfGraphics/GOG.html).
It was [Daniel C. Jones'](https://github.com/dcjones) brainchild and is now maintained by
the community.

## Package features

- Renders publication quality graphics to SVG, PNG, Postscript, and PDF
- Intuitive and consistent plotting interface
- Works with [IJulia](https://github.com/JuliaLang/IJulia.jl) out of the box
- Tight integration with [DataFrames.jl](https://github.com/JuliaStats/DataFrames.jl)
- Interactivity like panning, zooming, toggling powered by [Snap.svg](http://snapsvg.io/)
- Supports a large number of common plot types

## Quickstart

The latest release of **Gadfly** can be installed from the Julia REPL prompt with

     ```julia
     julia> Pkg.add("Gadfly")
     ```

This installs the package and any missing dependencies. **Gadfly** can be
loaded with

     ```julia
     julia> using Gadfly
     ```

See the [Plotting](@ref) for more information on plot invocations.

## Manual outline

     ```@contents
     Pages = [
         "man/plotting.md",
         "man/layers.md",
         "man/backends.md",
         "man/themes.md"
    ]
    Depth = 1
    ```

For reference, I'm using my branch of Gadfly: GiovineItalia/Gadfly.jl#879 and this pull-request branch.

@MichaelHatherly
Copy link
Member Author

What's your versioninfo() output? I'll take a look at that branch, not seen an error like that before.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Actually, it looks like Documenter.jl also scans all markdown files even if they are explicitly mentioned in make.jl? Because if I delete everything except for index.md in src/ then the SVG is included.

julia> versioninfo()
Julia Version 0.5.0-rc2+0
Commit 0350e57 (2016-08-12 11:25 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

@MichaelHatherly
Copy link
Member Author

scans all markdown files

Yes, all markdown files are parsed in src/. pages just specifies what will appear in the navmenu.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

all markdown files are parsed in src/.

It must be that Documenter.jl is erroring out on one of the plots then. Is there a way to know which plot it's failing on?

@MichaelHatherly
Copy link
Member Author

Not without stepping through it all probably.

What's the current status of Gadfly's deps for your branch? Should I checkout the master branches for all of them, or are the most recent tags sufficient?

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Most recent tags of everything should work. Also, I just pushed a commit to my branch removing an old markdown file from the previous docs, make sure to grab that version.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

So it looks like it is something src/lib/ that's causing that problem.

@MichaelHatherly
Copy link
Member Author

I'm hitting an InexactError in

docs/src/lib/geoms/geom_histogram.md:48:# Density instead of counts

namely, this block:

# Density instead of counts
plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut",
     Geom.histogram(bincount=30, density=true))
ERROR: LoadError: InexactError()
 in copy!(::Base.LinearFast, ::Array{Int64,1}, ::Base.LinearFast, ::Array{Float64,1}) at ./abstractarray.jl:559
 in broadcast!(::Base.#identity, ::Array{Int64,1}, ::Array{Float64,1}) at ./broadcast.jl:24
 in apply_statistic(::Gadfly.Stat.HistogramStatistic, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /home/mike/.julia/v0.5/Gadfly/src/statistics.jl:330
 in apply_statistics(::Array{Gadfly.StatisticElement,1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /home/mike/.julia/v0.5/Gadfly/src/statistics.jl:38
 in render_prepare(::Gadfly.Plot) at /home/mike/.julia/v0.5/Gadfly/src/Gadfly.jl:740
 in render(::Gadfly.Plot) at /home/mike/.julia/v0.5/Gadfly/src/Gadfly.jl:799
 in show at /home/mike/.julia/v0.5/Gadfly/src/Gadfly.jl:965 [inlined]
 in verbose_show(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("image/svg+xml")}, ::Gadfly.Plot) at ./multimedia.jl:50
 in #sprint#304(::Void, ::Function, ::Int64, ::Function, ::MIME{Symbol("image/svg+xml")}, ::Vararg{Any,N}) at ./strings/io.jl:37
 in stringmime(::MIME{Symbol("image/svg+xml")}, ::Gadfly.Plot) at ./multimedia.jl:65
 in runner(::Type{Documenter.Expanders.ExampleBlocks}, ::Base.Markdown.Code, ::Documenter.Documents.Page, ::Documenter.Documents.Document) at /home/mike/.julia/v0.5/Documenter/src/Expanders.jl:457
 in dispatch(::Type{Documenter.Expanders.ExpanderPipeline}, ::Base.Markdown.Code, ::Documenter.Documents.Page, ::Documenter.Documents.Document) at /home/mike/.julia/v0.5/Documenter/src/Selectors.jl:164
 in expand(::Documenter.Documents.Document) at /home/mike/.julia/v0.5/Documenter/src/Expanders.jl:29
 in dispatch(::Type{Documenter.Builder.DocumentPipeline}, ::Documenter.Documents.Document) at /home/mike/.julia/v0.5/Documenter/src/Selectors.jl:164
 in cd(::Documenter.##2#3{Documenter.Documents.Document}, ::String) at ./file.jl:59
 in #makedocs#1(::Bool, ::Array{Any,1}, ::Function) at /home/mike/.julia/v0.5/Documenter/src/Documenter.jl:159
 in (::Documenter.#kw##makedocs)(::Array{Any,1}, ::Documenter.#makedocs) at ./<missing>:0
 in include_from_node1(::String) at ./loading.jl:426
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
while loading /home/mike/.julia/v0.5/Gadfly/docs/make.jl, in expression starting on line 5

Error doesn't look quite the same as yours though.

@MichaelHatherly
Copy link
Member Author

Btw I was using this diff to see the last @example block:

diff --git a/src/Expanders.jl b/src/Expanders.jl
index b3f9993..8176f97 100644
--- a/src/Expanders.jl
+++ b/src/Expanders.jl
@@ -424,6 +424,9 @@ end
 # --------

 function Selectors.runner(::Type{ExampleBlocks}, x, page, doc)
+
+    println(x.code)
+
     matched = Utilities.nullmatch(r"^@example[ ]?(.*)$", x.language)
     isnull(matched) && error("invalid '@example' syntax: $(x.language)")
     # The sandboxed module -- either a new one or a cached one from this page.

@MichaelHatherly
Copy link
Member Author

And another InexactError on

docs/src/lib/stats/stat_y_jitter.md:25:plot(x=rand(500), y=rand(1:4, 500), Stat.y_jitter(range=0.5), Geom.point)

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

These InexactErrors are worrisome. I appreciate the sleuthing, but this looks like stuff that is broken in Gadfly.

Are Gadfly's tests passing for you?

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Also, I can confirm that when I eliminate the files with breakage, I get beautiful embedded SVGs 👍

@MichaelHatherly
Copy link
Member Author

Are Gadfly's tests passing for you?

I'll give that a try shortly.

@MichaelHatherly
Copy link
Member Author

Also, I can confirm that when I eliminate the files with breakage, I get beautiful embedded SVGs 👍

Ok, great. Would be nice to get the nice interactive plots too, but for now I'll merge this and add it to the next point release, hopefully to be released in the next few days.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Interactive plots are nice, but not a necessity. Thanks for looking into this!

Allow `image/svg+xml` output for `at-example` blocks when the object
to be displayed is capable of output the format. Should help with #229,
but is not yet a completely general solution.
@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Some of the InexactErrors were caused by this bug in Base: JuliaLang/julia#18122. So I think running on master should fix some of these problems.

@MichaelHatherly
Copy link
Member Author

Seems like that probably fixes that one, though on master I'm getting some package version conflicts that I'll need to sort out tomorrow.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 23, 2016

Seems like that probably fixes that one, though on master I'm getting some package version conflicts that I'll need to sort out tomorrow.

I appreciate the help, it doesn't look like JuliaLang/julia#18122 made into RC3 because I'm still getting this error on that version.

@MichaelHatherly
Copy link
Member Author

I appreciate the help

No prob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants