canvas

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

The Draw method signature declared in the Drawer interface implements the method separately on Line and Text struct.

Index

Constants

View Source
const CellSize float64 = 20

CellSize defines symbol's cell size.

Variables

This section is empty.

Functions

func DrawDiagram

func DrawDiagram(content string, output string, fontPath string) error

DrawDiagram generates the diagram and saves into the image file.

func X

func X(x float64) float64

X returns the symbols x position.

func Y

func Y(y float64) float64

Y returns the symbol y position.

Types

type Canvas

type Canvas struct {
	*gg.Context
	// contains filtered or unexported fields
}

Canvas defines the canvas basic elements.

func NewCanvas

func NewCanvas(ctx *gg.Context, font string, lineWidth float64) *Canvas

NewCanvas is a constructor method, which instantiates a new Canvas element.

type Diagram

type Diagram struct{}

Diagram defines a basic empty struct.

func (*Diagram) ParseASCIIArt

func (d *Diagram) ParseASCIIArt(str string) []*Figures

ParseASCIIArt parses a given ASCII string into a list of figures.

type Drawer

type Drawer interface {
	Draw(*Canvas)
}

Drawer interface defines the Canvas drawing method. Struct needs to implement the Draw method.

type Figures

type Figures struct {
	Line
	Text
}

Figures defines a compounded struct containing the Line and Text struct elements.

type Line

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

Line struct defines the line x & y coordinates, the starting and ending type and the color.

func NewLine

func NewLine(x0, y0 int, start string, x1, y1 int, end string, color string) *Line

NewLine draws a new line from (x0, y0) to (x1, y1) with the given color at the start and end symbol.

func (*Line) Draw

func (line *Line) Draw(ctx *Canvas)

Draw draws a line from (x0, y0) to (x1, y1) with the given color.

type Point

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

Point is an auxiliary struct used during parsing.

func NewPoint

func NewPoint(x, y int) *Point

NewPoint instantiates a new Point.

type Text

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

Text struct containing the text x and y coordinates and the color.

func NewText

func NewText(x0, y0 int, text, color string) *Text

NewText returns a new text annotation at (x0, y0) with the given color.

func (*Text) Draw

func (text *Text) Draw(ctx *Canvas)

Draw draws the text annotation at (x0, y0) with the given color.

Jump to

Keyboard shortcuts

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