Skip to content

Commit

Permalink
fix: crosshair label position (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Apr 2, 2024
1 parent c535803 commit 9381c21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
24 changes: 7 additions & 17 deletions src/component/1d/tool/XLabelPointer.tsx
@@ -1,5 +1,5 @@
import { Spectrum1D } from 'nmr-load-save';
import { useCallback, CSSProperties } from 'react';
import { CSSProperties } from 'react';

import { useBrushTracker } from '../../EventsTrackers/BrushTracker';
import { useMouseTracker } from '../../EventsTrackers/MouseTracker';
Expand All @@ -10,10 +10,8 @@ import useSpectrum from '../../hooks/useSpectrum';

const style: CSSProperties = {
cursor: 'crosshair',
transformOrigin: 'bottom right',
position: 'absolute',
top: '-18px',
left: '-30px',
paddingRight: '5px',
pointerEvents: 'none',
overflow: 'visible',
userSelect: 'none',
Expand All @@ -31,16 +29,6 @@ function XLabelPointer() {
(activeSpectrum as Spectrum1D)?.info.nucleus,
);

const getXValue = useCallback(
(xVal) => {
if (activeSpectrum) {
const xInvert = scaleX().invert(xVal);
return format(xInvert);
}
},
[activeSpectrum, format, scaleX],
);

if (
!activeSpectrum ||
brushState.step === 'brushing' ||
Expand All @@ -52,15 +40,17 @@ function XLabelPointer() {
) {
return null;
}

const x = scaleX().invert(position.x);

return (
<div
key="xLabelPointer"
style={{
...style,
transform: `translate(${position.x}px, ${position.y}px)`,
transform: `translate(${position.x}px, ${position.y}px) translate(-100%,-100%)`,
}}
>
<span>{getXValue(position.x)}</span>
<span>{format(x)}</span>
</div>
);
}
Expand Down
11 changes: 2 additions & 9 deletions src/component/2d/tools/XYLabelPointer.tsx
Expand Up @@ -10,17 +10,12 @@ import { get1DYScale, useScale2DX, useScale2DY } from '../utilities/scale';

const style: CSSProperties = {
cursor: 'crosshair',
transformOrigin: 'bottom right',
position: 'absolute',
top: '-18px',
left: '-88px',
paddingRight: '5px',
fontWeight: 'bold',
pointerEvents: 'none',
overflow: 'visible',
userSelect: 'none',
width: '85px',
textAlign: 'right',
zIndex: 9,
};

function XYLabelPointer({ layout, data1D }) {
Expand All @@ -46,7 +41,6 @@ function XYLabelPointer({ layout, data1D }) {

const nuclei = activeTab.split(',');
const [formatX, formatY] = useFormatNumberByNucleus(nuclei);
// const spectrum = useSpectrum();
const scale2DX = useScale2DX();
const scale2DY = useScale2DY();

Expand Down Expand Up @@ -140,10 +134,9 @@ function XYLabelPointer({ layout, data1D }) {

return (
<div
key="xLabelPointer"
style={{
...style,
transform: `translate(${position.x}px, ${position.y}px)`,
transform: `translate(${position.x}px, ${position.y}px) translate(-100%,-100%)`,
}}
>
<span>{formatY(getYValue())}</span>
Expand Down

0 comments on commit 9381c21

Please sign in to comment.