Skip to content

Commit 7f3a9c1

Browse files
committed
Allow floating point Widget positions
They happen.
1 parent 213a136 commit 7f3a9c1

6 files changed

+46
-17
lines changed

cmd/tools/gen-accessors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (t *templateData) addIdent(x *ast.Ident, receiverType, fieldName string) {
177177
switch x.String() {
178178
case "int":
179179
zeroValue = "0"
180+
case "float32":
181+
zeroValue = "0"
180182
case "string":
181183
zeroValue = `""`
182184
case "bool":

datadog-accessors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10833,7 +10833,7 @@ func (w *Widget) SetWidth(v int) {
1083310833
}
1083410834

1083510835
// GetX returns the X field if non-nil, zero value otherwise.
10836-
func (w *Widget) GetX() int {
10836+
func (w *Widget) GetX() float32 {
1083710837
if w == nil || w.X == nil {
1083810838
return 0
1083910839
}
@@ -10842,7 +10842,7 @@ func (w *Widget) GetX() int {
1084210842

1084310843
// GetXOk returns a tuple with the X field if it's non-nil, zero value otherwise
1084410844
// and a boolean to check if the value has been set.
10845-
func (w *Widget) GetXOk() (int, bool) {
10845+
func (w *Widget) GetXOk() (float32, bool) {
1084610846
if w == nil || w.X == nil {
1084710847
return 0, false
1084810848
}
@@ -10859,12 +10859,12 @@ func (w *Widget) HasX() bool {
1085910859
}
1086010860

1086110861
// SetX allocates a new w.X and returns the pointer to it.
10862-
func (w *Widget) SetX(v int) {
10862+
func (w *Widget) SetX(v float32) {
1086310863
w.X = &v
1086410864
}
1086510865

1086610866
// GetY returns the Y field if non-nil, zero value otherwise.
10867-
func (w *Widget) GetY() int {
10867+
func (w *Widget) GetY() float32 {
1086810868
if w == nil || w.Y == nil {
1086910869
return 0
1087010870
}
@@ -10873,7 +10873,7 @@ func (w *Widget) GetY() int {
1087310873

1087410874
// GetYOk returns a tuple with the Y field if it's non-nil, zero value otherwise
1087510875
// and a boolean to check if the value has been set.
10876-
func (w *Widget) GetYOk() (int, bool) {
10876+
func (w *Widget) GetYOk() (float32, bool) {
1087710877
if w == nil || w.Y == nil {
1087810878
return 0, false
1087910879
}
@@ -10890,7 +10890,7 @@ func (w *Widget) HasY() bool {
1089010890
}
1089110891

1089210892
// SetY allocates a new w.Y and returns the pointer to it.
10893-
func (w *Widget) SetY(v int) {
10893+
func (w *Widget) SetY(v float32) {
1089410894
w.Y = &v
1089510895
}
1089610896

helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func GetBool(v *bool) (bool, bool) {
2828
// to store v and returns a pointer to it.
2929
func Int(v int) *int { return &v }
3030

31+
// Float32 is a helper routine that allocates a new float32 value
32+
// to store v and returns a pointer to it.
33+
func Float32(v float32) *float32 { return &v }
34+
3135
// GetInt is a helper routine that returns a boolean representing
3236
// if a value was set, and if so, dereferences the pointer to it.
3337
func GetIntOk(v *int) (int, bool) {

screen_widgets.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ type Time struct {
8383

8484
type Widget struct {
8585
// Common attributes
86-
Type *string `json:"type,omitempty"`
87-
Title *bool `json:"title,omitempty"`
88-
TitleText *string `json:"title_text,omitempty"`
89-
TitleAlign *string `json:"title_align,omitempty"`
90-
TitleSize *int `json:"title_size,omitempty"`
91-
Height *int `json:"height,omitempty"`
92-
Width *int `json:"width,omitempty"`
93-
X *int `json:"x,omitempty"`
94-
Y *int `json:"y,omitempty"`
86+
Type *string `json:"type,omitempty"`
87+
Title *bool `json:"title,omitempty"`
88+
TitleText *string `json:"title_text,omitempty"`
89+
TitleAlign *string `json:"title_align,omitempty"`
90+
TitleSize *int `json:"title_size,omitempty"`
91+
Height *int `json:"height,omitempty"`
92+
Width *int `json:"width,omitempty"`
93+
X *float32 `json:"x,omitempty"`
94+
Y *float32 `json:"y,omitempty"`
9595

9696
// For Timeseries, TopList, EventTimeline, EvenStream, AlertGraph, CheckStatus, ServiceSummary, LogStream widgets
9797
Time *Time `json:"time,omitempty"`

screenboards_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func TestGetScreenboard(t *testing.T) {
2828
Type: String("image"),
2929
Height: Int(20),
3030
Width: Int(32),
31-
X: Int(32),
32-
Y: Int(7),
31+
X: Float32(32),
32+
Y: Float32(7),
3333
URL: String("http://path/to/image.jpg"),
3434
},
3535
{
@@ -158,6 +158,19 @@ func TestGetScreenboard(t *testing.T) {
158158
},
159159
},
160160
},
161+
{
162+
file: "screenboard_response_widget_float_position",
163+
want: &Screenboard{
164+
Widgets: []Widget{
165+
{
166+
Type: String("free_text"),
167+
Text: String("processed"),
168+
X: Float32(1),
169+
Y: Float32(70.83333333333334),
170+
},
171+
},
172+
},
173+
},
161174
}
162175
for _, tt := range tests {
163176
t.Run(tt.file, func(t *testing.T) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"widgets": [
3+
{
4+
"text": "processed",
5+
"x": 1,
6+
"y": 70.83333333333334,
7+
"type": "free_text"
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)