GnuplotEx.Spec (gnuplot_ex v0.2.0)

Inspectable command specifications for gnuplot.

Specs provide an intermediate representation that can be built, inspected, and then executed. Useful for debugging, testing, and understanding what commands will be sent to gnuplot.

Example

spec = GnuplotEx.Spec.build([
  [:set, :terminal, :svg],
  [:plot, "-", :with, :lines]
], [data])

# Inspect the spec
IO.inspect(spec)
# => %GnuplotEx.Spec{
#      commands: [[:set, :terminal, :svg], ...],
#      script: "set terminal svg;\nplot \"-\" with lines",
#      datasets: [[...]]
#    }

# Execute when ready
{:ok, _} = GnuplotEx.Spec.execute(spec)

Dry Mode

Use GnuplotEx.plot/3 with dry: true to get a spec without executing:

{:ok, spec} = GnuplotEx.plot(commands, data, dry: true)

Summary

Functions

Build a spec from commands and datasets.

Execute a spec, sending commands to gnuplot.

Get the formatted data that would be sent to gnuplot.

Format the spec as a readable string for inspection.

Types

t()

@type t() :: %GnuplotEx.Spec{
  commands: [list()],
  datasets: [list()],
  formatted_data: [String.t()] | nil,
  script: String.t()
}

Functions

build(commands, datasets \\ [])

@spec build([list()], [list()]) :: t()

Build a spec from commands and datasets.

The spec contains:

  • commands - Original command lists
  • script - Serialized gnuplot script
  • datasets - Original dataset lists
  • formatted_data - Pre-formatted data strings (populated on execute)

Example

spec = GnuplotEx.Spec.build([[:plot, 'sin(x)']], [])

execute(spec)

@spec execute(t()) :: {:ok, String.t()} | {:error, term()}

Execute a spec, sending commands to gnuplot.

Example

spec = GnuplotEx.Spec.build(commands, data)
{:ok, script} = GnuplotEx.Spec.execute(spec)

format_data(spec)

@spec format_data(t()) :: String.t()

Get the formatted data that would be sent to gnuplot.

Useful for debugging data transmission issues.

Example

spec = GnuplotEx.Spec.build(commands, data)
formatted = GnuplotEx.Spec.format_data(spec)
IO.puts(formatted)

to_string(spec)

@spec to_string(t()) :: String.t()

Format the spec as a readable string for inspection.

Example

spec = GnuplotEx.Spec.build(commands, data)
IO.puts(GnuplotEx.Spec.to_string(spec))