tplot

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 7 Imported by: 0

README

tplot

A terminal plotting library for tview and tcell written in Golang.

screenshot

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBarsRunes = []rune{'▃', '▄', '▆', '█'}
View Source
var DefaultBlockBindings = &BlockBindings{
	SplitH:       tcell.KeyCtrlS,
	SplitV:       tcell.KeyCtrlV,
	Delete:       tcell.KeyCtrlX,
	FlexBindings: DefaultFlexBindings,
	Reset:        tcell.KeyCtrlO,
}
View Source
var DefaultFlexBindings = &FlexBindings{
	FocusLeft:  tcell.KeyCtrlH,
	FocusDown:  tcell.KeyCtrlJ,
	FocusUp:    tcell.KeyCtrlK,
	FocusRight: tcell.KeyCtrlL,
}
View Source
var DefaultOHLCRunes = OHLCRunes{
	Same:          '─',
	HighOpenClose: '┬',
	LowOpenClose:  '┴',
	HighOpen:      '╻',
	LowClose:      '╹',
	High:          '╷',
	Low:           '╵',
	OpenClose:     '┼',
	Open:          '╽',
	Close:         '╿',
	Thick:         '┃',
	Thin:          '│',
}

DefaultOHLCRunes contains the default runes using the box drawing characters. Examples:

╽   ╷ ╷     │
┃╻  │ ╵ ┃ ─ ┼ ┼ ┬ ┴
╿╹  │
│

See more at: https://en.wikipedia.org/wiki/Box-drawing_character

View Source
var DefaultTicksRunes = []rune{'⎽', '⎼', '—', '⎻', '⎺'}

Functions

This section is empty.

Types

type Axis

type Axis struct {
	*tview.Box
	// contains filtered or unexported fields
}

Axis represents a chart Axis. The current implementation only supports a vertical axis.

func NewAxis

func NewAxis(factory DecimalFactory) *Axis

NewAxis creates a new instance of Axis.

func (*Axis) CalcWidth

func (a *Axis) CalcWidth() int

CalcWidth calculates the width of the axis.

func (*Axis) Draw

func (a *Axis) Draw(screen tcell.Screen)

Draw implements tview.Primitive.

func (*Axis) Highlight

func (a *Axis) Highlight() DecimalValue

Highlight returns the currently highlighted item.

func (*Axis) HighlightStyle

func (a *Axis) HighlightStyle() tcell.Style

HighlightStyle returns the style for highlighting an item on the axis.

func (*Axis) Scale

func (a *Axis) Scale() Scale

Scale returns the axis scale. May be nil.

func (*Axis) SetHighlight

func (a *Axis) SetHighlight(highlight DecimalValue)

SetHighlight sets the value for highlighting.

func (*Axis) SetHighlightStyle

func (a *Axis) SetHighlightStyle(highlightStyle tcell.Style)

SetHighlightStyle sets the style for highlighting an item on the axis.

func (*Axis) SetScale

func (a *Axis) SetScale(scale Scale)

SetScale sets the axis acale.

func (*Axis) SetStyle

func (a *Axis) SetStyle(style tcell.Style)

SetStyle sets a default axis style.

func (*Axis) Style

func (a *Axis) Style() tcell.Style

Style returns the default axis style.

type AxisBox

type AxisBox struct {
	*tview.Box
	// contains filtered or unexported fields
}

func NewAxisBox

func NewAxisBox(axis *Axis, content Primitive) *AxisBox

func (*AxisBox) Draw

func (a *AxisBox) Draw(screen tcell.Screen)

func (*AxisBox) Position

func (a *AxisBox) Position() Position

func (*AxisBox) SetPosition

func (a *AxisBox) SetPosition(position Position)

type Bars

type Bars struct {
	// contains filtered or unexported fields
}

func NewBars

func NewBars(factory DecimalFactory) *Bars

func (Bars) Data

func (b Bars) Data() []Decimal

func (Bars) DataSlice

func (b Bars) DataSlice() []Decimal

DataSlice returns data, but only the items that fit on the screen.

func (*Bars) Draw

func (b *Bars) Draw(screen tcell.Screen)

func (Bars) Runes

func (b Bars) Runes() []rune

func (Bars) Scale

func (b Bars) Scale() Scale

func (Bars) SetData

func (b Bars) SetData(data []Decimal)

func (Bars) SetRunes

func (b Bars) SetRunes(runes []rune)

func (Bars) SetScale

func (b Bars) SetScale(scale Scale)

func (Bars) SetSliceMethod

func (b Bars) SetSliceMethod(method SliceMethod)

func (Bars) SetSpacing

func (b Bars) SetSpacing(spacing int)

func (Bars) SetStyle

func (b Bars) SetStyle(style tcell.Style)

func (Bars) SliceMethod

func (b Bars) SliceMethod() SliceMethod

func (Bars) Spacing

func (b Bars) Spacing() int

func (Bars) Style

func (b Bars) Style() tcell.Style

func (Bars) Values

func (b Bars) Values() []Decimal

type BlockBindings

type BlockBindings struct {
	*FlexBindings
	SplitH tcell.Key
	SplitV tcell.Key
	Delete tcell.Key
	Reset  tcell.Key
}

type Container

type Container struct {
	*tview.Box
	// contains filtered or unexported fields
}

Container is a dynamic box that can dynamically render different primitives.

func NewContainer

func NewContainer() *Container

func (*Container) Draw

func (c *Container) Draw(screen tcell.Screen)

func (*Container) Focus

func (c *Container) Focus(delegate func(p tview.Primitive))

func (*Container) HasFocus

func (c *Container) HasFocus() bool

func (*Container) InputHandler

func (c *Container) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

func (*Container) MouseHandler

func (c *Container) MouseHandler() func(
	action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive),
) (consumed bool, capture tview.Primitive)

func (*Container) SetPrimitive

func (c *Container) SetPrimitive(item tview.Primitive)

type Decimal

type Decimal interface {
	IsZero() bool
	Add(Decimal) Decimal
	Sub(Decimal) Decimal
	Mul(Decimal) Decimal
	Div(Decimal) Decimal
	Equal(Decimal) bool
	GreaterThan(Decimal) bool
	LessThan(Decimal) bool
	Float64() float64
	String() string
	Round() Decimal
	IntPart() int64
}

type DecimalFactory

type DecimalFactory interface {
	Zero() Decimal
	NewFromInt64(int64) Decimal
}

type DecimalValue

type DecimalValue struct {
	// Decimal value.
	Decimal Decimal
	// Valid is ture when Decimal is defined.
	Valid bool
}

DecimalValue represents a decimal value that can be undefined, in which case Valid is set to false.

type Direction

type Direction int
const (
	DirectionVertical   Direction = tview.FlexRow
	DirectionHorizontal Direction = tview.FlexColumn
)

type Flex

type Flex struct {
	*tview.Flex
	// contains filtered or unexported fields
}

Flex is a wrapper around tview.Flex that allows easy keyboard navigation.

func NewFlex

func NewFlex() *Flex

func (*Flex) Bindings

func (f *Flex) Bindings() *FlexBindings

func (*Flex) Direction

func (f *Flex) Direction() Direction

func (*Flex) Focus

func (b *Flex) Focus(setFocus func(p tview.Primitive))

func (*Flex) FocusedItem

func (f *Flex) FocusedItem() (i int, count int, item tview.Primitive)

func (*Flex) InputHandler

func (b *Flex) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

func (*Flex) SetBindings

func (f *Flex) SetBindings(bindings *FlexBindings)

func (*Flex) SetDirection

func (f *Flex) SetDirection(direction Direction)

type FlexBindings

type FlexBindings struct {
	FocusLeft  tcell.Key
	FocusDown  tcell.Key
	FocusUp    tcell.Key
	FocusRight tcell.Key
}

type Float

type Float float64

Float is an implemnetation of Decimal that uses float64.

func (Float) Add

func (f Float) Add(other Decimal) Decimal

func (Float) Div

func (f Float) Div(other Decimal) Decimal

func (Float) Equal

func (f Float) Equal(other Decimal) bool

func (Float) Float64

func (f Float) Float64() float64

func (Float) GreaterThan

func (f Float) GreaterThan(other Decimal) bool

func (Float) IntPart

func (f Float) IntPart() int64

func (Float) IsZero

func (f Float) IsZero() bool

func (Float) LessThan

func (f Float) LessThan(other Decimal) bool

func (Float) Mul

func (f Float) Mul(other Decimal) Decimal

func (Float) Round

func (f Float) Round() Decimal

func (Float) String

func (f Float) String() string

func (Float) Sub

func (f Float) Sub(other Decimal) Decimal

type FloatFactory

type FloatFactory struct{}

func (FloatFactory) NewFromInt64

func (f FloatFactory) NewFromInt64(i int64) Decimal

func (FloatFactory) Zero

func (f FloatFactory) Zero() Decimal

type Focus

type Focus int
const (
	FocusLeft Focus = iota
	FocusDown
	FocusUp
	FocusRight
)

type OHLC

type OHLC struct {
	Timestamp  time.Time
	O, H, L, C Decimal
	V          Decimal
}

OHLC represents an OHLC item with a timestamp.

type OHLCCandles

type OHLCCandles struct {
	*tview.Box
	// contains filtered or unexported fields
}

func NewOHLCCandles

func NewOHLCCandles(factory DecimalFactory) *OHLCCandles

func (*OHLCCandles) Draw

func (o *OHLCCandles) Draw(screen tcell.Screen)

func (*OHLCCandles) NegativeStyle

func (o *OHLCCandles) NegativeStyle() tcell.Style

func (*OHLCCandles) PositiveStyle

func (o *OHLCCandles) PositiveStyle() tcell.Style

func (*OHLCCandles) Runes

func (o *OHLCCandles) Runes() OHLCRunes

Runes returns the current set of runes used to plot the chart.

func (*OHLCCandles) Scale

func (o *OHLCCandles) Scale() Scale

func (*OHLCCandles) SetData

func (o *OHLCCandles) SetData(data []OHLC)

func (*OHLCCandles) SetNegativeStyle

func (o *OHLCCandles) SetNegativeStyle(negativeStyle tcell.Style)

func (*OHLCCandles) SetPositiveStyle

func (o *OHLCCandles) SetPositiveStyle(positiveStyle tcell.Style)

func (*OHLCCandles) SetRunes

func (o *OHLCCandles) SetRunes(runes OHLCRunes)

SetRunes sets the runes used to plot the chart.

func (*OHLCCandles) SetScale

func (o *OHLCCandles) SetScale(scale Scale)

func (*OHLCCandles) SetSpacing

func (o *OHLCCandles) SetSpacing(spacing int)

func (*OHLCCandles) Spacing

func (o *OHLCCandles) Spacing() int

type OHLCChart

type OHLCChart struct {
	*tview.Box
	// contains filtered or unexported fields
}

OHLCChart is a Box component that can render OHLCChart data.

func NewOHLCChart

func NewOHLCChart(factory DecimalFactory) *OHLCChart

NewOHLCChart creates a new instance of the OHLC component.

func (*OHLCChart) AddOffset

func (o *OHLCChart) AddOffset(delta int)

func (*OHLCChart) AddSpacing

func (o *OHLCChart) AddSpacing(delta int)

func (*OHLCChart) Draw

func (o *OHLCChart) Draw(screen tcell.Screen)

Draw implements tview.Primitive.

func (*OHLCChart) InputHandler

func (o *OHLCChart) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

MouseHandler implements tview.Primitive.

func (*OHLCChart) Items

func (o *OHLCChart) Items() []OHLC

Items returns the current OHLC data.

func (*OHLCChart) Logger

func (o *OHLCChart) Logger() io.Writer

Logger returns the current logger set. Used for debugging.

func (*OHLCChart) MouseHandler

func (o *OHLCChart) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)

MouseHandler implements tview.Primitive.

func (*OHLCChart) NegativeStyle

func (o *OHLCChart) NegativeStyle() tcell.Style

func (*OHLCChart) OHLCAxisStyle

func (o *OHLCChart) OHLCAxisStyle() tcell.Style

func (*OHLCChart) OHLCCandlesRunes

func (o *OHLCChart) OHLCCandlesRunes() OHLCRunes

func (*OHLCChart) Offset

func (o *OHLCChart) Offset() int

Offset returns the current offset.

func (*OHLCChart) PositiveStyle

func (o *OHLCChart) PositiveStyle() tcell.Style

func (*OHLCChart) SetItems

func (o *OHLCChart) SetItems(items []OHLC)

SetItems sets the OHLC data.

func (*OHLCChart) SetLogger

func (o *OHLCChart) SetLogger(w io.Writer)

SetLogger sets the logger for debugging.

func (*OHLCChart) SetNegativeStyle

func (o *OHLCChart) SetNegativeStyle(negativeStyle tcell.Style)

func (*OHLCChart) SetOHLCAxisStyle

func (o *OHLCChart) SetOHLCAxisStyle(style tcell.Style)

func (*OHLCChart) SetOHLCCandlesRunes

func (o *OHLCChart) SetOHLCCandlesRunes(runes OHLCRunes)

func (*OHLCChart) SetOffset

func (o *OHLCChart) SetOffset(offset int)

SetOffset sets the scroll offset for OHLC data. It ensures it's always less than the size of the items and is never negative.

func (*OHLCChart) SetPositiveStyle

func (o *OHLCChart) SetPositiveStyle(positiveStyle tcell.Style)

func (*OHLCChart) SetSpacing

func (o *OHLCChart) SetSpacing(spacing int)

SetSpacing sets the chart spacing.

func (*OHLCChart) SetVolumeAxisStyle

func (o *OHLCChart) SetVolumeAxisStyle(style tcell.Style)

func (*OHLCChart) SetVolumeBarsRunes

func (o *OHLCChart) SetVolumeBarsRunes(runes []rune)

func (*OHLCChart) SetVolumeBarsStyle

func (o *OHLCChart) SetVolumeBarsStyle(style tcell.Style)

func (*OHLCChart) SetVolumeHeight

func (o *OHLCChart) SetVolumeHeight(fraction float64)

func (*OHLCChart) Spacing

func (o *OHLCChart) Spacing() int

Spacing returns the current spacing.

func (*OHLCChart) VolumeAxisStyle

func (o *OHLCChart) VolumeAxisStyle() tcell.Style

func (*OHLCChart) VolumeBarsRunes

func (o *OHLCChart) VolumeBarsRunes() []rune

func (*OHLCChart) VolumeBarsStyle

func (o *OHLCChart) VolumeBarsStyle() tcell.Style

type OHLCRunes

type OHLCRunes struct {
	Same          rune
	HighOpenClose rune
	LowOpenClose  rune
	HighOpen      rune
	LowClose      rune
	High          rune
	Low           rune
	OpenClose     rune
	Open          rune
	Close         rune
	Thick         rune
	Thin          rune
}

OHLCRunes contains definitions for each OHLC drawing.

type Position

type Position int
const (
	Right Position = iota
	Left
)

type Primitive

type Primitive interface {
	// SetRect is the tview.Primitive.SetRect method.
	SetRect(x, y, w, h int)
	// SetRect is the tview.Primitive.Draw method.
	Draw(screen tcell.Screen)
	// SetScale sets the scale to the Primitive.
	SetScale(Scale)
	// Scale returns the current scale used by the Primitive.
	Scale() Scale
}

Primitive is a tview.Primitive that can set and retrieve a Scale.

type Range

type Range struct {
	Min Decimal
	Max Decimal
	// contains filtered or unexported fields
}

func NewRange

func NewRange(factory DecimalFactory) Range

func (Range) Feed

func (r Range) Feed(value Decimal) Range

func (Range) IsSet

func (r Range) IsSet() bool

type Scale

type Scale interface {
	Copy() Scale
	// Size returns the current size.
	Size() int
	// SetSize sets the size.
	SetSize(int)
	// SetRange sets the range of the values.
	SetRange(Range)
	// Range returns the current range.
	Range() Range
	// NumDecimals returns the number of decimals
	// needed to draw the axis.
	NumDecimals() int
	// Value returns the place on scale.
	Value(Decimal) int
	// Reverse returns the min value for the place on
	// scale.
	Reverse(int) Decimal
}

Scale describes a component that can scale decimal values to terminal grid.

type ScaleLinear

type ScaleLinear struct {
	// contains filtered or unexported fields
}

Linear represents a linear scale.

func NewScaleLinear

func NewScaleLinear(factory DecimalFactory) *ScaleLinear

NewLinear constructs a new linear scale.

func (*ScaleLinear) Copy

func (a *ScaleLinear) Copy() Scale

func (*ScaleLinear) NumDecimals

func (a *ScaleLinear) NumDecimals() int

func (*ScaleLinear) Range

func (a *ScaleLinear) Range() Range

func (*ScaleLinear) Reverse

func (a *ScaleLinear) Reverse(i int) Decimal

func (*ScaleLinear) SetRange

func (a *ScaleLinear) SetRange(rng Range)

SetRange sets the scale range.

func (*ScaleLinear) SetSize

func (a *ScaleLinear) SetSize(size int)

SetSize sets the size.

func (*ScaleLinear) Size

func (a *ScaleLinear) Size() int

Size returns the scale size.

func (*ScaleLinear) Value

func (a *ScaleLinear) Value(v Decimal) int

Value returns a scaled value from decimal.

type SliceMethod

type SliceMethod int

SliceMethod describes the slicing method when the number of items in the slice is too large to be rendered on the screen.

const (
	// Last means only the last items will be kept in the slice.
	Last SliceMethod = iota
	// First means only the first items will be kept in the slice.
	First
)

type Ticks

type Ticks struct {
	// contains filtered or unexported fields
}

func NewTicks

func NewTicks(factory DecimalFactory) *Ticks

func (Ticks) Data

func (b Ticks) Data() []Decimal

func (Ticks) DataSlice

func (b Ticks) DataSlice() []Decimal

DataSlice returns data, but only the items that fit on the screen.

func (*Ticks) Draw

func (b *Ticks) Draw(screen tcell.Screen)

func (Ticks) Runes

func (b Ticks) Runes() []rune

func (Ticks) Scale

func (b Ticks) Scale() Scale

func (Ticks) SetData

func (b Ticks) SetData(data []Decimal)

func (Ticks) SetRunes

func (b Ticks) SetRunes(runes []rune)

func (Ticks) SetScale

func (b Ticks) SetScale(scale Scale)

func (Ticks) SetSliceMethod

func (b Ticks) SetSliceMethod(method SliceMethod)

func (Ticks) SetSpacing

func (b Ticks) SetSpacing(spacing int)

func (Ticks) SetStyle

func (b Ticks) SetStyle(style tcell.Style)

func (Ticks) SliceMethod

func (b Ticks) SliceMethod() SliceMethod

func (Ticks) Spacing

func (b Ticks) Spacing() int

func (Ticks) Style

func (b Ticks) Style() tcell.Style

func (Ticks) Values

func (b Ticks) Values() []Decimal

type Tile

type Tile struct {
	*Flex
	// contains filtered or unexported fields
}

Tile is a wrapper around Flex that allows the user to dynamically create and remove splits, and navigate thorugh them, similar to a tiling window manager. See DefaultBlockBindings for default keybindings.

After calling NewTile, the user should call SetFactory.

func NewTile

func NewTile() *Tile

func (*Tile) Factory

func (t *Tile) Factory() func() tview.Primitive

func (*Tile) InputHandler

func (t *Tile) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

func (*Tile) SetBindings

func (t *Tile) SetBindings(bindings *BlockBindings)

func (*Tile) SetFactory

func (t *Tile) SetFactory(factory func() tview.Primitive)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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