SunburstPlot
extends AbstractPlot
in package
The X field gives the labels, the Z field of the first trace gives the parents. A root node contains all the parents.
Table of Contents
Constants
- ROOT : mixed = 'Total'
- Label of the root node
- TYPE : string = 'sunburst'
- AGGREGATION_ALWAYS : mixed = 'always'
- The values are always aggregated, with a sum by default
- AGGREGATION_MODE : string = self::AGGREGATION_ALWAYS
- AGGREGATION_NEVER : mixed = 'never'
- The values are never aggregated: the plot displays a distribution
- AGGREGATION_OPTIONAL : mixed = 'optional'
- The values are aggregated if an aggregation is configured
- FEATURE_COLORS : null|string = self::FEATURE_COLORS_MARKER_COLORS
- The groups are processed to build the hierarchy: they are given as arrays
- FEATURE_COLORS_MARKER_COLOR : mixed = 'color'
- The feature colors are set in trace.marker.color
- FEATURE_COLORS_MARKER_COLORS : mixed = 'colors'
- The feature colors are set in trace.marker.colors
- FEATURE_COLORS_NONE : mixed = null
- No feature colors
- SORT_BY_X : bool = false
- X_MANDATORY : bool = true
- X_PROPERTY : string = 'labels'
- Y_MANDATORY : bool = true
- Y_PROPERTY : string = 'values'
- Z_PROPERTY : null|string = 'parents'
Properties
- $aggregation : null|string
- $colorFields : array<int, null|string>
- $colors : array<int, null|string>
- $data : array<string|int, mixed>
- $displayLegend : bool
- $horizontal : bool
- $layerId : string
- $layout : array<string|int, mixed>
- $project : Project
- $stacked : bool
- $theme : string
- $title : string
- $xFields : array<int, string>
- $yFields : array<int, string>
- $zFields : array<int, null|string>
Methods
- __construct() : mixed
- Create the plot from its configuration.
- buildTraces() : bool
- Build the plot traces from the given features.
- fetchData() : bool
- Fetch the layer data and build the plot traces.
- getAggregation() : null|string
- Get the aggregate function used for this plot.
- getData() : array<string|int, mixed>
- Get the Plotly traces with all their values.
- getLayerId() : string
- Get the identifier of the layer containing the data.
- getLayout() : array<string|int, mixed>
- Get the Plotly layout.
- getTitle() : string
- Get the plot title.
- getTraces() : array<string|int, mixed>
- Get the Plotly traces, in which the long lists of values are JsonColumn.
- getType() : string
- Get the plot type.
- isAggregated() : bool
- Tell if the values are aggregated by distinct X values.
- writeJson() : void
- Write the plot as JSON: title, data (traces) and layout.
- compareGroups() : int
- Compare two groups, to sort them as the database does.
- customizeLayout() : array<string|int, mixed>
- Customize the layout for the plot type.
- getColorColumn() : null|JsonColumn
- Get the colors of the groups of a trace, from a column of colors.
- getFieldAlias() : string
- Get the field alias, or the field name if it has no alias.
- getGroup() : array<string|int, mixed>
- Get the group of a feature: its parent and its label.
- getGroupFields() : array<int, string>
- Get the fields grouping the features in the database aggregation: the parent field if any, and the label field (X).
- getGroupFromValues() : array<string|int, mixed>
- Get the group (parent, label) from the values of the group fields.
- getTraceTemplate() : array<string|int, mixed>
- Get the trace template of the plot type.
- setAggregatedValues() : null|JsonColumn
- Set the nodes: the groups, the parents and the root.
- getParentField() : null|string
- Get the field containing the parent of the features.
Constants
ROOT
Label of the root node
public
mixed
ROOT
= 'Total'
TYPE
public
string
TYPE
= 'sunburst'
The plot type
AGGREGATION_ALWAYS
The values are always aggregated, with a sum by default
protected
mixed
AGGREGATION_ALWAYS
= 'always'
AGGREGATION_MODE
protected
string
AGGREGATION_MODE
= self::AGGREGATION_ALWAYS
When the values are aggregated
AGGREGATION_NEVER
The values are never aggregated: the plot displays a distribution
protected
mixed
AGGREGATION_NEVER
= 'never'
AGGREGATION_OPTIONAL
The values are aggregated if an aggregation is configured
protected
mixed
AGGREGATION_OPTIONAL
= 'optional'
FEATURE_COLORS
The groups are processed to build the hierarchy: they are given as arrays
protected
null|string
FEATURE_COLORS
= self::FEATURE_COLORS_MARKER_COLORS
How the feature colors are given to Plotly
FEATURE_COLORS_MARKER_COLOR
The feature colors are set in trace.marker.color
protected
mixed
FEATURE_COLORS_MARKER_COLOR
= 'color'
FEATURE_COLORS_MARKER_COLORS
The feature colors are set in trace.marker.colors
protected
mixed
FEATURE_COLORS_MARKER_COLORS
= 'colors'
FEATURE_COLORS_NONE
No feature colors
protected
mixed
FEATURE_COLORS_NONE
= null
SORT_BY_X
protected
bool
SORT_BY_X
= false
The features of a plot without aggregation are sorted by X, for example to draw lines. The aggregated values are always sorted by group (X value), ascending.
X_MANDATORY
protected
bool
X_MANDATORY
= true
The X field is mandatory
X_PROPERTY
protected
string
X_PROPERTY
= 'labels'
Trace property containing the X values
Y_MANDATORY
protected
bool
Y_MANDATORY
= true
The Y field is mandatory
Y_PROPERTY
protected
string
Y_PROPERTY
= 'values'
Trace property containing the Y values
Z_PROPERTY
protected
null|string
Z_PROPERTY
= 'parents'
Trace property containing the Z values
Properties
$aggregation
protected
null|string
$aggregation
The aggregate function, null if the values are not aggregated
$colorFields
protected
array<int, null|string>
$colorFields
= array()
Field containing the feature color, for each trace
$colors
protected
array<int, null|string>
$colors
= array()
Color of each trace
$data
protected
array<string|int, mixed>
$data
= array()
The Plotly traces, the long lists of values are JsonColumn
$displayLegend
protected
bool
$displayLegend
Display the legend
$horizontal
protected
bool
$horizontal
Display horizontal bars
$layerId
protected
string
$layerId
$layout
protected
array<string|int, mixed>
$layout
The Plotly layout
$project
protected
Project
$project
$stacked
protected
bool
$stacked
Stack the bars of the traces
$theme
protected
string
$theme
The dataviz theme: dark or light
$title
protected
string
$title
$xFields
protected
array<int, string>
$xFields
= array()
$yFields
protected
array<int, string>
$yFields
= array()
$zFields
protected
array<int, null|string>
$zFields
= array()
Z field of each trace
Methods
__construct()
Create the plot from its configuration.
public
__construct(Project $project, array<string|int, mixed> $plotConfig) : mixed
No data is fetched: call fetchData() or buildTraces() to build the traces.
Parameters
- $project : Project
-
the Lizmap project, the ACL must have been checked
- $plotConfig : array<string|int, mixed>
-
the plot configuration, see Project::parseDatavizPlotConfig()
buildTraces()
Build the plot traces from the given features.
public
buildTraces(iterable<string|int, mixed> $features) : bool
The features are read only once, so they can be given by a generator. For an aggregated plot, the features should be sorted by group (X value), as requested by fetchData(): the aggregation is done group by group. If they are not, an array of features is aggregated again by value; for a generator, false is returned and the features must be given again.
Parameters
- $features : iterable<string|int, mixed>
-
GeoJSON features (objects)
Return values
bool —false if the features are not valid, or not sorted by group
fetchData()
Fetch the layer data and build the plot traces.
public
fetchData([string $expFilter = '' ]) : bool
For aggregated plots, the values are aggregated by the database when possible (PostgreSQL layers). Otherwise, or if the database aggregation fails, all the features are requested with WFS and aggregated in PHP.
Parameters
- $expFilter : string = ''
-
a QGIS expression to filter the features
Return values
bool —false if the data cannot be fetched
getAggregation()
Get the aggregate function used for this plot.
public
getAggregation() : null|string
Return values
null|string —the aggregate function, null if the values are not aggregated
getData()
Get the Plotly traces with all their values.
public
getData() : array<string|int, mixed>
All the values are loaded in memory: for a large number of features, prefer writeJson() which uses less memory.
Return values
array<string|int, mixed> —the Plotly traces
getLayerId()
Get the identifier of the layer containing the data.
public
getLayerId() : string
Return values
string —the QGIS layer identifier
getLayout()
Get the Plotly layout.
public
getLayout() : array<string|int, mixed>
Return values
array<string|int, mixed> —the Plotly layout
getTitle()
Get the plot title.
public
getTitle() : string
Return values
string —the plot title
getTraces()
Get the Plotly traces, in which the long lists of values are JsonColumn.
public
getTraces() : array<string|int, mixed>
The traces can be written with JsonStreamWriter.
Return values
array<string|int, mixed> —the Plotly traces
getType()
Get the plot type.
public
getType() : string
Return values
string —the plot type, for example "bar" or "pie"
isAggregated()
Tell if the values are aggregated by distinct X values.
public
isAggregated() : bool
Return values
bool —true if the values are aggregated
writeJson()
Write the plot as JSON: title, data (traces) and layout.
public
writeJson(resource $output[, array<string|int, mixed> $properties = array() ]) : void
The values are copied from their temporary streams.
Parameters
- $output : resource
-
the output stream
- $properties : array<string|int, mixed> = array()
-
additional properties of the JSON object
compareGroups()
Compare two groups, to sort them as the database does.
protected
static compareGroups(mixed $a, mixed $b) : int
The groups are compared value by value when they are lists (sunburst: parent, label). The null values are after the others, as with ORDER BY ascending. The texts are compared by bytes, which may differ from the collation of the database: this order is only used when the features were not sorted by the server.
Parameters
- $a : mixed
-
the first group
- $b : mixed
-
the second group
Return values
int —negative, 0 or positive if $a is before, equal to or after $b
customizeLayout()
Customize the layout for the plot type.
protected
customizeLayout(array<string|int, mixed> $layout) : array<string|int, mixed>
No axis title is displayed.
Parameters
- $layout : array<string|int, mixed>
-
the default layout
Return values
array<string|int, mixed> —the layout of the plot type
getColorColumn()
Get the colors of the groups of a trace, from a column of colors.
protected
static getColorColumn(JsonColumn $column, null|string $defaultColor) : null|JsonColumn
The colors are read one by one, so the memory does not depend on the number of groups. The groups without color get the default color.
Parameters
- $column : JsonColumn
-
the color of each group, null if none
- $defaultColor : null|string
-
the color of the groups without color, null to keep them without color
Return values
null|JsonColumn —the colors, null if no group has a color
getFieldAlias()
Get the field alias, or the field name if it has no alias.
protected
getFieldAlias(string $field) : string
Parameters
- $field : string
-
the field name
Return values
string —the field alias or name
getGroup()
Get the group of a feature: its parent and its label.
protected
getGroup(object $properties, mixed $x) : array<string|int, mixed>
The same label can be used by several parents, so the values are aggregated by (parent, label).
Parameters
- $properties : object
-
the feature properties
- $x : mixed
-
the feature X value (label), not null
Return values
array<string|int, mixed> —the parent (null if none) and the label
getGroupFields()
Get the fields grouping the features in the database aggregation: the parent field if any, and the label field (X).
protected
getGroupFields() : array<int, string>
Return values
array<int, string> —the group fields
getGroupFromValues()
Get the group (parent, label) from the values of the group fields.
protected
getGroupFromValues(array<int, mixed> $values) : array<string|int, mixed>
Parameters
- $values : array<int, mixed>
-
the values of the fields given by getGroupFields()
Return values
array<string|int, mixed> —the parent (null if none) and the label
getTraceTemplate()
Get the trace template of the plot type.
protected
getTraceTemplate() : array<string|int, mixed>
Return values
array<string|int, mixed> —the Plotly trace properties, with empty data
setAggregatedValues()
Set the nodes: the groups, the parents and the root.
protected
setAggregatedValues(array<string|int, mixed> &$trace, JsonColumn|JsonRows|array<int, array<string|int, mixed>> $groups, JsonColumn|array<int, mixed> $values, null|array<string|int, mixed>|JsonColumn $colors) : null|JsonColumn
The value of a parent is the sum of the values of its children, the value of the root is the sum of all the values. Groups without parent are attached to the root.
As a label can be used by several parents, each node has a unique id: "p" and the parent position for a parent, "c" and the group position for a group, so a parent and a group attached to the root can not have the same id.
The groups are read one by one and written in JsonColumn, so the memory does not depend on the number of groups. Only the parents are kept in memory, then written after the groups, and the root last: Plotly builds the hierarchy from the ids, whatever the order of the nodes.
Parameters
- $trace : array<string|int, mixed>
-
the sunburst trace
- $groups : JsonColumn|JsonRows|array<int, array<string|int, mixed>>
-
the groups: [parent, label]
- $values : JsonColumn|array<int, mixed>
-
the aggregated value of each group
- $colors : null|array<string|int, mixed>|JsonColumn
-
the color of each group, null if none
Return values
null|JsonColumn —the colors of all the nodes, null if none
getParentField()
Get the field containing the parent of the features.
private
getParentField() : null|string
Return values
null|string —the parent field: the Z field of the first trace