diff --git a/Manifest.toml b/Manifest.toml index bd44108..a2a5986 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -162,9 +162,9 @@ version = "1.0.2" [[Pages]] deps = ["HTTP", "JSON", "PlotlyBase", "Sockets", "Test"] -path = "C:\\Users\\Eric\\.julia\\dev\\Pages" +git-tree-sha1 = "332f7eb1ad0b59f130bae643db6e0ea76b1146d2" uuid = "7c165e09-dada-5b64-9fdc-39b801c58527" -version = "0.2.1+" +version = "0.2.2" [[Pidfile]] deps = ["FileWatching", "Test"] diff --git a/README.md b/README.md index 0b29ff5..7e3bcc1 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,90 @@ [![][travis-img]][travis-url] [![][appveyor-img]][appveyor-url] +`Figures.jl` is a simple package that creates draggable figures in a browser window to display plots from various plotting packages. It currently works with `PlotlyJS.jl`. + +### Example + +```julia +julia> using PlotlyJS, Figures +julia> Figures.start() # You can enter a port, e.g. Figures.start(3000). Default is 8000. +``` + +This launches a server on localhost. Opening the browser to `http://localhost:8000` will show a blank page. + +Running + +```julia +julia> figure(1) +``` + +displays a draggable figure in the browser. + +![Figure 1](docs/images/figure1.png) + + +Running + +```julia +julia> function linescatter1() + trace1 = PlotlyJS.scatter(;x = 1:4, y = rand(4), mode = "markers") + trace2 = PlotlyJS.scatter(;x = 2:5, y = rand(4), mode = "lines") + trace3 = PlotlyJS.scatter(;x = 1:4, y = rand(4), mode = "lines+markers") + PlotlyJS.plot([trace1, trace2, trace3]) |> display +end +julia> linescatter1() +``` + +displays the interactive PlotlyJS chart in the figure. + +![Plotly Chart 1](docs/images/plotly1.png) + +A second figure can be created by running + +```julia +julia> figure(2) +julia> linescatter1() +``` + +![Plotly Chart 2](docs/images/plotly2.png) + +In addition to creating figures, the `figure` method can make an existing figure active again so that subsequent plots will be rendered on the active figure, e.g. + +```julia +julia> figure(1) +julia> linescatter1() +``` + +will display a new chart on the existing figure. + +You can add as many figures to the browser as you like + +![Plotly Chart 3](docs/images/plotly3.png) + +To remove figures, there is the method + +```julia +julia> closeall() +``` + +which closes all figures and + +```julia +julia> close(1) +``` + +which closes the specified figure. + +Alternatively, figures can be closed directly in the browser by double clicking them. + +### To Do + +* Add support for `VegaLite.jl` +* Add support for `Plots.jl` +* Add support for resizing figures, etc. [travis-img]: https://travis-ci.org/EricForgy/Figures.jl.svg?branch=master [travis-url]: https://travis-ci.org/EricForgy/Figures.jl [appveyor-img]: https://ci.appveyor.com/api/projects/status/github/EricForgy/Figures.jl?branch=master&svg=true -[appveyor-url]: https://ci.appveyor.com/project/EricForgy/figures-jl \ No newline at end of file +[appveyor-url]: https://ci.appveyor.com/project/EricForgy/figures-jl diff --git a/REQUIRE b/REQUIRE index c7dd12d..1743c37 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,3 @@ julia 1.0 Pages -Requires -Test \ No newline at end of file +Requires \ No newline at end of file diff --git a/docs/images/figure1.png b/docs/images/figure1.png new file mode 100644 index 0000000..2986320 Binary files /dev/null and b/docs/images/figure1.png differ diff --git a/docs/images/plotly1.png b/docs/images/plotly1.png new file mode 100644 index 0000000..8048408 Binary files /dev/null and b/docs/images/plotly1.png differ diff --git a/docs/images/plotly2.png b/docs/images/plotly2.png new file mode 100644 index 0000000..0c48b81 Binary files /dev/null and b/docs/images/plotly2.png differ diff --git a/docs/images/plotly3.png b/docs/images/plotly3.png new file mode 100644 index 0000000..d990f89 Binary files /dev/null and b/docs/images/plotly3.png differ diff --git a/src/Figures.jl b/src/Figures.jl index f880039..47bc6fe 100644 --- a/src/Figures.jl +++ b/src/Figures.jl @@ -33,6 +33,9 @@ function close(id::String) end close(id) = close(string(id)) +start(port=8000) = @async Pages.start(port) +syncstart(port=8000) = Pages.start(port) + function __init__() @require PlotlyJS="f0f68f2c-4968-5e81-91da-67840de0976a" include("packages/plotlyjs.jl") @@ -52,8 +55,6 @@ function __init__() read(joinpath(@__DIR__,"..","libs","plotly.min.js"),String) end - @async Pages.start() - pushdisplay(Display()) end