diff --git a/api/package.json b/api/package.json index cdae0b6cd..2ddc270c1 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/api", - "version": "10.33.2", + "version": "10.33.3", "description": "", "main": "index.js", "scripts": { diff --git a/dashboard/package.json b/dashboard/package.json index ddfc4bad8..3062a79dc 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/dashboard", - "version": "10.33.2", + "version": "10.33.3", "license": "Apache-2.0", "publishConfig": { "access": "public", diff --git a/dashboard/src/components/plugins/viz-components/cartesian/option/index.ts b/dashboard/src/components/plugins/viz-components/cartesian/option/index.ts index 6e6dc649a..704609036 100644 --- a/dashboard/src/components/plugins/viz-components/cartesian/option/index.ts +++ b/dashboard/src/components/plugins/viz-components/cartesian/option/index.ts @@ -45,7 +45,7 @@ export function getOption(conf: ICartesianChartConf, data: TPanelData, variables const customOptions = { xAxis: getXAxes(conf, xAxisData), - yAxis: getYAxes(conf, labelFormatters), + yAxis: getYAxes(conf, labelFormatters, series), series: [...series, ...regressionSeries], tooltip: getTooltip(conf, series, labelFormatters), grid: getGrid(conf), diff --git a/dashboard/src/components/plugins/viz-components/cartesian/option/y-axis.ts b/dashboard/src/components/plugins/viz-components/cartesian/option/y-axis.ts index 64303ce0d..412837935 100644 --- a/dashboard/src/components/plugins/viz-components/cartesian/option/y-axis.ts +++ b/dashboard/src/components/plugins/viz-components/cartesian/option/y-axis.ts @@ -1,6 +1,43 @@ +import _ from 'lodash'; import { ICartesianChartConf, IYAxisConf } from '../type'; -export function getYAxes(conf: ICartesianChartConf, labelFormatters: Record string>) { +type SeriesData = number[]; +type PartialSeriesConfType = { + yAxisIndex: number; + data: SeriesData; +}; + +function getReduceIntervalNeeds(series: PartialSeriesConfType[]) { + if (series.length === 0) { + return {}; + } + + const ret: Record = {}; + const datas: Record = {}; + series.forEach((s) => { + if (!datas[s.yAxisIndex]) { + datas[s.yAxisIndex] = [...s.data]; + return; + } + datas[s.yAxisIndex] = datas[s.yAxisIndex].concat(s.data); + }); + + Object.entries(datas).forEach(([index, data]) => { + const min = _.minBy(data) ?? 0; + const max = _.maxBy(data) ?? 0; + if (min === 0 && max === 0) { + ret[index] = 1; + } + }); + return ret; +} + +export function getYAxes( + conf: ICartesianChartConf, + labelFormatters: Record string>, + series: PartialSeriesConfType[], +) { + const intervals = getReduceIntervalNeeds(series); return conf.y_axes.map(({ nameAlignment, min, max, show, ...rest }: IYAxisConf, index: number) => { let position = rest.position; if (!position) { @@ -8,7 +45,7 @@ export function getYAxes(conf: ICartesianChartConf, labelFormatters: Record