scale

package
v0.0.0-...-ca9dcc0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package scale provides abstractions for scales that map from one domain to another and provide methods for indicating human-readable intervals in the input domain. The most common type of scale is a quantitative scale, such as a linear or log scale, which is captured by the Quantitative interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Linear

type Linear struct {
	// Min and Max specify the lower and upper bounds of the input
	// range. The input range [Min, Max] will be linearly mapped
	// to the output domain [0, 1].
	Min, Max float64

	// Base specifies a base for computing ticks. Ticks will be
	// placed at powers of Base; that is at n*Base^l for n ∈ ℤ and
	// some integer l. As a special case, a base of 0 alternates
	// between ticks at n*10^l and ticks at 5n*10^l.
	Base int

	// If Clamp is true, the input is clamped to [Min, Max].
	Clamp bool
}

func (Linear) Map

func (s Linear) Map(x float64) float64

func (*Linear) Nice

func (s *Linear) Nice(n int)

func (*Linear) SetClamp

func (s *Linear) SetClamp(clamp bool)

func (Linear) Ticks

func (s Linear) Ticks(n int) (major, minor []float64)

func (Linear) Unmap

func (s Linear) Unmap(y float64) float64

type Log

type Log struct {

	// Min and Max specify the lower and upper bounds of the input
	// range. The input range [Min, Max] will be mapped to the
	// output domain [0, 1]. The range [Min, Max] must not include
	// 0.
	Min, Max float64

	// Base specifies the base of the logarithm for computing
	// ticks. Typically, ticks will be placed at Base^n for n ∈ ℤ.
	Base int

	// If Clamp is true, the input is clamped to [Min, Max].
	Clamp bool
	// contains filtered or unexported fields
}

func NewLog

func NewLog(min, max float64, base int) (Log, error)

NewLog constructs a Log scale. If the arguments are out of range, it returns a RangeErr.

func (Log) Map

func (s Log) Map(x float64) float64

func (*Log) Nice

func (s *Log) Nice(n int)

func (*Log) SetClamp

func (s *Log) SetClamp(clamp bool)

func (Log) Ticks

func (s Log) Ticks(n int) (major, minor []float64)

func (Log) Unmap

func (s Log) Unmap(y float64) float64

type QQ

type QQ struct {
	Src, Dest Quantitative
}

A QQ maps from a source Quantitative scale to a destination Quantitative scale.

func (QQ) Map

func (q QQ) Map(x float64) float64

Map maps from a value x in the source scale's input range to a value y in the destination scale's input range.

func (QQ) Unmap

func (q QQ) Unmap(x float64) float64

Unmap maps from a value y in the destination scale's input range to a value x in the source scale's input range.

type Quantitative

type Quantitative interface {
	// Map maps from a value x in the input range to [0, 1]. If x
	// is outside the input range and clamping is enabled, x will
	// first be clamped to the input range.
	Map(x float64) float64

	// Unmap is the inverse of Map. That is, if x is in the input
	// range or clamping is disabled, x = Unmap(Map(x)). If
	// clamping is enabled and y is outside [0,1], the results are
	// undefined.
	Unmap(y float64) float64

	// SetClamp sets the clamping mode of this scale.
	SetClamp(bool)

	// Ticks returns a set of at most n major ticks, plus minor
	// ticks. These ticks will have "nice" values within the input
	// range. Both arrays are sorted in ascending order and minor
	// includes ticks in major.
	Ticks(n int) (major, minor []float64)

	// Nice expands the input range of this scale to "nice" values
	// for covering the input range with n major ticks. After
	// calling Nice(n), the first and last major ticks returned by
	// Ticks(n) will equal the lower and upper bounds of the input
	// range.
	Nice(n int)
}

A Quantative scale is an invertible function from some continuous input range to an output domain of [0, 1].

type RangeErr

type RangeErr string

RangeErr is an error that indicates some argument or value is out of range.

func (RangeErr) Error

func (r RangeErr) Error() string

Jump to

Keyboard shortcuts

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