You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: transaction.go
    path of file: ./repos/erda/internal/apps/msp/apm/service/datasources
    
    the code of the file until where you have to start completion: // 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 datasources

import (
	"context"
	"fmt"
	"strconv"
	"strings"
	"time"

	"github.com/ahmetb/go-linq/v3"

	"github.com/erda-project/erda-infra/providers/component-protocol/components/bubblegraph"
	structure "github.com/erda-project/erda-infra/providers/component-protocol/components/commodel/data-structure"
	"github.com/erda-project/erda-infra/providers/component-protocol/components/kv"
	"github.com/erda-project/erda-infra/providers/component-protocol/components/linegraph"
	stdtable "github.com/erda-project/erda-infra/providers/component-protocol/components/table"
	"github.com/erda-project/erda-infra/providers/i18n"
	"github.com/erda-project/erda-proto-go/msp/apm/service/pb"
	"github.com/erda-project/erda/internal/apps/msp/apm/service/view/card"
	"github.com/erda-project/erda/internal/apps/msp/apm/service/view/chart"
	"github.com/erda-project/erda/internal/apps/msp/apm/service/view/common"
	"github.com/erda-project/erda/internal/apps/msp/apm/service/view
    
func (p *provider) GetBubbleChart(ctx context.Context, bubbleType BubbleChartType, preferredChartPoints int64, start, end int64, tenantId, serviceId string, layer common.TransactionLayerType, path string) (*bubblegraph.Data, error) {
	var chartType pb.ChartType
	switch bubbleType {
	case BubbleChartReqDistribution:
		chartType = pb.ChartType_AvgDurationDistribution
	case BubbleChartSlowReqDistribution:
		chartType = pb.ChartType_SlowDurationDistribution
	case BubbleChartErrorReqDistribution:
		chartType = pb.ChartType_ErrorDurationDistribution
	default:
		return nil, fmt.Errorf("not supported bubbleChartType: %s", bubbleType)
	}

	interval := getInterval(start, end, time.Second, preferredChartPoints)
	baseChart := &chart.BaseChart{
		StartTime: start,
		EndTime:   end,
		Interval:  interval,
		TenantId:  tenantId,
		ServiceId: serviceId,
		Layers:    []common.TransactionLayerType{layer},
		LayerPath: path,
		FuzzyPath: false,
		Metric:    p.Metric,
	}

	data, err := chart.Selector(strings.ToLower(chartType.String()), baseChart, ctx)
	if err != nil {
		return nil, err
	}

	// convert model
	layout := "2006-01-02 15:04:05"
	yUnitGetter := func(chartType pb.ChartType) (structure.Type, structure.Precision) {
		switch strings.ToLower(chartType.String()) {
		case strings.ToLower(pb.ChartType_AvgDurationDistribution.String()), strings.ToLower(pb.ChartType_SlowDurationDistribution.String()), strings.ToLower(pb.ChartType_ErrorDurationDistribution.String()):
			return structure.Time, structure.Millisecond
		default:
			return structure.Number, ""
		}
	}
	yAxisFormatter := func(value float64) interface{} {
		switch strings.ToLower(chartType.String()) {
		case strings.ToLower(pb.ChartType_AvgDurationDistribution.String()), strings.ToLower(pb.ChartType_SlowDurationDistribution.String()), strings.ToLower(pb.ChartType_ErrorDurationDistribution.String()):
			return math.DecimalPlacesWithDigitsNumber(value/1e6, 2)
		default:
			return value
		}
	}

	dimension := linq.From(data.View).
		Select(func(i interface{}) interface{} { return i.(*pb.Chart).Dimension }).
		First()
	if dimension == nil {
		dimension = data.Type
	}

	yType, yUnit := yUnitGetter(chartType)
	builder := bubblegraph.NewDataBuilder().WithTitle(p.I18n.Text(ctx.Value(common.LangKey).(i18n.LanguageCodes), strings.ToLower(string(bubbleType)))).
		WithXOptions(bubblegraph.NewOptionsBuilder().WithType(structure.String).Build()).
		WithYOptions(bubblegraph.NewOptionsBuilder().WithType(yType).WithPrecision(yUnit).WithDimension(dimension.(string)).WithEnable(true).Build())
	for _, item := range data.View {
		builder.WithBubble(bubblegraph.NewBubbleBuilder().
			WithDimension(dimension.(string)).
			WithValueX(time.Unix(0, item.Timestamp*1e6).Format(layout)).
			WithValueY(yAxisFormatter(item.Value)).
			WithValueSize(item.ExtraValues[0]).
			Build())
	}
	bubble := builder.Build()

	return bubble, nil
}