|
1 | | -## Basics |
| 1 | +## Preliminaries |
2 | 2 |
|
3 | | -[plotly.js][_plotlyjs] figures are constructed by calling the function: |
| 3 | +PlotlyJS.jl is a Julia package that relies on the [plotly.js](https://plotly.com/javascript/) JavaScript library. |
| 4 | + |
| 5 | +In that library, figures are constructed by calling the function: |
4 | 6 |
|
5 | 7 | ```js |
6 | 8 | Plotly.newPlot(divid, data, layout, config, frames) |
7 | 9 | ``` |
8 | 10 |
|
9 | 11 | where |
10 | 12 |
|
11 | | -- `divid` is an html `div` element where the plot should appear |
12 | | -- `data` is an array of JSON objects describing the various `trace`s in the visualization |
13 | | -- `layout` is a JSON object describing the layout properties of the visualization. |
14 | | -- `config` is a JSON object describing the configuration properties of the visualization. See more detail [here](https://plotly.com/javascript/configuration-options/) |
15 | | -- `frames` can contain data and layout objects, which define any changes to be animated, and a traces object that defines which traces to animate. |
16 | | - |
17 | | -The `divid` argument is handled automatically by one of the supported |
18 | | -frontends, so users of this package will mostly be concerned about constructing |
19 | | -the `data`, `layout`, and (optionally) `config` and `frames` arguments. |
20 | | - |
21 | | -For a complete list of traces and their attributes see the [plotly.js chart attribute reference][_plotlyref]. |
22 | | - |
23 | | -<!-- As of version 0.6.0 of this package you can also view a local version of this |
24 | | -page that is a bit easier to navigate by calling the `PlotlyJS.docs()` function |
25 | | -from the Julia prompt. This will open an electron window with a local webpage |
26 | | -containing a version of that reference page. --> |
| 13 | +- `data` is an array of [JSON](https://developer.mozilla.org/en-US/docs/Glossary/JSON) objects |
| 14 | + describing the various data _traces_ in the visualization (see Note) |
| 15 | +- `layout` is a JSON object describing the presentation properties of the visualization |
| 16 | +- `config` is a JSON object describing the configuration properties of the visualization |
| 17 | + (see more detail [here](https://plotly.com/julia/configuration-options/)) |
| 18 | +- `frames` can contain data and layout objects, which define any changes to be animated, |
| 19 | + and a traces object that defines which traces to animate. |
| 20 | + |
| 21 | +The `divid` argument refers to an [html `<div>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/div) |
| 22 | +to control the plot on a page and is handled automatically by one of the supported |
| 23 | +front-ends. Users of this package will mostly be concerned about constructing |
| 24 | +the `data` and the `layout`, and (optionally) `config` and `frames` arguments. |
| 25 | + |
| 26 | +!!! note |
| 27 | + A _trace_ is a general term for how data is shown graphically on a plot, |
| 28 | + whether it is a scatter plot, bar chart, 3D surface, choropleth map or some other plot type. |
| 29 | + A trace is fundamentally a collection of data and the specifications of how that data should be plotted. |
| 30 | + For a complete list of traces and their attributes see the |
| 31 | + [plotly figure reference](https://plotly.com/julia/reference/). |
| 32 | + |
| 33 | +When we want to construct a `Plot` in PlotlyJS.jl for plotting on some display, we will usually have |
| 34 | +at least one trace `tr` along with a layout object `ly` which we combine together as `Plot(tr, ly)`. |
| 35 | +If we don't have a layout object then a template will supply a default layout for us. |
27 | 36 |
|
28 | 37 | ## Julia types |
29 | 38 |
|
30 | | -There are a handful of core Julia types for representing a visualization |
| 39 | +There are a handful of core Julia types for representing a visualization. |
31 | 40 |
|
32 | | -These are |
| 41 | +The `data`, `layout`, `frames`, `divid` and `config` fields of the `Plot` type, shown below, |
| 42 | +map to the arguments to the `Plotly.newplot` function. |
| 43 | +These types are defined in the PlotlyBase.jl package (a dependency of PlotlyJS.jl). |
| 44 | +These are shown (in a much simplified form) here: |
33 | 45 |
|
34 | 46 | ```julia |
35 | 47 | abstract type AbstractTrace end |
36 | 48 | abstract type AbstractLayout end |
37 | 49 |
|
38 | | -mutable struct GenericTrace{T <: AbstractDict{Symbol,Any}} <: AbstractTrace |
39 | | - fields::T |
| 50 | +mutable struct GenericTrace <: AbstractTrace |
| 51 | + fields::Dict{Symbol,Any} |
40 | 52 | end |
41 | 53 |
|
42 | | -mutable struct Layout{T <: AbstractDict{Symbol,Any}} <: AbstractLayout |
43 | | - fields::T |
44 | | - subplots::_Maybe{Subplots} |
| 54 | +mutable struct Layout <: AbstractLayout |
| 55 | + fields::Dict{Symbol,Any} |
| 56 | + subplots::Subplots |
45 | 57 | end |
46 | 58 |
|
47 | | -mutable struct PlotlyFrame{T <: AbstractDict{Symbol,Any}} <: AbstractPlotlyAttribute |
48 | | - fields::T |
| 59 | +mutable struct PlotlyFrame <: AbstractPlotlyAttribute |
| 60 | + fields::Dict{Symbol,Any} |
49 | 61 | end |
50 | 62 |
|
51 | | -mutable struct Plot{TT<:AbstractVector{<:AbstractTrace},TL<:AbstractLayout,TF<:AbstractVector{<:PlotlyFrame}} |
52 | | - data::TT |
53 | | - layout::TL |
| 63 | +mutable struct PlotConfig |
| 64 | + scrollZoom::Union{Nothing,Bool} = true |
| 65 | + editable::Union{Nothing,Bool} = false |
| 66 | + staticPlot::Union{Nothing,Bool} = false |
| 67 | +... |
| 68 | +end |
| 69 | + |
| 70 | +mutable struct Plot |
| 71 | + data::Vector{<:AbstractTrace} |
| 72 | + layout::AbstractLayout |
| 73 | + frames::Vector{<:PlotlyFrame} |
54 | 74 | divid::UUID |
55 | 75 | config::PlotConfig |
56 | | - frames::TF |
57 | 76 | end |
58 | 77 | ``` |
59 | 78 |
|
60 | | -The `data`, `layout`, `divid`, `config`, and `frames` fields of the `Plot` type map 1-1 to the arguments to the `Plotly.newplot` function. |
61 | | - |
62 | | - |
63 | | -[_plotlyjs]: https://plotly.com/javascript/ |
64 | | -[_plotlyref]: https://plotly.com/julia/reference/ |
| 79 | +The `data` field of the `Plot` type can be constructed from a single trace or a vector of multiple traces. |
| 80 | +Each trace is itself made up of a `Dict` type holding information about the type of trace |
| 81 | +and its data along with attributes for customising the plotting of that data. |
0 commit comments