diff options
Diffstat (limited to 'src/client/views/nodes/ImageBox.tsx')
-rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 32b9e20a4..22e242f77 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -250,6 +250,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this.dataDoc._freeform_panX_min = this.dataDoc._freeform_panX_min ? nw * NumCast(this.dataDoc._freeform_panX_min) : undefined; this.dataDoc._freeform_panY_max = this.dataDoc._freeform_panY_max ? nw * NumCast(this.dataDoc._freeform_panY_max) : undefined; this.dataDoc._freeform_panY_min = this.dataDoc._freeform_panY_min ? nw * NumCast(this.dataDoc._freeform_panY_min) : undefined; + return nw; }); @undoBatch rotate = action(() => { @@ -365,13 +366,13 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } }; - pushInfo = async (quiz: quizMode) => { + pushInfo = async (quiz: quizMode, i?: string) => { this._quizMode = quiz; this._loading = true; console.log('JHSDKFJHKSDJFHKSJDHFKJSDHFKJHSDKF'); const img = { - file: this.paths[0], + file: i ? i : this.paths[0], smart: quiz, }; const response = await axios.post('http://localhost:105/labels/', img, { @@ -387,6 +388,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }; createBoxes = (boxes: [[[number, number]]], texts: [string]) => { + const nscale = NumCast(this._props.PanelWidth()) * NumCast(this.layoutDoc._freeform_scale, 1); + const nw = nscale / NumCast(this.dataDoc[this.fieldKey + '_nativeWidth']); for (var i = 0; i < boxes.length; i++) { const coords = boxes[i] ? boxes[i] : []; const width = coords[1][0] - coords[0][0]; @@ -401,10 +404,11 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { _layout_fitWidth: true, // _layout_autoHeight: true, }); - newCol.x = coords[0][0]; - newCol.y = coords[0][1]; - // newCol.x = x * NumCast(this.dataDoc[this.fieldKey + '_nativeWidth']); - // newCol.y = y * NumCast(this.dataDoc[this.fieldKey + '_nativeHeight']); + const scaling = 1 / (this._props.NativeDimScaling?.() || 1); + newCol.x = coords[0][0] + NumCast(this._marqueeref.current?.left) * scaling; + newCol.y = coords[0][1] + NumCast(this._marqueeref.current?.top) * scaling; + // newCol[DocData].text_fontSize = height + 'px'; + newCol.zIndex = 1000; newCol.forceActive = true; newCol.quiz = text; @@ -414,22 +418,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this._loading = false; } }; - // static imageUrlToBase64 = async (imageUrl: string): Promise<string> => { - // try { - // const response = await fetch(imageUrl); - // const blob = await response.blob(); - - // return new Promise((resolve, reject) => { - // const reader = new FileReader(); - // reader.readAsDataURL(blob); - // reader.onloadend = () => resolve(reader.result as string); - // reader.onerror = error => reject(error); - // }); - // } catch (error) { - // console.error('Error:', error); - // throw error; - // } - // }; getImageDesc = async () => { this._loading = true; @@ -444,6 +432,16 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this._loading = false; }; + makeLabels = async () => { + this._loading = true; + try { + const hrefBase64 = await this.createCanvas(); + this.pushInfo(quizMode.NORMAL, hrefBase64); + } catch (error) { + console.log('Error'); + } + }; + levenshteinDistance = (a: string, b: string) => { const an = a.length; const bn = b.length; @@ -540,7 +538,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { const response = await gptAPICall(queryText, GPTCallType.QUIZ); const hexSent = this.extractHexAndSentences(response); console.log(hexSent.hexNumber); - doc.quiz = hexSent.sentences; + doc.quiz = hexSent.sentences?.replace(/UserAnswer/g, "user's answer").replace(/Rubric/g, 'rubric'); doc.backgroundColor = '#' + hexSent.hexNumber; } else { const match = this.compareWords(input, StrCast(doc.quiz)); @@ -789,6 +787,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this._getAnchor = AnchorMenu.Instance?.GetAnchor; AnchorMenu.Instance.gptFlashcards = this.getImageDesc; AnchorMenu.Instance.addToCollection = this._props.DocumentView?.()._props.addDocument; + AnchorMenu.Instance.makeLabels = this.makeLabels; AnchorMenu.Instance.marqueeWidth = this._marqueeref.current?.Width ?? 0; AnchorMenu.Instance.marqueeHeight = this._marqueeref.current?.Height ?? 0; this._marqueeref.current?.onTerminateSelection(); |