Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for stat panel value mappings #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ const (

const MixedSource = "-- Mixed --"

type MappingType string

const (
MappingTypeRange MappingType = "range"
MappingTypeRegex MappingType = "regex"
MappingTypeSpecial MappingType = "special"
MappingTypeValue MappingType = "value"
)

type (
// Panel represents panels of different types defined in Grafana.
Panel struct {
Expand Down Expand Up @@ -340,15 +349,16 @@ type (
Mode string `json:"mode"`
}
FieldConfigDefaults struct {
Unit string `json:"unit"`
NoValue string `json:"noValue,omitempty"`
Decimals *int `json:"decimals,omitempty"`
Min *float64 `json:"min,omitempty"`
Max *float64 `json:"max,omitempty"`
Color FieldConfigColor `json:"color"`
Thresholds Thresholds `json:"thresholds"`
Custom FieldConfigCustom `json:"custom"`
Links []Link `json:"links,omitempty"`
Unit string `json:"unit"`
NoValue string `json:"noValue,omitempty"`
Decimals *int `json:"decimals,omitempty"`
Min *float64 `json:"min,omitempty"`
Max *float64 `json:"max,omitempty"`
Color FieldConfigColor `json:"color"`
Thresholds Thresholds `json:"thresholds"`
Custom FieldConfigCustom `json:"custom"`
Links []Link `json:"links,omitempty"`
ValueMappings []ValueMapping `json:"mappings,omitempty"`
}
FieldConfigOverrideProperty struct {
ID string `json:"id"`
Expand Down Expand Up @@ -524,8 +534,30 @@ type (
YMin *float64 `json:"ymin,omitempty"`
YMax *float64 `json:"ymax,omitempty"`
}
ValueMapping struct {
MappingType string `json:"type,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
}
ValueMappingsOptions struct {
From *float64 `json:"from,omitempty"`
To *float64 `json:"to,omitempty"`
Pattern *string `json:"pattern,omitempty"`
Match *string `json:"match,omitempty"`
Result ValueMappingResult `json:"result,omitempty"`
}
ValueMappingResult struct {
Text *string `json:"text,omitempty"`
Color *string `json:"color,omitempty"`
Index *int `json:"index,omitempty"`
}
)

const MappingOptionFrom = "from"
const MappingOptionTo = "to"
const MappingOptionPattern = "pattern"
const MappingOptionMatch = "match"
const MappingOptionResult = "result"

// for an any panel
type Target struct {
RefID string `json:"refId"`
Expand Down