Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1181 cartesians yaxis cant deal with small numbers like 0.001 #1182

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "10.33.2",
"version": "10.33.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "10.33.2",
"version": "10.33.3",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
import _ from 'lodash';
import { ICartesianChartConf, IYAxisConf } from '../type';

export function getYAxes(conf: ICartesianChartConf, labelFormatters: Record<string, (p: $TSFixMe) => string>) {
type SeriesData = number[];
type PartialSeriesConfType = {
yAxisIndex: number;
data: SeriesData;
};

function getReduceIntervalNeeds(series: PartialSeriesConfType[]) {
if (series.length === 0) {
return {};
}

const ret: Record<string, number> = {};
const datas: Record<number, SeriesData> = {};
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, (p: $TSFixMe) => 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) {
position = index > 0 ? 'right' : 'left';
}
return {
...rest,
minInterval: 1,
minInterval: intervals[index] ?? 0,
show,
min: min ? min : undefined,
max: max ? max : undefined,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "10.33.2",
"version": "10.33.3",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "10.33.2",
"version": "10.33.3",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down