import { Injectable } from '@angular/core'; import * as _ from 'lodash'; import * as color from '../../config/colors'; import * as backgroundColor from '../../config/backgroundColor'; import * as legend from '../../config/legend' import * as series from '../../config/series' import * as toolbox from '../../config/toolbox' import * as tooltip from '../../config/tootip' import * as xAxis from '../../config/xAxis' import * as yAxis from '../../config/yAxis' import * as datazoom from '../../config/datazoom'; import { BasicLineChartParam, axisLabelRotate } from './basic-line-interface'; import { CommonService } from '../../service/common.service' @Injectable({ providedIn: 'root' }) export class BasicLineService { constructor( private commonService: CommonService ) { } style = this.commonService.changeFontSize(); // getOptionOfBasicLineChart = (data: BasicLineChartParam, bcacChartShowMenu: boolean = true, legendPosition: positionType) => { // let toolboxType = this.getToolbox(bcacChartShowMenu); // let legendType: { legend: any, grid: any } = data.style ? this.getLegendType(legendPosition, data.style) : this.getLegendType(legendPosition, this.commonService.changeFontSize()) // let grid = this.commonService.changeFontSize().interval // let option = { // backgroundColor: backgroundColor.backgroundColor, // color: color.defaultColors, // grid: grid, // toolbox: toolboxType, // legend: legend.getLegendBottomNoScroll(data.style), // tooltip: tooltip.getToolTipOfItemChart(data.style, data.unit), // xAxis: xAxis.getXaxisOfCategoryTick(data.xAxisName, data.xAxisDatas), // yAxis: yAxis.getYaxisOfValue(data.style, data.yAxisName, data.yNameGap), // series: series.getBasicLineChartSeries(data.datas, data.seriesNames) // } // return option; // } getDefaultOpitonsOfBasicLineChart = () => { let option = { backgroundColor: backgroundColor.backgroundColor, color: color.defaultColors, grid: this.style.interval, toolbox: toolbox.getToolboxBasicMenu(), legend: legend.getLegendBottomNoScroll(this.style), tooltip: tooltip.getToolTipOfItemChart(this.style), xAxis: xAxis.getXaxisOfCategoryTickDefault(this.style), yAxis: yAxis.getYaxisOfValue(this.style), series: series.getBasicLineChartSeriesWithoutData() } return option } // 更改toolbox显示状态 changeToolboxShow(options, bcacChartShowToolbox: boolean) { options.toolbox.show = bcacChartShowToolbox; } // 更改图例显示状态 changeLegendShow(options, bcacChartShowLegend: boolean) { options.legend.show = bcacChartShowLegend; } // 更改tooltipUnit changeTooltipUnit(options, tooltipUnit) { options.tooltip = tooltip.getToolTipOfItemChart(this.style, tooltipUnit); } // 更改x轴名称 changeXAxisName(chartOpt, xAxisName: string) { chartOpt.xAxis[0].name = xAxisName } // 更改y轴名称 changeYAxisName(chartOpt, yAxisName: string) { chartOpt.yAxis[0].name = yAxisName; } // 更改y轴名称距离 changeYAxisNameGap(chartOpt, yAxisNameGap: number) { chartOpt.yAxis[0].nameGap = yAxisNameGap; } // 更改x轴刻度label旋转 changeXAxisLabelRotate(chartOpt, xAxisLabelRotate: axisLabelRotate) { let rotate = 0; switch (xAxisLabelRotate) { case 'leftSmallAngle': rotate = 30 break; case 'leftBigAngle': rotate = 60 break; case 'rightSmallAngle': rotate = -30 break; case 'rightBigAngle': rotate = -60 break } chartOpt.xAxis[0].axisLabel.rotate = rotate; chartOpt.xAxis[0].axisLabel.formatter = (value: string): string => { let valueText = ''; if (value.length > 5) { valueText = value.substring(0, 5) + '...' } else { valueText = value } return valueText; } } // 更改y轴刻度label旋转 changeYAxisLabelRotate(chartOpt, yAxisLabelRotate: axisLabelRotate) { let rotate = 0; switch (yAxisLabelRotate) { case 'leftSmallAngle': rotate = 30 break; case 'leftBigAngle': rotate = 60 break; case 'rightSmallAngle': rotate = -30 break; case 'rightBigAngle': rotate = -60 break } chartOpt.yAxis[0].axisLabel.rotate = rotate; chartOpt.yAxis[0].axisLabel.formatter = (value: string): string => { let valueText = ''; if (value.length > 5) { valueText = value.substring(0, 5) + '...' } else { valueText = value } return valueText; } } // 更改chartData changeChartData(options, data: BasicLineChartParam) { options.xAxis[0].data = data.xAxisDatas; options.series = series.getBasicLineChartSeries(data.datas, data.seriesNames, data.markLine, data.markArea) } }