@@ -3,13 +3,10 @@ import type { Jcoupling, Range, Signal1D } from '@zakodium/nmr-types';
33
44import { useChartData } from '../../context/ChartContext.tsx' ;
55import { useDispatch } from '../../context/DispatchContext.tsx' ;
6- import { formatNumber } from '../../utility/formatNumber.ts' ;
76import { useScale2DX , useScale2DY } from '../utilities/scale.js' ;
87
98interface Range1DTraceProps {
109 position : number ;
11- value : number | undefined ;
12- format : string ;
1310 size : number ;
1411 orientation ?: 'horizontal' | 'vertical' ;
1512 opacity ?: number ;
@@ -19,7 +16,6 @@ interface Range1DTraceProps {
1916interface ElementLayout {
2017 groupTransform : string ;
2118 pathD : string ;
22- textTransform ?: string ;
2319 textProps : {
2420 x ?: number ;
2521 y ?: number ;
@@ -28,10 +24,6 @@ interface ElementLayout {
2824 } ;
2925}
3026
31- const Text = styled . text `
32- font-size: 11px;
33- fill: black;
34- ` ;
3527const Path = styled . path `
3628 fill: none;
3729 stroke-width: 1px;
@@ -48,16 +40,13 @@ const innerMargin = 10;
4840function Range1DTrace ( props : Range1DTraceProps ) {
4941 const {
5042 position,
51- value,
5243 size,
53- format,
5444 orientation = 'horizontal' ,
5545 opacity = 1 ,
5646 onClick,
5747 } = props ;
5848 const { margin } = useChartData ( ) ;
5949
60- const label = value ? formatNumber ( value , format ) : '' ;
6150 const half = Math . round ( size / 2 ) ;
6251
6352 const layout : ElementLayout =
@@ -76,7 +65,6 @@ function Range1DTrace(props: Range1DTraceProps) {
7665 groupTransform : `translate(${ position } ${ margin . top - innerMargin } )` ,
7766 pathD : `M0 0 L0 ${ length } L${ size } ${ length } L${ size } 0` ,
7867 textProps : { } ,
79- textTransform : `rotate(-90) translate(5 ${ half + 4 } )` ,
8068 } ;
8169
8270 return (
@@ -88,9 +76,6 @@ function Range1DTrace(props: Range1DTraceProps) {
8876 height = { orientation === 'vertical' ? size : margin . top }
8977 fill = "transparent"
9078 />
91- < Text transform = { layout . textTransform } { ...layout . textProps } >
92- { label }
93- </ Text >
9479 < Path d = { layout . pathD } />
9580 </ g >
9681 ) ;
@@ -110,48 +95,48 @@ export function Ranges1D(props: Ranges1DProps) {
11095 const scale = orientation === 'horizontal' ? scaleX : scaleY ;
11196
11297 return ranges . map ( ( range ) => {
113- const { from, to, integration , id } = range ;
98+ const { from, to, id } = range ;
11499 const start = scale ( to ) ;
115100 const size = scale ( from ) - start ;
116101
102+ function handleAddSignal ( e : React . MouseEvent < SVGGElement , MouseEvent > ) {
103+ const boundingRect = e . currentTarget . getBoundingClientRect ( ) ;
104+ const x = e . clientX - boundingRect . left + start ;
105+ const y = e . clientY - boundingRect . top + start ;
106+
107+ const valueInPixel = orientation === 'horizontal' ? x : y ;
108+ const delta = scale . invert ( valueInPixel ) ;
109+
110+ const updatedRange = structuredClone ( range ) ;
111+ const signal : Signal1D = {
112+ id : crypto . randomUUID ( ) ,
113+ delta,
114+ js : [
115+ {
116+ multiplicity : 'm' ,
117+ } as Jcoupling ,
118+ ] ,
119+ kind : 'signal' ,
120+ multiplicity : 'm' ,
121+ } ;
122+ updatedRange . signals . push ( signal ) ;
123+
124+ dispatch ( {
125+ type : 'UPDATE_RANGE' ,
126+ payload : {
127+ range : updatedRange ,
128+ spectrumId,
129+ } ,
130+ } ) ;
131+ }
132+
117133 return (
118134 < Range1DTrace
119135 orientation = { orientation }
120136 key = { id }
121137 position = { start }
122138 size = { size }
123- value = { integration }
124- format = "0.00"
125- onClick = { ( e ) => {
126- const boundingRect = e . currentTarget . getBoundingClientRect ( ) ;
127- const x = e . clientX - boundingRect . left + start ;
128- const y = e . clientY - boundingRect . top + start ;
129-
130- const valueInPixel = orientation === 'horizontal' ? x : y ;
131- const delta = scale . invert ( valueInPixel ) ;
132-
133- const updatedRange = structuredClone ( range ) ;
134- const signal : Signal1D = {
135- id : crypto . randomUUID ( ) ,
136- delta,
137- js : [
138- {
139- multiplicity : 'm' ,
140- } as Jcoupling ,
141- ] ,
142- kind : 'signal' ,
143- multiplicity : 'm' ,
144- } ;
145- updatedRange . signals . push ( signal ) ;
146-
147- dispatch ( {
148- type : 'UPDATE_RANGE' ,
149- payload : {
150- range : updatedRange ,
151- spectrumId,
152- } ,
153- } ) ;
154- } }
139+ onClick = { handleAddSignal }
155140 />
156141 ) ;
157142 } ) ;
0 commit comments