|
1 | 1 | import { |
2 | | - annotations, |
3 | | - boundingBoxes, |
4 | | - fixations |
| 2 | + annotations, |
| 3 | + boundingBoxes, |
| 4 | + fixations |
5 | 5 | } from '../data'; |
6 | 6 | import { |
7 | | - onMounted, |
8 | | - onUnmounted |
| 7 | + onMounted, |
| 8 | + onUnmounted |
9 | 9 | } from 'vue'; |
10 | 10 | import { |
11 | | - useAnnotationSessionStore |
| 11 | + useAnnotationSessionStore |
12 | 12 | } from '@/ts/stores/annotationSessionStore'; |
13 | 13 |
|
14 | 14 | const CSV_HEADER = 'fixation_id,box_id'; |
15 | 15 |
|
16 | 16 | const createCsv = () => { |
17 | | - const rows = annotations.value.map( annotation => { |
18 | | - const fixationId = fixations.value[ annotation.fixationIdx ]?.id ?? annotation.fixationIdx; |
19 | | - const boxId = boundingBoxes.value[ annotation.boxIdx ]?.id ?? annotation.boxIdx; |
| 17 | + const rows = annotations.value.map( annotation => { |
| 18 | + const fixationId = fixations.value[ annotation.fixationIdx ]?.id ?? annotation.fixationIdx; |
| 19 | + const boxId = boundingBoxes.value[ annotation.boxIdx ]?.id ?? annotation.boxIdx; |
20 | 20 |
|
21 | | - return `${fixationId},${boxId}`; |
22 | | - } ); |
| 21 | + return `${ fixationId },${ boxId }`; |
| 22 | + } ); |
23 | 23 |
|
24 | | - return [ |
25 | | - CSV_HEADER, |
26 | | - ...rows |
27 | | - ].join( '\n' ); |
| 24 | + return [ |
| 25 | + CSV_HEADER, |
| 26 | + ...rows |
| 27 | + ].join( '\n' ); |
28 | 28 | }; |
29 | 29 |
|
30 | 30 | const downloadCsv = ( data: string, fileName: string ) => { |
31 | | - const blob = new Blob( [ data ], { |
32 | | - 'type': 'text/csv;charset=utf-8;' |
33 | | - } ); |
34 | | - const url = URL.createObjectURL( blob ); |
35 | | - const a = document.createElement( 'a' ); |
| 31 | + const blob = new Blob( [ data ], { |
| 32 | + 'type': 'text/csv;charset=utf-8;' |
| 33 | + } ); |
| 34 | + const url = URL.createObjectURL( blob ); |
| 35 | + const a = document.createElement( 'a' ); |
36 | 36 |
|
37 | | - a.href = url; |
38 | | - a.download = fileName; |
39 | | - a.style.display = 'none'; |
| 37 | + a.href = url; |
| 38 | + a.download = fileName; |
| 39 | + a.style.display = 'none'; |
40 | 40 |
|
41 | | - document.body.appendChild( a ); |
42 | | - a.click(); |
43 | | - document.body.removeChild( a ); |
44 | | - URL.revokeObjectURL( url ); |
| 41 | + document.body.appendChild( a ); |
| 42 | + a.click(); |
| 43 | + document.body.removeChild( a ); |
| 44 | + URL.revokeObjectURL( url ); |
45 | 45 | }; |
46 | 46 |
|
47 | 47 | export const useExportFunction = () => { |
48 | | - const session = useAnnotationSessionStore(); |
| 48 | + const session = useAnnotationSessionStore(); |
49 | 49 |
|
50 | | - const exportCsv = () => { |
51 | | - const sessionId = session.sessionIds[ session.sessionIdx ]?.sessionId ?? 'current'; |
52 | | - const fileName = `session-${ sessionId }-annotations.csv`; |
| 50 | + const exportCsv = () => { |
| 51 | + const sessionId = session.sessionIds[ session.sessionIdx ]?.sessionId ?? 'current'; |
| 52 | + const fileName = `session-${ sessionId }-annotations.csv`; |
53 | 53 |
|
54 | | - downloadCsv( createCsv(), fileName ); |
55 | | - }; |
| 54 | + downloadCsv( createCsv(), fileName ); |
| 55 | + }; |
56 | 56 |
|
57 | | - onMounted( () => { |
58 | | - document.addEventListener( 'eyetap:export', exportCsv ); |
59 | | - } ); |
| 57 | + onMounted( () => { |
| 58 | + document.addEventListener( 'eyetap:export', exportCsv ); |
| 59 | + } ); |
60 | 60 |
|
61 | | - onUnmounted( () => { |
62 | | - document.removeEventListener( 'eyetap:export', exportCsv ); |
63 | | - } ); |
| 61 | + onUnmounted( () => { |
| 62 | + document.removeEventListener( 'eyetap:export', exportCsv ); |
| 63 | + } ); |
64 | 64 | }; |
0 commit comments