mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-04 06:39:40 +02:00
axis calculation fixed
This commit is contained in:
@@ -113,34 +113,21 @@ function setYAxisRangeData(min: number, max: number) {
|
|||||||
|
|
||||||
// this function does not set `hasSetYAxis` as there can be multiple data so we should calculate the range accordingly
|
// this function does not set `hasSetYAxis` as there can be multiple data so we should calculate the range accordingly
|
||||||
function setYAxisRangeFromPlotData(data: number[], plotType: PlotType) {
|
function setYAxisRangeFromPlotData(data: number[], plotType: PlotType) {
|
||||||
if (plotType === PlotType.BAR) {
|
dataSets.push(data);
|
||||||
dataSets.push(data);
|
|
||||||
|
|
||||||
let sum = new Array(data.length).fill(0);
|
const sum = new Array(data.length).fill(0);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
for (let dataSetIndex = 0; dataSetIndex < dataSets.length; dataSetIndex++) {
|
for (const entry of dataSets) {
|
||||||
sum[i] += dataSets[dataSetIndex][i];
|
sum[i] += entry[i];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xyChartData.yAxis = {
|
|
||||||
type: 'linear',
|
|
||||||
title: xyChartData.yAxis.title,
|
|
||||||
min: isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.min : Math.min(...sum),
|
|
||||||
max: Math.max(...sum),
|
|
||||||
};
|
|
||||||
} else if (plotType === PlotType.LINE) {
|
|
||||||
const minValue = Math.min(...data);
|
|
||||||
const maxValue = Math.max(...data);
|
|
||||||
const prevMinValue = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.min : Infinity;
|
|
||||||
const prevMaxValue = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.max : -Infinity;
|
|
||||||
xyChartData.yAxis = {
|
|
||||||
type: 'linear',
|
|
||||||
title: xyChartData.yAxis.title,
|
|
||||||
min: Math.min(prevMinValue, minValue),
|
|
||||||
max: Math.max(prevMaxValue, maxValue),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xyChartData.yAxis = {
|
||||||
|
type: 'linear',
|
||||||
|
title: xyChartData.yAxis.title,
|
||||||
|
min: isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.min : Math.min(...sum),
|
||||||
|
max: Math.max(...sum),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformDataWithoutCategory(data: number[], plotType: PlotType): SimplePlotDataType {
|
function transformDataWithoutCategory(data: number[], plotType: PlotType): SimplePlotDataType {
|
||||||
|
Reference in New Issue
Block a user