@@ -19,15 +19,15 @@ import RawDataPlotPanel from '@/components/RawDataPlotPanel';
1919import { Trash2 } from 'lucide-react' ;
2020import { flushSync } from 'react-dom' ;
2121import { isDarkRGB } from '@/libs/color' ;
22- import { filterRawPointsByAverage , filterRawPointsByAverageCurve } from '@/utils/filterRawByAverage' ;
23- import { filter } from 'd3' ;
22+ import { filterRawPointsByAverage } from '@/utils/filterRawByAverage' ;
23+ // import { filter } from 'd3';
2424const Plot = dynamic ( ( ) => import ( 'react-plotly.js' ) , { ssr : false } ) ;
2525
2626export default function LightCurvePlot ( ) {
2727 const {
2828 dataType, dataSelection, xAxis, errorBars, noOfBins, noOfDataPoint,
2929 plotType, pointSize, lineWidth, legendFontSize, labelFontSize, tooltipFontSize,
30- figure, rawFigure, avgPointRawMap, filterPercent, isFiltered, selectedSeries,
30+ figure, rawFigure, avgPointRawMap, filterPercent, isFiltered, selectedSeries,
3131 setSettings
3232 } = usePlotSettings ( ) ;
3333
@@ -41,8 +41,7 @@ export default function LightCurvePlot() {
4141
4242 const [ rawPlot , setRawPlot ] = useState < RawPoint [ ] | null > ( null ) ;
4343 const [ filteredRawPlot , setFilteredRawPlot ] = useState < { tracesSW : PlotTrace [ ] ; tracesLW : PlotTrace [ ] } > ( { tracesSW : [ ] , tracesLW : [ ] } ) ;
44- const [ filterBand , setFilterBand ] = useState < { minY : number ; maxY : number } | null > ( null ) ;
45- // const [rawColor, setRawColor] = useState<string>('#1f77b4');
44+
4645 const [ rawMarkerBorderColor , setRawMarkerBorderColor ] = useState < string > ( '#000000' ) ;
4746 const [ rawMarkerFillColor , setRawMarkerFillColor ] = useState < string > ( '#1f77b4' ) ;
4847 const [ rawLineColor , setRawLineColor ] = useState < string > ( '#1f77b4' ) ;
@@ -57,11 +56,6 @@ export default function LightCurvePlot() {
5756 const msPerDay = 86400 * 1000 ;
5857 return new Date ( MJD_EPOCH + mjd * msPerDay ) ;
5958 }
60-
61- // const [selectedImages, setSelectedImages] = useState<
62- // { id: string; imgSrc: string; label: string; cd: any }[]
63- // >([]);
64- // const imageCounter = useRef(1);
6559 type SelectedImg = {
6660 key : string ;
6761 imgThumbnailsSrc : string ;
@@ -128,6 +122,8 @@ export default function LightCurvePlot() {
128122 }
129123 const { traces : traceSW , patch : patchSW } = addTrace ( { wave : 'SW' , json : swJson , axis : xAxis , mode : dType , noOfBins, noOfDataPoint, timeKey, epoch, r_in : r1 , r_out : r2 , avgPointRawMap, markerFillColor, markerBorderColor, lineColor, plotType : plotType as 'lines' | 'markers' | 'lines+markers' , errorBars : errorBars as 'bar' | 'hide' | 'separate' | undefined , pointSize, lineWidth, dataMode } ) ;
130124 rawTracesSW . push ( ...traceSW ) ;
125+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
126+ // @ts -expect-error
131127 setSettings ( prev => ( {
132128 avgPointRawMap : {
133129 ...prev . avgPointRawMap ,
@@ -150,6 +146,9 @@ export default function LightCurvePlot() {
150146 } ) ) ;
151147 const { traces : traceLW , patch : patchLW } = addTrace ( { wave : 'LW' , json : lwJson , axis : xAxis , mode : dType , noOfBins, noOfDataPoint, timeKey, epoch, r_in : r1 , r_out : r2 , avgPointRawMap, markerFillColor, markerBorderColor, lineColor, plotType : plotType as 'lines' | 'markers' | 'lines+markers' , errorBars : errorBars as 'bar' | 'hide' | 'separate' | undefined , pointSize, lineWidth, dataMode } ) ;
152148 rawTracesLW . push ( ...traceLW ) ;
149+
150+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
151+ // @ts -expect-error
153152 setSettings ( prev => ( {
154153 avgPointRawMap : {
155154 ...prev . avgPointRawMap ,
@@ -252,11 +251,22 @@ export default function LightCurvePlot() {
252251
253252 useEffect ( ( ) => {
254253 if ( ! rawFigure || ! avgPointRawMap ) return ;
255- if ( ! isFiltered ) { setFilteredRawPlot ( rawFigure ) }
254+ if ( ! isFiltered ) { setFilteredRawPlot ( rawFigure )
255+ const fullData = [
256+ ...rawFigure . tracesSW . map ( tr => ( { ...tr , xaxis : 'x2' , yaxis : 'y' } ) ) ,
257+ ...rawFigure . tracesLW . map ( tr => ( { ...tr , xaxis : 'x2' , yaxis : 'y2' } ) ) ,
258+ ] ;
259+ setSettings ( {
260+ figure : {
261+ data : fullData ,
262+ layout : { ...figure ?. layout , shapes : [ ] }
263+ }
264+ } ) ;
265+ }
256266 else {
257267 const tracesSW = rawFigure . tracesSW . map ( t => ( { ...t } ) ) ;
258268 const tracesLW = rawFigure . tracesLW . map ( t => ( { ...t } ) ) ;
259-
269+ const shapes : any [ ] = [ ] ;
260270 tracesSW . forEach ( ( trace : PlotTrace ) => {
261271 const name = trace . name ?? "" ;
262272 if ( ! name . includes ( "_average" ) ) return ;
@@ -282,15 +292,53 @@ export default function LightCurvePlot() {
282292 const rawList = avgPointRawMap [ key ] ;
283293 if ( ! rawList ) return ;
284294
285- const { kept } = filterRawPointsByAverage ( rawList , avgY , filterPercent ) ;
295+ const { kept, minY, maxY } = filterRawPointsByAverage ( rawList , avgY , filterPercent ) ;
296+ shapes . push ( {
297+ type : "rect" ,
298+ xref : "x2" ,
299+ yref : "y" ,
300+ x0 : Math . min ( ...rawList . map ( p => p . x ) ) ,
301+ x1 : Math . max ( ...rawList . map ( p => p . x ) ) ,
302+ y0 : minY ,
303+ y1 : maxY ,
304+ fillcolor : "rgba(255, 255, 255, 0.2)" ,
305+ line : { width : 0 }
306+ } ) ;
286307
308+ if ( xAxis === 'phase' ) {
309+ shapes . push ( {
310+ type : "rect" ,
311+ xref : "x2" ,
312+ yref : "y" ,
313+ x0 : Math . min ( ...rawList . map ( p => p . x ) ) + 1 ,
314+ x1 : Math . max ( ...rawList . map ( p => p . x ) ) + 1 ,
315+ y0 : minY ,
316+ y1 : maxY ,
317+ fillcolor : "rgba(255, 255, 255, 0.2)" ,
318+ line : { width : 0 }
319+ } ) ;
320+ }
321+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
322+ // @ts -expect-error
287323 newRawTrace . x . push ( ...kept . map ( p => p . x ) ) ;
324+
325+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
326+ // @ts -expect-error
288327 newRawTrace . y . push ( ...kept . map ( p => p . y ) ) ;
328+
329+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
330+ // @ts -expect-error
289331 newRawTrace . err . push ( ...kept . map ( p => p . err ) ) ;
332+
333+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
334+ // @ts -expect-error
290335 newRawTrace . customdata . push ( ...kept . map ( p => p . customdata ) ) ;
291336 } ) ;
292337 newRawTrace . name = `${ base_raw_name } (${ newRawTrace . y . length } /${ rawFigure . tracesSW [ rawTraceIndex ] . y . length } )` ;
293338 if ( xAxis === 'phase' ) {
339+
340+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
341+ // @ts -expect-error
294342 newRawTrace . x = newRawTrace . x . concat ( ( newRawTrace . x as number [ ] ) . map ( v => v + 1 ) ) ;
295343 newRawTrace . y = newRawTrace . y . concat ( newRawTrace . y ) ;
296344 newRawTrace . err = newRawTrace . err . concat ( newRawTrace . err ) ;
@@ -323,15 +371,52 @@ export default function LightCurvePlot() {
323371 const rawList = avgPointRawMap [ key ] ;
324372 if ( ! rawList ) return ;
325373
326- const { kept } = filterRawPointsByAverage ( rawList , avgY , filterPercent ) ;
327-
374+ const { kept, minY, maxY } = filterRawPointsByAverage ( rawList , avgY , filterPercent ) ;
375+ shapes . push ( {
376+ type : "rect" ,
377+ xref : "x2" ,
378+ yref : "y2" ,
379+ x0 : Math . min ( ...rawList . map ( p => p . x ) ) ,
380+ x1 : Math . max ( ...rawList . map ( p => p . x ) ) ,
381+ y0 : minY ,
382+ y1 : maxY ,
383+ fillcolor : "rgba(255, 255, 255, 0.2)" ,
384+ line : { width : 0 }
385+ } ) ;
386+ if ( xAxis === 'phase' ) {
387+ shapes . push ( {
388+ type : "rect" ,
389+ xref : "x2" ,
390+ yref : "y2" ,
391+ x0 : Math . min ( ...rawList . map ( p => p . x ) ) + 1 ,
392+ x1 : Math . max ( ...rawList . map ( p => p . x ) ) + 1 ,
393+ y0 : minY ,
394+ y1 : maxY ,
395+ fillcolor : "rgba(255, 255, 255, 0.2)" ,
396+ line : { width : 0 }
397+ } ) ;
398+ }
399+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
400+ // @ts -expect-error
328401 newRawTrace . x . push ( ...kept . map ( p => p . x ) ) ;
402+
403+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
404+ // @ts -expect-error
329405 newRawTrace . y . push ( ...kept . map ( p => p . y ) ) ;
406+
407+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
408+ // @ts -expect-error
330409 newRawTrace . err . push ( ...kept . map ( p => p . err ) ) ;
410+
411+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
412+ // @ts -expect-error
331413 newRawTrace . customdata . push ( ...kept . map ( p => p . customdata ) ) ;
332414 } ) ;
333415 newRawTrace . name = `${ base_raw_name } (${ newRawTrace . y . length } /${ rawFigure . tracesLW [ rawTraceIndex ] . y . length } )` ;
334416 if ( xAxis === 'phase' ) {
417+
418+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
419+ // @ts -expect-error
335420 newRawTrace . x = newRawTrace . x . concat ( ( newRawTrace . x as number [ ] ) . map ( v => v + 1 ) ) ;
336421 newRawTrace . y = newRawTrace . y . concat ( newRawTrace . y ) ;
337422 newRawTrace . err = newRawTrace . err . concat ( newRawTrace . err ) ;
@@ -341,6 +426,18 @@ export default function LightCurvePlot() {
341426 } ) ;
342427
343428 setFilteredRawPlot ( { tracesSW, tracesLW } ) ;
429+
430+ const fullData = [
431+ ...tracesSW . map ( tr => ( { ...tr , xaxis : 'x2' , yaxis : 'y' } ) ) ,
432+ ...tracesLW . map ( tr => ( { ...tr , xaxis : 'x2' , yaxis : 'y2' } ) ) ,
433+ ] ;
434+ setSettings ( {
435+ figure : {
436+ data : fullData ,
437+ layout : { ...figure ?. layout , shapes }
438+ }
439+ } ) ;
440+
344441 }
345442 } , [ avgPointRawMap , dataSelection , rawFigure , filterPercent , isFiltered , xAxis ] ) ;
346443
@@ -366,7 +463,7 @@ export default function LightCurvePlot() {
366463 }
367464 } ) ;
368465
369- } , [ plotType , pointSize , lineWidth , rawFigure , filteredRawPlot , isFiltered ] ) ;
466+ } , [ plotType , pointSize , lineWidth ] ) ;
370467
371468 useEffect ( ( ) => {
372469 clearAll ( ) ;
0 commit comments