Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions docs/piechart/go-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Need a list of options.

## Default options

- None
- Calculation: `last`
- Visual outer radius: `"90%"`

## Available options

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

pie.WithVisual(pie.Visual{
Palette: pie.Palette{
Mode: pie.AutoMode, // or pie.CategoricalMode
},
OuterRadius: "90%",
})
```

Define visual properties of the pie chart including color palette mode.
Define the pie chart's radii and colors. Radius values can be percentages or unitless pixel strings.

```golang
pie.WithVisual(pie.Visual{
InnerRadius: "40%",
OuterRadius: "90%",
ColorPalette: []string{"#3366cc", "#dc3912"},
})
```

Set `InnerRadius` to create a doughnut chart. When omitted, the chart renders as a pie.

### WithShowLabels

```golang
pie.WithShowLabels(true)
```

Show labels inside the pie chart segments.

### WithFormat

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

Define the format for pie chart values.

### WithQuerySettings

```golang
package main

import pie "github.com/perses/plugins/piechart/sdk/go"

pie.WithQuerySettings([]pie.QuerySettingsItem{
{
QueryIndex: 0,
ColorMode: pie.FixedMode,
ColorValue: "#FF5733",
},
})
```

Define color settings for specific queries. Available color modes: `FixedMode`, `FixedSingleMode`.

## Example

```golang
package main

import (
"github.com/perses/perses/go-sdk/common"
"github.com/perses/perses/go-sdk/dashboard"
"github.com/perses/perses/go-sdk/panel"
"github.com/perses/perses/go-sdk/common"
pie "github.com/perses/plugins/piechart/sdk/go"
)

Expand All @@ -110,7 +109,8 @@ func main() {
Size: pie.MediumSize,
}),
pie.WithVisual(pie.Visual{
Palette: pie.Palette{Mode: pie.CategoricalMode},
InnerRadius: "40%",
OuterRadius: "90%",
}),
pie.WithFormat(&common.Format{
Unit: &common.BytesUnit,
Expand All @@ -120,5 +120,5 @@ func main() {
),
),
)
}```
}
```
26 changes: 25 additions & 1 deletion docs/piechart/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ spec:
format: <Format specification> # Optional
sort: <enum = "asc" | "desc"> # Optional
mode: <enum = "value" | "percentage"> # Optional
radius: <number>
showLabels: <boolean> # Optional
visual:
innerRadius: <string> # Optional
outerRadius: <string>
colorPalette: <array of strings> # Optional
```

## Legend-with-values specification
Expand All @@ -22,3 +26,23 @@ See [common plugin definitions](https://perses.dev/perses/docs/plugins/common/#c
## Format specification

See [common plugin definitions](https://perses.dev/perses/docs/plugins/common/#format-specification).

## Radii

`visual.outerRadius` is required and defaults to `"90%"`. Set `visual.innerRadius` to create a doughnut chart.
Radius values can be percentages or unitless pixel strings and are passed to Apache ECharts.

Persisted charts using the former top-level `radius` and `colorPalette` fields remain supported. The editor moves their
color settings into `visual` the next time the chart is saved; the former numeric `radius` did not affect rendering, so
these charts retain the `"90%"` rendered default.

```yaml
# A pie chart with an outer radius relative to the shorter panel edge.
visual:
outerRadius: "90%"

# A doughnut chart with a pixel inner radius and percentage outer radius.
visual:
innerRadius: "40"
outerRadius: "90%"
```
14 changes: 8 additions & 6 deletions piechart/schemas/migrate/migrate.cue
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ spec: {
showLabels: true
}

#colorMode: *#panel.fieldConfig.defaults.color.mode | null
if #colorMode == "shades" {
#mappedColor: *commonMigrate.#mapping.color[#panel.fieldConfig.defaults.color.fixedColor] | "#555555"
colorPalette: [#mappedColor]
}
visual: {
#colorMode: *#panel.fieldConfig.defaults.color.mode | null
if #colorMode == "shades" {
#mappedColor: *commonMigrate.#mapping.color[#panel.fieldConfig.defaults.color.fixedColor] | "#555555"
colorPalette: [#mappedColor]
}

radius: 50
outerRadius: "90%"
}
}
6 changes: 4 additions & 2 deletions piechart/schemas/migrate/tests/basic/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"position": "bottom"
},
"showLabels": true,
"colorPalette": ["#e02f44"],
"radius": 50
"visual": {
"colorPalette": ["#e02f44"],
"outerRadius": "90%"
}
}
}
10 changes: 9 additions & 1 deletion piechart/schemas/pie.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ spec: close({
format?: common.#format
sort?: "asc" | "desc"
mode?: "value" | "percentage"

showLabels?: bool
radius: number

// Deprecated top-level visual options remain accepted for persisted dashboards.
radius?: number
colorPalette?: [...string]
visual?: close({
innerRadius?: string
outerRadius: string
colorPalette?: [...string]
})
})
9 changes: 9 additions & 0 deletions piechart/schemas/tests/invalid/pie-numeric-radius.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "PieChart",
"spec": {
"calculation": "last",
"visual": {
"outerRadius": 90
}
}
}
7 changes: 7 additions & 0 deletions piechart/schemas/tests/invalid/pie-top-level-radius.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "PieChart",
"spec": {
"calculation": "last",
"outerRadius": "50"
}
}
10 changes: 10 additions & 0 deletions piechart/schemas/tests/invalid/pie-unsupported-visual-field.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"kind": "PieChart",
"spec": {
"calculation": "last",
"visual": {
"outerRadius": "90%",
"lineWidth": 1
}
}
}
9 changes: 9 additions & 0 deletions piechart/schemas/tests/valid/pie-legacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "PieChart",
"spec": {
"calculation": "last-number",
"radius": 50,
"showLabels": true,
"colorPalette": ["#3366cc", "#dc3912"]
}
}
10 changes: 10 additions & 0 deletions piechart/schemas/tests/valid/pie-radius-pixels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"kind": "PieChart",
"spec": {
"calculation": "last-number",
"visual": {
"innerRadius": "40",
"outerRadius": "200"
}
}
}
7 changes: 5 additions & 2 deletions piechart/schemas/tests/valid/pie.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
},
"sort": "desc",
"mode": "value",
"radius": 50,
"showLabels": true
"showLabels": true,
"visual": {
"innerRadius": "40%",
"outerRadius": "90%"
}
}
}
22 changes: 18 additions & 4 deletions piechart/sdk/go/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,37 @@ func WithLegend(legend Legend) Option {
}
}

func WithVisual(visual Visual) Option {
func WithShowLabels(showLabels bool) Option {
return func(builder *Builder) error {
builder.Visual = &visual
builder.ShowLabels = showLabels
return nil
}
}

func WithFormat(format *common.Format) Option {
func WithVisual(visual Visual) Option {
return func(builder *Builder) error {
builder.Format = format
if visual.OuterRadius == "" {
visual.OuterRadius = defaultOuterRadius
if builder.Visual != nil {
visual.OuterRadius = builder.Visual.OuterRadius
}
}
builder.Visual = &visual
return nil
}
}

// WithQuerySettings is deprecated. PieChart does not support query-specific colors.
func WithQuerySettings(querySettingsList []QuerySettingsItem) Option {
return func(builder *Builder) error {
builder.QuerySettings = &querySettingsList
return nil
}
}

func WithFormat(format *common.Format) Option {
return func(builder *Builder) error {
builder.Format = format
return nil
}
}
Loading
Loading