Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: linegraph and bubblegraph auto unit #203

Merged
merged 7 commits into from Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 60 additions & 3 deletions providers/component-protocol/components/bubblegraph/model.go
Expand Up @@ -14,12 +14,18 @@

package bubblegraph

import (
structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure"
)

// Below is standard struct for bubble graph related.
type (
// Data includes List.
Data struct {
Title string `json:"title"`
List []*Bubble `json:"list"`
Title string `json:"title"`
List []*Bubble `json:"list"`
XOptions *Options `json:"xOptions"`
YOptions []*Options `json:"yOptions"`
}

// Bubble .
Expand All @@ -42,6 +48,12 @@ type (
Unit string `json:"unit"`
}

// Options .
Options struct {
Dimension string `json:"dimension,omitempty"`
Structure *structure.DataStructure `json:"structure"`
}

// BubbleBuilder .
BubbleBuilder struct {
bubble *Bubble
Expand All @@ -51,11 +63,44 @@ type (
DataBuilder struct {
data *Data
}

// OptionsBuilder .
OptionsBuilder struct {
options *Options
}
)

// NewOptionsBuilder .
func NewOptionsBuilder() *OptionsBuilder {
return &OptionsBuilder{options: &Options{Structure: &structure.DataStructure{}}}
}

// WithDimension .
func (o *OptionsBuilder) WithDimension(dimension string) *OptionsBuilder {
o.options.Dimension = dimension
return o
}

// WithType .
func (o *OptionsBuilder) WithType(dataType structure.Type) *OptionsBuilder {
o.options.Structure.Type = dataType
return o
}

// WithPrecision .
func (o *OptionsBuilder) WithPrecision(precision structure.Precision) *OptionsBuilder {
o.options.Structure.Precision = precision
return o
}

// Build .
func (o *OptionsBuilder) Build() *Options {
return o.options
}

// NewDataBuilder .
func NewDataBuilder() *DataBuilder {
return &DataBuilder{data: &Data{}}
return &DataBuilder{data: &Data{XOptions: &Options{}, YOptions: []*Options{}}}
}

// WithTitle .
Expand All @@ -70,6 +115,18 @@ func (d *DataBuilder) WithBubble(bubbles ...*Bubble) *DataBuilder {
return d
}

// WithXOptions .
func (d *DataBuilder) WithXOptions(options *Options) *DataBuilder {
d.data.XOptions = options
return d
}

// WithYOptions .
func (d *DataBuilder) WithYOptions(options ...*Options) *DataBuilder {
d.data.YOptions = append(d.data.YOptions, options...)
return d
}

// Build .
func (d *DataBuilder) Build() *Data {
return d.data
Expand Down
31 changes: 31 additions & 0 deletions providers/component-protocol/components/bubblegraph/readme.md
@@ -0,0 +1,31 @@
## Bubble Graph Component

### Data Struct

| Field | Description |
| ---- | ---- |
| Title | The title of line graph |
| List | Defining multiple lines in a Line Graph |
| XOptions | X-axis property definition |
| YOptions | Y-axis property definition |

### Bubble Struct

| Field | Description |
| ---- | ---- |
| X | Y-Axis specific data |
| Y | Y-Axis specific data |
| Size | Bubble size |
| Group | Bubble group |
| Dimension | Dimension name |

### Options Struct

| Field | Description |
| ---- | ---- |
| Dimension | The title of line graph |
| Structure | Data Structure |

### Demo

[Bubble Graph Demo](../../examples/components/bubblegraph_demo)
@@ -0,0 +1,71 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package structure

//Type defined
const (
String Type = "string"
Number Type = "number"
Capacity Type = "capacity"
TrafficRate Type = "trafficRate"
Storage Type = "storage"
Timestamp Type = "timestamp"
Rate Type = "rate"
Date Type = "date"
Percent Type = "percent"
Throughput Type = "throughput"
)

//Precision defined
const (
K Precision = "K"
M Precision = "M"
B Precision = "B"
KB Precision = "KB"
MB Precision = "MB"
GB Precision = "GB"
TB Precision = "TB"
PB Precision = "PB"
EB Precision = "EB"
ZB Precision = "ZB"
YB Precision = "YB"
BSlashS Precision = "B/s"
KBSlashS Precision = "KB/s"
MBSlashS Precision = "MB/s"
GBSlashS Precision = "GB/s"
TBSlashS Precision = "TB/s"
PBSlashS Precision = "PB/s"
EBSlashS Precision = "EB/s"
ZBSlashS Precision = "ZB/s"
YBSlashS Precision = "YB/s"
Nanosecond Precision = "ns"
Microsecond Precision = "μs"
Millisecond Precision = "ms"
Second Precision = "s"
ReqSlashS Precision = "req/s"
)

type (
//Type .
Type string
//Precision .
Precision string
//DataStructure .
DataStructure struct {
Type Type `json:"type"`
Precision Precision `json:"precision"`
Enable bool `json:"enable"`
}
)
119 changes: 111 additions & 8 deletions providers/component-protocol/components/linegraph/model.go
Expand Up @@ -14,36 +14,129 @@

package linegraph

import "sync"
import (
"sync"

structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure"
)

// Below is standard struct for line graph related.
type (
// Data includes list.
Data struct {
Title string `json:"title"`
SubTitle string `json:"subTitle"`
Dimensions []string `json:"dimensions"`
XAxis *Axis `json:"xAxis"` // x axis
YAxis []*Axis `json:"yAxis"` // y axis
Inverse bool `json:"inverse"` // inverted xAxis and yAxis
Title string `json:"title"`
SubTitle string `json:"subTitle"`
Dimensions []string `json:"dimensions"`
XAxis *Axis `json:"xAxis"` // x axis
YAxis []*Axis `json:"yAxis"` // y axis
XOptions *Options `json:"xOptions"`
YOptions []*Options `json:"yOptions"`
Inverse bool `json:"inverse"` // inverted xAxis and yAxis
sync.RWMutex
}

// Axis defined struct.
Axis struct {
Dimension string `json:"dimension,omitempty"` // The xAxis can have no dimensions
Values []interface{} `json:"values"`
Inverse bool `json:"inverse"` // inverted values
}

// Options .
Options struct {
Dimension string `json:"dimension,omitempty"`
Structure *structure.DataStructure `json:"structure"`
Inverse bool `json:"inverse"` // inverted values
}

// DataBuilder .
DataBuilder struct {
data *Data
}

// OptionsBuilder .
OptionsBuilder struct {
options *Options
}
)

// NewOptionsBuilder .
func NewOptionsBuilder() *OptionsBuilder {
return &OptionsBuilder{options: &Options{Structure: &structure.DataStructure{}}}
}

// WithDimension .
func (o *OptionsBuilder) WithDimension(dimension string) *OptionsBuilder {
o.options.Dimension = dimension
return o
}

// WithType .
func (o *OptionsBuilder) WithType(dataType structure.Type) *OptionsBuilder {
o.options.Structure.Type = dataType
return o
}

// WithPrecision .
func (o *OptionsBuilder) WithPrecision(precision structure.Precision) *OptionsBuilder {
o.options.Structure.Precision = precision
return o
}

// Build .
func (o *OptionsBuilder) Build() *Options {
return o.options
}

// NewDataBuilder .
func NewDataBuilder() *DataBuilder {
return &DataBuilder{data: &Data{Dimensions: []string{}, XAxis: &Axis{}, YAxis: []*Axis{}, XOptions: &Options{}, YOptions: []*Options{}}}
}

// WithTitle .
func (d *DataBuilder) WithTitle(title string) *DataBuilder {
d.data.Title = title
return d
}

// WithXAxis .
func (d *DataBuilder) WithXAxis(values ...interface{}) *DataBuilder {
d.data.XAxis.Values = append(d.data.XAxis.Values, values...)
return d
}

// WithYAxis .
func (d *DataBuilder) WithYAxis(dimension string, values ...interface{}) *DataBuilder {
d.data.Dimensions = append(d.data.Dimensions, dimension)
d.data.YAxis = append(d.data.YAxis, &Axis{Dimension: dimension, Values: values})
return d
}

// WithXOptions .
func (d *DataBuilder) WithXOptions(options *Options) *DataBuilder {
d.data.XOptions = options
return d
}

// WithYOptions .
func (d *DataBuilder) WithYOptions(options ...*Options) *DataBuilder {
d.data.YOptions = append(d.data.YOptions, options...)
return d
}

// Build .
func (d *DataBuilder) Build() *Data {
return d.data
}

// New .
func New(title string) *Data {
return &Data{
Title: title,
Dimensions: *new([]string),
XAxis: new(Axis),
YAxis: *new([]*Axis),
XOptions: new(Options),
YOptions: *new([]*Options),
Inverse: false,
}
}
Expand All @@ -62,3 +155,13 @@ func (d *Data) SetYAxis(dimension string, values ...interface{}) {
d.Dimensions = append(d.Dimensions, dimension)
d.YAxis = append(d.YAxis, &Axis{Dimension: dimension, Values: values})
}

// SetXOptions .
func (d *Data) SetXOptions(options *Options) {
d.XOptions = options
}

// SetYOptions .
func (d *Data) SetYOptions(options ...*Options) {
d.YOptions = append(d.YOptions, options...)
}
33 changes: 33 additions & 0 deletions providers/component-protocol/components/linegraph/readme.md
@@ -0,0 +1,33 @@
## Line Graph Component

### Data Struct

| Field | Description |
| ---- | ---- |
| Title | The title of line graph |
| SubTitle | Deprecated,Not recommended |
| Dimensions | Defining multiple lines in a Line Graph |
| XAxis | X-axis specific data |
| YAxis | Y-axis specific data |
| XOptions | X-axis property definition |
| YOptions | Y-axis property definition |
| Inverse | inverted xAxis and yAxis |

### Axis Struct

| Field | Description |
| ---- | ---- |
| Dimension | Dimension name |
| Values | Axis specific data |

### Options Struct

| Field | Description |
| ---- | ---- |
| Dimension | The title of line graph |
| Structure | Data Structure |
| Inverse | Reverse axis values |

### Demo

[Line Graph Demo](../../examples/components/linegraph_demo)