chartbar

package
v0.0.0-...-931a278 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package chartbar 控制台绘制ascii柱状图

Index

Constants

This section is empty.

Variables

View Source
var DefaultCtx = NewCtx()

Functions

This section is empty.

Types

type Ctx

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

func NewCtx

func NewCtx(modOptions ...ModOption) *Ctx

func NewCtxWith

func NewCtxWith(ctx *Ctx, modOptions ...ModOption) *Ctx

NewCtxWith

在`ctx`参数基础上使用`modOptions`生成新的 Ctx

func (*Ctx) WithAnySlice

func (ctx *Ctx) WithAnySlice(a interface{}, iterateTransFn func(originItem interface{}) Item, modOptions ...ModOption) string

func (*Ctx) WithCsv

func (ctx *Ctx) WithCsv(filename string) (string, error)

func (*Ctx) WithItems

func (ctx *Ctx) WithItems(items []Item) string

WithItems

@param items: 注意,内部不会修改切片底层数据的值以及顺序

func (*Ctx) WithMap

func (ctx *Ctx) WithMap(m map[string]int) string

func (*Ctx) WithMapFloat

func (ctx *Ctx) WithMapFloat(m map[string]float64) string

type Item

type Item struct {
	Name string  // key
	Num  float64 // value
	// contains filtered or unexported fields
}

type ModOption

type ModOption func(option *Option)

type Option

type Option struct {
	MaxBarLength    int    // 柱状图形的最大长度
	DrawIconBlock   string // 柱状图实体绘制内容
	DrawIconPadding string // 柱状图空余部分绘制内容
	HideName        bool   // 是否隐藏图形旁边的Name字段
	HideNum         bool   // 是否隐藏图形旁边的Num字段

	Order          Order // 排序方式
	PrefixNumLimit int   // 只显示前`PrefixNumLimit`个元素,注意,可以和`SuffixNumLimit`同时使用
	SuffixNumLimit int   // 只显示后`SuffixNumLimit`个元素
}

type Order

type Order int
const (
	OrderOrigin    Order = iota + 1 // 原始序
	OrderAscCount                   // 按计数值升序排序
	OrderDescCount                  // 按计数值降序排序
	OrderAscName                    // 按字段名称升序排序
	OrderDescName                   // 按字段名称降序排序

	NoNumLimit = -1
)

Jump to

Keyboard shortcuts

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