Documentation
¶
Overview ¶
Package palettedb provides a public API for opening and querying the palettedb SQLite database from external programs.
Example ¶
Example shows fetching palettes by name. By-name lookups search the user's saved palettes first, then the built-ins, so "viridis" and "warm-sunset" resolve even against an empty database.
package main
import (
"fmt"
"log"
"github.com/aldernero/palettedb"
)
func main() {
db, err := palettedb.OpenDefault()
if err != nil {
log.Fatal(err)
}
defer db.Close()
// A discrete palette (built-in) as a gaul.Gradient.
grad, err := db.LoadDiscreteByName("viridis")
if err != nil {
log.Fatal(err)
}
for i := 0; i < 8; i++ {
r, g, b, _ := grad.ColorAtStop(i, 8).RGBA()
fmt.Printf("%d: #%02X%02X%02X\n", i, uint8(r>>8), uint8(g>>8), uint8(b>>8))
}
// A sine palette by name.
sp, err := db.LoadSineByName("warm-sunset")
if err != nil {
log.Fatal(err)
}
fmt.Println(sp.ColorAt(0.5))
// When the type is unknown, PaletteByName returns a gaul.Palette + its kind.
p, kind, err := db.PaletteByName("turbo")
if err != nil {
log.Fatal(err)
}
_ = p.ColorAt(0.42)
fmt.Println(kind)
}
Output:
Index ¶
- func BuiltinDiscreteByName(name string) (gaul.Gradient, error)
- func BuiltinNames(paletteType string) []string
- func BuiltinSineByName(name string) (gaul.SinePalette, error)
- func DefaultPath() (string, error)
- type DB
- func (d *DB) Close() error
- func (d *DB) List() ([]Entry, error)
- func (d *DB) ListNames(paletteType string) ([]string, error)
- func (d *DB) LoadDiscreteByName(name string) (gaul.Gradient, error)
- func (d *DB) LoadSineByName(name string) (gaul.SinePalette, error)
- func (d *DB) PaletteByName(name string) (gaul.Palette, string, error)
- type Entry
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuiltinDiscreteByName ¶ added in v0.1.4
BuiltinDiscreteByName returns the built-in discrete palette with the given name (case-insensitive) as a gaul.Gradient. Unlike LoadDiscreteByName it needs no open database.
func BuiltinNames ¶ added in v0.1.3
BuiltinNames returns the names of built-in palettes of the given type ("sine" or "discrete") ordered by name.
func BuiltinSineByName ¶ added in v0.1.4
func BuiltinSineByName(name string) (gaul.SinePalette, error)
BuiltinSineByName returns the built-in sine palette with the given name (case-insensitive). Unlike LoadSineByName it needs no open database.
func DefaultPath ¶ added in v0.1.2
DefaultPath returns the default database location used by OpenDefault (~/.config/palettedb/palettedb.db, honoring XDG_CONFIG_HOME).
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is an opened palette database.
func OpenDefault ¶
OpenDefault opens the palette database at the default XDG config path (~/.config/palettedb/palettedb.db).
func (*DB) List ¶ added in v0.1.2
List returns all palettes stored in the database ordered by name. Built-in palettes are not included.
func (*DB) ListNames ¶ added in v0.1.2
ListNames returns the names of stored palettes of the given type ("sine" or "discrete") ordered by name. Built-in palettes are not included.
func (*DB) LoadDiscreteByName ¶
LoadDiscreteByName loads a discrete palette by name as a gaul.Gradient, searching the user's saved palettes first and then the built-in palettes. Returns an error if no discrete palette with that name exists in either.
func (*DB) LoadSineByName ¶
func (d *DB) LoadSineByName(name string) (gaul.SinePalette, error)
LoadSineByName loads a sine palette by name, searching the user's saved palettes first and then the built-in palettes. Returns an error if no sine palette with that name exists in either.
func (*DB) PaletteByName ¶
PaletteByName looks up a palette of either type by name (saved palettes first, then built-ins) and returns it as a gaul.Palette along with its type ("sine" or "discrete"). Use this when the caller does not know the type.
type Entry ¶ added in v0.1.2
Entry describes a palette stored in the database.
func Builtins ¶ added in v0.1.3
func Builtins() []Entry
Builtins returns the read-only palettes compiled into the library (discrete colormaps such as viridis and turbo, plus sine palettes) ordered by name. They resolve through the same LoadSineByName/LoadDiscreteByName/PaletteByName lookups as stored palettes.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
palettedb
command
|
|
|
internal
|
|
|
builtins
Package builtins provides the read-only palettes that ship with palettedb — well-known data-visualization colormaps.
|
Package builtins provides the read-only palettes that ship with palettedb — well-known data-visualization colormaps. |
|
export
Package export writes palettes to interchange formats (GIMP .gpl and CSV).
|
Package export writes palettes to interchange formats (GIMP .gpl and CSV). |
|
resources
Package resources holds embedded icon assets for the palettedb UI.
|
Package resources holds embedded icon assets for the palettedb UI. |


