@@ -92,78 +92,77 @@ async function makeExampleSVG(color: string) {
9292}
9393
9494const SpeedVersusAccuracyPareto : React . FC < SpeedVersusAccuracyParetoProps > = ( props ) => {
95- throw new Error ( "failure" ) ;
96- // // Access ExpressionStylesContext
97- // const [expressionStyles, setExpressionStyles] = HerbieContext.useGlobal(HerbieContext.ExpressionStylesContext);
98- // const [color, setColor] = React.useState('red');
99- // // Access the global expressions field
100- // const [allExpressions, setExpressions] = HerbieContext.useGlobal(HerbieContext.ExpressionsContext);
101- // // get the spec
102- // const [spec, setSpec] = HerbieContext.useGlobal(HerbieContext.SpecContext);
103- // // get the costs and errors for each expression
104- // const [costs, setCosts] = HerbieContext.useGlobal(HerbieContext.CostContext);
105- // const [analyses, setAnalyses] = HerbieContext.useGlobal(HerbieContext.AnalysesContext);
106- // // convert error to percent accuracy
107- // const errorToAccuracy = (error: number) => error// 1 - error / 64;
108- // //get archived expressions
109- // const [archivedExpressions, setArchivedExpressions] = HerbieContext.useGlobal(HerbieContext.ArchivedExpressionsContext);
95+ // Access ExpressionStylesContext
96+ const [ expressionStyles , setExpressionStyles ] = HerbieContext . useGlobal ( HerbieContext . ExpressionStylesContext ) ;
97+ const [ color , setColor ] = React . useState ( 'red' ) ;
98+ // Access the global expressions field
99+ const [ allExpressions , setExpressions ] = HerbieContext . useGlobal ( HerbieContext . ExpressionsContext ) ;
100+ // get the spec
101+ const [ spec , setSpec ] = HerbieContext . useGlobal ( HerbieContext . SpecContext ) ;
102+ // get the costs and errors for each expression
103+ const [ costs , setCosts ] = HerbieContext . useGlobal ( HerbieContext . CostContext ) ;
104+ const [ analyses , setAnalyses ] = HerbieContext . useGlobal ( HerbieContext . AnalysesContext ) ;
105+ // convert error to percent accuracy
106+ const errorToAccuracy = ( error : number ) => error // 1 - error / 64;
107+ //get archived expressions
108+ const [ archivedExpressions , setArchivedExpressions ] = HerbieContext . useGlobal ( HerbieContext . ArchivedExpressionsContext ) ;
110109
111- // // get the spec's expression
112- // const naiveExpression = allExpressions.find(e => e.text === spec.expression);
113- // if (naiveExpression === undefined) {
114- // return <div></div>//Naive expression not found</div>
115- // }
116- // // get the cost and accuracy for the naiveExpression
117- // const naiveCost = costs.find(c => c.expressionId === naiveExpression.id)?.cost;
118- // const naiveError = analyses.find(a => a.expressionId === naiveExpression.id)?.data.meanBitsError;
119- // if (naiveCost === undefined || naiveError === undefined) {
120- // return <div></div>//Naive cost or error not found</div>
121- // }
122- // const naiveAccuracy = errorToAccuracy(naiveError);
123- // // get the ids of the selected expressions
124- // const [selectedExprIds, setSelectedExprIds] = HerbieContext.useGlobal(HerbieContext.CompareExprIdsContext);
125- // // get the selected expression id
126- // const naiveExpressionId = selectedExprIds.find(id => id === naiveExpression.id) || 0;
127-
128- // // get the clicked on expression
129- // const [selectedExprId, setSelectedExprId] = HerbieContext.useGlobal(HerbieContext.SelectedExprIdContext);
130-
131- // // filter selected expressions
132- // const filteredExpressionIds = selectedExprIds.filter(e => !archivedExpressions.includes(e));
133-
134- // // iterate through each expression to find its cost and accuracy and store them in an array as as [cost, accuracy] tuple
135- // const points = filteredExpressionIds.map(id => {
136- // const cost = costs.find(c => c.expressionId === id)?.cost;
137- // const error = analyses.find(a => a.expressionId === id)?.data.meanBitsError;
138- // if (cost === undefined || error === undefined) {
139- // return undefined;
140- // }
141- // const accuracy = errorToAccuracy(error);
142- // return { cost: cost, accuracy: accuracy, id: id } as Point;
143- // }).filter(p => p) as Point[];
144-
145- // return (
146- // <div className="speedVersusAccuracyPareto">
147- // {/* Use a ref to update the svg*/}
148- // <svg viewBox="-10 -25 840 360" ref={async (svg) => {
149- // if (!svg) {
150- // return
151- // }
152- // svg.innerHTML = ''
153- // const plot = await plotParetoPoints(64, { cost: naiveCost, accuracy: naiveAccuracy, id: naiveExpressionId }, points, selectedExprId, expressionStyles);
110+ // get the spec's expression
111+ const naiveExpression = allExpressions . find ( e => e . text === spec . expression ) ;
112+ if ( naiveExpression === undefined ) {
113+ return < div > </ div > //Naive expression not found</div>
114+ }
115+ // get the cost and accuracy for the naiveExpression
116+ const naiveCost = costs . find ( c => c . expressionId === naiveExpression . id ) ?. cost ;
117+ const naiveError = analyses . find ( a => a . expressionId === naiveExpression . id ) ?. data . meanBitsError ;
118+ if ( naiveCost === undefined || naiveError === undefined ) {
119+ return < div > </ div > //Naive cost or error not found</div>
120+ }
121+ const naiveAccuracy = errorToAccuracy ( naiveError ) ;
122+ // get the ids of the selected expressions
123+ const [ selectedExprIds , setSelectedExprIds ] = HerbieContext . useGlobal ( HerbieContext . CompareExprIdsContext ) ;
124+ // get the selected expression id
125+ const naiveExpressionId = selectedExprIds . find ( id => id === naiveExpression . id ) || 0 ;
126+
127+ // get the clicked on expression
128+ const [ selectedExprId , setSelectedExprId ] = HerbieContext . useGlobal ( HerbieContext . SelectedExprIdContext ) ;
129+
130+ //filter selected expressions
131+ const filteredExpressionIds = selectedExprIds . filter ( e => ! archivedExpressions . includes ( e ) ) ;
132+
133+ // iterate through each expression to find its cost and accuracy and store them in an array as as [cost, accuracy] tuple
134+ const points = filteredExpressionIds . map ( id => {
135+ const cost = costs . find ( c => c . expressionId === id ) ?. cost ;
136+ const error = analyses . find ( a => a . expressionId === id ) ?. data . meanBitsError ;
137+ if ( cost === undefined || error === undefined ) {
138+ return undefined ;
139+ }
140+ const accuracy = errorToAccuracy ( error ) ;
141+ return { cost : cost , accuracy : accuracy , id : id } as Point ;
142+ } ) . filter ( p => p ) as Point [ ] ;
143+
144+ return (
145+ < div className = "speedVersusAccuracyPareto" >
146+ { /* Use a ref to update the svg*/ }
147+ < svg viewBox = "-10 -25 840 360" ref = { async ( svg ) => {
148+ if ( ! svg ) {
149+ return
150+ }
151+ svg . innerHTML = ''
152+ const plot = await plotParetoPoints ( 64 , { cost : naiveCost , accuracy : naiveAccuracy , id : naiveExpressionId } , points , selectedExprId , expressionStyles ) ;
154153
155- // plot.querySelectorAll('[aria-label="dot"] circle').forEach((t: any) => {
156- // // if a point if clicked (onclick), set its clickedExpressionID
157- // t.onclick = async() => {
158- // setSelectedExprId(parseInt(t.getAttribute("data-id")));
159- // }
160- // });
161-
162- // ([...plot.children]).map(c => svg.appendChild(c))
163- // }
164- // }></svg>
165- // </div>
166- // );
154+ plot . querySelectorAll ( '[aria-label="dot"] circle' ) . forEach ( ( t : any ) => {
155+ // if a point if clicked (onclick), set its clickedExpressionID
156+ t . onclick = async ( ) => {
157+ setSelectedExprId ( parseInt ( t . getAttribute ( "data-id" ) ) ) ;
158+ }
159+ } ) ;
160+
161+ ( [ ...plot . children ] ) . map ( c => svg . appendChild ( c ) )
162+ }
163+ } > </ svg >
164+ </ div >
165+ ) ;
167166} ;
168167
169168export default SpeedVersusAccuracyPareto ;
0 commit comments