Skip to content
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

[WIP] Boxplot #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/model.ts
Expand Up @@ -4,7 +4,7 @@ import {Encoding} from 'vega-lite/build/src/encoding';
import {FieldDef} from 'vega-lite/build/src/fielddef';
import {Mark} from 'vega-lite/build/src/mark';
import {Type} from 'vega-lite/build/src/type';
import {FacetedUnitSpec} from 'vega-lite/build/src/spec';
import {FacetSpec} from 'vega-lite/build/src/spec';
import {StackProperties} from 'vega-lite/build/src/stack';

import {QueryConfig} from './config';
Expand Down Expand Up @@ -263,11 +263,11 @@ export class SpecQueryModel {
return specShorthand(this._spec);
}

private _encoding(): Encoding {
let encoding: Encoding = {};
private _encoding(): Encoding<string> {
let encoding: Encoding<string> = {};

for (const encQ of this._spec.encodings) {
let fieldDef: FieldDef = {};
let fieldDef: FieldDef<string> = {};

// For count field that is automatically added, convert to correct vega-lite fieldDef
if (isFieldQuery(encQ) && encQ.autoCount === true) {
Expand Down Expand Up @@ -313,7 +313,7 @@ export class SpecQueryModel {
* Convert a query to a Vega-Lite spec if it is completed.
* @return a Vega-Lite spec if completed, null otherwise.
*/
public toSpec(data?: Data): FacetedUnitSpec {
public toSpec(data?: Data): FacetSpec {
if (isWildcard(this._spec.mark)) return null;

let spec: any = {};
Expand Down
5 changes: 3 additions & 2 deletions src/query/encoding.ts
Expand Up @@ -15,6 +15,7 @@ import compileScaleType from 'vega-lite/build/src/compile/scale/type';

import {Wildcard, isWildcard, SHORT_WILDCARD, WildcardProperty} from '../wildcard';
import {AggregateOp} from 'vega-lite/build/src/aggregate';
import {CompositeAggregate} from 'vega-lite/build/src/compositemark';
import {FieldDef} from 'vega-lite/build/src/fielddef';

export type EncodingQuery = FieldQuery | ValueQuery;
Expand All @@ -40,7 +41,7 @@ export interface FieldQuery extends EncodingQueryBase {
channel: WildcardProperty<Channel>;

// FieldDef
aggregate?: WildcardProperty<AggregateOp>;
aggregate?: WildcardProperty<AggregateOp | CompositeAggregate>;
/** Internal flag for representing automatic count that are added to plots with only ordinal or binned fields. */
autoCount?: WildcardProperty<boolean>;
timeUnit?: WildcardProperty<TimeUnit>;
Expand Down Expand Up @@ -80,7 +81,7 @@ export type LegendQuery = FlatQueryWithEnableFlag<Legend>;
export function toFieldDef(fieldQ: FieldQuery,
props: (keyof FieldQuery)[] = ['aggregate', 'autoCount', 'bin', 'timeUnit', 'field', 'type']) {

return props.reduce((fieldDef: FieldDef, prop: keyof FieldQuery) => {
return props.reduce((fieldDef: FieldDef<string>, prop: keyof FieldQuery) => {
if (isWildcard(fieldQ[prop])) {
throw new Error(`Cannot convert ${JSON.stringify(fieldQ)} to fielddef: ${prop} is wildcard`);
} else if (fieldQ[prop] !== undefined) {
Expand Down
12 changes: 6 additions & 6 deletions src/query/shorthand.ts
@@ -1,9 +1,9 @@
import {AGGREGATE_OPS} from 'vega-lite/build/src/aggregate';
import {Channel, CHANNELS} from 'vega-lite/build/src/channel';
import {Formula} from 'vega-lite/build/src/transform';
import {FacetedUnitSpec} from 'vega-lite/build/src/spec';
import {FacetSpec} from 'vega-lite/build/src/spec';
import {SINGLE_TIMEUNITS, MULTI_TIMEUNITS} from 'vega-lite/build/src/timeunit';
import {Type, getFullName} from 'vega-lite/build/src/type';
import {VgFormulaTransform} from 'vega-lite/build/src/vega.schema';
import {toMap, isString} from 'datalib/src/util';

import {EncodingQuery, isFieldQuery, FieldQuery, isValueQuery} from './encoding';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const INCLUDE_ALL: PropIndex<boolean> =
.reduce((pi, prop) => pi.set(prop, true), new PropIndex<boolean>());


export function vlSpec(vlspec: FacetedUnitSpec,
export function vlSpec(vlspec: FacetSpec,
include: PropIndex<boolean> = INCLUDE_ALL,
replace: PropIndex<Replacer> = REPLACE_NONE) {
const specQ = fromSpec(vlspec);
Expand Down Expand Up @@ -152,7 +152,7 @@ export function spec(specQ: SpecQuery,
return parts.join('|');
}

export function calculate(formulaArr: Formula[]): string {
export function calculate(formulaArr: VgFormulaTransform[]): string {
return JSON.stringify(
formulaArr.reduce((m, calculateItem) => {
m[calculateItem.as] = calculateItem.expr;
Expand Down Expand Up @@ -364,11 +364,11 @@ export function parse(shorthand: string): SpecQuery {

if (splitPartKey === 'calculate') {
specQ.transform = specQ.transform || {};
let calculate: Formula[] = [];
let calculate: VgFormulaTransform[] = [];
let fieldExprMapping = JSON.parse(splitPartValue);

for (let field in fieldExprMapping) {
calculate.push({expr: fieldExprMapping[field], as: field});
calculate.push({type: 'formula', expr: fieldExprMapping[field], as: field}); // dont know if this right
}

specQ.transform.calculate = calculate;
Expand Down
4 changes: 2 additions & 2 deletions src/query/spec.ts
Expand Up @@ -10,7 +10,7 @@ import {contains, extend, keys, some} from '../util';

import {TransformQuery} from './transform';
import {EncodingQuery, isFieldQuery, isValueQuery} from './encoding';
import {FacetedUnitSpec} from 'vega-lite/build/src/spec';
import {FacetedCompositeUnitSpec} from 'vega-lite/build/src/spec';
import {toMap} from 'datalib/src/util';


Expand All @@ -34,7 +34,7 @@ export interface SpecQuery {
* @param {ExtendedUnitSpec} spec
* @returns
*/
export function fromSpec(spec: FacetedUnitSpec): SpecQuery {
export function fromSpec(spec: FacetedCompositeUnitSpec): SpecQuery { // dont know if this is right.
return extend(
spec.data ? { data: spec.data} : {},
spec.transform ? { transform: spec.transform } : {},
Expand Down
4 changes: 2 additions & 2 deletions src/query/transform.ts
@@ -1,8 +1,8 @@
import {Filter} from 'vega-lite/build/src/filter';
import {Formula} from 'vega-lite/build/src/transform';
import {VgFormulaTransform} from 'vega-lite/build/src/vega.schema';

export interface TransformQuery {
calculate?: Formula[];
calculate?: VgFormulaTransform[];
filter?: Filter | string | (Filter|string)[];
filterInvalid?: boolean;
}
2 changes: 1 addition & 1 deletion src/wildcard.ts
Expand Up @@ -252,7 +252,7 @@ export const DEFAULT_ENUM_INDEX: EnumIndex = {
mark: [Mark.POINT, Mark.BAR, Mark.LINE, Mark.AREA, Mark.TICK], // Mark.TEXT
channel: [X, Y, ROW, COLUMN, SIZE, COLOR], // TODO: TEXT

aggregate: [undefined, 'mean'],
aggregate: [undefined, 'boxplot'],
autoCount: DEFAULT_BOOLEAN_ENUM,
bin: DEFAULT_BOOLEAN_ENUM,
hasFn: DEFAULT_BOOLEAN_ENUM,
Expand Down