Skip to content

Commit abc66ca

Browse files
[BUGFIX] TimeSeriesChart: migration: handle lineWidth as string (#401)
* [BUGFIX] TimeSeriesChart: migration: handle lineWidth as string Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr> * simplify code using switch pattern Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr> * fix import Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr> * cover case in unit test Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr> * remove redundant code Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr> --------- Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr>
1 parent dd5c8c6 commit abc66ca

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

timeserieschart/schemas/migrate/migrate.cue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package migrate
1616
import (
1717
commonMigrate "github.com/perses/perses/cue/common/migrate"
1818
"strings"
19+
"strconv"
1920
)
2021

2122
#grafanaType: "timeseries" | "graph"
@@ -128,17 +129,17 @@ spec: {
128129
}
129130

130131
// visual
131-
#lineWidth: *#panel.fieldConfig.defaults.custom.lineWidth | null
132+
#lineWidthRaw: *#panel.fieldConfig.defaults.custom.lineWidth | null
133+
#lineWidth: [
134+
if (#lineWidthRaw & string) != _|_ { strconv.Atoi(#lineWidthRaw) },
135+
#lineWidthRaw,
136+
][0]
132137
if #lineWidth != null {
133-
if #lineWidth > 3 {
134-
visual: lineWidth: 3 // line width can't go beyond 3 in Perses
135-
}
136-
if #lineWidth < 0.25 {
137-
visual: lineWidth: 0.25 // line width can't go below 0.25 in Perses
138-
}
139-
if #lineWidth >= 0.25 && #lineWidth <= 3 {
140-
visual: lineWidth: #lineWidth
141-
}
138+
visual: lineWidth: [
139+
if #lineWidth > 3 { 3 }, // line width can't go beyond 3 in Perses
140+
if #lineWidth < 0.25 { 0.25 }, // line width can't go below 0.25 in Perses
141+
#lineWidth,
142+
][0]
142143
}
143144

144145
#lineStyle: *#panel.fieldConfig.defaults.custom.lineStyle.fill | null

timeserieschart/schemas/migrate/tests/basic-2/input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"insertNulls": false,
2727
"lineInterpolation": "linear",
28-
"lineWidth": 1,
28+
"lineWidth": "1",
2929
"pointSize": 5,
3030
"scaleDistribution": {
3131
"type": "linear"

0 commit comments

Comments
 (0)