washeet

package module
v0.0.0-...-e915897 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MPL-2.0 Imports: 6 Imported by: 0

README

washeet

Washeet is a spreadsheet web ui package written in golang. The project aims to provide a fast, light-weight, well polished spreadsheet ui targeting web applications that need to present streaming tabular data and allow user interactions. As of now it is very much in its early stages and only has some basic features like -

  • setting cell contents via api, but cells not yet user editable.
  • control cell font size, attributes like bold, italics and underline via api
  • control cell foreground/background via api
  • cell content alignment control via api.
  • all above features can be changed any time while sheet is running, taking advantage of 60 fps canvas.
  • individual column-width and row-height control via api.
  • cell cursor movements with mouse as well as with keyboard.
  • cell range selection with mouse as well as with keyboard.
  • copying cell/cell-range contents to clipboard.

API documentation

Things are still in flux, but see godoc for the current form.

Is there a demo/example ?

Yes, there is one in the demo sub-directory. The demo shows how to feed your data to the spreadsheet. The data in the demo is just random numbers but it could potentially come from outside, say from a websocket connection(s) from the server. See below for how to setup the demo. You must have installed Go version >= 1.11 and "GNU make" to do this. Technically you don't need "make" but it would certainly make things easier if you do. Obviously you would need a very recent browser with good web-assembly support like chrome/firefox.

# Get the package.
$ go get -u github.com/dennisfrancis/washeet

# Go to package's src root.
$ cd $GOPATH/src/github.com/dennisfrancis/washeet

# Build the demo
$ make demo

Run any http server in the demo directory as root. For instance

$ cd demo
$ python3 -m http.server

Open Chrome browser and point to "http://127.0.0.1:8000". Now you can see the demo in action!

Contributing

You are always welcome to submit a bug-report(issues) here or provide a pull request. Happy hacking !

Documentation

Overview

Package washeet provides a HTML5 canvas based spreadsheet user-interface for web-assembly target.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellAttribs

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

CellAttribs stores the attributes of a cell.

func NewDefaultCellAttribs

func NewDefaultCellAttribs() *CellAttribs

NewDefaultCellAttribs return a pointer to a new instance of CellAttribs with default settings.

func (*CellAttribs) GetAlignment

func (cAttribs *CellAttribs) GetAlignment() TextAlignType

GetAlignment returns the cell text alignment setting.

func (*CellAttribs) GetBGColor

func (cAttribs *CellAttribs) GetBGColor() *Color

GetBGColor returns the background color setting.

func (*CellAttribs) GetFGColor

func (cAttribs *CellAttribs) GetFGColor() *Color

GetFGColor returns the foreground color setting.

func (*CellAttribs) GetFontSize

func (cAttribs *CellAttribs) GetFontSize() uint8

GetFontSize returns the font size setting in pixels.

func (*CellAttribs) IsBold

func (cAttribs *CellAttribs) IsBold() bool

IsBold returns whether bold attribute is set or not.

func (*CellAttribs) IsItalics

func (cAttribs *CellAttribs) IsItalics() bool

IsItalics returns whether italics attribute is set or not.

func (*CellAttribs) IsUnderline

func (cAttribs *CellAttribs) IsUnderline() bool

IsUnderline returns whether underline attribute is set or not.

func (*CellAttribs) SetAlignment

func (cAttribs *CellAttribs) SetAlignment(align TextAlignType)

SetAlignment sets the cell text alignment setting.

func (*CellAttribs) SetBGColor

func (cAttribs *CellAttribs) SetBGColor(color *Color)

SetBGColor sets the background color.

func (*CellAttribs) SetBold

func (cAttribs *CellAttribs) SetBold(flag bool)

SetBold sets/unsets the cell text's bold attribute.

func (*CellAttribs) SetFGColor

func (cAttribs *CellAttribs) SetFGColor(color *Color)

SetFGColor sets the foreground color.

func (*CellAttribs) SetFontSize

func (cAttribs *CellAttribs) SetFontSize(size uint8)

SetFontSize sets the font size provided in pixels.

func (*CellAttribs) SetItalics

func (cAttribs *CellAttribs) SetItalics(flag bool)

SetItalics sets/unsets the cell text's italics attribute.

func (*CellAttribs) SetUnderline

func (cAttribs *CellAttribs) SetUnderline(flag bool)

SetUnderline sets/unsets the cell text's underline attribute.

type Color

type Color uint32

Color represents a color.

func NewColor

func NewColor(red, green, blue uint8) *Color

NewColor returns a pointer to a new Color object with "red", "blue" and "green" components.

func (*Color) Blue

func (color *Color) Blue() uint8

Blue returns the blue component of Color.

func (*Color) Green

func (color *Color) Green() uint8

Green returns the green component of Color.

func (*Color) Red

func (color *Color) Red() uint8

Red returns the red component of Color.

type Sheet

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

Sheet represents the spreadsheet user-interface.

func NewSheet

func NewSheet(container *js.Value, width float64, height float64, dSrc SheetDataProvider) *Sheet

NewSheet creates a spreadsheet ui within the given div container The new spreadsheet ui will be drawn in a canvas of dimensions (width, height) dSrc must be an implementation of SheetDataProvder which is used to draw the contents of the spreadsheet.

Note that the spreadsheet does not become visible after calling NewSheet. For that Start() method needs to be called.

func (*Sheet) Start

func (sheet *Sheet) Start()

Start starts the rendering of the spreadsheet and listens to user interactions.

func (*Sheet) Stop

func (sheet *Sheet) Stop()

Stop stops all internal user-event handlers, stops the rendering loop and cleans up the portion of canvas designated to Sheet created by NewSheet.

func (*Sheet) UpdateCell

func (sheet *Sheet) UpdateCell(column, row int64)

UpdateCell redraws the contents of the provided cell location.

func (*Sheet) UpdateRange

func (sheet *Sheet) UpdateRange(startColumn, startRow, endColumn, endRow int64)

UpdateRange redraws the contents of the provided range.

type SheetDataProvider

type SheetDataProvider interface {
	// GetDisplayString returns the content of the cell at (column,row) as a string.
	GetDisplayString(column int64, row int64) string

	// GetCellAttribs returns cell-attributes information via CellAttribs type.
	GetCellAttribs(column, row int64) *CellAttribs

	// GetColumnWidth returns the width of "column" column in pixels.
	GetColumnWidth(column int64) float64

	// GetRowHeight returns the height of "row" row in pixels.
	GetRowHeight(row int64) float64

	// TrimToNonEmptyRange trims given range represented by
	// { top-left cell (column = c1, row = r1), bottom-right cell (column = c2, row = r2)
	// to the biggest sub-range that does not have any leading/trailing empty columns/rows.
	// It returns false if given range is completely empty, else it returns true.
	TrimToNonEmptyRange(c1, r1, c2, r2 *int64) bool
}

SheetDataProvider is the interface that needs to be implemented by the user of washeet which is used to draw and populate the contents of the spreadsheet.

type SheetNotifier

type SheetNotifier interface {
	// UpdateCell call tells washeet that the specified cell contents have changed
	// and needs redrawing.
	UpdateCell(column, row int64)

	// UpdateRange call tells washeet that the specified range's contents have changed
	// and needs redrawing.
	UpdateRange(startColumn, startRow, endColumn, endRow int64)
}

SheetNotifier is the interface via which client-users of washeet can notify which cell/range has changed its contents.

type TextAlignType

type TextAlignType byte

TextAlignType is used to represent alignment of a cell's content.

const (
	// AlignLeft indicates left-alignment of cell-content.
	AlignLeft TextAlignType = iota
	// AlignCenter indicates center-alignment of cell-content.
	AlignCenter
	// AlignRight indicates right-alignment of cell-content.
	AlignRight
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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