Skip to content

Commit

Permalink
Merge branch 'master' into djbarnwal-db/legendInteractive
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Nov 18, 2019
2 parents d002977 + 50429d3 commit 76bdf54
Show file tree
Hide file tree
Showing 68 changed files with 178 additions and 172 deletions.
2 changes: 1 addition & 1 deletion site/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.12.2)
multipart-post (2.1.1)
nokogiri (1.10.4)
nokogiri (1.10.5)
mini_portile2 (~> 2.4.0)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
Expand Down
10 changes: 5 additions & 5 deletions src/channeldef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export function vgField(
const {bin, aggregate, timeUnit} = fieldDef;
if (isBinning(bin)) {
fn = binToString(bin);
suffix = (opt.binSuffix || '') + (opt.suffix || '');
suffix = (opt.binSuffix ?? '') + (opt.suffix ?? '');
} else if (aggregate) {
if (isArgmaxDef(aggregate)) {
argAccessor = `.${field}`;
Expand All @@ -601,7 +601,7 @@ export function vgField(
}
} else if (timeUnit) {
fn = String(timeUnit);
suffix = ((!contains(['range', 'mid'], opt.binSuffix) && opt.binSuffix) || '') + (opt.suffix || '');
suffix = ((!contains(['range', 'mid'], opt.binSuffix) && opt.binSuffix) || '') + (opt.suffix ?? '');
}
}
}
Expand Down Expand Up @@ -717,14 +717,14 @@ export function title(
config: Config,
{allowDisabling, includeDefault = true}: {allowDisabling: boolean; includeDefault?: boolean}
) {
const guide = getGuide(fieldDef) || {};
const guide = getGuide(fieldDef) ?? {};
const guideTitle = guide.title;
const def = includeDefault ? defaultTitle(fieldDef, config) : undefined;

if (allowDisabling) {
return getFirstDefined(guideTitle, fieldDef.title, def);
} else {
return guideTitle || fieldDef.title || def;
return guideTitle ?? fieldDef.title ?? def;
}
}

Expand All @@ -747,7 +747,7 @@ export function format(fieldDef: TypedFieldDef<string>) {
if (isTextFieldDef(fieldDef) && fieldDef.format) {
return fieldDef.format;
} else {
const guide = getGuide(fieldDef) || {};
const guide = getGuide(fieldDef) ?? {};
return guide.format;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/compile/axis/assemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function setAxisEncode(
vgProp: VgEncodeChannel,
vgRef: VgValueRef | readonly VgValueRef[]
) {
axis.encode = axis.encode || {};
axis.encode[part] = axis.encode[part] || {};
axis.encode[part].update = axis.encode[part].update || {};
axis.encode = axis.encode ?? {};
axis.encode[part] = axis.encode[part] ?? {};
axis.encode[part].update = axis.encode[part].update ?? {};
// TODO: remove as any after https://github.com/prisma/nexus-prisma/issues/291
(axis.encode[part].update[vgProp] as any) = vgRef;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/axis/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {UnitModel} from '../unit';

export function labels(model: UnitModel, channel: PositionScaleChannel, specifiedLabelsSpec: any) {
const fieldDef =
model.fieldDef(channel) ||
model.fieldDef(channel) ??
(channel === 'x' ? model.fieldDef('x2') : channel === 'y' ? model.fieldDef('y2') : undefined);
const axis = model.axis(channel);
const config = model.config;
Expand Down
6 changes: 3 additions & 3 deletions src/compile/axis/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function parseLayerAxes(model: LayerModel) {

if (resolve.axis[channel] === 'independent') {
// If axes are independent, concat the axisComponent array.
axes[channel] = (axes[channel] || []).concat(child.component.axes[channel]);
axes[channel] = (axes[channel] ?? []).concat(child.component.axes[channel]);

// Automatically adjust orient
for (const axisComponent of child.component.axes[channel]) {
Expand Down Expand Up @@ -250,14 +250,14 @@ function parseAxis(channel: PositionScaleChannel, model: UnitModel): AxisCompone
});

// 2) Add guide encode definition groups
const axisEncoding = axis.encoding || {};
const axisEncoding = axis.encoding ?? {};
const axisEncode = AXIS_PARTS.reduce((e: VgAxisEncode, part) => {
if (!axisComponent.hasAxisPart(part)) {
// No need to create encode for a disabled part.
return e;
}

const axisEncodingPart = guideEncodeEntry(axisEncoding[part] || {}, model);
const axisEncodingPart = guideEncodeEntry(axisEncoding[part] ?? {}, model);

const value = part === 'labels' ? encode.labels(model, channel, axisEncodingPart) : axisEncodingPart;

Expand Down
8 changes: 4 additions & 4 deletions src/compile/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function applyMarkConfig(e: VgEncodeEntry, model: UnitModel, propsList: (
}

export function getStyles(mark: MarkDef): string[] {
return [].concat(mark.type, mark.style || []);
return [].concat(mark.type, mark.style ?? []);
}

export function getMarkPropOrConfig<P extends keyof MarkConfig>(channel: P, mark: MarkDef, config: Config) {
Expand Down Expand Up @@ -142,7 +142,7 @@ function formatExpr(field: string, format: string) {
}

export function numberFormatExpr(field: string, specifiedFormat: string, config: Config) {
return formatExpr(field, specifiedFormat || config.numberFormat);
return formatExpr(field, specifiedFormat ?? config.numberFormat);
}

export function binFormatExpression(startField: string, endField: string, format: string, config: Config) {
Expand All @@ -167,7 +167,7 @@ export function timeFormatExpression(
): string {
if (!timeUnit || format) {
// If there is not time unit, or if user explicitly specify format for axis/legend/text.
format = format || rawTimeFormat; // only use provided timeFormat if there is no timeUnit.
format = format ?? rawTimeFormat; // only use provided timeFormat if there is no timeUnit.

if (format || alwaysReturn) {
return `${isUTCScale ? 'utc' : 'time'}Format(${field}, '${format}')`;
Expand All @@ -189,7 +189,7 @@ export function sortParams(
return array(orderDef).reduce(
(s, orderChannelDef) => {
s.field.push(vgField(orderChannelDef, fieldRefOption));
s.order.push(orderChannelDef.sort || 'ascending');
s.order.push(orderChannelDef.sort ?? 'ascending');
return s;
},
{field: [], order: []}
Expand Down
16 changes: 8 additions & 8 deletions src/compile/data/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function mergeMeasures(parentMeasures: Measures, childMeasures: Measures) {
for (const op of keys(ops)) {
if (field in parentMeasures) {
// add operator to existing measure field
parentMeasures[field][op] = new Set([...(parentMeasures[field][op] || []), ...ops[op]]);
parentMeasures[field][op] = new Set([...(parentMeasures[field][op] ?? []), ...ops[op]]);
} else {
parentMeasures[field] = {[op]: ops[op]};
}
Expand Down Expand Up @@ -93,22 +93,22 @@ export class AggregateNode extends DataFlowNode {
const {aggregate, field} = fieldDef;
if (aggregate) {
if (aggregate === 'count') {
meas['*'] = meas['*'] || {};
meas['*'] = meas['*'] ?? {};
meas['*']['count'] = new Set([vgField(fieldDef, {forAs: true})]);
} else {
if (isArgminDef(aggregate) || isArgmaxDef(aggregate)) {
const op = isArgminDef(aggregate) ? 'argmin' : 'argmax';
const argField = aggregate[op];
meas[argField] = meas[argField] || {};
meas[argField] = meas[argField] ?? {};
meas[argField][op] = new Set([vgField({op, field: argField}, {forAs: true})]);
} else {
meas[field] = meas[field] || {};
meas[field] = meas[field] ?? {};
meas[field][aggregate] = new Set([vgField(fieldDef, {forAs: true})]);
}

// For scale channel with domain === 'unaggregated', add min/max so we can use their union as unaggregated domain
if (isScaleChannel(channel) && model.scaleDomain(channel) === 'unaggregated') {
meas[field] = meas[field] || {};
meas[field] = meas[field] ?? {};
meas[field]['min'] = new Set([vgField({field, aggregate: 'min'}, {forAs: true})]);
meas[field]['max'] = new Set([vgField({field, aggregate: 'max'}, {forAs: true})]);
}
Expand All @@ -133,16 +133,16 @@ export class AggregateNode extends DataFlowNode {
const {op, field, as} = s;
if (op) {
if (op === 'count') {
meas['*'] = meas['*'] || {};
meas['*'] = meas['*'] ?? {};
meas['*']['count'] = new Set([as ? as : vgField(s, {forAs: true})]);
} else {
meas[field] = meas[field] || {};
meas[field] = meas[field] ?? {};
meas[field][op] = new Set([as ? as : vgField(s, {forAs: true})]);
}
}
}

for (const s of t.groupby || []) {
for (const s of t.groupby ?? []) {
dims.add(s);
}

Expand Down
6 changes: 3 additions & 3 deletions src/compile/data/assemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function makeWalkTree(data: VgData[]) {
if (node.parent instanceof SourceNode && !dataSource.source) {
// If node's parent is a root source and the data source does not refer to another data source, use normal format parse
dataSource.format = {
...(dataSource.format || {}),
...(dataSource.format ?? {}),
parse: node.assembleFormatParse()
};

Expand Down Expand Up @@ -245,14 +245,14 @@ export function assembleRootData(dataComponent: DataComponent, datasets: Dict<In
// move sources without transforms (the ones that are potentially used in lookups) to the beginning
let whereTo = 0;
for (const [i, d] of data.entries()) {
if ((d.transform || []).length === 0 && !d.source) {
if ((d.transform ?? []).length === 0 && !d.source) {
data.splice(whereTo++, 0, data.splice(i, 1)[0]);
}
}

// now fix the from references in lookup transforms
for (const d of data) {
for (const t of d.transform || []) {
for (const t of d.transform ?? []) {
if (t.type === 'lookup') {
t.from = dataComponent.outputNodes[t.from].getSource();
}
Expand Down
4 changes: 2 additions & 2 deletions src/compile/data/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function rangeFormula(model: ModelWithField, fieldDef: TypedFieldDef<string>, ch
if (binRequiresRange(fieldDef, channel)) {
// read format from axis or legend, if there is no format then use config.numberFormat

const guide = isUnitModel(model) ? model.axis(channel) || model.legend(channel) || {} : {};
const guide = isUnitModel(model) ? model.axis(channel) ?? model.legend(channel) ?? {} : {};

const startField = vgField(fieldDef, {expr: 'datum'});
const endField = vgField(fieldDef, {expr: 'datum', binSuffix: 'end'});
Expand All @@ -40,7 +40,7 @@ function getSignalsFromModel(model: Model, key: string) {
}

export function getBinSignalName(model: Model, field: string, bin: boolean | BinParams) {
const normalizedBin = normalizeBin(bin, undefined) || {};
const normalizedBin = normalizeBin(bin, undefined) ?? {};
const key = binKey(normalizedBin, field);
return model.getName(`${key}_bins`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ export class CalculateNode extends DataFlowNode {
}

export function sortArrayIndexField(fieldDef: TypedFieldDef<string>, channel: SingleDefChannel, opt?: FieldRefOption) {
return vgField(fieldDef, {prefix: channel, suffix: 'sort_index', ...(opt || {})});
return vgField(fieldDef, {prefix: channel, suffix: 'sort_index', ...(opt ?? {})});
}
4 changes: 2 additions & 2 deletions src/compile/data/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function draw(roots: readonly DataFlowNode[]) {
out.push(`<i>${node.debugName}</i>`);
} else if (node instanceof SourceNode) {
if (node.data.name || node.data.url) {
out.push(`<i>${node.data.name || node.data.url}</i>`);
out.push(`<i>${node.data.name ?? node.data.url}</i>`);
}
}

Expand All @@ -68,7 +68,7 @@ export function draw(roots: readonly DataFlowNode[]) {
label: getLabel(node),
hash:
node instanceof SourceNode
? node.data.url || node.data.name || node.debugName
? node.data.url ?? node.data.name ?? node.debugName
: String(node.hash()).replace(/"/g, '')
};

Expand Down
6 changes: 3 additions & 3 deletions src/compile/data/density.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class DensityTransformNode extends DataFlowNode {
constructor(parent: DataFlowNode, private transform: DensityTransform) {
super(parent);
this.transform = duplicate(transform); // duplicate to prevent side effects
const specifiedAs = this.transform.as || [undefined, undefined];
this.transform.as = [specifiedAs[0] || 'value', specifiedAs[1] || 'density'];
const specifiedAs = this.transform.as ?? [undefined, undefined];
this.transform.as = [specifiedAs[0] ?? 'value', specifiedAs[1] ?? 'density'];
}

public dependentFields() {
return new Set([this.transform.density, ...(this.transform.groupby || [])]);
return new Set([this.transform.density, ...(this.transform.groupby ?? [])]);
}

public producedFields() {
Expand Down
8 changes: 4 additions & 4 deletions src/compile/data/facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class FacetNode extends DataFlowNode {
return {
name: this[channel].name,
// Use data from the crossed one if it exist
source: crossedDataName || this.data,
source: crossedDataName ?? this.data,
transform: [
{
type: 'aggregate',
Expand All @@ -213,7 +213,7 @@ export class FacetNode extends DataFlowNode {
const hasSharedAxis: {row?: true; column?: true} = {};
for (const headerChannel of HEADER_CHANNELS) {
for (const headerType of HEADER_TYPES) {
const headers = (layoutHeaders[headerChannel] && layoutHeaders[headerChannel][headerType]) || [];
const headers = (layoutHeaders[headerChannel] && layoutHeaders[headerChannel][headerType]) ?? [];
for (const header of headers) {
if (header.axes?.length > 0) {
hasSharedAxis[headerChannel] = true;
Expand Down Expand Up @@ -268,8 +268,8 @@ export class FacetNode extends DataFlowNode {
crossedDataName = `cross_${this.column.name}_${this.row.name}`;

const fields: string[] = [].concat(
childIndependentFieldsWithStep.x || [],
childIndependentFieldsWithStep.y || []
childIndependentFieldsWithStep.x ?? [],
childIndependentFieldsWithStep.y ?? []
);
const ops = fields.map((): AggregateOp => 'distinct');

Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class FlattenTransformNode extends DataFlowNode {
super(parent);
this.transform = duplicate(transform); // duplicate to prevent side effects
const {flatten, as = []} = this.transform;
this.transform.as = flatten.map((f, i) => as[i] || f);
this.transform.as = flatten.map((f, i) => as[i] ?? f);
}

public dependentFields() {
Expand Down
4 changes: 2 additions & 2 deletions src/compile/data/fold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class FoldTransformNode extends DataFlowNode {
constructor(parent: DataFlowNode, private transform: FoldTransform) {
super(parent);
this.transform = duplicate(transform); // duplicate to prevent side effects
const specifiedAs = this.transform.as || [undefined, undefined];
this.transform.as = [specifiedAs[0] || 'key', specifiedAs[1] || 'value'];
const specifiedAs = this.transform.as ?? [undefined, undefined];
this.transform.as = [specifiedAs[0] ?? 'key', specifiedAs[1] ?? 'value'];
}

public dependentFields() {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/formatparse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function getImplicitFromFilterTransform(transform: FilterTransform) {
} else if (isFieldRangePredicate(filter)) {
val = filter.range[0];
} else if (isFieldOneOfPredicate(filter)) {
val = (filter.oneOf || filter['in'])[0];
val = (filter.oneOf ?? filter['in'])[0];
} // else -- for filter expression, we can't infer anything
if (val) {
if (isDateTime(val)) {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GeoJSONNode extends DataFlowNode {
}

public dependentFields() {
const fields = (this.fields || []).filter(isString) as string[];
const fields = (this.fields ?? []).filter(isString) as string[];
return new Set([...(this.geojson ? [this.geojson] : []), ...fields]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/impute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ImputeNode extends DataFlowNode {
}

public dependentFields() {
return new Set([this.transform.impute, this.transform.key, ...(this.transform.groupby || [])]);
return new Set([this.transform.impute, this.transform.key, ...(this.transform.groupby ?? [])]);
}

public producedFields() {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/joinaggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class JoinAggregateTransformNode extends DataFlowNode {
}

private getDefaultName(joinAggregateFieldDef: JoinAggregateFieldDef): string {
return joinAggregateFieldDef.as || vgField(joinAggregateFieldDef);
return joinAggregateFieldDef.as ?? vgField(joinAggregateFieldDef);
}

public hash() {
Expand Down
6 changes: 3 additions & 3 deletions src/compile/data/loess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class LoessTransformNode extends DataFlowNode {
constructor(parent: DataFlowNode, private transform: LoessTransform) {
super(parent);
this.transform = duplicate(transform); // duplicate to prevent side effects
const specifiedAs = this.transform.as || [undefined, undefined];
this.transform.as = [specifiedAs[0] || transform.on, specifiedAs[1] || transform.loess];
const specifiedAs = this.transform.as ?? [undefined, undefined];
this.transform.as = [specifiedAs[0] ?? transform.on, specifiedAs[1] ?? transform.loess];
}

public dependentFields() {
return new Set([this.transform.loess, this.transform.on, ...(this.transform.groupby || [])]);
return new Set([this.transform.loess, this.transform.on, ...(this.transform.groupby ?? [])]);
}

public producedFields() {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class LookupNode extends DataFlowNode {
model.component.data.outputNodes[fromOutputName] = fromOutputNode;
} else if (isSelectionLookup(transform)) {
const selName = transform.from.selection;
transform.as = transform.as || selName;
transform.as = transform.as ?? selName;
fromOutputNode = model.getSelectionComponent(varName(selName), selName).materialized;
if (!fromOutputNode) {
throw new Error(log.message.noSameUnitLookup(selName));
Expand Down
Loading

0 comments on commit 76bdf54

Please sign in to comment.