godrawio

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

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

Go to latest
Published: Aug 30, 2022 License: LGPL-2.1 Imports: 2 Imported by: 0

README

Go Draw - Golang mxGraph (draw.io) types

Gopher mascot

This package provides types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most famously used by app.diagrams.net, the new name of draw.io.

License

Check out the LICENSE file at the root folder of this repository. If you're reading this text from some other source that is not through the Git repository itself, the repository lives in github.com/pauloqueiroga/godraw.

Contributing

The package as it is fulfills all of my current needs, but it's not completely done. Feel free to create Pull Requests with any improvements and additions you'd like to see in this package.

build-test
Maintainability Rating Reliability Rating Security Rating Quality Gate Status
Bugs Code Smells Coverage

Documentation

Overview

Package godraw implements basic types and helper functions to work with mxGraph Model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	XMLName  xml.Name `xml:"mxCell"`
	ID       string   `xml:"id,attr"`
	Value    string   `xml:"value,attr,omitempty"`
	Style    Style    `xml:"style,attr,omitempty"`
	ParentID string   `xml:"parent,attr,omitempty"`
	Vertex   string   `xml:"vertex,attr,omitempty"`
	Edge     string   `xml:"edge,attr,omitempty"`
	SourceID string   `xml:"source,attr,omitempty"`
	TargetID string   `xml:"target,attr,omitempty"`
	Geometry *Geometry
}

A Cell represents an element of the graph model. A cell can be a layer (its ParentID points to the root cell's ID); a vertex in a graph (Vertex="1"); or an edge in a graph (Edge="1").

func NewImage

func NewImage(id, layerId, url string) *Cell

NewImage returns a new Vertex Cell, configured as an image, with given unique ID (id), parent ID (layerId) and image source URL (url). The new cell contains a default geometry which you might want to change.

func NewImageXY

func NewImageXY(id, layerId, url string, x int, y int) *Cell

NewImageXY returns a new Vertex Cell, configured as an image, with given unique ID (id), parent ID (layerId), image source URL (url), and coordinates (x and y).

func NewShape

func NewShape(id, layerId string) *Cell

NewShape returns a new Vertex Cell, configured with the given unique ID (id) and parent ID (layerId). The new cell contains a default geometry which you might want to change.

type Geometry

type Geometry struct {
	XMLName  xml.Name `xml:"mxGeometry"`
	X        int      `xml:"x,attr,omitempty"`
	Y        int      `xml:"y,attr,omitempty"`
	Width    string   `xml:"width,attr,omitempty"`
	Height   string   `xml:"height,attr,omitempty"`
	Relative string   `xml:"relative,attr,omitempty"`
	As       string   `xml:"as,attr"`
}

A Geometry can be slightly different for vertices or edges. When used with vertices, it carries the x and y coordinates, the width, and the height of the vertex. For edges, contains optional terminal and control points. In most cases, the "As" attribute will have the value "geometry".

type GraphModel

type GraphModel struct {
	XMLName xml.Name `xml:"mxGraphModel"`
	Dx      int      `xml:"dx,attr"`
	Dy      int      `xml:"dy,attr"`
	Arrows  string   `xml:"arrows,attr,omitempty"`
	Root    []Cell   `xml:"root>mxCell"`
}

A GraphModel implements a wrapper around the cells which are in charge of storing the actual graph data structure.

The model must have a top-level root cell which contains the layers (typically one layer is enough). All cells with Parent ID pointing to the root cell is a layer. All other cells shall have parent IDs pointing to layers, not the root cell.

func NewGraph

func NewGraph(layerId string) GraphModel

NewGraph returns a new graph model containing a root cell and one layer with ID layerId.

func (*GraphModel) Add

func (g *GraphModel) Add(c *Cell) *GraphModel

Add adds the given Cell to the root cell of the receiving graph model.

type Style

type Style struct {
	Attributes map[string]string
}

A Style is a map of key-value pairs to describe the style properties of each cell.

func (Style) MarshalXMLAttr

func (a Style) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr returns an XML attribute with the encoded value of Style. It implements xml.MarshalerAttr interface.

func (*Style) UnmarshalXMLAttr

func (a *Style) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr decodes a single XML attribute of type Style. It implements xml.UnmarshalerAttr interface.

Jump to

Keyboard shortcuts

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