diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DataVizBox.tsx | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx index 7a2715667..4eb241380 100644 --- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx +++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx @@ -47,6 +47,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { private _annotationLayer: React.RefObject<HTMLDivElement> = React.createRef(); anchorMenuClick?: () => undefined | ((anchor: Doc) => void); crop: ((region: Doc | undefined, addCrop?: boolean) => Doc | undefined) | undefined; + @observable schemaDataVizChildren: any; @observable _marqueeing: number[] | undefined; @observable _savedAnnotations = new ObservableMap<number, HTMLDivElement[]>(); @computed get annotationLayer() { @@ -322,50 +323,12 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { GPTPopup.Instance.addDoc = this.sidebarAddDocument; }; - datavizContextMenu = (e: React.MouseEvent): void => { - const cm = ContextMenu.Instance; - const options = cm.findByDescription('Options...'); - const optionItems = options && 'subitems' in options ? options.subitems : []; - optionItems.push({ description: `Ask GPT`, event: () => {this.askGPT()}, icon: 'lightbulb' }); - !options && cm.addItem({ description: 'Options...', subitems: optionItems, icon: 'eye' }); - }; - - async askGPT() { - let image_urls = await gptImageCall(Object.keys(this.records[0])[0]); - if (image_urls && image_urls[0]) { - const [result] = await Networking.PostToServer('/uploadRemoteImage', { sources: [image_urls[0]] }); - const source = Utils.prepend(result.accessPaths.agnostic.client); - //this.setImgUrls([[image_urls[0], source]]); - const anchor = this.rootDoc; - if (!anchor) return; - const newDoc = Docs.Create.ImageDocument(source, { - x: NumCast(anchor.x) + NumCast(anchor._width) + 10, - y: NumCast(anchor.y), - _height: 200, - _width: 200, - data_nativeWidth: 1024, - data_nativeHeight: 1024, - }); - if (Doc.IsInMyOverlay(anchor)) { - newDoc.overlayX = anchor.x; - newDoc.overlayY = NumCast(anchor.y) + NumCast(anchor._height); - Doc.AddToMyOverlay(newDoc); - } else { - this.props.addDocument?.(newDoc); - } - DocUtils.MakeLink(anchor, newDoc, { link_relationship: 'GPT Data Prompt' }); - } - } - @action updateSchemaViz = () => { - if (this.layoutDoc.dataViz_asSchema && DocCast(this.layoutDoc.dataViz_asSchema)){ - const getFrom = DocCast(this.layoutDoc.dataViz_asSchema) const keys = Cast(getFrom.schema_columnKeys, listSpec('string'))?.filter(key => key!="text"); if (!keys) return; const children = DocListCast(getFrom[Doc.LayoutFieldKey(getFrom)]); - var current: {[key: string]: string}[] = [] for (let i=1; i<children.length; i++){ var row: {[key:string]: string} = {}; @@ -378,14 +341,14 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } current.push(row) } - DataVizBox.dataset.set(CsvCast(this.rootDoc[this.fieldKey]).url.href, current ) } -} - render() { - this.updateSchemaViz(); + if (this.layoutDoc && this.layoutDoc.dataViz_asSchema){ + this.schemaDataVizChildren = DocListCast(DocCast(this.layoutDoc.dataViz_asSchema)[Doc.LayoutFieldKey(DocCast(this.layoutDoc.dataViz_asSchema))]).length + this.updateSchemaViz(); + } const scale = this.props.NativeDimScaling?.() || 1; return !this.records.length ? ( @@ -404,7 +367,6 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }} onWheel={e => e.stopPropagation()} ref={this._mainCont} - onContextMenu={this.datavizContextMenu} > <div className={'datatype-button'}> <Toggle text={' TABLE '} toggleType={ToggleType.BUTTON} type={Type.SEC} color={'black'} onClick={e => (this.layoutDoc._dataViz = DataVizView.TABLE)} toggleStatus={this.layoutDoc._dataViz === DataVizView.TABLE} /> |