plot

package
v0.0.0-...-a103044 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package plot implements basic plotting functionality that leverages Chrome/Chromium for cross-platform capabilities. It works on Windows, macOS and Linux.

Any plotting package that can write to an io.Writer is compatible.

See: https://github.com/wcharczuk/go-chart and https://github.com/gonum/plot/wiki/Drawing-to-an-Image-or-Writer:-How-to-save-a-plot-to-an-image.Image-or-an-io.Writer,-not-a-file.#writing-a-plot-to-an-iowriter

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoChromeInstalled indicates that chrome is not installed.
	// Chrome is required to display plots.
	ErrNoChromeInstalled = errors.New("no chrome installed")

	// ErrClosed means the plot window has already been closed
	ErrClosed = errors.New("plot closed")
)

Functions

This section is empty.

Types

type MIME

type MIME string

MIME Type is used to help Chrome recognize the format of the image.

const (
	// JPEG MIME Type
	JPEG MIME = "jpeg"

	// PNG MIME Type
	PNG MIME = "png"

	// SVG MIME Type
	SVG MIME = "svg+xml"
)

type Plot

type Plot struct {
	// The channel that indicates the plot window has been closed.
	// The window can be closed by the user or the Close function.
	Closed chan struct{}
	// contains filtered or unexported fields
}

Plot represents a plot window.

func Open

func Open(title string, width, height int) (*Plot, error)

Open creates a new plot window. Any plotting package that writes to an io.Writer (such as to file) is compatible. Optional wrappers for various plotting packages are provided in the subpackages.

Example:

import chart "github.com/wcharczuk/go-chart"

graph := chart.Chart{
   Series: []chart.Series{
      chart.TimeSeries{
         XValues: []time.Time{
            time.Now().AddDate(0, 0, -2),
            time.Now().AddDate(0, 0, -1),
            time.Now(),
         }
         YValues: []float64{9.0, 10.0, 11.0},
      },
   },
}

plt, _ := plot.Open("Linear", 150, 250)
graph.Render(chart.SVG, plt)
plt.Display(plot.None)
<-plt.Closed

func (*Plot) Close

func (p *Plot) Close() error

Close closes the plot window.

func (*Plot) Display

func (p *Plot) Display(scrollbar Scrollbar, mime ...MIME) error

Display will display the plot. The default mime is SVG. The default scrollbar option is none. This means the entire plot will be made to fit inside the window without requiring scrolling. If the plotting package you are using supports saving as SVG, then use it.

func (*Plot) Write

func (p *Plot) Write(d []byte) (int, error)

Write implements the io.Writer interface. Do not use this method directly. Any plotting package that writes to an io.Writer (such as to file) is compatible.

type Scrollbar

type Scrollbar uint8

Scrollbar is used to set whether the plot will scroll in the horizontal and/or vertical direction.

const (
	// Horizontal will add a horizontal scrollbar.
	Horizontal Scrollbar = 1 << iota

	// Vertical will add a vertical scrollbar.
	Vertical
)
const None Scrollbar = 0

None means that no scrollbar will be added. The plot's dimensions will be changed to fit into the the window.

Directories

Path Synopsis
wcharczuk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL