Documentation

Graphic_Data_Tutorial_Figure_Preview
in package

Class Graphic_Data_Tutorial_Figure_Preview

Table of Contents

Methods

build_interactive_figure_data()  : array{data: array, layout: array, config: array}
PHP port of producePlotlyLineFigure() / producePlotlyBarFigure() + injectOverlays().
generate_and_save_figure_previews()  : void
Generates and saves the "full_figure" and "figure_only" standalone HTML files for a figure post, and updates the associated post meta.
build_bar_chart_traces_and_layout()  : array{0: array, 1: array, 2: array}
PHP port of producePlotlyBarFigure()'s trace/layout construction.
build_code_figure_html()  : string
PHP port of buildCodeFigureHTML().
build_image_figure_html()  : string
PHP port of buildImageFigureHTML() (Internal/External figure types).
build_information_link()  : string
PHP port of buildInformationLink().
build_interactive_figure_html()  : string
PHP port of buildInteractiveFigureHTML().
build_line_chart_traces_and_layout()  : array{0: array, 1: array, 2: array}
PHP port of producePlotlyLineFigure()'s trace/layout construction.
compute_percentile()  : float|null
PHP port of computePercentile().
compute_standard_deviation()  : float
PHP port of computeStandardDeviation().
default_plotly_config()  : array<string|int, mixed>
Default Plotly config object, identical for line and bar charts.
escape_html()  : string
PHP port of escapeHtml().
filter_out_empty_string()  : array<string|int, mixed>
PHP port of the repeated `.filter(item => item !== "")` pattern.
flatten_interactive_arguments()  : array<string|int, mixed>
Flattens figure_interactive_arguments' [[key, value], ...] pairs into an assoc array, matching JS's Object.fromEntries(JSON.parse(interactive_arguments)).
generate_figure_html()  : array{html: string, filename: ?string, path: ?string}
PHP port of createFigureHtml() (admin/js/admin-preview-buttons.js).
get_info_value()  : mixed
PHP port of getInfoValue(). Returns the first populated property found in $info_obj.
inject_overlays()  : array<string|int, mixed>
PHP port of injectOverlays(). Mutates $layout by reference (axis types, shapes) and returns the overlay traces array (evaluation-period shading, event-marker lines).
js_parse_float()  : float|null
Approximates JS's parseFloat(): parses a leading numeric portion of a string, or returns null (JSON.stringify(NaN) serializes to null in JS, so null is the faithful equivalent).
js_parse_int()  : int|null
Approximates JS's parseInt(value, 10). Returns null (JSON-equivalent of NaN) when the value has no leading integer portion.
lighten_color()  : string
PHP port of the `lightenColor()` helper in plotly-bar.js.
mean_treating_na_as_zero()  : float|null
Mean of $values, treating null/''/case-insensitive-"NA"/non-numeric entries as 0 in the numerator while excluding only null and the exact literal "NA" from the denominator.
safe_image_url()  : string
PHP port of safeImageUrl().
safe_url()  : string
PHP port of safeUrl().
save_figure_html_file()  : string
Writes a generated figure HTML string to disk and updates upload-related post meta.
serialize_for_script()  : string
PHP port of serializeForScript().

Methods

build_interactive_figure_data()

PHP port of producePlotlyLineFigure() / producePlotlyBarFigure() + injectOverlays().

public static build_interactive_figure_data(array<string|int, mixed> $interactive_arguments_pairs, string $json_data_path) : array{data: array, layout: array, config: array}

Builds the pre-render Plotly {data, layout, config} for an Interactive figure from its raw figure_interactive_arguments and its data file. This is the PHP analog of what the browser stores into the figure_interactive_args_rendered hidden field.

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

Raw [[key, value], ...] pairs, as stored in figure_interactive_arguments.

$json_data_path : string

Absolute filesystem path to the figure's data .json file.

Return values
array{data: array, layout: array, config: array}

generate_and_save_figure_previews()

Generates and saves the "full_figure" and "figure_only" standalone HTML files for a figure post, and updates the associated post meta.

public static generate_and_save_figure_previews(int $post_id, array<string|int, mixed> $info_obj_full, array<string|int, mixed> $info_obj_figure_only[, array<string|int, mixed>|null $saved_figure = null ]) : void
Parameters
$post_id : int

Figure post ID.

$info_obj_full : array<string|int, mixed>

Info object for the full_figure variant.

$info_obj_figure_only : array<string|int, mixed>

Info object for the figure_only variant.

$saved_figure : array<string|int, mixed>|null = null

Interactive figure data (data/layout/config), or null.

build_bar_chart_traces_and_layout()

PHP port of producePlotlyBarFigure()'s trace/layout construction.

private static build_bar_chart_traces_and_layout(array<string|int, mixed> $args, array<string|int, mixed> $data_to_be_plotted) : array{0: array, 1: array, 2: array}
Parameters
$args : array<string|int, mixed>

Flattened figure_interactive_arguments.

$data_to_be_plotted : array<string|int, mixed>

Column-oriented data (column name => array of values).

Return values
array{0: array, 1: array, 2: array}

[main traces, layout, config]

build_code_figure_html()

PHP port of buildCodeFigureHTML().

private static build_code_figure_html(string $normalized_figure_id, string $embed_code) : string
Parameters
$normalized_figure_id : string

Figure ID as a string.

$embed_code : string

Raw embed HTML/CSS/JS.

Return values
string

build_image_figure_html()

PHP port of buildImageFigureHTML() (Internal/External figure types).

private static build_image_figure_html(string $image_type, string $normalized_figure_id, string $image_url, string $image_alt, string $normalized_root_url) : string
Parameters
$image_type : string

'Internal' or 'External'.

$normalized_figure_id : string

Figure ID as a string.

$image_url : string

Image URL.

$image_alt : string

Image alt text.

$normalized_root_url : string

Site root URL.

Return values
string

PHP port of buildInformationLink().

private static build_information_link(string $url, string $text, string $icon, string $class_name) : string
Parameters
$url : string

Link URL.

$text : string

Link text.

$icon : string

Display icon.

$class_name : string

Additional CSS class.

Return values
string

build_interactive_figure_html()

PHP port of buildInteractiveFigureHTML().

private static build_interactive_figure_html(string $figure_content_element_id, string $figure_title, array<string|int, mixed>|null $saved_figure) : string
Parameters
$figure_content_element_id : string

Target element ID for the Plotly chart.

$figure_title : string

Figure title (used for aria-label).

$saved_figure : array<string|int, mixed>|null

{data, layout, config} array, or null.

Return values
string

build_line_chart_traces_and_layout()

PHP port of producePlotlyLineFigure()'s trace/layout construction.

private static build_line_chart_traces_and_layout(array<string|int, mixed> $args, array<string|int, mixed> $data_to_be_plotted) : array{0: array, 1: array, 2: array}
Parameters
$args : array<string|int, mixed>

Flattened figure_interactive_arguments.

$data_to_be_plotted : array<string|int, mixed>

Column-oriented data (column name => array of values).

Return values
array{0: array, 1: array, 2: array}

[main traces, layout, config]

compute_percentile()

PHP port of computePercentile().

private static compute_percentile(array<string|int, mixed> $values, float $percentile) : float|null
Parameters
$values : array<string|int, mixed>

Raw values.

$percentile : float

Percentile (0-100).

Return values
float|null

compute_standard_deviation()

PHP port of computeStandardDeviation().

private static compute_standard_deviation(array<string|int, mixed> $values) : float
Parameters
$values : array<string|int, mixed>

Raw values.

Return values
float

default_plotly_config()

Default Plotly config object, identical for line and bar charts.

private static default_plotly_config() : array<string|int, mixed>
Return values
array<string|int, mixed>

escape_html()

PHP port of escapeHtml().

private static escape_html(mixed $value) : string
Parameters
$value : mixed

Value to escape.

Return values
string

filter_out_empty_string()

PHP port of the repeated `.filter(item => item !== "")` pattern.

private static filter_out_empty_string(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>

Raw values.

Return values
array<string|int, mixed>

flatten_interactive_arguments()

Flattens figure_interactive_arguments' [[key, value], ...] pairs into an assoc array, matching JS's Object.fromEntries(JSON.parse(interactive_arguments)).

private static flatten_interactive_arguments(array<string|int, mixed> $pairs) : array<string|int, mixed>
Parameters
$pairs : array<string|int, mixed>

Array of [key, value] pairs.

Return values
array<string|int, mixed>

generate_figure_html()

PHP port of createFigureHtml() (admin/js/admin-preview-buttons.js).

private static generate_figure_html(int $post_id, string $root_url, array<string|int, mixed> $info_obj[, array<string|int, mixed>|null $saved_figure = null ][, string $figure_type = 'Interactive' ]) : array{html: string, filename: ?string, path: ?string}
Parameters
$post_id : int

Figure post ID.

$root_url : string

Site root URL.

$info_obj : array<string|int, mixed>

Info object (status, figureType, captions, links, etc).

$saved_figure : array<string|int, mixed>|null = null

Interactive figure data (data/layout/config), or null.

$figure_type : string = 'Interactive'

Fallback figure type if info_obj has none. Default 'Interactive'.

Return values
array{html: string, filename: ?string, path: ?string}

get_info_value()

PHP port of getInfoValue(). Returns the first populated property found in $info_obj.

private static get_info_value(array<string|int, mixed> $info_obj, array<string|int, mixed> $keys[, mixed $fallback = '' ]) : mixed
Parameters
$info_obj : array<string|int, mixed>

Info object.

$keys : array<string|int, mixed>

Property names to check, in priority order.

$fallback : mixed = ''

Default value.

inject_overlays()

PHP port of injectOverlays(). Mutates $layout by reference (axis types, shapes) and returns the overlay traces array (evaluation-period shading, event-marker lines).

private static inject_overlays(array<string|int, mixed> &$layout, array<string|int, mixed> $main_traces, array<string|int, mixed> $args, array<string|int, mixed> $data_to_be_plotted[, string $x_axis_type_when_no_x = 'date' ]) : array<string|int, mixed>

Unlike the source, which relies on Plotly's live post-render autorange resolution to populate layout.yaxis.range before this runs, this PHP port has no live render pass. When no explicit y-axis range is available, it falls back to the min/max of the main traces' y-values as an approximation — a documented, minor divergence from Plotly's real (undocumented) autorange padding, acceptable for demo/tutorial content.

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

Layout array (by reference).

$main_traces : array<string|int, mixed>

Main data traces (for the autorange fallback).

$args : array<string|int, mixed>

Flattened figure_interactive_arguments.

$data_to_be_plotted : array<string|int, mixed>

Column-oriented data.

$x_axis_type_when_no_x : string = 'date'

'category' or 'date' — what layout.xaxis.type should be when XAxis === 'None' (bar charts only; line charts always use 'date').

Return values
array<string|int, mixed>

Overlay traces.

js_parse_float()

Approximates JS's parseFloat(): parses a leading numeric portion of a string, or returns null (JSON.stringify(NaN) serializes to null in JS, so null is the faithful equivalent).

private static js_parse_float(mixed $value) : float|null
Parameters
$value : mixed

Value to parse.

Return values
float|null

js_parse_int()

Approximates JS's parseInt(value, 10). Returns null (JSON-equivalent of NaN) when the value has no leading integer portion.

private static js_parse_int(mixed $value) : int|null
Parameters
$value : mixed

Value to parse.

Return values
int|null

lighten_color()

PHP port of the `lightenColor()` helper in plotly-bar.js.

private static lighten_color(string $hex[, float $factor = 0.2 ]) : string
Parameters
$hex : string

Hex color (e.g. "#0c7d83").

$factor : float = 0.2

Lightening factor.

Return values
string

mean_treating_na_as_zero()

Mean of $values, treating null/''/case-insensitive-"NA"/non-numeric entries as 0 in the numerator while excluding only null and the exact literal "NA" from the denominator.

private static mean_treating_na_as_zero(array<string|int, mixed> $values) : float|null

This numerator/denominator inconsistency exists in the source and is replicated here.

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

Raw values.

Return values
float|null

safe_image_url()

PHP port of safeImageUrl().

private static safe_image_url(mixed $value[, string $fallback = '' ]) : string
Parameters
$value : mixed

Image URL value.

$fallback : string = ''

Fallback image URL.

Return values
string

safe_url()

PHP port of safeUrl().

private static safe_url(mixed $value[, string $fallback = '#' ]) : string
Parameters
$value : mixed

URL value.

$fallback : string = '#'

Fallback URL.

Return values
string

save_figure_html_file()

Writes a generated figure HTML string to disk and updates upload-related post meta.

private static save_figure_html_file(int $post_id, string $filename, string $html_content) : string

Mirrors custom_file_upload_handler() (includes/admin-figure.php), but writes directly instead of going through $_FILES/AJAX since this runs entirely server-side.

Parameters
$post_id : int

Figure post ID.

$filename : string

Filename without extension (e.g. "figure-42").

$html_content : string

HTML document content.

Return values
string

Absolute path the file was written to.

serialize_for_script()

PHP port of serializeForScript().

private static serialize_for_script(mixed $value) : string
Parameters
$value : mixed

Value to serialize.

Return values
string
On this page

Search results