google_jsgraph

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: BSD-3-Clause Imports: 8 Imported by: 2

Documentation

Overview

package google_jsgraph provides google javascript bar graph and pie graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustEmit

func MustEmit(graphs map[string]Graph) template.HTML

MustEmit emits the javascript chunk that renders the graphs. In graphs, the keys are the ids of the div tags where the graphs go. The keys must match [a-z0-9]+ or else MustEmit panics. The return value of MustEmit belongs in the head section of the html document.

Types

type BarGraph

type BarGraph struct {

	// The graph data
	Data GraphData

	// Palette consists of the RGB colors to use in the bar graph.
	// e.g []String{"FF0000", "00FF00", "0000FF"}
	Palette []string
}

BarGraph represents a bar graph.

func (*BarGraph) EmitCode

func (b *BarGraph) EmitCode(name string, sb *strings.Builder)

func (*BarGraph) EmitPackages

func (b *BarGraph) EmitPackages(packages map[string]struct{})

type Graph

type Graph interface {

	// Emits the package names this graph depends on to the packages map.
	EmitPackages(packages map[string]struct{})

	// Emits the the code within the drawCharts() function that draws this
	// graph.
	EmitCode(name string, sb *strings.Builder)
}

Graph represents a Google javascript graph

type GraphData

type GraphData interface {

	// The number of X data points
	XLen() int

	// The number of Y data points
	YLen() int

	// The title of the X labels
	XTitle() string

	// Return 0-based label for X axis
	XLabel(x int) string

	// Return 0-based label for Y axis
	YLabel(y int) string

	// Return value at (x, y)
	Value(x, y int) float64
}

GraphData represents a dataset to be graphed.

type PieGraph

type PieGraph struct {

	// The graph data. YLen should be 1.
	Data GraphData

	// Optional: Palette consists of the RGB colors to use in the pie graph.
	// e.g []String{"FF0000", "00FF00", "0000FF"}. If omitted, Google chooses
	// the palette.
	Palette []string
}

PieGraph represents a pie graph.

func (*PieGraph) EmitCode

func (p *PieGraph) EmitCode(name string, sb *strings.Builder)

func (*PieGraph) EmitPackages

func (p *PieGraph) EmitPackages(packages map[string]struct{})

Jump to

Keyboard shortcuts

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