Skip to content

Commit dbd5726

Browse files
committed
Add support for units and includeZero in Yaxis
* Adds IncludeZero to support whether to always include zero or not. Default is to always include zero. * Adds IncludeUnits (units in Datadog json) to determine whether to show the unit label to the left of the yaxis or not.
1 parent dc324c0 commit dbd5726

File tree

3 files changed

+88
-18
lines changed

3 files changed

+88
-18
lines changed

dashboards.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ type GraphEvent struct {
5252
}
5353

5454
type Yaxis struct {
55-
Min *float64 `json:"min,omitempty"`
56-
AutoMin bool `json:"-"`
57-
Max *float64 `json:"max,omitempty"`
58-
AutoMax bool `json:"-"`
59-
Scale *string `json:"scale,omitempty"`
55+
Min *float64 `json:"min,omitempty"`
56+
AutoMin bool `json:"-"`
57+
Max *float64 `json:"max,omitempty"`
58+
AutoMax bool `json:"-"`
59+
Scale *string `json:"scale,omitempty"`
60+
IncludeZero *bool `json:"includeZero,omitempty"`
61+
IncludeUnits *bool `json:"units,omitempty"`
6062
}
6163

6264
// UnmarshalJSON is a Custom Unmarshal for Yaxis.Min/Yaxis.Max. If the datadog API

dashboards_test.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,33 @@ type YAxisTestSuite struct {
2525

2626
func (suite *YAxisTestSuite) SetupTest() {
2727
// Custom Y.Min, Y.Max
28-
suite.yJSON = []byte(`{"min":0,"max":1,"scale":"linear"}`)
28+
suite.yJSON = []byte(`{"min":0,"max":1,"scale":"linear","includeZero":true,"units":true}`)
2929
suite.yMarshalledJSON = suite.yJSON
3030
yMinFloat := float64(0)
3131
yMaxFloat := float64(1)
3232
yScale := "linear"
33+
yIncludeZero := true
34+
yIncludeUnits := true
3335
suite.y = Yaxis{
34-
Min: &yMinFloat,
35-
AutoMin: false,
36-
Max: &yMaxFloat,
37-
AutoMax: false,
38-
Scale: &yScale,
36+
Min: &yMinFloat,
37+
AutoMin: false,
38+
Max: &yMaxFloat,
39+
AutoMax: false,
40+
Scale: &yScale,
41+
IncludeZero: &yIncludeZero,
42+
IncludeUnits: &yIncludeUnits,
3943
}
4044
// Auto Y.Min, Y.Max
41-
suite.yAutoMinMaxJSON = []byte(`{"min":"auto","max":"auto","scale":"linear"}`)
42-
suite.yAutoMinMaxMarshalledJSON = []byte(`{"scale":"linear"}`)
45+
suite.yAutoMinMaxJSON = []byte(`{"min":"auto","max":"auto","scale":"linear","includeZero":true,"units":true}`)
46+
suite.yAutoMinMaxMarshalledJSON = []byte(`{"scale":"linear","includeZero":true,"units":true}`)
4347
suite.yAutoMinMax = Yaxis{
44-
Min: nil,
45-
AutoMin: true,
46-
Max: nil,
47-
AutoMax: true,
48-
Scale: &yScale,
48+
Min: nil,
49+
AutoMin: true,
50+
Max: nil,
51+
AutoMax: true,
52+
Scale: &yScale,
53+
IncludeZero: &yIncludeZero,
54+
IncludeUnits: &yIncludeUnits,
4955
}
5056
}
5157

datadog-accessors.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10770,6 +10770,68 @@ func (w *Widget) SetY(v int) {
1077010770
w.Y = &v
1077110771
}
1077210772

10773+
// GetIncludeUnits returns the IncludeUnits field if non-nil, zero value otherwise.
10774+
func (y *Yaxis) GetIncludeUnits() bool {
10775+
if y == nil || y.IncludeUnits == nil {
10776+
return false
10777+
}
10778+
return *y.IncludeUnits
10779+
}
10780+
10781+
// GetIncludeUnitsOk returns a tuple with the IncludeUnits field if it's non-nil, zero value otherwise
10782+
// and a boolean to check if the value has been set.
10783+
func (y *Yaxis) GetIncludeUnitsOk() (bool, bool) {
10784+
if y == nil || y.IncludeUnits == nil {
10785+
return false, false
10786+
}
10787+
return *y.IncludeUnits, true
10788+
}
10789+
10790+
// HasIncludeUnits returns a boolean if a field has been set.
10791+
func (y *Yaxis) HasIncludeUnits() bool {
10792+
if y != nil && y.IncludeUnits != nil {
10793+
return true
10794+
}
10795+
10796+
return false
10797+
}
10798+
10799+
// SetIncludeUnits allocates a new y.IncludeUnits and returns the pointer to it.
10800+
func (y *Yaxis) SetIncludeUnits(v bool) {
10801+
y.IncludeUnits = &v
10802+
}
10803+
10804+
// GetIncludeZero returns the IncludeZero field if non-nil, zero value otherwise.
10805+
func (y *Yaxis) GetIncludeZero() bool {
10806+
if y == nil || y.IncludeZero == nil {
10807+
return false
10808+
}
10809+
return *y.IncludeZero
10810+
}
10811+
10812+
// GetIncludeZeroOk returns a tuple with the IncludeZero field if it's non-nil, zero value otherwise
10813+
// and a boolean to check if the value has been set.
10814+
func (y *Yaxis) GetIncludeZeroOk() (bool, bool) {
10815+
if y == nil || y.IncludeZero == nil {
10816+
return false, false
10817+
}
10818+
return *y.IncludeZero, true
10819+
}
10820+
10821+
// HasIncludeZero returns a boolean if a field has been set.
10822+
func (y *Yaxis) HasIncludeZero() bool {
10823+
if y != nil && y.IncludeZero != nil {
10824+
return true
10825+
}
10826+
10827+
return false
10828+
}
10829+
10830+
// SetIncludeZero allocates a new y.IncludeZero and returns the pointer to it.
10831+
func (y *Yaxis) SetIncludeZero(v bool) {
10832+
y.IncludeZero = &v
10833+
}
10834+
1077310835
// GetMax returns the Max field if non-nil, zero value otherwise.
1077410836
func (y *Yaxis) GetMax() float64 {
1077510837
if y == nil || y.Max == nil {

0 commit comments

Comments
 (0)