Skip to content

Commit 09ce278

Browse files
committed
feat(piechart): radius configuration enabled
Signed-off-by: Daniel Chromik <dchromik@redhat.com>
1 parent 40d0976 commit 09ce278

22 files changed

Lines changed: 882 additions & 113 deletions

docs/piechart/go-sdk.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Need a list of options.
1515

1616
## Default options
1717

18-
- None
18+
- Calculation: `last`
19+
- Visual outer radius: `"90%"`
1920

2021
## Available options
2122

@@ -43,13 +44,29 @@ package main
4344
import pie "github.com/perses/plugins/piechart/sdk/go"
4445

4546
pie.WithVisual(pie.Visual{
46-
Palette: pie.Palette{
47-
Mode: pie.AutoMode, // or pie.CategoricalMode
48-
},
47+
OuterRadius: "90%",
4948
})
5049
```
5150

52-
Define visual properties of the pie chart including color palette mode.
51+
Define the pie chart's radii and colors. Radius values can be percentages or unitless pixel strings.
52+
53+
```golang
54+
pie.WithVisual(pie.Visual{
55+
InnerRadius: "40%",
56+
OuterRadius: "90%",
57+
ColorPalette: []string{"#3366cc", "#dc3912"},
58+
})
59+
```
60+
61+
Set `InnerRadius` to create a doughnut chart. When omitted, the chart renders as a pie.
62+
63+
### WithShowLabels
64+
65+
```golang
66+
pie.WithShowLabels(true)
67+
```
68+
69+
Show labels inside the pie chart segments.
5370

5471
### WithFormat
5572

@@ -69,33 +86,15 @@ pie.WithFormat(&common.Format{
6986

7087
Define the format for pie chart values.
7188

72-
### WithQuerySettings
73-
74-
```golang
75-
package main
76-
77-
import pie "github.com/perses/plugins/piechart/sdk/go"
78-
79-
pie.WithQuerySettings([]pie.QuerySettingsItem{
80-
{
81-
QueryIndex: 0,
82-
ColorMode: pie.FixedMode,
83-
ColorValue: "#FF5733",
84-
},
85-
})
86-
```
87-
88-
Define color settings for specific queries. Available color modes: `FixedMode`, `FixedSingleMode`.
89-
9089
## Example
9190

9291
```golang
9392
package main
9493

9594
import (
95+
"github.com/perses/perses/go-sdk/common"
9696
"github.com/perses/perses/go-sdk/dashboard"
9797
"github.com/perses/perses/go-sdk/panel"
98-
"github.com/perses/perses/go-sdk/common"
9998
pie "github.com/perses/plugins/piechart/sdk/go"
10099
)
101100

@@ -110,7 +109,8 @@ func main() {
110109
Size: pie.MediumSize,
111110
}),
112111
pie.WithVisual(pie.Visual{
113-
Palette: pie.Palette{Mode: pie.CategoricalMode},
112+
InnerRadius: "40%",
113+
OuterRadius: "90%",
114114
}),
115115
pie.WithFormat(&common.Format{
116116
Unit: &common.BytesUnit,
@@ -120,5 +120,5 @@ func main() {
120120
),
121121
),
122122
)
123-
}```
123+
}
124124
```

docs/piechart/model.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ spec:
88
format: <Format specification> # Optional
99
sort: <enum = "asc" | "desc"> # Optional
1010
mode: <enum = "value" | "percentage"> # Optional
11-
radius: <number>
11+
showLabels: <boolean> # Optional
12+
visual:
13+
innerRadius: <string> # Optional
14+
outerRadius: <string>
15+
colorPalette: <array of strings> # Optional
1216
```
1317
1418
## Legend-with-values specification
@@ -22,3 +26,23 @@ See [common plugin definitions](https://perses.dev/perses/docs/plugins/common/#c
2226
## Format specification
2327
2428
See [common plugin definitions](https://perses.dev/perses/docs/plugins/common/#format-specification).
29+
30+
## Radii
31+
32+
`visual.outerRadius` is required and defaults to `"90%"`. Set `visual.innerRadius` to create a doughnut chart.
33+
Radius values can be percentages or unitless pixel strings and are passed to Apache ECharts.
34+
35+
Persisted charts using the former top-level `radius` and `colorPalette` fields remain supported. The editor moves their
36+
color settings into `visual` the next time the chart is saved; the former numeric `radius` did not affect rendering, so
37+
these charts retain the `"90%"` rendered default.
38+
39+
```yaml
40+
# A pie chart with an outer radius relative to the shorter panel edge.
41+
visual:
42+
outerRadius: "90%"
43+
44+
# A doughnut chart with a pixel inner radius and percentage outer radius.
45+
visual:
46+
innerRadius: "40"
47+
outerRadius: "90%"
48+
```

piechart/schemas/migrate/migrate.cue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ spec: {
5252
showLabels: true
5353
}
5454

55-
#colorMode: *#panel.fieldConfig.defaults.color.mode | null
56-
if #colorMode == "shades" {
57-
#mappedColor: *commonMigrate.#mapping.color[#panel.fieldConfig.defaults.color.fixedColor] | "#555555"
58-
colorPalette: [#mappedColor]
59-
}
55+
visual: {
56+
#colorMode: *#panel.fieldConfig.defaults.color.mode | null
57+
if #colorMode == "shades" {
58+
#mappedColor: *commonMigrate.#mapping.color[#panel.fieldConfig.defaults.color.fixedColor] | "#555555"
59+
colorPalette: [#mappedColor]
60+
}
6061

61-
radius: 50
62+
outerRadius: "90%"
63+
}
6264
}

piechart/schemas/migrate/tests/basic/expected.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"position": "bottom"
88
},
99
"showLabels": true,
10-
"colorPalette": ["#e02f44"],
11-
"radius": 50
10+
"visual": {
11+
"colorPalette": ["#e02f44"],
12+
"outerRadius": "90%"
13+
}
1214
}
1315
}

piechart/schemas/pie.cue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ spec: close({
3030
format?: common.#format
3131
sort?: "asc" | "desc"
3232
mode?: "value" | "percentage"
33+
3334
showLabels?: bool
34-
radius: number
35+
36+
// Deprecated top-level visual options remain accepted for persisted dashboards.
37+
radius?: number
3538
colorPalette?: [...string]
39+
visual?: close({
40+
innerRadius?: string
41+
outerRadius: string
42+
colorPalette?: [...string]
43+
})
3644
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"kind": "PieChart",
3+
"spec": {
4+
"calculation": "last",
5+
"visual": {
6+
"outerRadius": 90
7+
}
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"kind": "PieChart",
3+
"spec": {
4+
"calculation": "last",
5+
"outerRadius": "50"
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"kind": "PieChart",
3+
"spec": {
4+
"calculation": "last",
5+
"visual": {
6+
"outerRadius": "90%",
7+
"lineWidth": 1
8+
}
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"kind": "PieChart",
3+
"spec": {
4+
"calculation": "last-number",
5+
"radius": 50,
6+
"showLabels": true,
7+
"colorPalette": ["#3366cc", "#dc3912"]
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"kind": "PieChart",
3+
"spec": {
4+
"calculation": "last-number",
5+
"visual": {
6+
"innerRadius": "40",
7+
"outerRadius": "200"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)