Utilities
SomeGraphs.Utilities
—
Module
Utility functions for defining graph types. We do not re-export all symbols from this sub-module to the global
SomeGraphs
namespace. You can safely ignore these unless you are implementing a new graph type.
SomeGraphs.Validations.Maybe
—
Type
Maybe{T} = Union{T, Nothing}
The type to use when maybe there is a value, maybe there isn't. This is exactly as if writing the explicit
Union
with
Nothing
but is shorter and more readable. This is extremely common.
SomeGraphs.Common.validate_graph
—
Function
validate_graph(::Graph)::Maybe{AbstractString}
Validate that the combination of data and configuration in a graph is valid, after validating each one separately. This isn't invoked manually, instead it is called by the overall
validate
of the graph. It is provided (with a default empty implementation) to allow for type-specific validations.
SomeGraphs.Common.graph_to_figure
—
Function
graph_to_figure(graph::Graph)::PlotlyFigure
Render a graph given its data and configuration. Technically this just converts the graph to a
PlotlyFigure
which Julia knows how display for us, rather than actually display the graph. The implementation depends on the specific graph type.
You can just write
graph.fig
instead of
graph_to_figure(graph)
.
When saving a figure to a file, Plotly in its infinite wisdom ignores the graph
width
and
height
specified inside the figure, (except for saving HTML file). You should therefore use
save_graph
rather than call
savefig
on the result of
graph_to_figure
.
SomeGraphs.Common.graph_to_json
—
Function
graph_to_json(graph::Graph)::AbstractString
Render a graph given its data and configuration, as a JSON string describing the Plotly figure. Since this is plain text, it can be handed to any other programming language that has a Plotly binding (e.g., to display the interactive graph in a Python or R Jupyter notebook).
You can just write
graph.json
instead of
graph_to_json(graph)
.
SomeGraphs.Common.graph_to_image
—
Function
graph_to_image(graph::Graph, format::AbstractString)::Vector{UInt8}
Render a graph as a static image in the
format
(e.g.
"svg"
or
"png"
), in memory. Unlike the Plotly
savefig
function, this obeys the
width
and
height
of the graph's configuration: the image is exactly that size. A graph which doesn't set them gets Plotly's default size (700 by 450 pixels), as an interactive graph does. Rendering an image starts a Kaleido process, which is slow the first time.
You can just write
graph.svg
(as a string) or
graph.png
instead.
SomeGraphs.Common.graph_to_html
—
Function
graph_to_html(graph::Graph; standalone::Bool = false)::String
Render a graph as an HTML page, which shows the interactive Plotly figure. The page loads plotly.js from the internet, unless it is
standalone
, and then it includes it (a few megabytes), so it works offline. This is what
save_graph
writes to an
.html
file.
You can just write
graph.html
(or
graph.standalone_html
) instead.
SomeGraphs.Utilities.plotly_figure
—
Function
plotly_figure(trace::GenericTrace, layout::Layout)::PlotlyFigure
plotly_figure(traces::AbstractVector{<:GenericTrace}, layout::Layout)::PlotlyFigure
Wrap a
trace
or a set of
traces
with the accompanying
layout
in a
PlotlyFigure
.
SomeGraphs.Utilities.validate_colors
—
Function
validate_colors(
colors_data_context::ValidationContext,
colors_data::Maybe{Union{AbstractVector{<:AbstractString}, AbstractVector{<:Real}}},
colors_configuration_context::ValidationContext,
colors_configuration::ColorsConfiguration,
mask::Maybe{Union{AbstractVector{Bool},BitVector}} = nothing,
)::Nothing
validate_colors(
colors_data_context::ValidationContext,
colors_data::AbstractMatrix{<:Real},
colors_configuration_context::ValidationContext,
colors_configuration::ColorsConfiguration,
mask::Nothing = nothing,
)::Nothing
Validate that the
colors_data
from the
colors_data_context
is valid and consistent with the
colors_configuration
from the
colors_configuration_context
. For example, if the color configuration contains a categorical color mapping, this will validate that all the color names in the data are valid keys of this mapping.
If a
mask
is specified, do not validate colors in the data whose matching value in the mask is false. A mask is not supported for a matrix of colors.
SomeGraphs.Utilities.fill_color
—
Function
fill_color(line_color::Maybe{AbstractString})::Maybe{AbstractString}
Return a fill color based on a
line_color
. The fill color is twice as transparent as the line color.
SomeGraphs.Utilities.ConfiguredColors
—
Type
@kwdef mutable struct ConfiguredColors
colors_title::Maybe{AbstractString}
colors_configuration::ColorsConfiguration
colors_scale_index::Maybe{Integer}
original_color_values::Maybe{
Union{AbstractVector{<:AbstractString}, AbstractVector{<:Real}, AbstractMatrix{<:Real}},
}
final_colors_values::Maybe{
Union{AbstractVector{<:AbstractString}, AbstractVector{<:Real}, AbstractMatrix{<:Real}},
}
final_colors_range::Maybe{Range}
final_categorical_palette::Maybe{CategoricalColors} = nothing
scaled_colors_palette::Maybe{AbstractVector{<:Tuple{Real, AbstractString}}}
show_in_legend::Bool
show_scale::Bool
end
Colors data after applying the configuration. The
final_categorical_palette
is the categorical palette of categorical colors, either as configured or (for
AutomaticColors
) as picked automatically.
SomeGraphs.Utilities.configured_colors
—
Function
configured_colors(;
colors_configuration::ColorsConfiguration,
colors_title::Maybe{AbstractString},
colors_values::Maybe{Union{AbstractVector{<:Real}, AbstractVector{<:AbstractString}, AbstractMatrix{<:Real}}},
next_colors_scale_index::AbstractVector{<:Integer},
mask::Maybe{Union{AbstractVector{Bool}, BitVector, AbstractMatrix{Bool}, BitMatrix}} = nothing,
)::ConfiguredColors
Apply the colors configuration to the colors data. The
mask
(if any) marks the shown entities; the hidden ones get no categorical color, and are left out of the implicit range of the colors scale unless the scale
include_hidden
is set. An empty categorical value gets the color of the empty value in the palette. If the palette has none, it gets no color.
SomeGraphs.Utilities.validate_axis_sizes
—
Function
validate_axis_sizes(;
axis_name::AbstractString,
graphs_gap::Maybe{Real} = nothing,
n_graphs::Integer = 1,
annotation_size::AnnotationSize,
n_annotations::Integer,
dendogram_size::Maybe{Real} = nothing,
pixel_length::Real,
)::Nothing
Verify there is at least some space left for the actual graph after leaving space for gaps and/or annotations. These are in pixels, and the
pixel_length
is the most the axis may have: the length which the configured margins leave in the figure (see
MarginsConfiguration
). The margins grow to hold the content of their sides, so the axis may end up shorter; the layout then scales the gaps, annotations and dendogram down to at most a third of the axis.
SomeGraphs.Utilities.validate_values
—
Function
validate_values(
values_data_context::ValidationContext,
values_data::Maybe{AbstractVector{<:Real}},
axis_configuration_context::ValidationContext,
axis_configuration::AxisConfiguration,
)::Nothing
Validate that the
values_data
from the
values_data_context
is valid and consistent with the
axis_configuration
from the
axis_configuration_context
. Specifically this ensures that if a
log_base
is applied, all the values are positive.
SomeGraphs.Utilities.validate_numeric_values
—
Function
validate_numeric_values(
context::ValidationContext,
field::AbstractString,
values::Maybe{AbstractVector};
is_required::Bool = false,
)::Nothing
Validate that the
values
of a
VectorValuesData
field
are numeric and finite (if specified, or at all if
is_required
).
SomeGraphs.Utilities.numeric_values
—
Function
numeric_values(values_data::VectorValuesData)::Maybe{AbstractVector{<:Real}}
The values of a
VectorValuesData
which was validated to be numeric.
SomeGraphs.Utilities.shared_values_title
—
Function
shared_values_title(
context::ValidationContext,
field::AbstractString,
role::AbstractString,
values_datas::AbstractVector{VectorValuesData},
)::Maybe{AbstractString}
The title shared by the
values_datas
of the
role
of the entries of a
field
(e.g., the
x
of each of the
lines
): the one non-
nothing
title among them. Two different titles are an error.
SomeGraphs.Utilities.masked_values
—
Function
masked_values(
values::Maybe{AbstractVector},
mask::Maybe{Union{AbstractVector{Bool}, BitVector}},
order::Maybe{AbstractVector{<:Integer}},
)::Maybe{AbstractVector}
Reorder the
values
by the
order
(if any) and keep only the entries whose
mask
is true (if any). The result is shorter than the input when a mask is given.
SomeGraphs.Utilities.entities_hovers
—
Function
entities_hovers(entities::VectorEntitiesData)::Maybe{AbstractVector{<:AbstractString}}
The hover to show for each of the
entities
: its name, followed by whatever its
hovers
say in addition to it. This is
nothing
if the entities have neither.
SomeGraphs.Utilities.displayed_annotations
—
Function
displayed_annotations(
annotations::AbstractVector{AnnotationData},
order::Maybe{AbstractVector{<:Integer}},
)::AbstractVector{AnnotationData}
The annotations which are actually drawn, in the order they are drawn in: reordered by the
order
, leaving out the ones that are not
is_shown
. A hidden annotation gives up its place, so the rest of the row closes up.
SomeGraphs.Utilities.scale_axis_value
—
Function
scale_axis_value(scale_configuration::ScaleConfiguration, value::Real; clamp::Bool = true)::Float64
scale_axis_value(scale_configuration::ScaleConfiguration, value::Nothing; clamp::Bool = true)::Nothing
Scale a single
value
according to the
scale_configuration
. This deals with log scales and percent scaling. By default,
clamp
the values to a specified explicit range.
SomeGraphs.Utilities.scale_axis_values
—
Function
scale_axis_values(
scale_configuration::ScaleConfiguration,
values::AbstractVector{<:Maybe{Real}};
clamp::Bool = true,
copy::Bool = false,
)::AbstractVector{<:Maybe{AbstractFloat}}
scale_axis_values(
scale_configuration::ScaleConfiguration,
values::AbstractMatrix{<:Maybe{Real}};
clamp::Bool = true,
copy::Bool = false,
)::AbstractMatrix{<:Maybe{AbstractFloat}}
scale_axis_values(
scale_configuration::ScaleConfiguration,
values::Nothing;
clamp::Bool = true,
copy::Bool = false,
)::Nothing
Scale a vector (or a matrix) of
values
according to the
scale_configuration
. This deals with log scales and percent scaling. By default,
clamp
the values to a specified explicit range. If
copy
we always return a copy of the data (so it can be safely modified further without impacting the original data). If the
values
are
nothing
, so is the result.
SomeGraphs.Utilities.plotly_axis_value
—
Function
plotly_axis_value(scale_configuration::ScaleConfiguration, scaled_value::Real; is_plotly_log::Bool)::Real
plotly_axis_value(scale_configuration::ScaleConfiguration, scaled_value::Nothing; is_plotly_log::Bool)::Nothing
Convert a single
scaled_value
(as returned by
scale_axis_value
) to the coordinate Plotly expects. If
is_plotly_log
, a
Log10Base
axis is a Plotly log axis (see
set_layout_axis!
), which expects the real (not log) value. Otherwise, this returns the scaled value.
SomeGraphs.Utilities.plotly_axis_values
—
Function
plotly_axis_values(
scale_configuration::ScaleConfiguration,
scaled_values::AbstractVector{<:Maybe{Real}};
is_plotly_log::Bool,
)::AbstractVector{<:Maybe{Real}}
Convert a vector of
scaled_values
(as returned by
scale_axis_values
) to the coordinates Plotly expects. See
plotly_axis_value
.
SomeGraphs.Utilities.scale_size_values
—
Function
scale_size_values(
sizes_configuration::SizesConfiguration,
values::Maybe{AbstractVector{<:Real}},
mask::Maybe{Union{AbstractVector{Bool}, BitVector}} = nothing,
)::Maybe{AbstractVector{<:Real}}
Scale a vector of
values
according to
sizes_configuration
. The
mask
(if any) marks the shown entities; the hidden ones are left out of the implicit range of the sizes unless the scale
include_hidden
is set.
SomeGraphs.Utilities.SizesLegendEntry
—
Type
@kwdef struct SizesLegendEntry
value::Real
pixel_size::Real
label::AbstractString
end
An entry of the legend of sizes. The
value
includes the
log_regularization
(if any). It is drawn with a symbol of the
pixel_size
, labeled by the
label
. The
label
shows the value the way the ticks of an axis with the same scale do: the value for a linear or a
Log10Base
scale, and the log value (the power) for a
Log2Base
scale.
SomeGraphs.Utilities.sizes_legend_entries
—
Function
sizes_legend_entries(
sizes_configuration::SizesConfiguration,
values::AbstractVector{<:Real},
mask::Maybe{Union{AbstractVector{Bool}, BitVector}} = nothing,
)::AbstractVector{SizesLegendEntry}
The entries of the legend of the sizes
values
, as mapped by the
sizes_configuration
(see
scale_size_values
).
The entries are "nice" values, chosen the way ticks are. For a linear scale these are multiples of a step of 1, 2 or 5 times a power of 10. For a
Log10Base
scale these are the digits, or 1, 2 and 5, or the powers of 10 (or of 100 etc.). If the range is too small for these, it uses linear steps instead. For a
Log2Base
scale, these are linear steps of the log values. This uses the finest step whose entries are at least 1 pixel apart, with no more than 6 entries. If that gives fewer than 3 entries, it uses the next finer step instead, if its entries are at least 1 pixel apart (it has at most 8 entries). If fewer than 2 such values fit in the range, the entries are the ends of the range. If all the values are the same, there is a single entry.
If a value was clamped to the
minimum
(or
maximum
) of the scale, the end of the legend is at that value, with a "≤ " (or "≥ ") prefix. It replaces the nearest entry if that is less than 1 pixel away, and is added to the entries otherwise.
SomeGraphs.Utilities.text_width
—
Function
text_width(text::AbstractString; font_size::Real = 12)::Float64
The width in pixels of a
text
written in Lato (the default font) of
font_size
pixels. This adds the advance width of each character and the kerning of each pair of adjacent characters, from the Lato font which Kaleido bundles. A character which is not in the table counts as the widest one. Plotly's own measure of a text (in Kaleido) may be up to 0.6 pixels wider.
SomeGraphs.Utilities.SidesContent
—
Type
@kwdef mutable struct SidesContent
least_plot_width::Float64
least_plot_height::Float64
left::Float64 = 0
right::Float64 = 0
top::Float64 = 0
bottom::Float64 = 0
end
SidesContent(figure_configuration::FigureConfiguration)
How far the content beyond the plot's area reaches on each side, in pixels. This is the tick labels, the titles of the axes and of the figure, the titles of the annotations, and the side panel. A graph makes one of these for its layout. Each part of the layout grows each side to the farthest it reaches. Each margin is then the content of its side plus the configured margin (see
set_layout_margins!
).
A label near an end of its axis may reach past that end, into the side next to it. How far it is from that end is bounded from below by the
least_plot_width
and
least_plot_height
of the plot's area. Made from a
figure_configuration
, these are half the figure's width and height, or half of Plotly's default size (700 by 450 pixels) when the figure doesn't set them.
SomeGraphs.Utilities.plotly_layout
—
Function
plotly_layout(
figure_configuration::FigureConfiguration;
sides_content::SidesContent,
title::Maybe{AbstractString},
has_legend::Bool,
has_hovers::Bool = false,
shapes::Maybe{AbstractVector{Shape}} = nothing,
)::Layout
Create a Plotly
Layout
object. If
has_legend
, the legends are shown; each is set by
set_layout_legend!
.
The
title
(if any) is drawn below the top of the figure, separated from it by the top margin (see
MarginsConfiguration
). It is added to the
sides_content
. The margins themselves are set by
set_layout_margins!
.
SomeGraphs.Utilities.plotly_legend
—
Function
plotly_legend(index::Integer)::String
The name of the Plotly legend of an
index
:
legend
for 1, and
legend2
,
legend3
, etc. for the rest. A trace is shown in a legend by giving this name as its
legend
.
SomeGraphs.Utilities.set_layout_legend!
—
Function
set_layout_legend!(layout::Layout, index::Integer; title::Maybe{AbstractString})::Nothing
Set the Plotly legend of an
index
(see
plotly_legend
) in a
layout
, with its
title
. Its place is set by
place_side_panel!
.
SomeGraphs.Utilities.place_side_panel!
—
Function
place_side_panel!(
layout::Layout,
figure_configuration::FigureConfiguration,
items::AbstractVector{SidePanelItem};
sides_content::SidesContent,
)::Nothing
Place the legends and color bars of the
items
in the side panel to the right of the plot, as described in
FigureConfiguration
, and add its width to the right of the
sides_content
. This must be called after everything else was added to the
layout
, and before
set_layout_margins!
.
Plotly can't place a legend at a pixel offset, so a legend is anchored at the plot's right edge, with its entries indented to its column, and a transparent background. Plotly doesn't indent the legend's title, so this is drawn as a text label above the legend's (transparent) title. A color bar is placed at its column by its padding.
SomeGraphs.Utilities.set_layout_margins!
—
Function
set_layout_margins!(
layout::Layout,
figure_configuration::FigureConfiguration,
sides_content::SidesContent,
)::Nothing
Set each margin of the
layout
to how far the
sides_content
reaches on that side, plus that side's margin in the
figure_configuration
. This must be called last, when the
sides_content
is complete.
SomeGraphs.Utilities.plotly_title
—
Function
plotly_title(title::Maybe{AbstractString})::Maybe{AbstractDict}
Return the Plotly form of a
title
(of the figure, an axis, a color bar, ...), or
nothing
if there is none. Plotly ignores a title given as a plain string, so it is given as the
text
of the title.
SomeGraphs.Utilities.axis_ticks_prefix
—
Function
axis_ticks_prefix(scale_configuration::ScaleConfiguration)::Maybe{AbstractString}
Return the prefix for the ticks of a
scale_configuration
.
SomeGraphs.Utilities.axis_ticks_suffix
—
Function
axis_ticks_suffix(scale_configuration::ScaleConfiguration)::Maybe{AbstractString}
Return the suffix for the ticks of a
scale_configuration
.
SomeGraphs.Utilities.axis_screen_ticks_angle
—
Function
axis_screen_ticks_angle(ticks_angle::Nothing, is_vertical_axis::Bool)::Real
axis_screen_ticks_angle(ticks_angle::Real, is_vertical_axis::Bool)::Real
Convert the axis-relative
ticks_angle
(0 = parallel to the axis, ±90 = perpendicular) to the screen angle used by Plotly's
tickangle
(0 = horizontal). A vertical axis is parallel when standing the text up (bottom-to-top, -90). A
nothing
angle keeps the labels horizontal, the readable orientation for numbers regardless of the axis direction.
The screen angle is always between -90 and 90, so the text is never upside down. A label of a vertical axis at a negative
ticks_angle
lies on the same line it would at
ticks_angle - 90
, but reads the other way.
SomeGraphs.Utilities.set_layout_axis!
—
Function
set_layout_axis!(
layout::Layout,
axis::Maybe{AbstractString},
axis_configuration::AxisConfiguration;
sides_content::SidesContent,
title::Maybe{AbstractString} = nothing,
range::Maybe{Range} = nothing,
labels_range::Maybe{Range} = range,
ticks_labels::Maybe{AbstractVector{<:AbstractString}} = nothing,
ticks_values::Maybe{AbstractVector{<:Real}} = nothing,
domain::Maybe{AbstractVector{<:Real}} = nothing,
is_tick_axis::Bool = true,
is_zeroable::Bool = true,
is_reversed::Bool = false,
is_plotly_log::Bool = false,
)::Nothing
Add a Plotly
axis
in a
layout
using the
axis_configuration
. The
axis
is the name given by
plotly_axis
, which must not be
nothing
. If
is_reversed
, the axis runs backwards (right to left, or top to bottom), which is how the left (or lower) side of a mirrored bars graph grows away from the axis it shares with the other side.
The
ticks_values
and
ticks_labels
(if any) give explicit ticks. Unless
is_tick_axis
, no ticks are shown at all. Unless
is_zeroable
, the zero line is left to Plotly (otherwise, it is shown for linear scales only).
If
is_plotly_log
, a
Log10Base
axis is a Plotly log axis, which picks its own ticks for the real (not log) values. The coordinates on such an axis must be given by
plotly_axis_values
. The
range
is still the scaled (log) range.
The axis' tick labels and title are added to the
sides_content
, which the margins are computed from. The labels are the
ticks_labels
, or else the widest Plotly could pick for the
labels_range
. This is the
range
by default. When Plotly picks the range itself (no
range
), it must be given as the widest range Plotly may pick. Plotly draws the title just beyond the labels.
SomeGraphs.Utilities.set_layout_twin_log_axis!
—
Function
set_layout_twin_log_axis!(;
layout::Layout,
letter::AbstractString,
twin_index::Integer,
axis_configuration::AxisConfiguration,
title::Maybe{AbstractString},
range::Range,
sides_content::SidesContent,
)::Nothing
Add the 1st Plotly
letter
axis in a
layout
for a
Log10Base
axis_configuration
, for traces that must be given the scaled (log) values. This is needed when Plotly computes something from the values (such as a histogram), since it would compute it from the real values on a Plotly log axis.
The 1st axis is a hidden linear axis, which the traces use. A twin Plotly log axis (at the
twin_index
) is drawn over it, with the same range, so it shows the ticks of the real values. Plotly only draws it where a trace uses it (see
push_twin_log_axis_traces!
). The twin axis' labels and title are added to the
sides_content
(see
set_layout_axis!
).
SomeGraphs.Utilities.push_twin_log_axis_traces!
—
Function
push_twin_log_axis_traces!(
traces::AbstractVector{GenericTrace};
letter::AbstractString,
twin_index::Integer,
n_cross_axes::Integer = 1,
)::Nothing
Push to the
traces
an empty trace on the twin Plotly log axis (see
set_layout_twin_log_axis!
) for each of the
n_cross_axes
of the other letter, since Plotly only draws an axis (and its grid) in the sub-graphs where a trace uses it.
SomeGraphs.Utilities.set_layout_colorscale!
—
Function
set_layout_colorscale!(;
layout::Layout,
colors_scale_index::Integer,
colors_configuration::ColorsConfiguration,
scaled_colors_palette::Maybe{AbstractVector{<:Tuple{Real, AbstractString}}},
range::Maybe{Range} = nothing,
ticks_range::Maybe{Range} = range,
title::Maybe{AbstractString},
show_scale::Bool,
figure_configuration::FigureConfiguration,
side_panel_items::AbstractVector{SidePanelItem},
sides_content::SidesContent,
)::Nothing
Set a
colorscale
in a Plotly
layout
, as specified by a
colors_configuration
. A shown scale is a color bar, which is pushed to the
side_panel_items
to be placed by
place_side_panel!
.
A Plotly color bar shows the ticks of its (scaled) values. For a
Log10Base
scale these are the log values, so a shown
Log10Base
scale gets its own ticks instead, which show the real values. They are chosen in the
ticks_range
, which must be given, the way Plotly chooses the ticks of a log axis.
A color bar's length is a fraction of the plot's area, so its ticks depend on the plot's height. This must therefore be called after everything above and below the plot's area was added to the
sides_content
.
SomeGraphs.Utilities.plotly_line_dash
—
Function
plotly_line_dash(line_style::LineStyle)::Maybe{AbstractString}
Return the Plotly
line_dash
for a
line_style
.
SomeGraphs.Utilities.SubGraph
—
Type
@kwdef struct SubGraph
index::Integer
n_graphs::Integer
graphs_gap::Maybe{Real}
mirrored::Bool = false
n_annotations::Integer = 0
annotation_size::Maybe{AnnotationSize} = nothing
dendogram_size::Maybe{Real} = nothing
pixel_length::Maybe{Real} = nothing
end
Identify one sub-graph out of a set of
n_graphs
adjacent graphs along some axis. If the
index
is 1, this is the 1st sub-graph (used top initialize some values such as the legend group title). If
graphs_gap
is
nothing
then the sub-graphs are plotted on top of each other, which affects axis parameters; otherwise, the sub-graphs are plotted with this gap, which affects layout parameters.
If
mirrored
, the sub-graphs are paired - an odd one and the even one following it - and the
graphs_gap
is only placed between the pairs; the two sub-graphs of a pair are adjacent, meeting at the axis they share. The
n_graphs
must then be even.
This also supports
n_annotations
(of the other axis) with
annotation_size
(along this axis). If the index is negative, it is the (negated) index of an annotation (of the other axis).
If the
index
is 0, this is the dendogram graph (of the other axis) with
dendogram_size
(along this axis).
The
graphs_gap
,
annotation_size
and
dendogram_size
are in pixels. The
pixel_length
is the length of the plot's area along this axis, in pixels, which turns them into fractions of the axis. It must be given to compute the sub-graph's domain.
SomeGraphs.Utilities.plotly_sub_graph_axes
—
Function
plotly_sub_graph_axes(;
basis_sub_graph::Maybe{SubGraph} = nothing,
values_sub_graph::Maybe{SubGraph} = nothing,
values_orientation::ValuesOrientation,
)::Tuple{
Maybe{Integer},
Maybe{AbstractFloat},
Maybe{Integer},
Maybe{AbstractFloat},
}
Return the X axis index and zero value, and the Y axis index and zero value, for a sub-graph.
SomeGraphs.Utilities.plotly_sub_graph_domain
—
Function
plotly_sub_graph_domain(sub_graph::SubGraph)::Maybe{AbstractVector{<:AbstractFloat}}
Return the plotly domain (region of the overall figure) for a specific
sub_graph
.
SomeGraphs.Utilities.plotly_axis
—
Function
plotly_axis(
prefix::AbstractString,
index::Maybe{Integer};
short::Bool = false,
force::Bool = false,
)::Maybe{AbstractString}
Return the Plotly axis name for a given index. If
short
just use the
prefix
, otherwise add
axis
. If
force
give a result even for the 1st (typically implicit, unnamed) axis.
SomeGraphs.Utilities.validate_graph_bands
—
Function
validate_graph_bands(
field::AbstractString,
bands_configuration::BandsConfiguration,
bands_data::BandsData,
axis_configuration::Maybe{AxisConfiguration} = nothing,
)::Nothing
Validate that the bands configuration and data is compatible. Assumes these are specified as the same
field
in both the graph's data and configuration.
SomeGraphs.Utilities.push_horizontal_bands_shapes
—
Function
push_horizontal_bands_shapes(
shapes::AbstractVector{Shape},
axis_configuration::AxisConfiguration,
scaled_values_range::Range,
bands_data::BandsData,
bands_configuration::BandsConfiguration,
bands_scale::Real = 1;
cross_ref::AbstractString = "x domain",
is_plotly_log::Bool = false,
)::Nothing
Push shapes for plotting horizontal bands. These shapes need to be placed in the layout and not the traces because Plotly.
The bands stretch across the whole of the
cross_ref
axis. When the graph is split into sub-graphs, push the bands once per sub-graph, using each one's own axis, so they do not stretch across the gaps between them.
If
is_plotly_log
, the coordinates are for a Plotly log axis (see
plotly_axis_value
).
SomeGraphs.Utilities.push_vertical_bands_shapes
—
Function
push_vertical_bands_shapes(
shapes::AbstractVector{Shape},
axis_configuration::AxisConfiguration,
scaled_values_range::Range,
bands_data::BandsData,
bands_configuration::BandsConfiguration,
bands_scale::Real = 1;
cross_ref::AbstractString = "y domain",
is_plotly_log::Bool = false,
)::Nothing
Push shapes for plotting vertical bands. These shapes need to be places in the layout and not the traces because Plotly.
The bands stretch across the whole of the
cross_ref
axis. When the graph is split into sub-graphs, push the bands once per sub-graph, using each one's own axis, so they do not stretch across the gaps between them.
If
is_plotly_log
, the coordinates are for a Plotly log axis (see
plotly_axis_value
).
SomeGraphs.Utilities.push_diagonal_bands_shapes
—
Function
push_diagonal_bands_shapes(
shapes::AbstractVector{Shape},
axis_configuration::AxisConfiguration,
x_scaled_values_range::Range,
y_scaled_values_range::Range,
bands_data::BandsData,
bands_configuration::BandsConfiguration;
is_plotly_log::Bool = false,
)::Nothing
Push shapes for plotting diagonal bands. These shapes need to be placed in the layout and not the traces because Plotly.
If
is_plotly_log
, the coordinates are for Plotly log axes (see
plotly_axis_value
).
SomeGraphs.Utilities.MaybeRange
—
Type
@kwdef mutable struct MaybeRange
minimum::Maybe{Float32} = nothing
maximum::Maybe{Float32} = nothing
end
A range of values (possibly partially specified).
SomeGraphs.Utilities.Range
—
Type
@kwdef mutable struct Range
minimum::Float32
maximum::Float32
end
A range of values (fully specified).
SomeGraphs.Utilities.collect_range!
—
Function
collect_range!(
range::MaybeRange,
values::Maybe{Union{Tuple{Vararg{Maybe{Real}}}, AbstractVector{<:Maybe{Real}}}},
)::Nothing
Expand the
range
to cover the
values
(ignoring
nothing
values).
collect_hidden_range!(
range::MaybeRange,
scale_configuration::ScaleConfiguration,
scaled_values::AbstractVector{<:Real},
mask::Maybe{Union{AbstractVector{Bool}, BitVector}},
)::Nothing
Expand the implicit
range
to cover the hidden
scaled_values
(the ones whose
mask
is false), if the scale does
include_hidden
. The shown values are collected by whoever draws them.
SomeGraphs.Utilities.range_values
—
Function
range_values(
scale_configuration::ScaleConfiguration,
values::AbstractArray,
mask::Maybe{AbstractArray{Bool}},
)::AbstractArray
The
values
which take part in the implicit range: all of them, unless the scale does not
include_hidden
, in which case only the ones shown by the
mask
.
SomeGraphs.Utilities.final_scaled_range
—
Function
final_scaled_range(
implicit_scaled_range::Union{Range, MaybeRange},
scale_configuration::ScaleConfiguration
)::Range
final_scaled_range(
implicit_scaled_range::Union{Range, MaybeRange},
axis_configuration::AxisConfiguration
)::Range
Compute the final range given the
implicit_scaled_range
computed from the values and the explicit
minimum
and
maximum
of the
scale_configuration
. Given an
axis_configuration
, the range is also grown by its
expand_fraction
. Only a drawn axis expands, since the expansion exists to keep markers clear of the plot border.
SomeGraphs.Utilities.prefer_data
—
Function
prefer_data(data_value::Any, configuration_value::Any)::Any
prefer_data(data_values::Maybe{AbstractVector}, index::Integer, configuration_value::Any)::Any
Return a value to use, prefering the data value (which may be in a vector, where a
nothing
vector or entry also falls back to the configuration value) to the configuration value.
Index
-
SomeGraphs.Utilities -
SomeGraphs.Utilities.ConfiguredColors -
SomeGraphs.Utilities.MaybeRange -
SomeGraphs.Utilities.Range -
SomeGraphs.Utilities.SidesContent -
SomeGraphs.Utilities.SizesLegendEntry -
SomeGraphs.Utilities.SubGraph -
SomeGraphs.Validations.Maybe -
SomeGraphs.Common.graph_to_figure -
SomeGraphs.Common.graph_to_html -
SomeGraphs.Common.graph_to_image -
SomeGraphs.Common.graph_to_json -
SomeGraphs.Common.validate_graph -
SomeGraphs.Utilities.axis_screen_ticks_angle -
SomeGraphs.Utilities.axis_ticks_prefix -
SomeGraphs.Utilities.axis_ticks_suffix -
SomeGraphs.Utilities.collect_hidden_range! -
SomeGraphs.Utilities.collect_range! -
SomeGraphs.Utilities.configured_colors -
SomeGraphs.Utilities.displayed_annotations -
SomeGraphs.Utilities.entities_hovers -
SomeGraphs.Utilities.fill_color -
SomeGraphs.Utilities.final_scaled_range -
SomeGraphs.Utilities.masked_values -
SomeGraphs.Utilities.numeric_values -
SomeGraphs.Utilities.place_side_panel! -
SomeGraphs.Utilities.plotly_axis -
SomeGraphs.Utilities.plotly_axis_value -
SomeGraphs.Utilities.plotly_axis_values -
SomeGraphs.Utilities.plotly_figure -
SomeGraphs.Utilities.plotly_layout -
SomeGraphs.Utilities.plotly_legend -
SomeGraphs.Utilities.plotly_line_dash -
SomeGraphs.Utilities.plotly_sub_graph_axes -
SomeGraphs.Utilities.plotly_sub_graph_domain -
SomeGraphs.Utilities.plotly_title -
SomeGraphs.Utilities.prefer_data -
SomeGraphs.Utilities.push_diagonal_bands_shapes -
SomeGraphs.Utilities.push_horizontal_bands_shapes -
SomeGraphs.Utilities.push_twin_log_axis_traces! -
SomeGraphs.Utilities.push_vertical_bands_shapes -
SomeGraphs.Utilities.range_values -
SomeGraphs.Utilities.scale_axis_value -
SomeGraphs.Utilities.scale_axis_values -
SomeGraphs.Utilities.scale_size_values -
SomeGraphs.Utilities.set_layout_axis! -
SomeGraphs.Utilities.set_layout_colorscale! -
SomeGraphs.Utilities.set_layout_legend! -
SomeGraphs.Utilities.set_layout_margins! -
SomeGraphs.Utilities.set_layout_twin_log_axis! -
SomeGraphs.Utilities.shared_values_title -
SomeGraphs.Utilities.sizes_legend_entries -
SomeGraphs.Utilities.text_width -
SomeGraphs.Utilities.validate_axis_sizes -
SomeGraphs.Utilities.validate_colors -
SomeGraphs.Utilities.validate_graph_bands -
SomeGraphs.Utilities.validate_numeric_values -
SomeGraphs.Utilities.validate_values