From e0dbe3a59d2e1e61fda951c250ef8d43cc0ccd3d Mon Sep 17 00:00:00 2001 From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> Date: Mon, 15 Jul 2024 01:38:38 -0400 Subject: layout options/preview progress --- .../views/nodes/DataVizBox/DocCreatorMenu.scss | 14 ++ .../views/nodes/DataVizBox/DocCreatorMenu.tsx | 250 +++++++++++++-------- 2 files changed, 174 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss b/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss index 71ad9e105..e3530c0ef 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss @@ -271,12 +271,26 @@ } .docCreatorMenu-layout-preview-window { + padding: 5px; + overflow: scroll; aspect-ratio: 1 / 1; + display: grid; width: 85%; border: 1px solid whitesmoke; border-radius: 5px; background-color: rgb(34, 34, 37); margin-top: 10px; + -ms-overflow-style: none; + scrollbar-width: none; + + .docCreatorMenu-layout-preview-item { + display: flex; + justify-content: center; + align-items: center; + border-radius: 3px; + border: solid 1px lightblue; + } } } + diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx index a45234a79..c8b414c59 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx @@ -1,9 +1,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { IReactionDisposer, ObservableMap, action, makeObservable, observable, reaction, runInAction } from 'mobx'; +import { IReactionDisposer, ObservableMap, action, computed, makeObservable, observable, reaction, runInAction } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { returnAll, returnFalse, setupMoveUpEvents } from '../../../../ClientUtils'; -import { Doc } from '../../../../fields/Doc'; +import { Doc, NumListCast } from '../../../../fields/Doc'; import { DocCast, ImageCast } from '../../../../fields/Types'; import { ImageField } from '../../../../fields/URLField'; import { emptyFunction } from '../../../../Utils'; @@ -16,6 +16,7 @@ import './DocCreatorMenu.scss'; import { Id } from '../../../../fields/FieldSymbols'; import { Colors } from 'browndash-components'; import { MakeTemplate } from '../../../util/DropConverter'; +import { threadId } from 'worker_threads'; export enum LayoutType { Stacked = 'stacked', @@ -37,7 +38,7 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { @observable _templateRefToDoc?: ObservableMap; @observable _selectedTemplate: Doc | undefined = undefined; - @observable _selectedLayout: LayoutType | undefined = undefined; + @observable _layout: {type?: LayoutType, yMargin: number, xMargin: number, rows?:number, columns?: number} = {yMargin: 0, xMargin: 0}; @observable _layoutPreview: boolean = false; @observable _pageX: number = 0; @@ -62,6 +63,35 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { @action setDataViz = (dataViz: DataVizBox) => { this._dataViz = dataViz }; @action setTemplateDocs = (docs: Doc[]) => {this._templateDocs = docs.map(doc => doc.annotationOn ? DocCast(doc.annotationOn):doc)}; + @computed get docsToRender() { + return NumListCast(this._dataViz?.layoutDoc.dataViz_selectedRows); + } + + @computed get rowsCount(){ + switch (this._layout.type) { + case LayoutType.Row: case LayoutType.Stacked: + return 1; + case LayoutType.Column: + return this.docsToRender.length; + case LayoutType.Grid: + return this._layout.rows ?? 0; + default: + return 0; + } + } + + @computed get columnsCount(){ + switch (this._layout.type) { + case LayoutType.Row: + return this.docsToRender.length; + case LayoutType.Column: case LayoutType.Stacked: + return 1; + case LayoutType.Grid: + return this._layout.columns ?? 0; + default: + return 0; + } + } @action onPointerDown = (e: PointerEvent) => { @@ -158,40 +188,50 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { ); } + @action updateXMargin = (input: string) => { this._layout.xMargin = Number(input) }; + @action updateYMargin = (input: string) => { this._layout.yMargin = Number(input) }; + @action updateDimensions = (dimension: 'x' | 'y', input: string) => { + if (dimension === 'x') { + this._layout.rows = Number(input); + } else { + this._layout.columns = Number(input); + } + }; + get layoutConfigOptions() { - const optionInput = (title: string) => { + const optionInput = (title: string, func: Function) => { return (
{title}
- + func(e.currentTarget.value)} className='docCreatorMenu-input config layout-config'/>
); } - switch (this._selectedLayout) { + switch (this._layout.type) { case LayoutType.Row: case LayoutType.Column: return (
- {optionInput('Y Margin:')} - {optionInput('X Margin:')} + {optionInput('Y Margin:', this.updateYMargin)} + {optionInput('X Margin:', this.updateXMargin)}
); case LayoutType.Grid: return ( <>
- {optionInput('Y Margin:')} - {optionInput('X Margin:')} + {optionInput('Y Margin:', this.updateYMargin)} + {optionInput('X Margin:', this.updateXMargin)}
Dimensions:
- + {this.updateDimensions('x', e.currentTarget.value); this.forceUpdate()}}/>
x
- + this.updateDimensions('y', e.currentTarget.value)}/>
); @@ -203,8 +243,38 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { } get layoutPreviewContents() { + const docWidth = Number(this._selectedTemplate?._width); + const docHeight = Number(this._selectedTemplate?._height); + const horizontalSpan: number = (docWidth + this._layout.xMargin) * this.columnsCount - this._layout.xMargin; + const verticalSpan: number = (docHeight + this._layout.yMargin) * this.rowsCount - this._layout.yMargin; + const largerSpan: number = horizontalSpan > verticalSpan ? horizontalSpan : verticalSpan; + const scaleDownFactor: number = largerSpan / 235; + const scaledWidth = docWidth / scaleDownFactor; + const scaledHeight = docHeight / scaleDownFactor; + + console.log(this.rowsCount); + console.log(this.columnsCount) + return ( -
+
+ {this.docsToRender.map(num => +
+ {num} +
+ )}
); @@ -220,7 +290,7 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { setupMoveUpEvents(this, e, returnFalse, emptyFunction, undoable(clickEv => { clickEv.stopPropagation(); - runInAction(() => this._selectedLayout = option); + runInAction(() => this._layout.type = option); }, 'open actions menu') ) }> @@ -248,7 +318,7 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> {
-
{this._selectedLayout ? this._selectedLayout.toUpperCase() : 'Choose Layout'}
+
{this._layout.type ? this._layout.type.toUpperCase() : 'Choose Layout'}
{layoutOption(LayoutType.Stacked)} {layoutOption(LayoutType.Grid)} @@ -270,7 +340,7 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> {
- {this._selectedLayout ? this.layoutConfigOptions: null} + {this._layout.type ? this.layoutConfigOptions: null} {this._layoutPreview ? this.layoutPreviewContents : null} {selectionBox(100, 30, 'Repeat:', undefined, repeatOptions.map(num => ))}
@@ -279,79 +349,61 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> { render() { return ( -
this._ref = r} - style={{ - display: '', - left: this._pageX, - top: this._pageY, - width: this._shouldDisplay ? 300 : 0, - height: this._shouldDisplay ? 400 : 0, - background: SnappingManager.userBackgroundColor, - color: SnappingManager.userColor, - }}> - {!this._shouldDisplay ? undefined : - <> -
- setupMoveUpEvents( - this, - e, - (e) => { - this._dragging = true; - this._startPos = {x: 0, y: 0}; - this._startPos.x = e.pageX - (this._ref?.getBoundingClientRect().left ?? 0); - this._startPos.y = e.pageY - (this._ref?.getBoundingClientRect().top ?? 0); - return true; - }, - emptyFunction, - undoable(clickEv => { - clickEv.stopPropagation(); - }, 'drag menu') - ) - } - onPointerMove={e => this.onPointerMove(e)} - onPointerUp={() => this._dragging = false} - > - - - + -
-
- {this._menuContent === 'templates' ? this.templatesPreviewContents : this.optionsMenuContents} - - } + + + +
+
+ {this._menuContent === 'templates' ? this.templatesPreviewContents : this.optionsMenuContents} +
+ }
) } -- cgit v1.2.3-70-g09d2