Skip to content

Commit

Permalink
Encode graph panel axis config
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Dec 22, 2023
1 parent 765aafd commit 544dc25
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion encoder/golang/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ func (encoder *Encoder) encodeGraph(panel sdk.Panel) jen.Code {
encoder.encodeGraphDraw(*panel.GraphPanel),
)

// TODO: XAxis(), RightYAxis(), LeftYAxis(), SeriesOverride()
// TODO: SeriesOverride()

settings = append(
settings,
encoder.encodeGraphAxis("XAxis", panel.GraphPanel.Xaxis),
)

if len(panel.GraphPanel.Yaxes) >= 1 {
settings = append(
settings,
encoder.encodeGraphAxis("LeftYAxis", panel.GraphPanel.Yaxes[0]),
)
}
if len(panel.GraphPanel.Yaxes) >= 2 {
settings = append(
settings,
encoder.encodeGraphAxis("RightYAxis", panel.GraphPanel.Yaxes[1]),
)
}

// Null
if panel.GraphPanel.NullPointMode != "" {
Expand Down Expand Up @@ -64,6 +82,41 @@ func (encoder *Encoder) encodeGraph(panel sdk.Panel) jen.Code {
)
}

func (encoder *Encoder) encodeGraphAxis(graphOptName string, axis sdk.Axis) jen.Code {
var opts []jen.Code

// Unit
if axis.Format != "" {
opts = append(opts, graphQual("Unit").Call(lit(axis.Format)))
}
// Hide
if !axis.Show {
opts = append(opts, graphQual("Hide").Call())
}
// LogBase
if axis.LogBase != 0 {
opts = append(opts, graphQual("LogBase").Call(lit(axis.LogBase)))
}
// Label
if axis.Label != "" {
opts = append(opts, graphQual("Label").Call(lit(axis.Label)))
}
// Min
if axis.Min != nil {
opts = append(opts, graphQual("Min").Call(lit(axis.Min.Value)))
}
// Max
if axis.Max != nil {
opts = append(opts, graphQual("Max").Call(lit(axis.Max.Value)))
}

if len(opts) == 0 {
return nil
}

return graphQual(graphOptName).Call(opts...)
}

func (encoder *Encoder) encodeGraphLegend(legend sdk.Legend) jen.Code {
var legendOpts []jen.Code

Expand Down

0 comments on commit 544dc25

Please sign in to comment.