@@ -22,10 +22,12 @@ import {
2222} from '@visx/legend' ;
2323import { scaleOrdinal } from 'd3-scale' ;
2424import { pickProps } from '../../common/helpers' ;
25- import { on } from '../../messenger' ;
25+ import { emit , on } from '../../messenger' ;
2626import chroma from 'chroma-js' ;
2727import { ImageSourceSolver } from '../../compute/raytracer/image-source' ;
2828import { useSolver } from '../../store' ;
29+ import PropertyRowCheckbox from "../parameter-config/property-row/PropertyRowCheckbox" ;
30+ import { createPropertyInputs } from '../parameter-config/SolverComponents' ;
2931// accessors
3032const getTime = ( d ) => d . time ;
3133const getPressure = ( d ) => d . pressure [ 0 ] ;
@@ -87,11 +89,19 @@ const useUpdate = () => {
8789
8890
8991const Chart = ( { uuid, width = 400 , height = 200 , events = false } : LTPChartProps ) => {
90- const { info, data, from} = useResult ( state => pickProps ( [ "info" , "data" , "from" ] , state . results [ uuid ] as Result < ResultKind . LinearTimeProgression > ) ) ;
92+ const { info, data : _data , from} = useResult ( state => pickProps ( [ "info" , "data" , "from" ] , state . results [ uuid ] as Result < ResultKind . LevelTimeProgression > ) ) ;
9193
9294 const [ count , update ] = useUpdate ( ) ;
95+ const [ data , setData ] = useState ( _data ) ;
9396
94- useEffect ( ( ) => on ( "UPDATE_RESULT" , ( e ) => e . uuid === uuid && update ( ) ) , [ uuid ] )
97+
98+ useEffect ( ( ) => on ( "UPDATE_RESULT" , ( e ) => {
99+ if ( e . uuid === uuid ) {
100+ //@ts -ignore
101+ setData ( e . result . data ) ;
102+ // update();
103+ }
104+ } ) , [ uuid ] )
95105
96106 const scalePadding = 60 ;
97107 const scaleWidth = width - scalePadding ;
@@ -102,7 +112,7 @@ const Chart = ({ uuid, width = 400, height = 200, events = false }: LTPChartProp
102112 range : [ 0 , scaleWidth ] ,
103113 domain : [ 0 , Math . max ( ...data . map ( getTime ) ) ] ,
104114 } ) ,
105- [ width , count ] ,
115+ [ width , data ] ,
106116 ) ;
107117
108118 const scaleHeight = height - scalePadding ;
@@ -112,12 +122,12 @@ const Chart = ({ uuid, width = 400, height = 200, events = false }: LTPChartProp
112122 range : [ scaleHeight , 0 ] ,
113123 domain : [ 0 , Math . max ( ...data . map ( getPressure ) ) ] ,
114124 } ) ,
115- [ height , count ] ,
125+ [ height , data ] ,
116126 ) ;
117127
118128 const ordinalColorScale = useMemo (
119129 ( ) => scaleOrdinal (
120- range ( 1 , info . maxOrder + 1 ) ,
130+ range ( 0 , info . maxOrder + 1 ) ,
121131 getOrderColors ( info . maxOrder + 1 )
122132 ) ,
123133 [ info . maxOrder ]
@@ -169,16 +179,35 @@ const Chart = ({ uuid, width = 400, height = 200, events = false }: LTPChartProp
169179
170180
171181export const LTPChart = ( { uuid, width = 400 , height = 300 , events = false } : LTPChartProps ) => {
172- const { name, info} = useResult ( state => pickProps ( [ "name" , "info" ] , state . results [ uuid ] as Result < ResultKind . LinearTimeProgression > ) ) ;
182+ const { name, info} = useResult ( state => pickProps ( [ "name" , "info" ] , state . results [ uuid ] as Result < ResultKind . LevelTimeProgression > ) ) ;
183+
184+ const [ order , setMaxOrder ] = useState ( info . maxOrder ) ;
185+
186+ useEffect ( ( ) => on ( "UPDATE_RESULT" , ( e ) => {
187+ if ( e . uuid === uuid ) {
188+ //@ts -ignore
189+ setMaxOrder ( e . result . info . maxOrder ) ;
190+ }
191+ } ) , [ uuid ] ) ;
192+
173193 const ordinalColorScale = useMemo (
174194 ( ) => scaleOrdinal (
175- range ( 1 , info . maxOrder + 1 ) ,
176- getOrderColors ( info . maxOrder + 1 )
195+ range ( 0 , order + 1 ) ,
196+ getOrderColors ( order + 1 )
177197 ) ,
178- [ info . maxOrder ]
198+ [ order ]
179199 ) ;
200+ // const ordinalColorScale = scaleOrdinal(
201+ // range(1, info.maxOrder+1),
202+ // getOrderColors(info.maxOrder+1)
203+ // );
180204
205+ const { from} = useResult ( state => pickProps ( [ "from" ] , state . results [ uuid ] as Result < ResultKind . LevelTimeProgression > ) ) ;
206+ let imagesourcesolver = useSolver . getState ( ) . solvers [ from ] as ImageSourceSolver ;
181207
208+ const { PropertyTextInput, PropertyNumberInput, PropertyCheckboxInput } = createPropertyInputs < ImageSourceSolver > (
209+ "IMAGESOURCE_SET_PROPERTY"
210+ ) ;
182211
183212 return width < 10 ? null : (
184213 < VerticalContainer >
@@ -197,7 +226,7 @@ export const LTPChart = ({ uuid, width = 400, height = 300, events = false }: LT
197226 key = { `legend-quantile-${ i } ` }
198227 margin = "0 5px"
199228 onClick = { ( ) => {
200- if ( events ) alert ( `clicked: ${ JSON . stringify ( label ) } ` ) ;
229+ // if (events) alert(`clicked: ${JSON.stringify(label)}`);
201230 } }
202231 >
203232 < svg width = { legendGlyphSize } height = { legendGlyphSize } >
@@ -206,6 +235,18 @@ export const LTPChart = ({ uuid, width = 400, height = 300, events = false }: LT
206235 < LegendLabel align = "left" margin = "0 0 0 4px" >
207236 { label . text }
208237 </ LegendLabel >
238+ < PropertyRowCheckbox
239+ value = { imagesourcesolver . plotOrders . includes ( label . datum ) }
240+ onChange = { ( e ) =>
241+ {
242+ emit ( "IMAGESOURCE_SET_PROPERTY" , { uuid : from , property : "toggleOrder" , value : label . datum } )
243+ if ( this != undefined ) {
244+ //@ts -ignore
245+ console . log ( this . refs . complete . state . checked )
246+ }
247+ }
248+ }
249+ />
209250 </ LegendItem >
210251 ) ) }
211252 </ LegendContainer >
0 commit comments