-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(obs-lib): add panel overrides (#1037)
- Loading branch information
1 parent
421f99d
commit 9cc20a9
Showing
2 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package grafana | ||
|
||
type Override struct { | ||
Matcher *Matcher | ||
Properties []*Property | ||
} | ||
|
||
type Matcher struct { | ||
ID string | ||
Options any | ||
} | ||
|
||
func NewByNameMatcher(name string) *Matcher { | ||
return &Matcher{ | ||
ID: "byName", | ||
Options: name, | ||
} | ||
} | ||
|
||
type MatcherReducer string | ||
|
||
const ( | ||
MatcherReducerLastNotNull MatcherReducer = "lastNotNull" | ||
) | ||
|
||
type MatcherOp string | ||
|
||
const ( | ||
MatcherOpGTE MatcherOp = "gte" | ||
) | ||
|
||
type ByValueMatcherOptions struct { | ||
Reducer MatcherReducer | ||
Op MatcherOp | ||
Value float64 | ||
} | ||
|
||
func NewByValueMatcher(options *ByValueMatcherOptions) *Matcher { | ||
return &Matcher{ | ||
ID: "byValue", | ||
Options: map[string]any{ | ||
"reducer": options.Reducer, | ||
"op": options.Op, | ||
"value": options.Value, | ||
}, | ||
} | ||
} | ||
|
||
type MatcherType string | ||
|
||
const ( | ||
MatcherTypeTime MatcherType = "time" | ||
) | ||
|
||
func NewByTypeMatcher(t MatcherType) *Matcher { | ||
return &Matcher{ | ||
ID: "byType", | ||
Options: t, | ||
} | ||
} | ||
|
||
func NewByRegexpMatcher(regex string) *Matcher { | ||
return &Matcher{ | ||
ID: "byRegexp", | ||
Options: regex, | ||
} | ||
} | ||
|
||
func NewByQueryMatcher(refID string) *Matcher { | ||
return &Matcher{ | ||
ID: "byFrameRefID", | ||
Options: refID, | ||
} | ||
} | ||
|
||
type Property struct { | ||
ID string | ||
Value any | ||
} | ||
|
||
type ColorMode string | ||
|
||
const ( | ||
ColorModeFixed ColorMode = "fixed" | ||
) | ||
|
||
type ColorPropertyOptions struct { | ||
Mode ColorMode | ||
FixedColor string | ||
} | ||
|
||
func NewColorProperty(options *ColorPropertyOptions) *Property { | ||
return &Property{ | ||
ID: "color", | ||
Value: map[string]any{ | ||
"mode": options.Mode, | ||
"fixedColor": options.FixedColor, | ||
}, | ||
} | ||
} | ||
|
||
type UnitValue string | ||
|
||
const ( | ||
UnitValueBlock UnitValue = "block" | ||
) | ||
|
||
func NewUnitProperty(value UnitValue) *Property { | ||
return &Property{ | ||
ID: "unit", | ||
Value: value, | ||
} | ||
} | ||
|
||
type LinksPropertyOptions struct { | ||
TargetBlank bool | ||
Title string | ||
URL string | ||
} | ||
|
||
func NewLinksProperty(options *LinksPropertyOptions) *Property { | ||
return &Property{ | ||
ID: "links", | ||
Value: map[string]any{ | ||
"targetBlank": options.TargetBlank, | ||
"title": options.Title, | ||
"url": options.URL, | ||
}, | ||
} | ||
} | ||
|
||
func NewHiddenProperty(value bool) *Property { | ||
return &Property{ | ||
ID: "custom.hidden", | ||
Value: value, | ||
} | ||
} | ||
|
||
func NewWidthProperty(value float64) *Property { | ||
return &Property{ | ||
ID: "custom.width", | ||
Value: value, | ||
} | ||
} | ||
|
||
type CellOptionsMode string | ||
|
||
const ( | ||
CellOptionsModeBasic CellOptionsMode = "basic" | ||
) | ||
|
||
type CellOptionsType string | ||
|
||
const ( | ||
CellOptionsTypeColorBackground CellOptionsType = "color-background" | ||
) | ||
|
||
type CellOptionsOptions struct { | ||
Mode CellOptionsMode | ||
Type CellOptionsType | ||
} | ||
|
||
func NewCellOptions(options *CellOptionsOptions) *Property { | ||
return &Property{ | ||
ID: "custom.cellOptions", | ||
Value: map[string]any{ | ||
"mode": options.Mode, | ||
"type": options.Type, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters