diff options
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DataVizBox.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DataVizBox.tsx | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx index a4a4028f2..4883385bb 100644 --- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx +++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx @@ -1,9 +1,11 @@ import { action, computed, observable } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; -import { Cast, StrCast } from '../../../../fields/Types'; +import { Doc, FieldResult } from '../../../../fields/Doc'; +import { Cast, NumCast, StrCast } from '../../../../fields/Types'; import { CsvField } from '../../../../fields/URLField'; -import { ViewBoxBaseComponent } from '../../DocComponent'; +import { Docs } from '../../../documents/Documents'; +import { ViewBoxAnnotatableComponent, ViewBoxBaseComponent } from '../../DocComponent'; import { FieldViewProps, FieldView } from '../FieldView'; import { ChartBox } from './ChartBox'; import './DataVizBox.scss'; @@ -15,11 +17,42 @@ enum DataVizView { } @observer -export class DataVizBox extends ViewBoxBaseComponent<FieldViewProps>() { +export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { + // says we have an object and any string + // 2 ways of doing it + // @observable private pairs: { [key: string]: number | string | undefined }[] = []; + // @observable private pairs: { [key: string]: FieldResult }[] = []; @observable private pairs: { x: number; y: number }[] = []; + private _chartBox: ChartBox | undefined; + // // another way would be store a schema that defines the type of data we are expecting from an imported doc + + // method1() { + // this.pairs[0].x = 3; + // } + + // method() { + // // this.pairs[0].x = 3; + // // go through the pairs + // const x = this.pairs[0].x; + // if (typeof x == 'number') { + // let x1 = Number(x); + // // let x1 = NumCast(x); + // } + // } + + // could use field result + // [key: string]: FieldResult; + // instead of numeric x,y in there, // TODO: nda - make this use enum values instead // @observable private currView: DataVizView = DataVizView.TABLE; + + // TODO: nda - use onmousedown and onmouseup when dragging and changing height and width to update the height and width props only when dragging stops + + setChartBox = (chartBox: ChartBox) => { + this._chartBox = chartBox; + }; + @computed get currView() { if (this.rootDoc._dataVizView) { return StrCast(this.rootDoc._dataVizView); @@ -28,6 +61,32 @@ export class DataVizBox extends ViewBoxBaseComponent<FieldViewProps>() { } } + scrollFocus = (doc: Doc, smooth: boolean) => { + // reconstruct the view based on the anchor -> + // keep track of the datavizbox view and the type of chart we're rendering + + // use dataview to restore part of it and then pass on the rest to the chartbox + + // pseudocode + setTimeout(() => this._chartBox?.scrollFocus(doc, smooth)); /* smooth parameter true = do animations */ + return 0; + }; + + getAnchor() { + // store whatever information would allow me to reselect the same thing (store parameters I would pass to get the exact same element) + const anchor = + // this._COMPONENTNAME._getAnchor() ?? + this._chartBox?._getAnchor() ?? + Docs.Create.TextanchorDocument({ + /*put in some options*/ + }); + + anchor.dataView = this.currView; + + this.addDocument(anchor); + return anchor; + // have some other function in code that + } constructor(props: any) { super(props); if (!this.rootDoc._dataVizView) { @@ -45,7 +104,7 @@ export class DataVizBox extends ViewBoxBaseComponent<FieldViewProps>() { case 'table': return <TableBox pairs={this.pairs} />; case 'histogram': - return <ChartBox rootDoc={this.rootDoc} pairs={this.pairs} />; + return <ChartBox getAnchor={this.getAnchor} setChartBox={this.setChartBox} rootDoc={this.rootDoc} pairs={this.pairs} dataDoc={this.dataDoc} />; // case "histogram": // return (<HistogramBox rootDoc={this.rootDoc} pairs={this.pairs}/>) } |