Lizmap Web Client 3.11.0

ScatterPlot extends AbstractPlot
in package

Build the Plotly data and layout of a plot from the layer features.

The plot types only define their trace template and their specific behaviours with the constants and methods below.

The features are read one by one: the plot never keeps them in memory. Depending on the aggregation, the traces contain either one value per feature (raw traces) or one value per distinct X value (aggregated traces).

Table of Contents

Constants

TYPE  : string = 'scatter'
AGGREGATION_ALWAYS  : mixed = 'always'
The values are always aggregated, with a sum by default
AGGREGATION_MODE  : string = self::AGGREGATION_OPTIONAL
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_COLOR
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 = true
X_MANDATORY  : bool = true
X_PROPERTY  : string = 'x'
Y_MANDATORY  : bool = true
Y_PROPERTY  : string = 'y'
Z_PROPERTY  : null|string = null

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()  : mixed
Get the group of a feature for the aggregation.
getGroupFields()  : array<int, string>
Get the fields grouping the features in the database aggregation.
getGroupFromValues()  : mixed
Get the group from the values of the group fields returned by the database.
getTraceTemplate()  : array<string|int, mixed>
Get the trace template of the plot type.
setAggregatedValues()  : null|array<string|int, mixed>|JsonColumn
Set the aggregated values in the trace.

Constants

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_OPTIONAL

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

protected null|string FEATURE_COLORS = self::FEATURE_COLORS_MARKER_COLOR

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 = true

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 = 'x'

Trace property containing the X values

Y_MANDATORY

protected bool Y_MANDATORY = true

The Y field is mandatory

Y_PROPERTY

protected string Y_PROPERTY = 'y'

Trace property containing the Y values

Z_PROPERTY

protected null|string Z_PROPERTY = null

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

$layout

protected array<string|int, mixed> $layout

The Plotly layout

$stacked

protected bool $stacked

Stack the bars of the traces

$theme

protected string $theme

The dataviz theme: dark or light

$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>

By default, the axis titles are the aliases of the X and Y fields, when there is only one field for the axis.

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 for the aggregation.

protected getGroup(object $properties, mixed $x) : mixed

By default, the features are grouped by X value.

Parameters
$properties : object

the feature properties

$x : mixed

the feature X value, not null

Return values
mixed —

the group value, a scalar or an array

getGroupFields()

Get the fields grouping the features in the database aggregation.

protected getGroupFields() : array<int, string>

They must give the same groups as getGroup().

Return values
array<int, string> —

the group fields, the X field by default

getGroupFromValues()

Get the group from the values of the group fields returned by the database.

protected getGroupFromValues(array<int, mixed> $values) : mixed
Parameters
$values : array<int, mixed>

the values of the fields given by getGroupFields()

Return values
mixed —

the group value, as returned by getGroup()

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 aggregated values in the trace.

protected setAggregatedValues(array<string|int, mixed> &$trace, JsonColumn|JsonRows|array<int, mixed> $groups, JsonColumn|array<int, mixed> $values, null|array<string|int, mixed>|JsonColumn $colors) : null|array<string|int, mixed>|JsonColumn

By default, the groups are the categories and the aggregated values are the values of the trace.

The groups and the values are usually JsonColumn, never loaded in memory: a plot type processing them must read them with foreach. The groups given by several fields (sunburst) are JsonRows.

Parameters
$trace : array<string|int, mixed>

the trace

$groups : JsonColumn|JsonRows|array<int, mixed>

the groups, sorted

$values : JsonColumn|array<int, mixed>

the aggregated value of each group

$colors : null|array<string|int, mixed>|JsonColumn

the color of each group

Return values
null|array<string|int, mixed>|JsonColumn —

the colors of the trace values

On this page

Search results