Skip to content

Commit

Permalink
fix: large negative spectra peak scale
Browse files Browse the repository at this point in the history
close #1657
  • Loading branch information
hamed-musallam committed Dec 13, 2023
1 parent 76fb39b commit 19fd560
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/component/1d/utilities/scale.ts
Expand Up @@ -42,17 +42,23 @@ function getYScale(
spectrumId: number | null | string = null,
) {
const { height, margin, verticalAlign, yDomain, yDomains } = options;
const _height =
verticalAlign === 'center'
? (height - 40) / 2
: height - margin.bottom - 40;
let domainY: [number, number] | [] = [];
if (spectrumId === null || yDomains[spectrumId] === undefined) {
domainY = [0, yDomain[1]];
let domainY: number[] = yDomain;
if (spectrumId && yDomains?.[spectrumId]) {
domainY = yDomains[spectrumId];
}
const [min, max] = domainY;
let bottomShift = 40;

if (verticalAlign === 'center') {
bottomShift = 0;
const maxim = Math.max(Math.abs(max), Math.abs(min));
domainY = [-maxim, maxim];
} else {
domainY = [0, yDomains[spectrumId][1]];
domainY = [0, domainY[1]];
}
return scaleLinear(domainY, [_height, margin.top]);
const innerHeight = height - margin.bottom - bottomShift;

return scaleLinear(domainY, [innerHeight, margin.top]);
}

interface IntegralYScaleOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/component/reducer/helper/Zoom1DManager.ts
Expand Up @@ -61,7 +61,7 @@ function setZoom(
]);
const [min, max] = shareYDomain ? yDomain : yDomains[id];
const maxPoint = Math.max(Math.abs(max), Math.abs(min));
const scalePoint = maxPoint === max ? 0 : min;
const scalePoint = maxPoint === Math.max(max) ? 0 : min;
const t = zoomIdentity
.translate(
0,
Expand Down

0 comments on commit 19fd560

Please sign in to comment.