diff options
author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-20 20:18:31 -0500 |
---|---|---|
committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-20 20:18:31 -0500 |
commit | 5c147db2e12be2a5aeb57647eda3f4ab43bc697b (patch) | |
tree | a74675518974f17a4fc21dbf6506592de761a348 | |
parent | d218c0998b333c9bf6e905e999ce8b0bf02a72f7 (diff) | |
parent | 2ec7f43648e5360bb3adb92443d7055abd269346 (diff) |
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web
-rw-r--r-- | src/client/views/DocumentDecorations.tsx | 7 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 1 | ||||
-rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 17 | ||||
-rw-r--r-- | src/client/views/collections/CollectionFreeFormView.tsx | 1 | ||||
-rw-r--r-- | src/client/views/collections/CollectionSchemaView.tsx | 43 | ||||
-rw-r--r-- | src/client/views/nodes/CollectionFreeFormDocumentView.tsx | 9 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 30 |
7 files changed, 68 insertions, 40 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index dccab1dc5..4e109d475 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -25,12 +25,9 @@ export class DocumentDecorations extends React.Component { if (element.props.isTopMost) { return bounds; } - let transform = element.props.ScreenToLocalTransform().inverse(); + let transform = (element.props.ScreenToLocalTransform().scale(element.props.Scaling)).inverse(); var [sptX, sptY] = transform.transformPoint(0, 0); - // var [bptX, bptY] = transform.transformDirection(element.width, element.height); - let doc = element.props.Document; - let [bptX, bptY] = [doc.GetNumber(KeyStore.Width, 0), doc.GetNumber(KeyStore.Height, 0)]; - [bptX, bptY] = transform.transformPoint(bptX, bptY); + let [bptX, bptY] = transform.transformPoint(element.props.PanelSize[0], element.props.PanelSize[1]); return { x: Math.min(sptX, bounds.x), y: Math.min(sptY, bounds.y), r: Math.max(bptX, bounds.r), b: Math.max(bptY, bounds.b) diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 6d3d4d4c2..2f8337d8e 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -110,6 +110,7 @@ Documents.initProtos(() => { <DocumentView Document={mainContainer} AddDocument={undefined} RemoveDocument={undefined} ScreenToLocalTransform={() => Transform.Identity} Scaling={1} + PanelSize={[0, 0]} isTopMost={true} ContainingCollectionView={undefined} /> <DocumentDecorations /> diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index ceb638ab4..5e30c0390 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -242,6 +242,20 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { @observable private Document: Opt<Document>; + @action + setScaling = (r: any) => { + let nativeWidth = this.Document!.GetNumber(KeyStore.NativeWidth, 0); + let nativeHeight = this.Document!.GetNumber(KeyStore.NativeWidth, 0); + this._parentScaling = nativeWidth > 0 ? r.entry.width / nativeWidth : 1; + this._nativeWidth = r.entry.width ? r.entry.width : nativeWidth; + this._nativeHeight = nativeWidth ? r.entry.width / nativeWidth * nativeHeight : nativeHeight; + } + + @observable + private _nativeWidth = 0; + @observable + private _nativeHeight = 0; + render() { if (!this.Document) return <div></div> @@ -253,6 +267,7 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { AddDocument={undefined} RemoveDocument={undefined} Scaling={this._parentScaling} + PanelSize={[this._nativeWidth, this._nativeHeight]} ScreenToLocalTransform={() => { let { scale, translateX, translateY } = Utils.GetScreenTransform(this._mainCont); var props = CollectionDockingView.Instance.props; @@ -264,7 +279,7 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { if (nativeWidth > 0 && (layout.indexOf("CollectionFreeForm") == -1 || layout.indexOf("AnnotationsKey") != -1)) { // contents of documents should be scaled if document is not a freeform view, or if the freeformview is an annotation layer (presumably on a document that is not a freeformview) - return <Measure onResize={action((r: any) => this._parentScaling = nativeWidth > 0 ? r.entry.width / nativeWidth : 1)}> + return <Measure onResize={this.setScaling}> {({ measureRef }) => <div ref={measureRef}> {content} </div>} </Measure> } diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx index a6f34dfdf..3a66ebb75 100644 --- a/src/client/views/collections/CollectionFreeFormView.tsx +++ b/src/client/views/collections/CollectionFreeFormView.tsx @@ -249,6 +249,7 @@ export class CollectionFreeFormView extends CollectionViewBase { ScreenToLocalTransform={this.getTransform} isTopMost={false} Scaling={1} + PanelSize={[doc.GetNumber(KeyStore.Width, 0), doc.GetNumber(KeyStore.Height, 0)]} ContainingCollectionView={this} />); })} </div> diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx index fa37e0e76..f3217d55d 100644 --- a/src/client/views/collections/CollectionSchemaView.tsx +++ b/src/client/views/collections/CollectionSchemaView.tsx @@ -1,5 +1,5 @@ import React = require("react") -import { action, observable } from "mobx"; +import { action, computed, observable } from "mobx"; import { observer } from "mobx-react"; import Measure from "react-measure"; import ReactTable, { CellInfo, ComponentPropsGetterR, ReactTableDefaults } from "react-table"; @@ -21,6 +21,8 @@ export class CollectionSchemaView extends CollectionViewBase { private _mainCont = React.createRef<HTMLDivElement>(); + private DIVIDER_WIDTH = 5; + @observable selectedIndex = 0; @@ -116,27 +118,38 @@ export class CollectionSchemaView extends CollectionViewBase { } } - innerScreenToLocal(tx: number, ty: number) { - return () => this.props.ScreenToLocalTransform().transform(new Transform(-tx - 5 - COLLECTION_BORDER_WIDTH, -ty - COLLECTION_BORDER_WIDTH, 1)) + getTransform = (): Transform => { + return this.props.ScreenToLocalTransform().translate(- COLLECTION_BORDER_WIDTH - this.DIVIDER_WIDTH - this._dividerX, - COLLECTION_BORDER_WIDTH).scale(1 / this._parentScaling); + } + + @action + setScaling = (r: any) => { + const children = this.props.Document.GetList<Document>(this.props.fieldKey, []); + const selected = children.length > this.selectedIndex ? children[this.selectedIndex] : undefined; + this._panelWidth = r.entry.width; + this._panelHeight = r.entry.height ? r.entry.height : this._panelHeight; + this._parentScaling = r.entry.width / selected!.GetNumber(KeyStore.NativeWidth, r.entry.width); } @observable _parentScaling = 1; // used to transfer the dimensions of the content pane in the DOM to the ParentScaling prop of the DocumentView @observable _dividerX = 0; - @observable _dividerY = 0; + @observable _panelWidth = 0; + @observable _panelHeight = 0; render() { const columns = this.props.Document.GetList(KeyStore.ColumnsKey, [KeyStore.Title, KeyStore.Data, KeyStore.Author]) const children = this.props.Document.GetList<Document>(this.props.fieldKey, []); const selected = children.length > this.selectedIndex ? children[this.selectedIndex] : undefined; let me = this; let content = this.selectedIndex == -1 || !selected ? (null) : ( - <Measure onResize={action((r: any) => this._parentScaling = r.entry.width / selected.GetNumber(KeyStore.NativeWidth, r.entry.width))}> + <Measure onResize={this.setScaling}> {({ measureRef }) => <div ref={measureRef}> <DocumentView Document={selected} AddDocument={this.addDocument} RemoveDocument={this.removeDocument} - ScreenToLocalTransform={this.innerScreenToLocal(me._dividerX, me._dividerY)}//TODO This should probably be an actual transform + ScreenToLocalTransform={this.getTransform} Scaling={this._parentScaling} isTopMost={false} + PanelSize={[this._panelWidth, this._panelHeight]} ContainingCollectionView={me} /> </div> } @@ -146,6 +159,7 @@ export class CollectionSchemaView extends CollectionViewBase { <div onPointerDown={this.onPointerDown} ref={this._mainCont} className="collectionSchemaView-container" style={{ borderWidth: `${COLLECTION_BORDER_WIDTH}px` }} > <Measure onResize={action((r: any) => { this._dividerX = r.entry.width; + this._panelHeight = r.entry.height; })}> {({ measureRef }) => <div ref={measureRef} className="collectionSchemaView-tableContainer" style={{ position: "relative", float: "left", width: `${this._splitPercentage}%`, height: "100%" }}> @@ -154,14 +168,11 @@ export class CollectionSchemaView extends CollectionViewBase { pageSize={children.length} page={0} showPagination={false} - columns={columns.map(col => { - return ( - { - Header: col.Name, - accessor: (doc: Document) => [doc, col], - id: col.Id - }) - })} + columns={columns.map(col => ({ + Header: col.Name, + accessor: (doc: Document) => [doc, col], + id: col.Id + }))} column={{ ...ReactTableDefaults.column, Cell: this.renderCell @@ -171,8 +182,8 @@ export class CollectionSchemaView extends CollectionViewBase { </div> } </Measure> - <div className="collectionSchemaView-dividerDragger" style={{ position: "relative", background: "black", float: "left", width: "5px", height: "100%" }} onPointerDown={this.onDividerDown} /> - <div className="collectionSchemaView-previewRegion" style={{ position: "relative", float: "left", width: `calc(${100 - this._splitPercentage}% - 5px)`, height: "100%" }}> + <div className="collectionSchemaView-dividerDragger" style={{ position: "relative", background: "black", float: "left", width: `${this.DIVIDER_WIDTH}px`, height: "100%" }} onPointerDown={this.onDividerDown} /> + <div className="collectionSchemaView-previewRegion" style={{ position: "relative", float: "left", width: `calc(${100 - this._splitPercentage}% - ${this.DIVIDER_WIDTH}px)`, height: "100%" }}> {content} </div> </div > diff --git a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx index bb85f85a3..7cad6ffc1 100644 --- a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx +++ b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx @@ -77,7 +77,9 @@ export class CollectionFreeFormDocumentView extends React.Component<DocumentView getTransform = (): Transform => { - return this.props.ScreenToLocalTransform().translate(-this.props.Document.GetNumber(KeyStore.X, 0), -this.props.Document.GetNumber(KeyStore.Y, 0)); + var parentScaling = this.nativeWidth > 0 ? this.width / this.nativeWidth : 1; + return this.props.ScreenToLocalTransform(). + translate(-this.props.Document.GetNumber(KeyStore.X, 0), -this.props.Document.GetNumber(KeyStore.Y, 0)).scale(1 / parentScaling); } render() { @@ -93,7 +95,10 @@ export class CollectionFreeFormDocumentView extends React.Component<DocumentView backgroundColor: "transparent" }} > - <DocumentView {...this.props} Scaling={parentScaling} ScreenToLocalTransform={this.getTransform} /> + <DocumentView {...this.props} + Scaling={parentScaling} + ScreenToLocalTransform={this.getTransform} + /> </div> ); } diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index e9b1d5c8a..7cf00a116 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -31,6 +31,7 @@ export interface DocumentViewProps { isTopMost: boolean; //tfs: This shouldn't be necessary I don't think Scaling: number; + PanelSize: number[]; } export interface JsxArgs extends DocumentViewProps { Keys: { [name: string]: Key } @@ -127,7 +128,7 @@ export class DocumentView extends React.Component<DocumentViewProps> { e.stopPropagation(); return; } - this._contextMenuCanOpen = e.button == 2; + this._contextMenuCanOpen = true; if (this.active && !e.isDefaultPrevented()) { e.stopPropagation(); if (e.buttons === 2) { @@ -245,9 +246,6 @@ export class DocumentView extends React.Component<DocumentViewProps> { SelectionManager.SelectDoc(this, ctrlPressed) } - screenToLocalTransform = () => { - return this.props.ScreenToLocalTransform().transform(Transform.Identity.scale(1 / this.props.Scaling)); - } render() { if (!this.props.Document) return <div></div> @@ -255,19 +253,19 @@ export class DocumentView extends React.Component<DocumentViewProps> { if (!lkeys || lkeys === "<Waiting>") { return <p>Error loading layout keys</p>; } - let bindings = { + let documentBindings = { ...this.props, - ScreenToLocalTransform: this.screenToLocalTransform, // adds 'Scaling' to the screen to local Xf isSelected: this.isSelected, select: this.select } as any; for (const key of this.layoutKeys) { - bindings[key.Name + "Key"] = key; // this maps string values of the form <keyname>Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data + documentBindings[key.Name + "Key"] = key; // this maps string values of the form <keyname>Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data } for (const key of this.layoutFields) { let field = this.props.Document.Get(key); - bindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field; + documentBindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field; } + /* tfs: Should this be moved to CollectionFreeformView or another component that renders @@ -278,26 +276,26 @@ export class DocumentView extends React.Component<DocumentViewProps> { if (backgroundLayout) { let backgroundView = () => (<JsxParser components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView }} - bindings={bindings} + bindings={documentBindings} jsx={this.backgroundLayout} showWarnings={true} onError={(test: any) => { console.log(test) }} />); - bindings.BackgroundView = backgroundView; + documentBindings.BackgroundView = backgroundView; } - var width = this.props.Document.GetNumber(KeyStore.NativeWidth, 0); - var strwidth = width > 0 ? width.toString() + "px" : "100%"; - var height = this.props.Document.GetNumber(KeyStore.NativeHeight, 0); - var strheight = height > 0 ? height.toString() + "px" : "100%"; + var nativeWidth = this.props.Document.GetNumber(KeyStore.NativeWidth, 0); + var nativeHeight = this.props.Document.GetNumber(KeyStore.NativeHeight, 0); + var nodeWidth = nativeWidth > 0 ? nativeWidth.toString() + "px" : "100%"; + var nodeHeight = nativeHeight > 0 ? nativeHeight.toString() + "px" : "100%"; var scaling = this.props.Scaling; return ( - <div className="documentView-node" ref={this._mainCont} style={{ width: strwidth, height: strheight, transformOrigin: "left top", transform: `scale(${scaling},${scaling})` }} + <div className="documentView-node" ref={this._mainCont} style={{ width: nodeWidth, height: nodeHeight, transformOrigin: "left top", transform: `scale(${scaling},${scaling})` }} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown} > <JsxParser components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView }} - bindings={bindings} + bindings={documentBindings} jsx={this.layout} showWarnings={true} onError={(test: any) => { console.log(test) }} |