github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/examples/components/bubblegraph_demo/bubblegraph/provider.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  	"github.com/erda-project/erda-infra/base/servicehub"
    19  	"github.com/erda-project/erda-infra/providers/component-protocol/components/bubblegraph"
    20  	"github.com/erda-project/erda-infra/providers/component-protocol/components/bubblegraph/impl"
    21  	structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure"
    22  	"github.com/erda-project/erda-infra/providers/component-protocol/cpregister/base"
    23  	"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
    24  )
    25  
    26  type provider struct {
    27  	impl.DefaultBubbleGraph
    28  }
    29  
    30  // RegisterInitializeOp .
    31  func (p *provider) RegisterInitializeOp() (opFunc cptype.OperationFunc) {
    32  	return func(sdk *cptype.SDK) cptype.IStdStructuredPtr {
    33  		data := bubblegraph.NewDataBuilder().
    34  			WithTitle("test bubble graph component").
    35  			WithXOptions(bubblegraph.NewOptionsBuilder().WithType(structure.Number).Build()).
    36  			WithYOptions(bubblegraph.NewOptionsBuilder().WithType(structure.Number).Build()).
    37  			WithBubble(bubblegraph.NewBubbleBuilder().
    38  				WithValueX(1).
    39  				WithValueY(100).
    40  				WithValueSize(10).
    41  				WithGroup("test group").
    42  				WithDimension("test dimension").
    43  				Build()).
    44  			WithBubble(bubblegraph.NewBubbleBuilder().
    45  				WithValueX(2).
    46  				WithValueY(200).
    47  				WithValueSize(20).
    48  				WithGroup("test group").
    49  				WithDimension("test dimension").
    50  				Build()).
    51  			WithBubble(bubblegraph.NewBubbleBuilder().
    52  				WithX(&bubblegraph.Axis{Value: 3}).
    53  				WithY(&bubblegraph.Axis{Value: 300}).
    54  				WithSize(&bubblegraph.BubbleSize{Value: 30}).
    55  				WithGroup("test group").
    56  				WithDimension("test dimension").
    57  				Build()).
    58  			WithBubble(bubblegraph.NewBubbleBuilder().
    59  				WithX(&bubblegraph.Axis{Value: 4}).
    60  				WithY(&bubblegraph.Axis{Value: 400}).
    61  				WithSize(&bubblegraph.BubbleSize{Value: 40}).
    62  				WithGroup("test group").
    63  				WithDimension("test dimension").
    64  				Build()).
    65  			WithBubble(bubblegraph.NewBubbleBuilder().
    66  				WithX(&bubblegraph.Axis{Value: 5}).
    67  				WithY(&bubblegraph.Axis{Value: 400}).
    68  				WithSize(&bubblegraph.BubbleSize{Value: 50}).
    69  				WithGroup("test group").
    70  				WithDimension("test dimension").
    71  				Build()).
    72  			WithBubble(bubblegraph.NewBubbleBuilder().
    73  				WithX(&bubblegraph.Axis{Value: 6}).
    74  				WithY(&bubblegraph.Axis{Value: 600}).
    75  				WithSize(&bubblegraph.BubbleSize{Value: 60}).
    76  				WithGroup("test group").
    77  				WithDimension("test dimension").
    78  				Build()).
    79  			WithBubble(bubblegraph.NewBubbleBuilder().
    80  				WithX(&bubblegraph.Axis{Value: 7}).
    81  				WithY(&bubblegraph.Axis{Value: 700}).
    82  				WithSize(&bubblegraph.BubbleSize{Value: 70}).
    83  				WithGroup("test group").
    84  				WithDimension("test dimension").
    85  				Build()).
    86  			Build()
    87  
    88  		p.StdDataPtr = data
    89  		return nil
    90  	}
    91  }
    92  
    93  // RegisterRenderingOp .
    94  func (p *provider) RegisterRenderingOp() (opFunc cptype.OperationFunc) {
    95  	return p.RegisterInitializeOp()
    96  }
    97  
    98  func init() {
    99  	base.InitProviderWithCreator("bubblegraph-demo", "bubblegraph", func() servicehub.Provider { return &provider{} })
   100  }