GnuplotEx.Dataset.Helpers (gnuplot_ex v0.5.1)

Shared utilities for dataset formatting.

Provides stream-based formatting for efficient memory usage with large datasets.

Summary

Functions

Format 3D grid dataset for pm3d surface rendering.

Format a single data point as a space-separated string.

Format dataset as a text stream for gnuplot inline data.

Format a single value for gnuplot.

Functions

format_grid(data)

@spec format_grid(Enumerable.t()) :: Enumerable.t()

Format 3D grid dataset for pm3d surface rendering.

Inserts blank lines between rows when the first column (x/u) value changes. This is required for gnuplot's pm3d to render surfaces correctly.

Example

iex> data = [[0, 0, 1], [0, 1, 2], [1, 0, 3], [1, 1, 4]]
iex> data |> GnuplotEx.Dataset.Helpers.format_grid() |> Enum.join()
"0 0 1\n0 1 2\n\n1 0 3\n1 1 4\ne\n"

format_point(point)

@spec format_point(list() | tuple()) :: String.t()

Format a single data point as a space-separated string.

Handles both list and tuple formats.

Examples

iex> GnuplotEx.Dataset.Helpers.format_point([1, 2, 3])
"1 2 3"

iex> GnuplotEx.Dataset.Helpers.format_point({1.5, 2.5})
"1.5 2.5"

format_text(data)

@spec format_text(Enumerable.t()) :: Enumerable.t()

Format dataset as a text stream for gnuplot inline data.

Returns a Stream that yields formatted rows followed by the gnuplot end-of-data marker (e).

Supports both flat data (list of points) and grid data (list of rows of points). Grid data gets blank lines between rows for pm3d surface rendering.

Example

iex> data = [[0, 0], [1, 2], [2, 4]]
iex> data |> GnuplotEx.Dataset.Helpers.format_text() |> Enum.join()
"0 0\n1 2\n2 4\ne\n"

format_value(value)

@spec format_value(number() | String.t()) :: String.t()

Format a single value for gnuplot.

Examples

iex> GnuplotEx.Dataset.Helpers.format_value(42)
"42"

iex> GnuplotEx.Dataset.Helpers.format_value(3.14)
"3.14"

iex> GnuplotEx.Dataset.Helpers.format_value("label")
"label"

iex> GnuplotEx.Dataset.Helpers.format_value("with space")
"\"with space\""