Skip to content
Draft
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
18 changes: 14 additions & 4 deletions src/component/1d-2d/FieldEdition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PopoverNextProps } from '@blueprintjs/core';
import { PopoverNext } from '@blueprintjs/core';
import styled from '@emotion/styled';
import { revalidateLogic } from '@tanstack/react-form';
import type { ReactNode } from 'react';
import type { ReactElement, ReactNode } from 'react';
import { useMemo, useState } from 'react';
import { AppForm, coerceNumberInput, useForm } from 'react-science/ui';
import { match } from 'ts-pattern';
Expand All @@ -20,6 +20,7 @@ interface FieldProps {
value: number | string;
inputType?: InputType;
onChange: (value: string) => void;
rightElement?: ReactElement;
}

interface FieldEditionsProps extends FieldProps {
Expand All @@ -43,7 +44,16 @@ export function FieldEdition(props: FieldEditionsProps) {
onClose={() => setIsOpen(false)}
onInteraction={() => setIsOpen(true)}
content={
<Field onChange={handleChange} value={value} inputType={inputType} />
<Field
onChange={handleChange}
value={value}
inputType={inputType}
rightElement={
props.rightElement && (
<span onClick={() => setIsOpen(false)}>{props.rightElement}</span>
)
}
/>
}
{...PopoverProps}
>
Expand All @@ -70,7 +80,7 @@ function validationSchema(
}

function Field(props: FieldProps) {
const { value, inputType = 'text', onChange } = props;
const { value, inputType = 'text', onChange, rightElement } = props;

const validation = useMemo(() => {
return validationSchema(inputType).transform(({ value }) => {
Expand Down Expand Up @@ -99,7 +109,7 @@ function Field(props: FieldProps) {
inputType === 'number' ? (
<field.NumericInput autoFocus />
) : (
<field.Input autoFocus />
<field.Input autoFocus rightElement={rightElement} />
)
}
</form.AppField>
Expand Down
2 changes: 2 additions & 0 deletions src/component/2d/SVGContent2D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DirectAxis2D from './DirectAxis2D.tsx';
import IndirectAxis2D from './IndirectAxis2D.tsx';
import { FidContainer } from './fid/FidContainer.js';
import { FTContainer } from './ft/FTContainer.js';
import { LinkedSignals } from './linked-signals/LinkedSignals.js';
import type { Spectrum1DTraces } from './useTracesSpectra.js';
import { SignalsGuideLines } from './zones/SignalsGuideLines.js';
import Zones from './zones/Zones.js';
Expand All @@ -26,6 +27,7 @@ export function SVGContent2D({ spectra }: Chart2DProps) {
<Zones />
<ZonesAssignmentsLabels />
</ShareDataProvider>
<LinkedSignals />
</ClipPathContainer>

<SpectrumInfoBlock />
Expand Down
10 changes: 8 additions & 2 deletions src/component/2d/SignalDeltaLine.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import styled from '@emotion/styled';
import { assert } from '@zakodium/utils';
import type { CSSProperties } from 'react';

import { useChartData } from '../context/ChartContext.js';

import { useScale2DX, useScale2DY } from './utilities/scale.js';

const SignalLine = styled.line`
opacity: 0.5;
stroke: green;
stroke-width: 2;
`;

interface SignalDeltaLineProps {
delta: number;
axis: 'X' | 'Y';
show: boolean;
color?: string;
style?: CSSProperties;
}

function SignalDeltaLine(props: SignalDeltaLineProps) {
const { delta, axis, show } = props;
const { delta, axis, show, color = 'green', style } = props;
const { xDomain, yDomain } = useChartData();
const scaleX = useScale2DX();
const scaleY = useScale2DY();
Expand All @@ -29,6 +31,8 @@ function SignalDeltaLine(props: SignalDeltaLineProps) {
return (
<SignalLine
key={`signalLine_${delta}_X`}
stroke={color}
style={style}
x1={scaleX(delta)}
x2={scaleX(delta)}
y1={scaleY(yDomain[0])}
Expand All @@ -40,6 +44,8 @@ function SignalDeltaLine(props: SignalDeltaLineProps) {
return (
<SignalLine
key={`signalLine_${delta}_Y`}
stroke={color}
style={style}
x1={scaleX(xDomain[0])}
x2={scaleX(xDomain[1])}
y1={scaleY(delta)}
Expand Down
65 changes: 65 additions & 0 deletions src/component/2d/linked-signals/LinkedSignal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import styled from '@emotion/styled';
import type { KeyboardEvent } from 'react';

import { useDispatch } from '../../context/DispatchContext.js';
import { useShareData } from '../../context/ShareDataContext.js';
import { useHighlight } from '../../highlight/index.js';
import { useScale2DX, useScale2DY } from '../utilities/scale.js';
import type { PositionedLinkedSignal } from '../utilities/signalCrossings.js';

import { LinkedSignalAssignmentLabel } from './LinkedSignalAssignmentLabel.js';

const Wrapper = styled.g`
&:hover > circle:first-of-type {
fill: green;
stroke-width: 5;
}
`;

interface LinkedSignalProps {
signal: PositionedLinkedSignal;
}

export function LinkedSignal({ signal }: LinkedSignalProps) {
const scaleX = useScale2DX();
const scaleY = useScale2DY();
const dispatch = useDispatch();
const { data: newLabel, setData } = useShareData<string | null>();
const diaIDs = [...signal.xDiaIDs, ...signal.yDiaIDs];
const { show, hide } = useHighlight(diaIDs, { type: 'LINKED_SIGNAL' });
const id = `${signal.xSignalId}:${signal.ySignalId}`;

Check failure on line 30 in src/component/2d/linked-signals/LinkedSignal.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'ySignalId' does not exist on type 'PositionedLinkedSignal'.

Check failure on line 30 in src/component/2d/linked-signals/LinkedSignal.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'xSignalId' does not exist on type 'PositionedLinkedSignal'.

Check failure on line 30 in src/component/2d/linked-signals/LinkedSignal.tsx

View workflow job for this annotation

GitHub Actions / nodejs / test-package

Property 'ySignalId' does not exist on type 'PositionedLinkedSignal'.

Check failure on line 30 in src/component/2d/linked-signals/LinkedSignal.tsx

View workflow job for this annotation

GitHub Actions / nodejs / test-package

Property 'xSignalId' does not exist on type 'PositionedLinkedSignal'.

function handleKeyDown(event: KeyboardEvent<SVGGElement>) {
if (event.key === 'Backspace' || event.key === 'Delete') {
event.preventDefault();
event.stopPropagation();
dispatch({ type: 'DELETE_2D_SIGNAL_LINK', payload: { id } });
if (newLabel === id) {
setData(null);
}
}
}

return (
<Wrapper onKeyDown={handleKeyDown} onMouseEnter={show} onMouseLeave={hide}>
<circle
cx={scaleX(signal.xDelta)}
cy={scaleY(signal.yDelta)}
r={4}
fill="transparent"
stroke="green"
strokeWidth={2}
style={{ cursor: 'pointer' }}
tabIndex={0}
onMouseEnter={(event) => event.currentTarget.focus()}
onMouseLeave={(event) => event.currentTarget.blur()}
onClick={(event) => {
event.stopPropagation();
setData(id);
}}
/>

<LinkedSignalAssignmentLabel signal={signal} />
</Wrapper>
);
}
Loading
Loading