Documentation ¶
Overview ¶
Package chart implements common chart/plot types.
The following chart types are available:
StripChart Visualize set of numeric values ScatterChart Plot (x,y) data (with optional error bars) and/or functions HistChart Produce histograms from data BarChart Show (x,y) data as bars BoxChart Box charts to visualize distributions PieChart Pie and Ring charts
Chart tries to provides useful defaults and produce nice charts without sacrificing accuracy. The generated charts look good and are higly customizable but will not match the visual quality of handmade photoshop charts or the statistical features of charts produced by S or R.
Creating charts consists of the following steps:
- Create chart object
- Configure chart, axis, autoscaling etc.
- Add one ore more data sets
- Render chart to one or more graphic outputs
You may change the configuration at any step or render to different outputs.
The different chart types and their fields are all simple struct types where the zero value provides suitable defaults. All fields are exported, even if you are not supposed to manipulate them directy or are 'output fields'. E.g. the common Data field of all chart types will store the sample data added with one or more Add... methods. Some fields are mere output which expose internal stuff for your use like the Data2Screen and Screen2Data functions of the Ranges. Some fields are even input/output fields: E.g. you may set the Range.TicSetting.Delta to some positive value which will be used as the spacing between tics on that axis; on the other hand if you leave Range.TicSetting.Delta at its default 0 you indicate to the plotting routine to automatically determine the tic delta which is then reported back in this fields.
All charts (except pie/ring charts) contain at least one axis represented by a field of type Range. Axis can be differented into following categories:
o Date/Time axis (Time=true): The values on this axis are interpreted as seconds since the Unix epoc, tics are labeld in date and time units. (The Log and Category fields are simply ignored for Date/Time axis.) o Real valued axis (Time=false). Those come in different flavours: - Simple linear real valued axis (Log=false, Category=nil). - Logrithmic axis (Log=True). Such an axis may cover only a range of ]0,inf[ - Categorical axis (Log=false, Category!=nil): The values 0, 1, 2, ... are labeled with the strings in Category. (You might want to set up the range manually, e.g. with the Fixed() method of Range)
How the axis is autoscaled can be controlled for both ends of the axis individually by MinMode and MaxMode which allow a fine control of the (auto-) scaling.
After setting up the chart, adding data, samples, functions you can render the chart to a Graphics output. This process will set several internal fields of the chart. If you reuse the chart, add additional data and output it again these fields might no longer indicate 'automatical/default' but contain the value calculated in the first output round.
Index ¶
- Variables
- func AbsoluteValue(value, sum float64) (s string)
- func FmtFloat(f float64) string
- func GenericBars(bg BasicGraphics, bars []Barinfo, style Style)
- func GenericBoxes(bg BasicGraphics, boxes []Box, width int, style Style)
- func GenericCircle(bg BasicGraphics, x, y, r int, style Style)
- func GenericKey(bg BasicGraphics, x, y int, key Key, options PlotOptions)
- func GenericPath(mg MinimalGraphics, x, y []int, style Style)
- func GenericRect(mg MinimalGraphics, x, y, w, h int, style Style)
- func GenericRings(bg BasicGraphics, wedges []Wedgeinfo, x, y, ro, ri int, eccentricity float64)
- func GenericScatter(bg BasicGraphics, points []EPoint, plotstyle PlotStyle, style Style)
- func GenericSymbol(bg BasicGraphics, x, y int, style Style)
- func GenericTextLen(mg MinimalGraphics, t string, font Font) (width int)
- func GenericWedge(mg MinimalGraphics, x, y, ro, ri int, phi, psi, ecc float64, style Style)
- func GenericXAxis(bg BasicGraphics, rng Range, y, ym int, options PlotOptions)
- func GenericYAxis(bg BasicGraphics, rng Range, x, xm int, options PlotOptions)
- func IntegerValue(value, sum float64) (s string)
- func NextSymbol(s int) int
- func PercentValue(value, sum float64) (s string)
- func PercentilInt(data []int, p int) int
- func SanitizeRect(x, y, w, h, r int) (int, int, int, int)
- func SixvalFloat64(data []float64, p int) (min, lq, med, avg, uq, max float64)
- func SixvalInt(data []int, p int) (min, lq, med, avg, uq, max int)
- func SymbolIndex(s int) (idx int)
- type BarChart
- type BarChartData
- type Barinfo
- type BasicGraphics
- type Box
- type BoxChart
- type BoxChartData
- type CatValue
- type CategoryChartData
- type CategoryValue
- type Chart
- type EPoint
- type Expansion
- type Font
- type FontSize
- type Graphics
- type GridMode
- type HistChart
- type HistChartData
- type Kernel
- type Key
- type KeyEntry
- type LayoutData
- type LineStyle
- type MinimalGraphics
- type MirrorAxis
- type PieChart
- type PlotElement
- type PlotOptions
- type PlotStyle
- type Point
- type Range
- type RangeMode
- type Real
- type ScatterChart
- func (c *ScatterChart) AddData(name string, data []EPoint, plotstyle PlotStyle, style Style)
- func (c *ScatterChart) AddDataGeneric(name string, data []XYErrValue, plotstyle PlotStyle, style Style)
- func (c *ScatterChart) AddDataPair(name string, x, y []float64, plotstyle PlotStyle, style Style)
- func (c *ScatterChart) AddFunc(name string, f func(float64) float64, plotstyle PlotStyle, style Style)
- func (c *ScatterChart) Plot(g Graphics)
- func (c *ScatterChart) Reset()
- type ScatterChartData
- type StripChart
- type Style
- type Tic
- type TicSetting
- type Value
- type Wedgeinfo
- type XYErrValue
- type XYValue
Constants ¶
This section is empty.
Variables ¶
var ( KeyHorSep float32 = 1.5 // Horizontal spacing between key box and content KeyVertSep float32 = 0.5 // Vertical spacing between key box and content KeyColSep float32 = 2.0 // Horizontal spacing between two columns in key KeySymbolWidth float32 = 5 // Horizontal length/space reserved for symbol KeySymbolSep float32 = 2 // Horizontal spacing bewteen symbol and text KeyRowSep float32 = 0.75 // Vertical spacing between individual rows. )
The following variables control the layout of the key/legend box. All values are in font-units (fontheight for vertical, fontwidth for horizontal values)
var CharacterWidth = map[int]float32{'a': 16.8, 'b': 17.0, 'c': 15.2, 'd': 16.8, 'e': 16.8, 'f': 8.5, 'g': 17.0,
'h': 16.8, 'i': 5.9, 'j': 5.9, 'k': 16.8, 'l': 6.9, 'm': 25.5, 'n': 16.8, 'o': 16.8, 'p': 17.0, 'q': 17.0,
'r': 10.2, 's': 15.2, 't': 8.4, 'u': 16.8, 'v': 15.4, 'w': 22.2, 'x': 15.2, 'y': 15.2, 'z': 15.2,
'A': 20.2, 'B': 20.2, 'C': 22.2, 'D': 22.2, 'E': 20.2, 'F': 18.6, 'G': 23.5, 'H': 22.0, 'I': 8.2, 'J': 15.2,
'K': 20.2, 'L': 16.8, 'M': 25.5, 'N': 22.0, 'O': 23.5, 'P': 20.2, 'Q': 23.5, 'R': 21.1, 'S': 20.2, 'T': 18.5,
'U': 22.0, 'V': 20.2, 'W': 29.0, 'X': 20.2, 'Y': 20.2, 'Z': 18.8, ' ': 8.5,
'1': 16.8, '2': 16.8, '3': 16.8, '4': 16.8, '5': 16.8, '6': 16.8, '7': 16.8, '8': 16.8, '9': 16.8, '0': 16.8,
'.': 8.2, ',': 8.2, ':': 8.2, ';': 8.2, '+': 17.9, '"': 11.0, '*': 11.8, '%': 27.0, '&': 20.2, '/': 8.4,
'(': 10.2, ')': 10.2, '=': 18.0, '?': 16.8, '!': 8.5, '[': 8.2, ']': 8.2, '{': 10.2, '}': 10.2, '$': 16.8,
'<': 18.0, '>': 18.0, '§': 16.8, '°': 12.2, '^': 14.2, '~': 18.0,
}
CharacterWidth is a table of the (relative) width of common runes.
var DefaultOptions = map[PlotElement]Style{ MajorAxisElement: Style{LineColor: color.NRGBA{0, 0, 0, 0xff}, LineWidth: 2, LineStyle: SolidLine}, MinorAxisElement: Style{LineColor: color.NRGBA{0, 0, 0, 0xff}, LineWidth: 2, LineStyle: SolidLine}, MajorTicElement: Style{LineColor: color.NRGBA{0, 0, 0, 0xff}, LineWidth: 1, LineStyle: SolidLine}, MinorTicElement: Style{LineColor: color.NRGBA{0, 0, 0, 0xff}, LineWidth: 1, LineStyle: SolidLine}, ZeroAxisElement: Style{LineColor: color.NRGBA{0x40, 0x40, 0x40, 0xff}, LineWidth: 1, LineStyle: SolidLine}, GridLineElement: Style{LineColor: color.NRGBA{0x80, 0x80, 0x80, 0xff}, LineWidth: 1, LineStyle: SolidLine}, GridBlockElement: Style{LineColor: color.NRGBA{0xe6, 0xfc, 0xfc, 0xff}, LineWidth: 0, FillColor: color.NRGBA{0xe6, 0xfc, 0xfc, 0xff}}, KeyElement: Style{LineColor: color.NRGBA{0x20, 0x20, 0x20, 0xff}, LineWidth: 1, LineStyle: SolidLine, FillColor: color.NRGBA{0xf0, 0xf0, 0xf0, 0xc0}, Font: Font{Size: SmallFontSize}}, TitleElement: Style{LineColor: color.NRGBA{0, 0, 0, 0xff}, LineWidth: 1, LineStyle: SolidLine, FillColor: color.NRGBA{0xec, 0xc7, 0x50, 0xff}, Font: Font{Size: LargeFontSize}}, RangeLimitElement: Style{Font: Font{Size: SmallFontSize}}, }
DefaultStyle maps chart elements to styles.
var ExpandABitFraction = 0.5
ExpandABitFraction is the fraction of a major tic spacing added during axis range expansion with the ExpandABit mode.
var PieChartHighlight = 0.15 // How much are flaged segments offset.
var PieChartShrinkage = 0.66 // Scaling factor of radius of next data set.
var StandardColors = []color.Color{}
Standard colors used by AutoStyle
var StandardLineStyles = []LineStyle{SolidLine, DashedLine, DottedLine, LongDashLine, LongDotLine}
Standard line styles used by AutoStyle (fill=false)
var StandardSymbols = []int{'o', '=', '%', '&', '+', 'X', '*', '@', '#', 'A', 'Z'}
Standard symbols used by AutoStyle
var Symbol = []int{
'o',
'=',
'%',
'&',
'+',
'X',
'*',
'0',
'@',
'#',
'A',
'W',
'V',
'Z',
'.',
}
Symbol is the list of different symbols.
var Units = []string{" y", " z", " a", " f", " p", " n", " µ", "m", " k", " M", " G", " T", " P", " E", " Z", " Y"}
Units are the SI prefixes for 10^3n
Functions ¶
func AbsoluteValue ¶
AbsoluteValue will format value (ignoring sum). It is a convenience function which can be assigned to the PieChart.FmtVal or PieChart.FmtKey field.
func FmtFloat ¶
FmtFloat yields a string representation of f. E.g. 12345.67 --> "12.3 k"; 0.09876 --> "99 m"
func GenericBars ¶
func GenericBars(bg BasicGraphics, bars []Barinfo, style Style)
GenericBars draws the bars in the given style using bg. TODO: Is Bars and Generic Bars useful at all? Replaceable by rect?
func GenericBoxes ¶
func GenericBoxes(bg BasicGraphics, boxes []Box, width int, style Style)
GenericBoxes draws box plots. (Default implementation for box plots). The values for each box in boxes are in screen coordinates!
func GenericCircle ¶
func GenericCircle(bg BasicGraphics, x, y, r int, style Style)
GenericCircle approximates a circle of radius r around (x,y) with lines.
func GenericKey ¶
func GenericKey(bg BasicGraphics, x, y int, key Key, options PlotOptions)
GenericKey draws the key onto bg at (x,y).
func GenericPath ¶
func GenericPath(mg MinimalGraphics, x, y []int, style Style)
GenericPath is the incomplete implementation of a list of points connected by straight lines. Incomplete: Dashed lines won't work properly.
func GenericRect ¶
func GenericRect(mg MinimalGraphics, x, y, w, h int, style Style)
GenericRect draws a rectangle of size w x h at (x,y). Drawing is done by simple lines only.
func GenericRings ¶
func GenericRings(bg BasicGraphics, wedges []Wedgeinfo, x, y, ro, ri int, eccentricity float64)
GeenricRings draws wedges for pie/ring charts charts. The pie's/ring's center is at (x,y) with ri and ro the inner and outer diameter. Eccentricity allows to correct for non-square pixels (e.g. in text mode).
func GenericScatter ¶
func GenericScatter(bg BasicGraphics, points []EPoint, plotstyle PlotStyle, style Style)
GenericScatter draws the given points according to style. style.FillColor is used as color of error bars and style.FontSize is used as the length of the endmarks of the error bars. Both have suitable defaults if the FontXyz are not set. Point coordinates and errors must be provided in screen coordinates.
func GenericSymbol ¶
func GenericSymbol(bg BasicGraphics, x, y int, style Style)
GenericSymbol draws the symbol defined by style at (x,y).
func GenericTextLen ¶
func GenericTextLen(mg MinimalGraphics, t string, font Font) (width int)
GenericTextLen tries to determine the width in pixel of t if rendered into mg in using font.
func GenericWedge ¶
func GenericWedge(mg MinimalGraphics, x, y, ro, ri int, phi, psi, ecc float64, style Style)
GenericWedge draws a pie/wedge just by lines
func GenericXAxis ¶
func GenericXAxis(bg BasicGraphics, rng Range, y, ym int, options PlotOptions)
GenericXAxis draws the x-axis with range rng solely by graphic primitives of bg. The x-axis is drawn at y on the screen and the mirrored x-axis is drawn at ym.
func GenericYAxis ¶
func GenericYAxis(bg BasicGraphics, rng Range, x, xm int, options PlotOptions)
GenericYAxis draws the y-axis with the range rng solely by graphic primitives of bg. The y.axis and the mirrord y-axis are drawn at x and ym respectively.
func IntegerValue ¶
IntegerValue will format value (ignoring sum) as an integer. It is a convenience function which can be assigned to the PieChart.FmtVal or PieChart.FmtKey field.
func NextSymbol ¶
NextSymbol returns the next symbol of s: Either in the global list Symbol or (if not found there) the next character.
func PercentValue ¶
PercentValue formats value as percentage of sum. It is a convenience function which can be assigned to the PieChart.FmtVal or PieChart.FmtKey field.
func PercentilInt ¶
Return p percentil of pre-sorted integer data. 0 <= p <= 100.
func SanitizeRect ¶
SanitizeRect returns the top left corner and the positive width and height of the given (possibly unsanitized) rectangle taking into account the line width r.
func SixvalFloat64 ¶
Compute minimum, p percentil, median, average, 100-p percentil and maximum of values in data.
func SixvalInt ¶
Compute minimum, p percentil, median, average, 100-p percentil and maximum of values in data.
func SymbolIndex ¶
SymbolIndex returns the index of the symbol s in Symbol or -1 if not found.
Types ¶
type BarChart ¶
type BarChart struct {
XRange, YRange Range
Title string // Title of the chart
Key Key // Key/Legend
Horizontal bool // Display as horizontal bars (unimplemented)
Stacked bool // Display different data sets ontop of each other (default is side by side)
ShowVal int // Display values: 0: don't show; 1: above bar, 2: centerd in bar; 3: at top of bar
ShowValFormat func(float64) string
SameBarWidth bool // all data sets use the same (smalest of all data sets) bar width
BarWidthFac float64 // if nonzero: scale determined bar width with this factor
Options PlotOptions // visual apperance, nil to use DefaultOptions
Data []BarChartData
}
BarChart draws simple bar charts. (Use CategoricalBarChart if your x axis is categorical, that is not numeric.)
Stacking is on a "both bars have _identical_ x values" basis.
func (*BarChart) AddDataPair ¶
AddDataPair is a convenience method to add all the (x[i],y[i]) pairs to the chart.
type BarChartData ¶
BarChartData encapsulates data sets in a bar chart.
type Barinfo ¶
type Barinfo struct {
// contains filtered or unexported fields
}
Barinfo describes a rectangular bar (e.g. in a histogram or a bar plot).
type BasicGraphics ¶
type BasicGraphics interface { MinimalGraphics Symbol(x, y int, style Style) // Put symbol s at (x,y) Rect(x, y, w, h int, style Style) // Draw (w x h) rectangle at (x,y) Wedge(x, y, ro, ri int, phi, psi float64, style Style) // Wedge Path(x, y []int, style Style) // Path of straight lines Options() PlotOptions // access to current PlotOptions }
BasicGraphics is an interface of the most basic graphic primitives. Any type which implements BasicGraphics can use generic implementations of the Graphics methods.
type Box ¶
type Box struct { X float64 // x-position of the box Avg float64 // "average" value (uncommon in std. box plots, but sometimes useful) Q1, Med, Q3 float64 // lower quartil, median and upper quartil Low, High float64 // low and hig end of whiskers (normaly last point in the 1.5*IQR range of Q1/3) Outliers []float64 // list of y-values of outliers }
Box represents a box in an boxplot.
type BoxChart ¶
type BoxChart struct {
XRange, YRange Range // x and y axis
Title string // Title of the chart
Key Key // Key/legend
Options PlotOptions
Data []BoxChartData // the data sets to draw
}
BoxChart represents box charts.
To faciliate standard use of box plots, the method AddSet() exists which will calculate the various elents of a box (e.g. med, q3, outliers, ...) from raw data.
func (*BoxChart) AddSet ¶
AddSet will add to last data set in the chart one new box calculated from data. If outlier is true, than outliers (1.5*IQR from 25/75 percentil) are drawn. If outlier is false, than the wiskers extend from min to max.
func (*BoxChart) NextDataSet ¶
NextDataSet adds a new (empty) data set to chart. After adding the data set you can fill this last data set with AddSet()
type BoxChartData ¶
BoxChartData encapsulates a data set in a box chart
type CategoryChartData ¶
type CategoryValue ¶
CategoryValue is the interface for any type of data which is a category-real-pair.
type Chart ¶
type Chart interface { Plot(g Graphics) // Plot the chart to g. Reset() // Reset any setting made during last plot. }
Chart ist the very simple interface for all charts: They can be plotted to a graphics output.
type EPoint ¶
type EPoint struct {
X, Y float64
DeltaX, DeltaY float64 // Full range of x and y error, NaN for no errorbar.
OffX, OffY float64 // Offset of error range (must be < Delta)
}
EPoint represents a point in two dimensions (X,Y) with possible error ranges in both dimensions. To faciliate common symetric errors, OffX/Y defaults to 0 and only DeltaX/Y needs to be set up.
func (EPoint) BoundingBox ¶
type Expansion ¶
type Expansion int
Expansion determines the way an axis range is expanded to align nicely with the tics on the axis.
const ( ExpandNextTic Expansion = iota // Set min/max to next tic really below/above min/max of data. ExpandToTic // Set to next tic below/above or equal to min/max of data. ExpandTight // Use data min/max as limit. ExpandABit // Like ExpandToTic and add/subtract ExpandABitFraction of tic distance. )
Suitable values for Expand in RangeMode.
type Font ¶
type Font struct { Name string // "": default Size FontSize // relative size of font to default in output graphics Color color.Color // "": default, other: use this }
Font describes a font.
type FontSize ¶
type FontSize int
FontSize is the relative font size used in chart. Five sizes seem enough.
type Graphics ¶
type Graphics interface { BasicGraphics Dimensions() (int, int) // character-width / height Begin() // start of chart drawing End() // Done, cleanup // All stuff is preprocessed: sanitized, clipped, strings formated, integer coords, // screen coordinates, XAxis(xr Range, ys, yms int, options PlotOptions) // Draw x axis xr at screen position ys (and yms if mirrored) YAxis(yr Range, xs, xms int, options PlotOptions) // Same for y axis. Scatter(points []EPoint, plotstyle PlotStyle, style Style) // Points, Lines and Line+Points Boxes(boxes []Box, width int, style Style) // Boxplots Bars(bars []Barinfo, style Style) // any type of histogram/bars Rings(wedeges []Wedgeinfo, x, y, ro, ri int) // Pie/ring diagram elements Key(x, y int, key Key, options PlotOptions) // place key at x,y }
Graphics is the interface all chart drivers have to implement
type HistChart ¶
type HistChart struct {
XRange, YRange Range // Lower limit of YRange is fixed to 0 and not available for input
Title string // Title of chart
Key Key // Key/Legend
Counts bool // Display counts instead of frequencies
Stacked bool // Display different data sets ontop of each other
Shifted bool // Shift non-stacked bars sideways (and make them smaler)
FirstBin float64 // center of the first (lowest bin)
BinWidth float64 // Width of bins (0: auto)
Gap float64 // gap between bins in (bin-width units): 0<=Gap<1,
Sep float64 // separation of bars in one bin (in bar width units) -1<Sep<1
Kernel Kernel // Smoothing kernel (usable only for non-stacked histograms)
Options PlotOptions // general stylistic optins
Data []HistChartData
}
HistChart represents histogram charts.
Histograms should not be mixed up with bar charts produced by BarChart: Histograms are computed (binified) automatically from the raw data.
func (*HistChart) AddDataGeneric ¶
AddDataGeneric is the generic version which allows the addition of any type implementing the Value interface.
func (*HistChart) AddDataInt ¶
AddDataInt is a convenience method to add integer data (a simple wrapper around AddData).
type HistChartData ¶
HistChartData encapsulates one data set in a histogram chart.
type Kernel ¶
Kernel is a smoothing kernel for histograms.
var ( // 1/2 RectangularKernel = func(x float64) float64 { if x >= -1 && x < 1 { return 0.5 } return 0 } // 1 - |x| TriangularKernel = func(x float64) float64 { if x >= -1 && x < 1 { return 1 - math.Abs(x) } return 0 } // 15/16 * (1-x^2)^2 BisquareKernel Kernel = func(x float64) float64 { if x >= -1 && x < 1 { a := (1 - x*x) return 15.0 / 16.0 * a * a } return 0 } // 35/32 * (1-x^2)^3 TriweightKernel Kernel = func(x float64) float64 { if x >= -1 && x < 1 { a := (1 - x*x) return 35.0 / 32.0 * a * a * a } return 0 } // 3/4 * (1-x^2) EpanechnikovKernel Kernel = func(x float64) float64 { if x >= -1 && x < 1 { return 3.0 / 4.0 * (1.0 - x*x) } return 0 } // 1/sqrt(2pi) * exp(-1/2x^2) GaussKernel Kernel = func(x float64) float64 { return sqrt2piinv * math.Exp(-0.5*x*x) } )
Some common smoothing kernels. All are identical 0 outside [-1,1[.
type Key ¶
type Key struct { Hide bool // Don't show key/legend if true Cols int // Number of colums to use. If <0 fill rows before colums Border int // -1: off, 0: std, 1...:other styles Pos string // default "" is "itr" Entries []KeyEntry // List of entries in the legend X, Y int }
Key encapsulates settings for keys/legends in a chart.
Key placement is governed by Pos which may take the following values:
otl otc otr +-------------+ o: outside olt |itl itc itr| ort i: inside | | t: top olc |icl icc icr| orc c: centered | | b: bottom olb |ibl ibc ibr| orb l: left +-------------+ c: centered obl obc obr r: right
type KeyEntry ¶
type KeyEntry struct { Text string // Text to display PlotStyle PlotStyle // What to show: symbol, line, bar or combination thereof Style Style // How to show }
KeyEntry encapsulates an antry in the key/legend.
type LayoutData ¶
type LayoutData struct {
Width, Height int // width and height of graph area
Left, Top int // left and top margin
KeyX, KeyY int // x and y coordiante of key
NumXtics, NumYtics int // suggested numer of tics for both axis
}
LayoutData encapsulates the layout of the graph area in the whole drawing area.
type MinimalGraphics ¶
type MinimalGraphics interface { Background() (r, g, b, a uint8) // Color of background FontMetrics(font Font) (fw float32, fh int, mono bool) // Return fontwidth and -height in pixel TextLen(t string, font Font) int // Length=width of t in screen units if set on font Line(x0, y0, x1, y1 int, style Style) // Draw line from (x0,y0) to (x1,y1) Text(x, y int, t string, align string, rot int, f Font) // Put t at (x,y) rotated by rot aligned [[tcb]][lcr] }
MinimalGraphics is the interface any graphics driver must implement, so that he can fall back to the generic routines for the higher level outputs.
type MirrorAxis ¶
type MirrorAxis int
MirrorAxis describes if and how an axis is drawn on the oposite side of a chart,
const ( MirrorAxisAndTics MirrorAxis = 0 // draw a full mirrored axis including tics MirrorNothing MirrorAxis = -1 // do not draw a mirrored axis MirrorAxisOnly MirrorAxis = 1 // just draw a mirrord axis, but omit tics )
type PieChart ¶
type PieChart struct { Title string // The title Key Key // The Key/Legend Inner float64 // relative radius of inner white are (set to 0.7 to produce ring chart) Options PlotOptions Data []CategoryChartData // The data FmtVal func(value, sume float64) string // add value labels to pie segments FmtKey func(value, sume float64) string // add value labels to key entries }
PieChart represents pie and ring charts. Data is exported but it you should use the AddData, AddDataPair and AddIntDataPair methods to populate this field. The FmtVal and FmtKey function are used to format optional labels on the pie segments (FmtVal) and on the legend/key entries if non nil. The FmtKey must be set before adding data via the AddXY methods.
func (*PieChart) AddDataPair ¶
func (*PieChart) AddIntDataPair ¶
type PlotElement ¶
type PlotElement int
PlotElement identifies one element in a plot/chart
const ( MajorAxisElement PlotElement = iota MinorAxisElement MajorTicElement MinorTicElement ZeroAxisElement GridLineElement GridBlockElement KeyElement TitleElement RangeLimitElement )
type PlotOptions ¶
type PlotOptions map[PlotElement]Style
PlotOptions contains a Style for each PlotElement. If a PlotOption does not contain a certainPlotElement the value in DefaultStyle is used.
type PlotStyle ¶
type PlotStyle int
PlotStyle describes how data and functions are drawn in scatter plots. Can be used to describe how a key entry is drawn
type Point ¶
type Point struct{ X, Y float64 }
Point is a point in two dimensions (x,y) implementing XYValue.
type Range ¶
type Range struct { Label string // Label of axis MinMode, MaxMode RangeMode // How to handel min and max of this axis/range TicSetting TicSetting // How to handle tics. DataMin, DataMax float64 // Actual min/max values from data. If both zero: not calculated ShowLimits bool // Display axis Min and Max values on plot ShowZero bool // Add line to show 0 of this axis Category []string // If not empty (and neither Log nor Time): Use Category[n] as tic label at pos n+1. // The following values are set up during plotting Min, Max float64 // Actual minium and maximum of this axis/range. Tics []Tic // List of tics to display // The following functions are set up during plotting Norm func(float64) float64 // Function to map [Min:Max] to [0:1] InvNorm func(float64) float64 // Inverse of Norm() Data2Screen func(float64) int // Function to map data value to screen position Screen2Data func(int) float64 // Inverse of Data2Screen }
Range encapsulates all information about an axis.
func (*Range) Fixed ¶
Fixed is a helper (just reduces typing) functions which turns of autoscaling and sets the axis range to [min,max] and the tic distance to delta.
func (*Range) Reset ¶
func (r *Range) Reset()
Reset the fields in r which have been set up during a plot.
func (*Range) Setup ¶
Setup several fields of the Range r according to RangeModes and TicSettings. DataMin and DataMax of r must be present and should indicate lowest and highest value present in the data set. The following fields of r are filled:
(T)Min and (T)Max lower and upper limit of axis, (T)-version for date/time axis Tics slice of tics to draw TicSetting.(T)Delta actual tic delta Norm and InvNorm mapping of [lower,upper]_data --> [0:1] and inverse Data2Screen mapping of data to screen coordinates Screen2Data inverse of Data2Screen
The parameters desiredNumberOfTics and maxNumberOfTics are what the say. sWidth and sOffset are screen-width and -offset and are used to set up the Data-Screen conversion functions. If revert is true, than screen coordinates are assumed to be the other way around than mathematical coordinates.
TODO(vodo) seperate screen stuff into own method.
type RangeMode ¶
type RangeMode struct { Fixed bool // If false: autoscaling. If true: use (T)Value/TValue as fixed setting Constrained bool // If false: full autoscaling. If true: use (T)Lower (T)Upper as limits Expand Expansion // One of ExpandNextTic, ExpandTight, ExpandABit Value float64 // Value of end point of axis in Fixed=true mode, ignorder otherwise Lower, Upper float64 // Lower and upper limit for constrained autoscaling }
RangeMode describes how one end of an axis is set up. There are basically three different main modes:
- Fixed: Fixed==true. Use Value/TValue as fixed value this ignoring the actual data range.
- Unconstrained autoscaling: Fixed==false && Constrained==false. Set range to whatever data requires.
- Constrained autoscaling: Fixed==false && Constrained==true. Scale axis according to data present, but limit scaling to intervall [Lower,Upper]
For both autoscaling modes Expand defines how much expansion is done below/above the lowest/highest data point.
type ScatterChart ¶
type ScatterChart struct {
XRange, YRange Range // X and Y axis
Title string // Title of the chart
Key Key // Key/Legend
Options PlotOptions
Data []ScatterChartData // The actual data (filled with Add...-methods)
NSamples int // number of samples for function plots
}
ScatterChart represents scatter charts, line charts and function plots.
func (*ScatterChart) AddData ¶
func (c *ScatterChart) AddData(name string, data []EPoint, plotstyle PlotStyle, style Style)
AddData adds points in data to chart. A key/legend entry is produced if name is not empty.
func (*ScatterChart) AddDataGeneric ¶
func (c *ScatterChart) AddDataGeneric(name string, data []XYErrValue, plotstyle PlotStyle, style Style)
AddDataGeneric is the generiv version of AddData which allows any type to be plotted that implements the XYErrValue interface.
func (*ScatterChart) AddDataPair ¶
func (c *ScatterChart) AddDataPair(name string, x, y []float64, plotstyle PlotStyle, style Style)
AddDataPair is a convenience method which wrapps around AddData: It adds the points (x[n],y[n]) to the chart.
func (*ScatterChart) AddFunc ¶
func (c *ScatterChart) AddFunc(name string, f func(float64) float64, plotstyle PlotStyle, style Style)
AddFunc adds a function f to this chart. A key/legend entry is produced if name is not empty.
func (*ScatterChart) Plot ¶
func (c *ScatterChart) Plot(g Graphics)
Plot outputs the scatter chart to the graphic output g.
type ScatterChartData ¶
type ScatterChartData struct { Name string // The name of this data set. TODO: unused? PlotStyle PlotStyle // Points, Lines+Points or Lines only Style Style // Color, sizes, pointtype, linestyle, ... Samples []EPoint // The actual points for scatter/lines charts Func func(float64) float64 // The function to draw. }
ScatterChartData encapsulates a data set or function in a scatter chart. Not both Samples and Func may be non nil at the same time.
type StripChart ¶
type StripChart struct { Jitter bool // Add jitter to help distinguish overlapping values ScatterChart // The embeded ScatterChart is responsible for all drawing }
StripChart represents very simple strip charts.
func (*StripChart) AddData ¶
func (sc *StripChart) AddData(name string, data []float64, style Style)
AddData adds data to the strip chart.
func (*StripChart) AddDataGeneric ¶
func (sc *StripChart) AddDataGeneric(name string, data []Value)
func (*StripChart) Plot ¶
func (sc *StripChart) Plot(g Graphics)
Plot outputs the strip chart sc to g.
type Style ¶
type Style struct { Symbol int // 0: no symbol; any codepoint: this symbol SymbolColor color.Color // color of symbol SymbolSize float64 // scaling factor of symbol LineStyle LineStyle // SolidLine, DashedLine, DottedLine, .... see below LineColor color.Color // color of line LineWidth int // 0: no line, >=1 width of line in pixel Font Font // the font to use FillColor color.Color }
Style contains all information about all graphic elements in a chart. All colors are in the form "#rrggbb" with rr/gg/bb hexvalues. Not all elements of a plot use all fields in this struct.
func AutoStyle ¶
AutoStyle produces a styles based on StandardColors, StandardLineStyles, and StandardSymbols. Call with fill = true for charts with filled elements (hist, bar, cbar, pie).
func ElementStyle ¶
func ElementStyle(options PlotOptions, element PlotElement) Style
type Tic ¶
type Tic struct { Pos float64 // position of the tic on the axis (in data coordinates). LabelPos float64 // position of the label on the axis (in data coordinates). Label string // the Label of the tic Align int // alignment of the label: -1: left/top, 0 center, 1 right/bottom (unused) }
Tic describs a single tic on an axis.
type TicSetting ¶
type TicSetting struct { Hide bool // dont show tics if true HideLabels bool // don't show tic labels if true Tics int // 0: across axis, 1: inside, 2: outside, other: off Minor int // 0: off, 1: auto, >1: number of intervalls (not number of tics!) Delta float64 // wanted step between major tics. 0 means auto Grid GridMode // GridOff, GridLines, GridBlocks Mirror MirrorAxis // 0: mirror axis and tics, -1: don't mirror anything, 1: mirror axis only (no tics) // Format is used to print the tic labels. If unset FmtFloat is used. Format func(float64) string UserDelta bool // true if Delta was input }
TicSetting describes how (if at all) tics are shown on an axis.
type Value ¶
type Value interface {
XVal() float64
}
Value is the interface for any type of data representable by a real. Its standard implementation here is Real (float64).
type Wedgeinfo ¶
type Wedgeinfo struct {
Phi, Psi float64 // Start and ende of wedge. Fuill circle if |phi-psi| > 4pi
Text, Tp string // label text and text position: [ico]
Style Style // style of this wedge
Font Font // font of text
Shift int // Highlighting of wedge
}
Wedgeinfo describes a wedge in a pie chart.
type XYErrValue ¶
type XYErrValue interface { XVal() float64 YVal() float64 XErr() (float64, float64) // X-range [min,max], error intervall. Use NaN to indicate "no error". YErr() (float64, float64) // Y-range error interval (like XErr). }
XYErrValue is the interface for any type of data which is point-like (x,y) and has some measurement error.