github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/examples/components/complexgraph_demo/complexgraph/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 complexgraph 16 17 import ( 18 "github.com/erda-project/erda-infra/base/servicehub" 19 structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure" 20 "github.com/erda-project/erda-infra/providers/component-protocol/components/complexgraph" 21 "github.com/erda-project/erda-infra/providers/component-protocol/components/complexgraph/impl" 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.DefaultComplexGraph 28 } 29 30 // RegisterInitializeOp . 31 func (p *provider) RegisterInitializeOp() (opFunc cptype.OperationFunc) { 32 return func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 33 data := complexgraph.NewDataBuilder(). 34 WithTitle("test Graph"). 35 WithDimensions("Evaporation", "Precipitation", "Temperature"). 36 WithXAxis(complexgraph.NewAxisBuilder(). 37 WithType(complexgraph.Category). 38 WithData("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"). 39 WithDataStructure(structure.String, "", false). 40 Build()). 41 WithYAxis(complexgraph.NewAxisBuilder(). 42 WithType(complexgraph.Value). 43 WithName("Evaporation"). 44 WithPosition(complexgraph.Right). 45 WithDimensions("Evaporation"). 46 WithDataStructure(structure.String, "ml", false). 47 Build()). 48 WithYAxis(complexgraph.NewAxisBuilder(). 49 WithType(complexgraph.Value). 50 WithName("Precipitation"). 51 WithPosition(complexgraph.Right). 52 WithDimensions("Precipitation"). 53 WithDataStructure(structure.String, "ml", false). 54 Build()). 55 WithYAxis(complexgraph.NewAxisBuilder(). 56 WithType(complexgraph.Value). 57 WithName("Temperature"). 58 WithPosition(complexgraph.Left). 59 WithDataStructure(structure.String, "°C", false). 60 WithDimensions("Temperature"). 61 Build()). 62 WithSeries(complexgraph.NewSereBuilder(). 63 WithName("Evaporation"). 64 WithType(complexgraph.Bar). 65 WithDimension("Evaporation"). 66 WithData(2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3). 67 Build()). 68 WithSeries(complexgraph.NewSereBuilder(). 69 WithName("Precipitation"). 70 WithType(complexgraph.Bar). 71 WithDimension("Precipitation"). 72 WithData(2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3). 73 Build()). 74 WithSeries(complexgraph.NewSereBuilder(). 75 WithName("Temperature"). 76 WithType(complexgraph.Line). 77 WithDimension("Temperature"). 78 WithData(2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2). 79 Build()). 80 Build() 81 return &impl.StdStructuredPtr{ 82 StdDataPtr: data, 83 } 84 } 85 } 86 87 // RegisterRenderingOp . 88 func (p *provider) RegisterRenderingOp() (opFunc cptype.OperationFunc) { 89 return p.RegisterInitializeOp() 90 } 91 92 func init() { 93 base.InitProviderWithCreator("complexgraph-demo", "complexgraph", func() servicehub.Provider { return &provider{} }) 94 }