Skip to content

Commit

Permalink
Fix Series.Filter regression for assigning series to multiple charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jentfoo committed Jan 10, 2025
1 parent 1958b50 commit 0d67ace
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bar_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func makeBasicBarChartOption() BarChartOption {
seriesList := NewSeriesListDataFromValues([][]float64{
{2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3},
{2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3},
})
}, ChartTypeBar)
for index := range seriesList {
seriesList[index].Label.Show = true
}
Expand Down
11 changes: 8 additions & 3 deletions series.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type SeriesLabel struct {
// Show flag for label
Show bool
// Distance to the host graphic element.
Distance int
Distance int // TODO - do we want to replace with just Offset?
// Position defines the label position.
Position string
// Offset specifies an offset from the position.
Expand Down Expand Up @@ -85,6 +85,7 @@ type SeriesMarkLine struct {
Data []SeriesMarkData
}

// Series references a population of data.
type Series struct {
index int
// Type is the type of series, it can be "line", "bar" or "pie". Default value is "line".
Expand All @@ -108,6 +109,10 @@ type Series struct {
// Min value of series
Max *float64
}

// SeriesList is a list of series to be rendered on the chart, typically constructed using NewSeriesListLine,
// NewSeriesListBar, NewSeriesListHorizontalBar, NewSeriesListPie, NewSeriesListRadar, or NewSeriesListFunnel.
// These Series can be appended to each other if multiple chart types should be rendered to the same axis.
type SeriesList []Series

func (sl SeriesList) init() {
Expand All @@ -122,7 +127,7 @@ func (sl SeriesList) init() {
func (sl SeriesList) Filter(chartType string) SeriesList {
arr := make(SeriesList, 0)
for index, item := range sl {
if item.Type == "" || item.Type == chartType {
if item.Type == chartType || (chartType == ChartTypeLine && item.Type == "") {
arr = append(arr, sl[index])
}
}
Expand Down Expand Up @@ -199,7 +204,7 @@ type seriesSummary struct {
AverageValue float64
}

// Summary get summary of series
// Summary returns numeric summary of series values (population statistics).
func (s *Series) Summary() seriesSummary {
minIndex := -1
maxIndex := -1
Expand Down

0 comments on commit 0d67ace

Please sign in to comment.