dataviewer

package module
v0.0.0-...-41c218c Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 8 Imported by: 1

README

go-dataviewer

Visualize your data in browser.

install

go get github.com/LiMoMoMo/go-dataviewer

steps

  1. embed viewer to your struct.
import (
	viewer "github.com/LiMoMoMo/go-dataviewer"
)

type Demo struct {
	viewer.Viewer
}
  1. implement GetVal(name string)
func (b *Demo) GetVal(name string) interface{} {
	val, ok := tempMap[name]
	if !ok {
		tempMap[name] = 0
	}
	tempMap[name] = val + rand.Intn(100)
	switch name {
	case "Value":
		return int64(rand.Intn(100))
	case "Memory":
		return int64(rand.Intn(1024 * 1024))
	case "BandWidth":
		return int64(rand.Intn(1024 * 1024))
	case "Rank":
		return tempMap
	}
	return ""
}
  1. register your data's name and type
demo.Register("Value", viewer.TypeValue)
demo.Register("Memory", viewer.TypeMemory)
demo.Register("BandWidth", viewer.TypeBandWidth)
demo.Register("Rank", viewer.TypeRank)
  1. start Run
demo := Demo{}
demo.SetChild(&demo, ctx)
...
demo.SetHttp("0.0.0.0:8946", 1)
demo.Run()
  1. visit http://127.0.0.1:8946/view in your browser, you will see somethings like this:

viewer

Documentation

Index

Constants

View Source
const (
	DEFAULTINTERVAL = 2
	VIEWERPATH      = "/view"
	AJAXPATH        = "/data"
	TYPEPATH        = "/types"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	// contains filtered or unexported methods
}

type ViewType

type ViewType int32
const (
	TypeValue     ViewType = 0
	TypeBandWidth ViewType = 1
	TypeMemory    ViewType = 2
	TypeRank      ViewType = 3
)

type Viewer

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

func (*Viewer) Register

func (v *Viewer) Register(name string, t ViewType) error

func (*Viewer) Run

func (v *Viewer) Run()

func (*Viewer) SetChild

func (v *Viewer) SetChild(c baseViewer, ctx context.Context)

func (*Viewer) SetHttp

func (v *Viewer) SetHttp(addr string, interval int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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