@@ -13,19 +13,54 @@ import { useContext, useMemo, useState } from "react";
1313import { DeviceInfoContext } from "../../contexts/DeviceInfoContext" ;
1414import { ParameterDisplayGroupsContext } from "../../contexts/ParameterDisplayGroupsContext" ;
1515import { useScanContext } from "../../hooks/useScanContext" ;
16- import { ScanParameterInfo } from "../../types/ScanParameterInfo" ;
16+ import {
17+ ScanParameterInfo ,
18+ ScanPattern ,
19+ scanPatterns ,
20+ } from "../../types/ScanParameterInfo" ;
1721
1822const generateScanValues = (
1923 start : number ,
2024 stop : number ,
2125 points : number ,
22- scatter : boolean ,
26+ pattern : ScanPattern ,
2327) => {
24- const values = Array . from (
25- { length : points } ,
26- ( _ , i ) => start + ( i * ( stop - start ) ) / ( points - 1 ) ,
27- ) ;
28- return scatter ? values . sort ( ( ) => Math . random ( ) - 0.5 ) : values ;
28+ const linspace = ( n : number ) =>
29+ Array . from ( { length : n } , ( _ , i ) => start + ( i * ( stop - start ) ) / ( n - 1 ) ) ;
30+
31+ switch ( pattern ) {
32+ case "linear" :
33+ return linspace ( points ) ;
34+ case "scatter" :
35+ return linspace ( points ) . sort ( ( ) => Math . random ( ) - 0.5 ) ;
36+ case "centred" : {
37+ const base = linspace ( points ) ;
38+ const mid = Math . floor ( ( points - 1 ) / 2 ) ;
39+ const order = [ mid ] ;
40+ for ( let k = 1 ; order . length < points ; k ++ ) {
41+ if ( mid - k >= 0 ) order . push ( mid - k ) ;
42+ if ( mid + k < points ) order . push ( mid + k ) ;
43+ }
44+ return order . map ( ( i ) => base [ i ] ) ;
45+ }
46+ case "forwardReverse" : {
47+ const base = linspace ( points ) ;
48+ return [ ...base , ...base . reverse ( ) ] ;
49+ }
50+ }
51+ } ;
52+
53+ const renderPatternLabel = ( pattern : ScanPattern ) : string => {
54+ switch ( pattern ) {
55+ case "linear" :
56+ return "Linear" ;
57+ case "scatter" :
58+ return "Scatter" ;
59+ case "centred" :
60+ return "Centred" ;
61+ case "forwardReverse" :
62+ return "Forward and reverse" ;
63+ }
2964} ;
3065
3166export const ParameterCard = ( {
@@ -96,6 +131,8 @@ export const ParameterCard = ({
96131 ) ;
97132 } , [ param , parameterDisplayGroups , deviceInfo ] ) ;
98133
134+ const pattern = param . generation . pattern ?? "linear" ;
135+
99136 return (
100137 < div style = { { display : "flex" , flexDirection : "column" , gap : 8 } } >
101138 < div
@@ -196,9 +233,7 @@ export const ParameterCard = ({
196233 dispatchScanInfoStateUpdate ( {
197234 type : "UPDATE_PARAMETER" ,
198235 index,
199- payload : {
200- id : e . target . value ,
201- } ,
236+ payload : { id : e . target . value } ,
202237 } ) ;
203238 } }
204239 renderValue = { ( value ) => {
@@ -238,7 +273,7 @@ export const ParameterCard = ({
238273 Number ( e . target . value ) ,
239274 param . generation . stop ,
240275 param . generation . points ,
241- param . generation . scatter ,
276+ pattern ,
242277 ) ,
243278 } ,
244279 } )
@@ -273,7 +308,7 @@ export const ParameterCard = ({
273308 param . generation . start ,
274309 Number ( e . target . value ) ,
275310 param . generation . points ,
276- param . generation . scatter ,
311+ pattern ,
277312 ) ,
278313 } ,
279314 } )
@@ -309,7 +344,7 @@ export const ParameterCard = ({
309344 param . generation . start ,
310345 param . generation . stop ,
311346 Number ( e . target . value ) ,
312- param . generation . scatter ,
347+ pattern ,
313348 ) ,
314349 } ,
315350 } )
@@ -324,26 +359,32 @@ export const ParameterCard = ({
324359 } }
325360 />
326361 </ div >
327- < FormControlLabel
328- control = {
329- < Checkbox
330- checked = { param . generation . scatter ?? false }
331- onChange = { ( e ) => {
332- dispatchScanInfoStateUpdate ( {
333- type : "UPDATE_PARAMETER" ,
334- index : index ! ,
335- payload : {
336- generation : {
337- ... param . generation ,
338- scatter : e . target . checked ,
339- } ,
362+ < FormControl fullWidth size = "small" >
363+ < InputLabel > Scan pattern </ InputLabel >
364+ < Select
365+ label = "Scan pattern"
366+ value = { pattern }
367+ onChange = { ( e ) => {
368+ dispatchScanInfoStateUpdate ( {
369+ type : "UPDATE_PARAMETER" ,
370+ index : index ! ,
371+ payload : {
372+ generation : {
373+ ... param . generation ,
374+ pattern : e . target . value as ScanPattern ,
340375 } ,
341- } ) ;
342- } }
343- />
344- }
345- label = "Scatter"
346- />
376+ } ,
377+ } ) ;
378+ } }
379+ renderValue = { ( selected ) => renderPatternLabel ( selected as ScanPattern ) }
380+ >
381+ { scanPatterns . map ( ( pattern ) => (
382+ < MenuItem key = { pattern } value = { pattern } >
383+ { renderPatternLabel ( pattern ) }
384+ </ MenuItem >
385+ ) ) }
386+ </ Select >
387+ </ FormControl >
347388 </ >
348389 ) : (
349390 < >
0 commit comments