github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/components/bubblegraph/model.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package bubblegraph 16 17 import ( 18 structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure" 19 ) 20 21 // Below is standard struct for bubble graph related. 22 type ( 23 // Data includes List. 24 Data struct { 25 Title string `json:"title"` 26 List []*Bubble `json:"list"` 27 XOptions *Options `json:"xOptions"` 28 YOptions []*Options `json:"yOptions"` 29 } 30 31 // Bubble . 32 Bubble struct { 33 X *Axis `json:"x"` 34 Y *Axis `json:"y"` 35 Size *BubbleSize `json:"size"` 36 Group string `json:"group"` 37 Dimension string `json:"dimension"` 38 } 39 40 // BubbleSize . 41 BubbleSize struct { 42 Value float64 `json:"value"` 43 Structure *structure.DataStructure `json:"structure"` 44 } 45 46 // Axis . 47 Axis struct { 48 Value interface{} `json:"value"` 49 Unit string `json:"unit"` 50 } 51 52 // Options . 53 Options struct { 54 Dimension string `json:"dimension,omitempty"` 55 Structure *structure.DataStructure `json:"structure"` 56 } 57 58 // BubbleBuilder . 59 BubbleBuilder struct { 60 bubble *Bubble 61 } 62 63 // DataBuilder . 64 DataBuilder struct { 65 data *Data 66 } 67 68 // OptionsBuilder . 69 OptionsBuilder struct { 70 options *Options 71 } 72 ) 73 74 // NewOptionsBuilder . 75 func NewOptionsBuilder() *OptionsBuilder { 76 return &OptionsBuilder{options: &Options{Structure: &structure.DataStructure{}}} 77 } 78 79 // WithDimension . 80 func (o *OptionsBuilder) WithDimension(dimension string) *OptionsBuilder { 81 o.options.Dimension = dimension 82 return o 83 } 84 85 // WithType . 86 func (o *OptionsBuilder) WithType(dataType structure.Type) *OptionsBuilder { 87 o.options.Structure.Type = dataType 88 return o 89 } 90 91 // WithEnable . 92 func (o *OptionsBuilder) WithEnable(enable bool) *OptionsBuilder { 93 o.options.Structure.Enable = enable 94 return o 95 } 96 97 // WithPrecision . 98 func (o *OptionsBuilder) WithPrecision(precision structure.Precision) *OptionsBuilder { 99 o.options.Structure.Precision = precision 100 return o 101 } 102 103 // Build . 104 func (o *OptionsBuilder) Build() *Options { 105 return o.options 106 } 107 108 // NewDataBuilder . 109 func NewDataBuilder() *DataBuilder { 110 return &DataBuilder{data: &Data{XOptions: &Options{}, YOptions: []*Options{}}} 111 } 112 113 // WithTitle . 114 func (d *DataBuilder) WithTitle(title string) *DataBuilder { 115 d.data.Title = title 116 return d 117 } 118 119 // WithBubble . 120 func (d *DataBuilder) WithBubble(bubbles ...*Bubble) *DataBuilder { 121 d.data.List = append(d.data.List, bubbles...) 122 return d 123 } 124 125 // WithXOptions . 126 func (d *DataBuilder) WithXOptions(options *Options) *DataBuilder { 127 d.data.XOptions = options 128 return d 129 } 130 131 // WithYOptions . 132 func (d *DataBuilder) WithYOptions(options ...*Options) *DataBuilder { 133 d.data.YOptions = append(d.data.YOptions, options...) 134 return d 135 } 136 137 // Build . 138 func (d *DataBuilder) Build() *Data { 139 return d.data 140 } 141 142 // NewBubbleBuilder . 143 func NewBubbleBuilder() *BubbleBuilder { 144 return &BubbleBuilder{bubble: &Bubble{X: &Axis{}, Y: &Axis{}, Size: &BubbleSize{}}} 145 } 146 147 // WithValueX . 148 func (bb *BubbleBuilder) WithValueX(v interface{}) *BubbleBuilder { 149 bb.bubble.X.Value = v 150 return bb 151 } 152 153 // WithX . 154 func (bb *BubbleBuilder) WithX(x *Axis) *BubbleBuilder { 155 bb.bubble.X = x 156 return bb 157 } 158 159 // WithValueY . 160 func (bb *BubbleBuilder) WithValueY(v interface{}) *BubbleBuilder { 161 bb.bubble.Y.Value = v 162 return bb 163 } 164 165 // WithY . 166 func (bb *BubbleBuilder) WithY(y *Axis) *BubbleBuilder { 167 bb.bubble.Y = y 168 return bb 169 } 170 171 // WithSize . 172 func (bb *BubbleBuilder) WithSize(size *BubbleSize) *BubbleBuilder { 173 bb.bubble.Size = size 174 return bb 175 } 176 177 // WithValueSize . 178 func (bb *BubbleBuilder) WithValueSize(v float64) *BubbleBuilder { 179 bb.bubble.Size.Value = v 180 return bb 181 } 182 183 // WithGroup . 184 func (bb *BubbleBuilder) WithGroup(group string) *BubbleBuilder { 185 bb.bubble.Group = group 186 return bb 187 } 188 189 // WithDimension . 190 func (bb *BubbleBuilder) WithDimension(dimension string) *BubbleBuilder { 191 bb.bubble.Dimension = dimension 192 return bb 193 } 194 195 // Build . 196 func (bb *BubbleBuilder) Build() *Bubble { 197 return bb.bubble 198 }