import { Injectable } from '@angular/core'; import { HorizontalBarData } from './horizontal-bar-interface' import * as _ from 'lodash'; // import * as config from '../../config/public-api' 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 color from '../../config/colors'; import * as brush from '../../config/brush' import * as datazoom from '../../config/datazoom'; import * as backgroundColor from '../../config/backgroundColor'; import { CommonService } from '../../service/common.service'; import { axisLabelRotate } from './horizontal-bar-interface' @Injectable({ providedIn: 'root' }) export class HorizontalBarService { constructor( private commonService: CommonService ) { } getHorizontalBarDefaultOption() { let style = this.commonService.changeFontSize(); let option = { color: color.defaultColors, backgroundColor: backgroundColor.backgroundColor, grid: this.commonService.changeFontSize().interval, legend: legend.getAboveBlock(style), toolbox: toolbox.getToolboxBasicMenu(), tooltip: tooltip.getCommonTooltipOfAxis(), xAxis: xAxis.getValueXAxis(style), yAxis: yAxis.getCategoryYAxis(style), series: series.getBarChartSeries(style) } return option; } // 更改toolbox显示状态 changeToolboxShow(chartOptions, show: boolean) { chartOptions.toolbox.show = show } // 更改图例显示状态 changeLegendShow(chartOptions, show: boolean) { chartOptions.legend.show = show } // 更改数据 changeChartData(chartOptions, data: HorizontalBarData) { let style = this.commonService.changeFontSize(); chartOptions.yAxis.data = data.yData chartOptions.series = series.getBarChartSeries(style, data) } // 更改tooltip changeTooltip(chartOpt, tooltipUnit: string | string[]) { chartOpt.tooltip = tooltip.getCommonTooltipOfAxis(tooltipUnit) } // 更改XAxisName changeXAxisName(chartOpt, xAxisName: string) { chartOpt.xAxis.name = xAxisName; } // 更改yAxisName changeYAxisName(chartOpt, yAxisName: string) { chartOpt.yAxis.name = yAxisName; } // 更改yAxisNameGap changeYAxisNameGap(chartOpt, yAxisNameGap: number) { chartOpt.yAxis.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.axisLabel.rotate = rotate; chartOpt.xAxis.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.axisLabel.rotate = rotate; chartOpt.yAxis.axisLabel.formatter = (value: string): string => { let valueText = ''; if (value.length > 5) { valueText = value.substring(0, 5) + '...' } else { valueText = value } return valueText; } } }