gopie

package module
v0.0.0-...-6c406c8 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: MIT Imports: 11 Imported by: 7

README

gopie

Package gopie renders pie charts to SVG.

Installation

To install gopie package run:

go get -u github.com/eugenezinovyev/gopie

Dependencies

This package depends on the following packages:

  • github.com/golang/freetype/truetype
  • golang.org/x/image/font
  • github.com/satori/go.uuid

These package are used for chart label dimensions measure. Check limitations of github.com/golang/freetype package if you plan to use label font different than the default one.

Defaults

  • Font used for label size measurement: Roboto Medium
  • Default slice colors: Material Design palette 400 (see: https://material.io/color)
  • Stroke color: white
  • Label font family: Roboto Medium
  • Label font size: 12
  • Label line length: 10px
  • Label line width: 2px
  • Label text padding: 4px
  • DPI ued for label size measurement: 92
  • Chart width: 200px
  • Chart height: 200px
  • Font: Roboto Medium
  • Embed font: false
  • Inner raduis: 0px

Usage

	chart := gopie.PieChart{
		Values: []gopie.Value{
			gopie.Value{Value: 1, Label: "One"},
			gopie.Value{Value: 2, Label: "Two"},
			gopie.Value{Value: 5, Label: "Five"},
		},
	}

	svgBytes, err := chart.SVG()

Custom slice colors

Check example in ./_examples/custom_colors

	chart := gopie.PieChart{
		...
		SliceColors:    []string{"firebrick", "sandybrown", "mediumseagreen", "deepskyblue"},
		...
	}

Embed font

Check example in ./_examples/font

	robotoRegular, err := ioutil.ReadFile("Roboto-Regular.ttf")
	check(err)
	chart.SetFont(robotoRegular)

Donut

Check example in ./_examples/donut

	chart := gopie.PieChart{
		...
		InnerRadius:    90, // Forces chart to leave empty circle with 90px radius at center
		...
	}

You can also check ./_examples folder for more examples of usage.

Licence

MIT

Documentation

Overview

Package gopie renders pie charts to SVG.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PieChart

type PieChart struct {
	Width          float64  // SVG Width. Default is 200.
	Height         float64  // SVG Height. Default is 200.
	Values         []Value  // Chart values.
	SliceColors    []string // Colors to be used for pie slices and label lines.
	StrokeColor    string   // Slice stroke color. Default is "#ffffff".
	StrokeWidth    float64  // Slice stroke width. Default is 0 px.
	FontSize       float64  // Label font size. Default is 12 px.
	FontFamily     string   // Label font family. Default is "Roboto Medium".
	LabelLine      float64  // Label line length. Default is 10 px.
	LabelLineWidth float64  // Label line width. Default is 2 px.
	LabelPadding   float64  // Label text padding. Default is 4 px.
	DPI            float64  // DPI. Default is 92.

	EmbedFont   bool    // Whether embed font or not. Default is false.
	InnerRadius float64 // Inner radius or donut chart. Default is 0 which means by default pie chart will be rendered.
	// contains filtered or unexported fields
}

PieChart struct represents a pie chart rendering options.

func (PieChart) SVG

func (o PieChart) SVG() (svgBytes []byte, err error)

SVG function renders pie chart to SVG

func (*PieChart) SetFont

func (c *PieChart) SetFont(ttf []byte) (err error)

SetFont function sets font for the chart. The parameter should contain bytes of TTF font.

type Value

type Value struct {
	Value float64 // Value.
	Label string  // Label of value.
}

Value represents chart value.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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