Skip to content

Commit

Permalink
Add mainspec prop to read mark from main view
Browse files Browse the repository at this point in the history
Remove ../node_modules prefix


asdf
  • Loading branch information
ssharif6 committed Aug 8, 2018
1 parent 7e7f3d4 commit 5da835b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/components/encoding-pane/encoding-shelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {ConnectDropTarget, DropTarget, DropTargetCollector, DropTargetSpec} from
import * as TetherComponent from 'react-tether';
import {SHAPE} from 'vega-lite/build/src/channel';
import {POINT, TEXT} from 'vega-lite/build/src/mark';
import {TopLevelFacetedUnitSpec} from 'vega-lite/build/src/spec';
import {contains} from 'vega-lite/build/src/util';
import {ActionHandler} from '../../actions/index';
import {
Expand Down Expand Up @@ -46,6 +47,8 @@ export interface EncodingShelfPropsBase extends ActionHandler<SpecEncodingAction
schema: Schema;

mark: ShelfMark;

mainSpec: TopLevelFacetedUnitSpec;
}

interface EncodingShelfProps extends EncodingShelfPropsBase, EncodingShelfDropTargetProps {};
Expand Down Expand Up @@ -84,7 +87,7 @@ class EncodingShelfBase extends React.PureComponent<
}

public render() {
const {id, connectDropTarget, fieldDef, valueDef, handleAction, mark} = this.props;
const {id, connectDropTarget, fieldDef, mainSpec, valueDef, handleAction, mark} = this.props;

const isWildcardShelf = isWildcard(id.channel);
return connectDropTarget(
Expand All @@ -103,6 +106,7 @@ class EncodingShelfBase extends React.PureComponent<
valueDef={valueDef}
handleAction={handleAction}
mark={mark}
mainSpec={mainSpec}
/> :
<FieldCustomizer
shelfId={id}
Expand Down
14 changes: 10 additions & 4 deletions src/components/encoding-pane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as CSSModules from 'react-css-modules';
import {connect} from 'react-redux';
import {Channel} from 'vega-lite/build/src/channel';
import {FieldOneOfPredicate, FieldRangePredicate} from 'vega-lite/build/src/predicate';
import {TopLevelFacetedUnitSpec} from 'vega-lite/build/src/spec';
import {FilterAction} from '../../actions';
import {ActionHandler} from '../../actions/index';
import {createDispatchHandler} from '../../actions/redux-action';
Expand All @@ -13,7 +14,7 @@ import {ShelfAction, SPEC_CLEAR} from '../../actions/shelf';
import {ShelfUnitSpec, State} from '../../models';
import {VoyagerConfig} from '../../models/config';
import {isShelfFieldDef, isShelfValueDef, ShelfFieldDef} from '../../models/shelf';
import {selectConfig, selectDataset, selectShelfPreview} from '../../selectors';
import {selectConfig, selectDataset, selectMainSpec, selectShelfPreview} from '../../selectors';
import {selectSchemaFieldDefs} from '../../selectors/index';
import {selectFilters, selectShelfSpec} from '../../selectors/shelf';
import {FilterPane} from '../filter-pane';
Expand All @@ -34,6 +35,8 @@ interface EncodingPanelProps extends ActionHandler<ShelfAction | ResultAsyncActi
fieldDefs: ShelfFieldDef[];

config: VoyagerConfig;

mainSpec: TopLevelFacetedUnitSpec;
}

class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
Expand Down Expand Up @@ -108,7 +111,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
private encodingShelf(channel: Channel) {
// This one can't be wildcard, thus we use VL's Channel, not our ShelfChannel

const {handleAction, spec, specPreview, schema} = this.props;
const {handleAction, mainSpec, spec, specPreview, schema} = this.props;
const {encoding} = specPreview || spec;
const {mark} = specPreview || spec;
const encodingChannel = encoding[channel];
Expand All @@ -121,6 +124,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
handleAction={handleAction}
valueDef={isShelfValueDef(encodingChannel) ? encodingChannel : undefined}
mark={mark}
mainSpec={mainSpec}
/>
);
}
Expand All @@ -135,7 +139,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
}

private wildcardShelf(index: number) {
const {handleAction, spec, specPreview, schema} = this.props;
const {handleAction, spec, specPreview, schema, mainSpec} = this.props;
const {anyEncodings} = specPreview || spec;
const {mark} = specPreview || spec;
const id = {
Expand All @@ -152,6 +156,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
handleAction={handleAction}
valueDef={undefined} // don't support constant value for wildcard shelf
mark = {mark}
mainSpec={mainSpec}
/>
);
}
Expand Down Expand Up @@ -181,7 +186,8 @@ export const EncodingPane = connect(
schema: selectDataset(state).schema,
fieldDefs: selectSchemaFieldDefs(state),
specPreview: selectShelfPreview(state).spec,
config: selectConfig(state)
config: selectConfig(state),
mainSpec: selectMainSpec(state)
};
},
createDispatchHandler<ShelfAction>()
Expand Down
15 changes: 7 additions & 8 deletions src/components/encoding-pane/value-customizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as CSSModules from 'react-css-modules';
import Form from 'react-jsonschema-form';
import {debounce} from 'throttle-debounce';
import {Channel} from 'vega-lite/build/src/channel';
import {TopLevelFacetedUnitSpec} from 'vega-lite/build/src/spec';
import {ActionHandler, SPEC_VALUE_CHANGE, SpecEncodingAction} from "../../actions";
import {ShelfId, ShelfMark, ShelfValueDef} from "../../models";
import * as styles from './value-customizer.scss';
Expand All @@ -12,6 +13,7 @@ export interface ValueCustomizerProps extends ActionHandler<SpecEncodingAction>
shelfId: ShelfId;
valueDef: ShelfValueDef;
mark: ShelfMark;
mainSpec: TopLevelFacetedUnitSpec;
}

export class ValueCustomizerBase extends React.PureComponent<ValueCustomizerProps, {}> {
Expand All @@ -24,7 +26,7 @@ export class ValueCustomizerBase extends React.PureComponent<ValueCustomizerProp
}

public render() {
const {shelfId, valueDef, mark} = this.props;
const {shelfId, valueDef} = this.props;
const formData = generateValueDefFormData(shelfId, valueDef) || {};
const {schema, uiSchema} = generateValueEditorSchema(shelfId.channel as Channel);
return (
Expand All @@ -35,20 +37,17 @@ export class ValueCustomizerBase extends React.PureComponent<ValueCustomizerProp
formData={formData}
onChange={this.changeValue}
>
{mark !== '?' &&
<a onClick={this.resetValue}>Reset</a>
}
<a onClick={this.resetValue}>Reset</a>
<button type="submit" style={{display: 'none'}}>Submit</button>
</Form>
</div>
);
}

protected resetValue(e: any) {
// read default values of mark from VL
// Then call SPEC_VALUE_CHANGE with the corresponding valueDef
const {shelfId, handleAction, mark} = this.props;
const value = getDefaultsForChannel(shelfId.channel as Channel, mark);
const {shelfId, handleAction, mark, mainSpec} = this.props;
// If mark is set to auto, read from main spec
const value = getDefaultsForChannel(shelfId.channel as Channel, mark === '?' ? mainSpec.mark as ShelfMark : mark);
const valueDef: ShelfValueDef = {value};

handleAction({
Expand Down
2 changes: 1 addition & 1 deletion src/selectors/shelf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {FieldOneOfPredicate, FieldRangePredicate} from 'vega-lite/build/src/pred
import {GenericState, State, UndoableStateBase} from '../models/index';
// tslint:enable:no-unused-variable

import {isAutoCountQuery, isFieldQuery} from 'compassql/build/src/query/encoding';
import {Query} from 'compassql/build/src/query/query';
import {SpecQuery} from 'compassql/build/src/query/spec';
import {createSelector} from 'reselect';
import {isAutoCountQuery, isFieldQuery} from '../../node_modules/compassql/build/src/query/encoding';
import {PlotTabState} from '../models';
import {ShelfFilter} from '../models/shelf/filter';
import {getDefaultGroupBy, Shelf, ShelfGroupBy, toQuery} from '../models/shelf/index';
Expand Down

0 comments on commit 5da835b

Please sign in to comment.