1
1
2
- import { StrictMode , useEffect , useRef , useState } from 'react' ;
2
+ import { useEffect , useRef , useState } from 'react' ;
3
3
import gosling , { GoslingComponent , GoslingSpec , HiGlassSpec } from 'gosling.js' ;
4
- import type { Datum } from 'gosling.js/dist/src/gosling-schema' ;
5
- import type { AltGoslingSpec , PreviewAlt , AltTrack , AltDataStatistics } from './schema/alt-gosling-schema' ;
4
+ import type { Datum , AltGoslingSpec , PreviewAlt , AltTrack , AltDataStatistics } from '@alt-gosling/schema/alt-gosling-schema' ;
5
+
6
+ import { getAlt , updateAlt } from './alt-gosling-model' ;
7
+ import { renderAltTree , renderDataPanel } from './render' ;
6
8
7
9
// import Grid from '@mui/material/Grid';
8
10
// import TextField from '@mui/material/TextField';
9
11
10
- import { getAlt , updateAlt } from './alt-gosling-model' ;
11
- import { renderAltTree , renderDataPanel } from './render' ;
12
+
12
13
13
14
// import Button from '@mui/material/Button';
14
15
@@ -94,7 +95,7 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
94
95
95
96
function updateDataPanelDisplay ( altTrack : AltTrack , altDataStatistics : AltDataStatistics ) {
96
97
// console.log('updating data panel...')
97
- setAmountOfDataFetched ( amountOfDataFetched + 1 )
98
+ setAmountOfDataFetched ( amountOfDataFetched + 1 ) ;
98
99
// check if id is the same
99
100
// check if range is the same
100
101
@@ -105,7 +106,7 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
105
106
106
107
useEffect ( ( ) => {
107
108
// console.log('now its updated', selectedAltPanel)
108
- } , [ selectedAltPanel ] )
109
+ } , [ selectedAltPanel ] ) ;
109
110
110
111
// The state of useState is updated asynchronously
111
112
// Therefore, we update the panel based on SelectedAltPanel
@@ -136,25 +137,25 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
136
137
137
138
// get latest AltGoslingSpec
138
139
139
- const updatedAlt = updateAlt ( AltPanels . current [ selectedAltPanel ] . data , data . id , data . data )
140
+ const updatedAlt = updateAlt ( AltPanels . current [ selectedAltPanel ] . data , data . id , data . data ) ;
140
141
updateAltPanelDisplay ( updatedAlt ) ;
141
- updateDataPanelDisplay ( updatedAlt . tracks [ 0 ] , updatedAlt . tracks [ 0 ] . data . details . dataStatistics )
142
+ updateDataPanelDisplay ( updatedAlt . tracks [ 0 ] , updatedAlt . tracks [ 0 ] . data . details . dataStatistics ) ;
142
143
143
144
} ) ;
144
145
}
145
146
146
147
return ( ) => {
147
148
gosRef . current ?. api . unsubscribe ( 'rawData' ) ;
148
- }
149
+ } ;
149
150
} , [ gosRef . current ] ) ;
150
151
151
152
152
153
153
154
const AltPanelComponent = ( ) => {
154
155
// console.log('altcomp rerender')
155
156
return (
156
- < div className = "editor-alt-text-panel" >
157
- { selectedAltPanel >= 0 &&
157
+ < div className = "editor-alt-text-panel" >
158
+ { selectedAltPanel >= 0 &&
158
159
// AltPanels.current.length > selectedAltPanel &&
159
160
AltPanels . current [ selectedAltPanel ] &&
160
161
Object . keys ( AltPanels . current [ selectedAltPanel ] . data ) . length > 0 ? (
@@ -168,14 +169,14 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
168
169
</ >
169
170
) : null }
170
171
</ div >
171
- )
172
- }
172
+ ) ;
173
+ } ;
173
174
174
175
const DataPanelComponent = ( ) => {
175
176
// console.log('datapanel rerender')
176
177
return (
177
- < div className = "editor-data-panel" >
178
- { /* {selectedDataPanel >= 0 &&
178
+ < div className = "editor-data-panel" >
179
+ { /* {selectedDataPanel >= 0 &&
179
180
// AltPanels.current.length > selectedAltPanel &&
180
181
DataPanels.current[selectedDataPanel] ? ( */ }
181
182
< >
@@ -188,13 +189,15 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
188
189
</ >
189
190
{ /* ) : null} */ }
190
191
</ div >
191
- )
192
- }
192
+ ) ;
193
+ } ;
193
194
194
195
195
196
return (
196
197
< >
197
- < GoslingComponent ref = { gosRef } { ...props } compiled = { ( gs : GoslingSpec , hs : HiGlassSpec , additionalData : any ) => { setSpecProcessed ( additionalData [ '_processedSpec' ] as AltGoslingSpec ) } } />
198
+ < GoslingComponent ref = { gosRef } { ...props } compiled = { ( gs : GoslingSpec , hs : HiGlassSpec , additionalData : any ) => {
199
+ setSpecProcessed ( additionalData [ '_processedSpec' ] as AltGoslingSpec ) ;
200
+ } } />
198
201
199
202
< AltPanelComponent />
200
203
@@ -204,8 +207,8 @@ export const AltGoslingComponent = (props: AltGoslingCompProps) => {
204
207
<Button variant="contained" onClick={doSomething}>Reset example</Button>
205
208
</div> */ }
206
209
</ >
207
- )
208
- }
210
+ ) ;
211
+ } ;
209
212
210
213
export default AltGoslingComponent ;
211
214
@@ -336,7 +339,7 @@ export default AltGoslingComponent;
336
339
337
340
338
341
// // i want the ref to point to goslingcomponent
339
- // //
342
+ // //
340
343
341
344
// // export const AltGoslingComponent = forwardRef<GoslingRef>((props, gosRef) => {
342
345
@@ -378,7 +381,7 @@ export default AltGoslingComponent;
378
381
// // useEffect(() => {
379
382
// // gosApi.subscribe('rawData', (_: string, data: {id: string, data: Datum[]}) => {
380
383
// // console.log('Updated data was seen for', data.id);
381
- // // });
384
+ // // });
382
385
// // // return () => {
383
386
// // // gosApi.unsubscribe('rawData');
384
387
// // // }
0 commit comments