From 1902a1aa0302d42cfc9a8eab4def31c1e9ee2b36 Mon Sep 17 00:00:00 2001 From: Leto Date: Wed, 13 Sep 2023 16:34:08 +0800 Subject: [PATCH 1/2] feat(dashboard): determine cartesian chart's yaxis minInterval by data --- .../viz-components/cartesian/option/index.ts | 2 +- .../viz-components/cartesian/option/y-axis.ts | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) 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 Date: Wed, 13 Sep 2023 16:38:18 +0800 Subject: [PATCH 2/2] chore: publish v10.33.3 --- api/package.json | 2 +- dashboard/package.json | 2 +- package.json | 2 +- settings-form/package.json | 2 +- website/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) 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/package.json b/package.json index b5edd5968..e9b94817b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/root", - "version": "10.33.2", + "version": "10.33.3", "private": true, "workspaces": [ "api", diff --git a/settings-form/package.json b/settings-form/package.json index 999dcff4c..9527b0fd9 100644 --- a/settings-form/package.json +++ b/settings-form/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/settings-form", - "version": "10.33.2", + "version": "10.33.3", "license": "Apache-2.0", "publishConfig": { "access": "public", diff --git a/website/package.json b/website/package.json index c7b5c851e..8b311c6f6 100644 --- a/website/package.json +++ b/website/package.json @@ -2,7 +2,7 @@ "name": "@devtable/website", "private": true, "license": "Apache-2.0", - "version": "10.33.2", + "version": "10.33.3", "scripts": { "dev": "vite", "preview": "vite preview"