Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 9a41c02f

Přidáno uživatelem Dominik Poch před asi 2 roky(ů)

Added mapped annotation

Mapped annotation to instance and separated them to different tag occurrences

Zobrazit rozdíly:

webapp/contexts/AnnotationContext.tsx
1 1
import React, { createContext, useEffect, useState } from 'react';
2 2
import { AnnotationInfo, TagInstanceInfo } from '../api';
3
import { Occurrence, Tag } from '../components/types/tag';
3
import { Tag } from '../components/types/tag';
4 4
import { annotationController } from '../controllers';
5 5

  
6 6
/**
......
34 34
     * Deletes an occurrence of an annotation.
35 35
     * @param occurrence Occurrence that should be deleted.
36 36
     */
37
    deleteOccurrence: (occurrence: Occurrence) => void;
37
    deleteOccurrence: (occurrence: TagInstanceInfo) => void;
38 38

  
39 39
    /**
40 40
     * Changes a position of an occurrence of an annotation.
41 41
     * @param occurrence Occurrence whose position should be changed.
42 42
     * @param newValue New value of the position.
43 43
     */
44
    changePosition: (occurrence: Occurrence, newValue: number) => void;
44
    changePosition: (occurrence: TagInstanceInfo, newValue: number) => void;
45 45

  
46 46
    /**
47 47
     * Changes a length of an occurrence of an annotation.
48 48
     * @param occurrence Occurrence whose length should be changed.
49 49
     * @param newValue New value of the length.
50 50
     */
51
    changeLength: (occurrence: Occurrence, newValue: number) => void;
51
    changeLength: (occurrence: TagInstanceInfo, newValue: number) => void;
52 52

  
53 53
    annotation: AnnotationInfo | null;
54
    mappedTags: Tag[] | null;
54 55
    refreshAnnotation: () => void;
55 56
}
56 57

  
......
91 92
     * Default implementation of deleteOccurrence method.
92 93
     * @param occurrence Occurrence that should be deleted.
93 94
     */
94
    deleteOccurrence: (occurrence: Occurrence) => {
95
    deleteOccurrence: (occurrence: TagInstanceInfo) => {
95 96
        return;
96 97
    },
97 98

  
......
100 101
     * @param occurrence Occurrence whose position should be changed.
101 102
     * @param newValue A new position.
102 103
     */
103
    changePosition: (occurrence: Occurrence, newValue: number) => {
104
    changePosition: (occurrence: TagInstanceInfo, newValue: number) => {
104 105
        return;
105 106
    },
106 107

  
......
109 110
     * @param occurrence Occurrence whose length should be changed.
110 111
     * @param newValue A new length.
111 112
     */
112
    changeLength: (occurrence: Occurrence, newValue: number) => {
113
    changeLength: (occurrence: TagInstanceInfo, newValue: number) => {
113 114
        return;
114 115
    },
115 116

  
116 117
    annotation: null,
118
    mappedTags: null,
117 119
    refreshAnnotation: () => {
118 120
        return;
119 121
    },
......
135 137
     */
136 138
    const [tags, setTags] = useState<TagInstanceInfo[] | null>(null);
137 139

  
140
    const [mappedTags, setMappedTags] = useState<Tag[] | null>(null);
141

  
138 142
    /**
139 143
     * Default implementation of addOccurrence method.
140 144
     * @param tag The tag with new occurrence.
......
155 159
     * Deletes an occurrence of an annotation.
156 160
     * @param occurrence Occurrence that should be deleted.
157 161
     */
158
    const deleteOccurrence = (occurrence: Occurrence) => {
162
    const deleteOccurrence = (occurrence: TagInstanceInfo) => {
159 163
        //TODO: Implement method (should use objects from server API)
160 164
    };
161 165

  
......
164 168
     * @param occurrence Occurrence whose position should be changed.
165 169
     * @param newValue New value of the position.
166 170
     */
167
    const changePosition = (occurrence: Occurrence, newValue: number) => {
171
    const changePosition = (occurrence: TagInstanceInfo, newValue: number) => {
168 172
        //TODO: Implement method (should use objects from server API)
169 173
    };
170 174

  
......
173 177
     * @param occurrence Occurrence whose length should be changed.
174 178
     * @param newValue New value of the length.
175 179
     */
176
    const changeLength = (occurrence: Occurrence, newValue: number) => {
180
    const changeLength = (occurrence: TagInstanceInfo, newValue: number) => {
177 181
        //TODO: Implement method (should use objects from server API)
178 182
    };
179 183

  
184
    const remapAnnotations = (data: AnnotationInfo) => {
185
        let map = new Map<number, Tag>();
186
        data.tagInstances?.forEach((tagInstance) => {
187
            if (map.has(tagInstance.instance ?? 0)) {
188
                let tag = map.get(tagInstance.instance ?? 0);
189
                tag!.occurrences = [...tag!.occurrences, tagInstance];
190
            } else {
191
                map.set(tagInstance.position ?? 0, {
192
                    name: tagInstance.tagName ?? '',
193
                    category: tagInstance.tagCategoryName ?? '',
194
                    visible: true,
195
                    occurrences: [tagInstance],
196
                });
197
            }
198
        });
199

  
200
        setMappedTags(Array.from(map.values()));
201
    };
202

  
180 203
    async function refreshAnnotation() {
181 204
        const data = await annotationController.annotationAnnotationIdGet(
182 205
            props.annotationId
183 206
        );
184 207

  
208
        remapAnnotations(data.data);
185 209
        setAnnotation(data.data ?? null);
186 210
    }
187 211

  
......
204 228
                changePosition,
205 229
                refreshAnnotation,
206 230
                annotation,
231
                mappedTags,
207 232
            }}
208 233
        >
209 234
            {props.children}

Také k dispozici: Unified diff