Skip to content

Commit 6875adc

Browse files
committed
Add mainspec prop to read mark from main view
Remove ../node_modules prefix
1 parent 7e7f3d4 commit 6875adc

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/components/encoding-pane/encoding-shelf.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as TetherComponent from 'react-tether';
77
import {SHAPE} from 'vega-lite/build/src/channel';
88
import {POINT, TEXT} from 'vega-lite/build/src/mark';
99
import {contains} from 'vega-lite/build/src/util';
10+
import {TopLevelFacetedUnitSpec} from '../../../node_modules/vega-lite/build/src/spec';
1011
import {ActionHandler} from '../../actions/index';
1112
import {
1213
SPEC_FIELD_ADD, SPEC_FIELD_MOVE, SPEC_FIELD_REMOVE, SPEC_FUNCTION_ADD_WILDCARD,
@@ -46,6 +47,8 @@ export interface EncodingShelfPropsBase extends ActionHandler<SpecEncodingAction
4647
schema: Schema;
4748

4849
mark: ShelfMark;
50+
51+
mainSpec: TopLevelFacetedUnitSpec;
4952
}
5053

5154
interface EncodingShelfProps extends EncodingShelfPropsBase, EncodingShelfDropTargetProps {};
@@ -84,7 +87,7 @@ class EncodingShelfBase extends React.PureComponent<
8487
}
8588

8689
public render() {
87-
const {id, connectDropTarget, fieldDef, valueDef, handleAction, mark} = this.props;
90+
const {id, connectDropTarget, fieldDef, mainSpec, valueDef, handleAction, mark} = this.props;
8891

8992
const isWildcardShelf = isWildcard(id.channel);
9093
return connectDropTarget(
@@ -103,6 +106,7 @@ class EncodingShelfBase extends React.PureComponent<
103106
valueDef={valueDef}
104107
handleAction={handleAction}
105108
mark={mark}
109+
mainSpec={mainSpec}
106110
/> :
107111
<FieldCustomizer
108112
shelfId={id}

src/components/encoding-pane/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as CSSModules from 'react-css-modules';
55
import {connect} from 'react-redux';
66
import {Channel} from 'vega-lite/build/src/channel';
77
import {FieldOneOfPredicate, FieldRangePredicate} from 'vega-lite/build/src/predicate';
8+
import {TopLevelFacetedUnitSpec} from 'vega-lite/build/src/spec';
89
import {FilterAction} from '../../actions';
910
import {ActionHandler} from '../../actions/index';
1011
import {createDispatchHandler} from '../../actions/redux-action';
@@ -13,7 +14,7 @@ import {ShelfAction, SPEC_CLEAR} from '../../actions/shelf';
1314
import {ShelfUnitSpec, State} from '../../models';
1415
import {VoyagerConfig} from '../../models/config';
1516
import {isShelfFieldDef, isShelfValueDef, ShelfFieldDef} from '../../models/shelf';
16-
import {selectConfig, selectDataset, selectShelfPreview} from '../../selectors';
17+
import {selectConfig, selectDataset, selectMainSpec, selectShelfPreview} from '../../selectors';
1718
import {selectSchemaFieldDefs} from '../../selectors/index';
1819
import {selectFilters, selectShelfSpec} from '../../selectors/shelf';
1920
import {FilterPane} from '../filter-pane';
@@ -34,6 +35,8 @@ interface EncodingPanelProps extends ActionHandler<ShelfAction | ResultAsyncActi
3435
fieldDefs: ShelfFieldDef[];
3536

3637
config: VoyagerConfig;
38+
39+
mainSpec: TopLevelFacetedUnitSpec;
3740
}
3841

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

111-
const {handleAction, spec, specPreview, schema} = this.props;
114+
const {handleAction, mainSpec, spec, specPreview, schema} = this.props;
112115
const {encoding} = specPreview || spec;
113116
const {mark} = specPreview || spec;
114117
const encodingChannel = encoding[channel];
@@ -121,6 +124,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
121124
handleAction={handleAction}
122125
valueDef={isShelfValueDef(encodingChannel) ? encodingChannel : undefined}
123126
mark={mark}
127+
mainSpec={mainSpec}
124128
/>
125129
);
126130
}
@@ -135,7 +139,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
135139
}
136140

137141
private wildcardShelf(index: number) {
138-
const {handleAction, spec, specPreview, schema} = this.props;
142+
const {handleAction, spec, specPreview, schema, mainSpec} = this.props;
139143
const {anyEncodings} = specPreview || spec;
140144
const {mark} = specPreview || spec;
141145
const id = {
@@ -152,6 +156,7 @@ class EncodingPanelBase extends React.PureComponent<EncodingPanelProps, {}> {
152156
handleAction={handleAction}
153157
valueDef={undefined} // don't support constant value for wildcard shelf
154158
mark = {mark}
159+
mainSpec={mainSpec}
155160
/>
156161
);
157162
}
@@ -181,7 +186,8 @@ export const EncodingPane = connect(
181186
schema: selectDataset(state).schema,
182187
fieldDefs: selectSchemaFieldDefs(state),
183188
specPreview: selectShelfPreview(state).spec,
184-
config: selectConfig(state)
189+
config: selectConfig(state),
190+
mainSpec: selectMainSpec(state)
185191
};
186192
},
187193
createDispatchHandler<ShelfAction>()

src/components/encoding-pane/value-customizer.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as CSSModules from 'react-css-modules';
33
import Form from 'react-jsonschema-form';
44
import {debounce} from 'throttle-debounce';
55
import {Channel} from 'vega-lite/build/src/channel';
6+
import {TopLevelFacetedUnitSpec} from 'vega-lite/build/src/spec';
67
import {ActionHandler, SPEC_VALUE_CHANGE, SpecEncodingAction} from "../../actions";
78
import {ShelfId, ShelfMark, ShelfValueDef} from "../../models";
89
import * as styles from './value-customizer.scss';
@@ -12,6 +13,7 @@ export interface ValueCustomizerProps extends ActionHandler<SpecEncodingAction>
1213
shelfId: ShelfId;
1314
valueDef: ShelfValueDef;
1415
mark: ShelfMark;
16+
mainSpec: TopLevelFacetedUnitSpec;
1517
}
1618

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

2628
public render() {
27-
const {shelfId, valueDef, mark} = this.props;
29+
const {shelfId, valueDef} = this.props;
2830
const formData = generateValueDefFormData(shelfId, valueDef) || {};
2931
const {schema, uiSchema} = generateValueEditorSchema(shelfId.channel as Channel);
3032
return (
@@ -35,20 +37,17 @@ export class ValueCustomizerBase extends React.PureComponent<ValueCustomizerProp
3537
formData={formData}
3638
onChange={this.changeValue}
3739
>
38-
{mark !== '?' &&
39-
<a onClick={this.resetValue}>Reset</a>
40-
}
40+
<a onClick={this.resetValue}>Reset</a>
4141
<button type="submit" style={{display: 'none'}}>Submit</button>
4242
</Form>
4343
</div>
4444
);
4545
}
4646

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

5453
handleAction({

src/selectors/shelf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {FieldOneOfPredicate, FieldRangePredicate} from 'vega-lite/build/src/pred
44
import {GenericState, State, UndoableStateBase} from '../models/index';
55
// tslint:enable:no-unused-variable
66

7+
import {isAutoCountQuery, isFieldQuery} from 'compassql/build/src/query/encoding';
78
import {Query} from 'compassql/build/src/query/query';
89
import {SpecQuery} from 'compassql/build/src/query/spec';
910
import {createSelector} from 'reselect';
10-
import {isAutoCountQuery, isFieldQuery} from '../../node_modules/compassql/build/src/query/encoding';
1111
import {PlotTabState} from '../models';
1212
import {ShelfFilter} from '../models/shelf/filter';
1313
import {getDefaultGroupBy, Shelf, ShelfGroupBy, toQuery} from '../models/shelf/index';

0 commit comments

Comments
 (0)