-
-
Notifications
You must be signed in to change notification settings - Fork 167
Esefah meng history strip #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NanaKwame
wants to merge
6
commits into
esefah-meng
Choose a base branch
from
esefah-meng-history-strip
base: esefah-meng
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a679d9e
pushing this so it is easier to ask for help. code is kinda messy
NanaKwame 2eb45a3
cleanup 1
NanaKwame fdf2c63
cleanup 2
NanaKwame 82b2fa4
implemented feedback from Jonathan in PR
NanaKwame ba9b9fc
clean up
NanaKwame 8515e2e
more clean up
NanaKwame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const getInVis = require('../util/immutable-utils').getInVis; | ||
|
|
||
| import {createStandardAction} from 'typesafe-actions'; | ||
| import {HistoryRecord} from '../store/factory/History'; | ||
|
|
||
|
|
||
| /** | ||
| * TODO: Action creator to derive a history based on an existing dataset source. | ||
| * A derived history shares an existing source dataset. | ||
| * | ||
| * @param {Object} historyId - The id of the history to derive. | ||
| */ | ||
| export function mergeHistory (historyId: number) { | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
|
|
||
| // action creators prefixed with "base" should only be called by their redux-thunk function wrappers - jzong | ||
| export const baseAddHistory = createStandardAction('ADD_HISTORY')<HistoryRecord, number>(); | ||
| export const updateHistoryProperty = createStandardAction('UPDATE_HISTORY_PROPERTY')<{property: string, value: any}, number>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import * as React from 'react'; | ||
| import {HistoryList} from './history/HistoryList'; | ||
|
|
||
| export class HistoryToolbar extends React.PureComponent<{}, {modalIsOpen: boolean}> { | ||
| constructor(props) { | ||
| super(props); | ||
| } | ||
|
|
||
| public render() { | ||
| return ( | ||
| <div id='history-toolbar'> | ||
| <h2>History</h2> | ||
| <HistoryList /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import * as React from 'react'; | ||
| import {connect} from 'react-redux'; | ||
| import {View, parse, Spec} from 'vega'; | ||
| import {HistoryRecord, HistoryState} from '../../store/factory/History'; | ||
| import {cleanSpecForPreview} from '../../ctrl/demonstrations'; | ||
| import {startDragging, stopDragging} from '../../actions/inspectorActions'; | ||
| import {DraggingStateRecord, HistoryDraggingState} from '../../store/factory/Inspector'; | ||
| import sg from '../../ctrl/signals'; | ||
| import {MODE, SELECTED, CELL} from '../../store/factory/Signal'; | ||
| import {NumericValueRef, StringValueRef, tupleid} from 'vega'; | ||
| import {channelName} from '../../actions/bindChannel'; | ||
| import {setMarkVisual} from '../../actions/markActions'; | ||
| import * as vega from 'vega'; | ||
| import bindChannel from '../../actions/bindChannel'; | ||
| import {ColumnRecord, Schema} from '../../store/factory/Dataset'; | ||
| import { AnyAction } from 'redux'; | ||
| import {ThunkDispatch} from 'redux-thunk'; | ||
| import {State} from '../../store'; | ||
| import {setSignal} from '../../actions/signalActions'; | ||
| import {SignalValue} from 'vega-typings/types'; | ||
| import {batchGroupBy} from '../../reducers/historyOptions'; | ||
|
|
||
| const ctrl = require('../../ctrl'); | ||
|
|
||
|
|
||
| interface OwnProps { | ||
| id: string, | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| history: HistoryRecord // TODO: use History.ts for you just have to pass the id | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
|
|
||
| groupNames: any[]; | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| } | ||
| interface DispatchProps { | ||
| startDragging: (d: DraggingStateRecord) => void; | ||
| stopDragging: () => void; | ||
| setMarkVisual: (payload: {property: string, def: NumericValueRef | StringValueRef}, markId: number) => void; | ||
|
|
||
| bindChannel: (dsId: number, field: ColumnRecord, markId: number, property: string) => void; | ||
|
|
||
| setSignal: (value: SignalValue, signal: string) => void; | ||
| } | ||
|
|
||
| function mapDispatchToProps(dispatch: ThunkDispatch<State, null, AnyAction>, ownProps: OwnProps): DispatchProps { | ||
| return { | ||
| startDragging: (d: DraggingStateRecord) => { | ||
| dispatch(startDragging(d)); }, | ||
| stopDragging: () => { | ||
| dispatch(stopDragging()); }, | ||
| setMarkVisual: (p, markId) => { | ||
| dispatch(setMarkVisual(p, markId)); | ||
| }, | ||
| bindChannel: (dsId: number, field: ColumnRecord, markId: number, property: string) => { | ||
| dispatch(bindChannel(dsId, field, markId, property)); | ||
| }, | ||
| setSignal: (value: SignalValue, signal: string) => { | ||
| dispatch(setSignal(value, signal)); | ||
| } | ||
| }; | ||
| } | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
|
|
||
| export class HistoryItemInspector extends React.Component<OwnProps & DispatchProps> { | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| } | ||
|
|
||
| private width = 100; // these should match baseSignals in demonstrations.ts | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| private height = 100; // | ||
|
|
||
| public handleClick = (historyId: number) => { | ||
|
|
||
| } | ||
| public handleDragStart = (historyId: number) => { | ||
| this.props.startDragging(HistoryDraggingState({historyId})); | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
|
|
||
| sg.set(MODE, 'channels'); | ||
| ctrl.update(); | ||
| } | ||
|
|
||
| public handleDragEnd = (evt: React.DragEvent<HTMLDivElement>, opts?) => { | ||
| const props = this.props; | ||
| const sel = sg.get(SELECTED); | ||
| const cell = sg.get(CELL); | ||
| const dropped = tupleid(sel) && tupleid(cell); | ||
|
|
||
| try { | ||
| const lyraId = +sel.mark.role.split('lyra_')[1]; // id of thing that was dropped onto | ||
|
|
||
| if (dropped) { | ||
| const channel = channelName(cell.key); | ||
| let fieldName, dsId; | ||
| if (channel === 'x' || channel === 'y' || channel === 'color' || channel === 'size') { | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| // set scale | ||
| let channelScaleIds = this.props.history.getIn(["guides"]) | ||
| .map((g) => { | ||
| return channel == 'x' || channel == 'y' ? g.scale : channel == 'size' ? g[channel] : g.fill; | ||
| }) | ||
| .filter((scaleId) => { | ||
| let scaleName = scaleId ? this.props.history.getIn(["scales"]).get(scaleId).name : null; | ||
| return scaleName === channel; | ||
| }); | ||
|
|
||
| fieldName = channelScaleIds.map((scaleId) => { | ||
| let scaleRecord = this.props.history.getIn(["scales"]).get(scaleId); | ||
| return scaleRecord.get('_domain').length > 0 ? scaleRecord.get('_domain')[0].field : null; | ||
| }).first(); | ||
|
|
||
| dsId = channelScaleIds.map((scaleId) => { | ||
| let scaleRecord = this.props.history.getIn(["scales"]).get(scaleId); | ||
| return scaleRecord.get('_domain').length > 0 ? scaleRecord.get('_domain')[0].data : null; | ||
| }).first(); | ||
|
|
||
|
|
||
| } | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
|
|
||
| const bindField = this.props.history.getIn(["datasets", String(dsId), "_schema", fieldName]).toJS(); | ||
| vega.extend(bindField, opts); // Aggregate or Bin passed in opts. | ||
| props.bindChannel(dsId, bindField, lyraId, cell.key); | ||
| } else { | ||
| // update the whole symbol/mark: shape, size | ||
| // the history has the signals | ||
| let relevantProps = ["size", "shape", "fill", "fillOpacity", "stroke", "strokeWidth"]; | ||
| let historyMark = this.props.history.getIn(["marks", String(lyraId)]); // assume mark is the same as before. wanna revert to old settings of old mark | ||
|
|
||
| batchGroupBy.start(); | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| relevantProps.forEach((prop) => { | ||
| let historyProp = historyMark.getIn(["encode", "update", prop]); | ||
| if (historyProp.signal) { | ||
| let historySigVal = this.props.history.getIn(["signals", historyProp.signal]).value; | ||
| this.props.setSignal(historySigVal, historyProp.signal); // update Store | ||
| sg.set(historyProp.signal, historySigVal, false); // update Vega | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| } | ||
| }); | ||
| batchGroupBy.end(); | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| } | ||
| } catch (e) { | ||
| console.error('Unable to bind primitive'); | ||
| console.error(e); | ||
| } | ||
|
|
||
| this.props.stopDragging(); | ||
|
NanaKwame marked this conversation as resolved.
|
||
| sg.set(MODE, 'handles'); | ||
| sg.set(CELL, {}); | ||
|
|
||
| ctrl.update(); // Apply changes | ||
|
|
||
| } | ||
|
|
||
| private historyToSpec(preview: HistoryRecord): Spec { | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| let historySpec = ctrl.export(false, this.props.history); | ||
| if (historySpec.marks) { | ||
| historySpec = cleanSpecForPreview(historySpec, this.width, this.height, null, parseInt(this.props.id), true); | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| return historySpec; | ||
| } | ||
|
|
||
| private view; | ||
|
|
||
|
|
||
| public componentDidMount() { | ||
| const spec = this.historyToSpec(this.props.history); | ||
| this.view = new View(parse(spec), { | ||
| renderer: 'svg', // renderer (canvas or svg) | ||
| container: `#history-test-${this.props.id}` // parent DOM container | ||
| }); | ||
| this.view.width(this.width); | ||
| // this.view.signal("width", this.width); | ||
| this.view.height(this.height); | ||
| // this.view.signal("height", this.height); | ||
| this.view.runAsync(); | ||
| } | ||
|
|
||
| public render() { | ||
|
|
||
| return ( | ||
| <div id={`history-test-${this.props.id}`} | ||
| className={"history-preview"} | ||
| draggable={true} | ||
| key={this.props.id} | ||
| onClick={() => this.handleClick(parseInt(this.props.id))} | ||
| onDragStart={() => this.handleDragStart(parseInt(this.props.id))} | ||
| onDragEnd={this.handleDragEnd}></div> | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export const HistoryItem = connect( | ||
| null, | ||
| mapDispatchToProps | ||
| )(HistoryItemInspector); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import {Map} from 'immutable'; | ||
| import * as React from 'react'; | ||
| import {connect} from 'react-redux'; | ||
| import {updateHistoryProperty} from '../../actions/historyActions'; | ||
| import {State} from '../../store'; | ||
| import {HistoryItem} from './HistoryItem'; | ||
| import {MarkRecord} from '../../store/factory/Mark'; | ||
|
|
||
| const getIn = require('../../util/immutable-utils').getIn; | ||
|
|
||
| interface OwnProps { | ||
| } | ||
| interface StateProps { | ||
| history: any[]; | ||
| groupNames: string[]; | ||
| } | ||
|
|
||
| interface DispatchProps { | ||
| updateHistoryProperty: (payload: {property: string, value: any}, id: number) => void; | ||
| } | ||
|
|
||
| function mapState(state: State): StateProps { | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| const marks: Map<string, MarkRecord> = state.getIn(['vis', 'present', 'marks']); | ||
| const groupNames = marks.filter((mark: MarkRecord) => { | ||
| return mark.type === 'group'; | ||
| }).map((v) => { | ||
| return v.name.replace(" ", "_"); | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| }).toList().toJSON(); | ||
| let history = [...getIn(state, 'vis').past]; | ||
| history.push(getIn(state, 'vis').present); | ||
| return { | ||
| history, | ||
| groupNames: groupNames | ||
| }; | ||
| } | ||
|
|
||
| const mapDispatch: DispatchProps = { | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| updateHistoryProperty | ||
| }; | ||
|
|
||
| class BaseHistoryList extends React.Component<OwnProps & StateProps & DispatchProps> { | ||
| public render() { | ||
|
|
||
| return ( | ||
| <div id='history-list' > | ||
| {this.props.history.map( | ||
| (item, idx) => { | ||
| return <HistoryItem id={idx+''} key={idx+''} history={item} groupNames={this.props.groupNames} /> | ||
|
NanaKwame marked this conversation as resolved.
Outdated
|
||
| } | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const HistoryList = connect(mapState, mapDispatch)(BaseHistoryList); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.