Skip to content

Commit

Permalink
refactor: don't interpret numbers as truth values
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Nov 13, 2019
1 parent 698fc0b commit 473eefa
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/compile/facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class FacetModel extends ModelWithField {
name,
data,
groupby,
...(cross || fields.length
...(cross || fields.length > 0
? {
aggregate: {
...(cross ? {cross} : {}),
Expand Down
2 changes: 1 addition & 1 deletion src/compile/mark/valueref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export function tooltipForEncoding(
}
}

return keyValues.length ? {signal: `{${keyValues.join(', ')}}`} : undefined;
return keyValues.length > 0 ? {signal: `{${keyValues.join(', ')}}`} : undefined;
}

export function text(
Expand Down
4 changes: 2 additions & 2 deletions src/compile/selection/assemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function assembleTopLevelSignals(model: UnitModel, signals: Signal[]) {
const name = selCmpt.name;
const store = stringValue(name + STORE);
const hasSg = signals.filter(s => s.name === name);
if (!hasSg.length) {
if (hasSg.length === 0) {
const resolve = selCmpt.resolve === 'global' ? 'union' : selCmpt.resolve;
const isMulti = selCmpt.type === 'multi' ? ', true)' : ')';
signals.push({
Expand All @@ -99,7 +99,7 @@ export function assembleTopLevelSignals(model: UnitModel, signals: Signal[]) {

if (hasSelections) {
const hasUnit = signals.filter(s => s.name === 'unit');
if (!hasUnit.length) {
if (hasUnit.length === 0) {
signals.unshift({
name: 'unit',
value: {},
Expand Down
6 changes: 3 additions & 3 deletions src/compile/selection/transforms/legends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const legendBindings: TransformCompiler = {
const sgName = `${selName}_${prefix}`;
const hasSignal = signals.filter(s => s.name === sgName);

if (!hasSignal.length) {
if (hasSignal.length === 0) {
const events = stream.merge
.map(markName(`${prefix}_symbols`))
.concat(stream.merge.map(markName(`${prefix}_labels`)));
Expand Down Expand Up @@ -87,12 +87,12 @@ const legendBindings: TransformCompiler = {
const valid = values.map(v => `${v} !== null`).join(' && ');
const update = `${valid} ? {fields: ${fields}, values: [${values.join(', ')}]} : null`;

if (selCmpt.events && values.length) {
if (selCmpt.events && values.length > 0) {
tuple.on.push({
events: values.map(signal => ({signal})),
update
});
} else if (values.length) {
} else if (values.length > 0) {
tuple.update = update;
delete tuple.value;
delete tuple.on;
Expand Down
4 changes: 2 additions & 2 deletions src/compile/selection/transforms/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ const project: TransformCompiler = {
}
}

if (keys(timeUnits).length) {
if (keys(timeUnits).length > 0) {
proj.timeUnit = new TimeUnitNode(null, timeUnits);
}
},

signals: (model, selCmpt, allSignals) => {
const name = selCmpt.name + TUPLE_FIELDS;
const hasSignal = allSignals.filter(s => s.name === name);
return hasSignal.length
return hasSignal.length > 0
? allSignals
: allSignals.concat({
name,
Expand Down
4 changes: 2 additions & 2 deletions src/compile/selection/transforms/scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const scaleBindings: TransformCompiler = {
},

topLevelSignals: (model, selCmpt, signals) => {
const bound = selCmpt.scales.filter(proj => !signals.filter(s => s.name === proj.signals.data).length);
const bound = selCmpt.scales.filter(proj => signals.filter(s => s.name === proj.signals.data).length === 0);

// Top-level signals are only needed for multiview displays and if this
// view's top-level signals haven't already been generated.
if (!model.parent || isTopLevelLayer(model) || !bound.length) {
if (!model.parent || isTopLevelLayer(model) || bound.length === 0) {
return signals;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compositemark/errorbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export function errorBarParams<
...(outerSpec.transform || []),
...bins,
...timeUnits,
...(!aggregate.length ? [] : [{aggregate, groupby}]),
...(aggregate.length === 0 ? [] : [{aggregate, groupby}]),
...postAggregateCalculates
],
groupby,
Expand Down
2 changes: 1 addition & 1 deletion src/normalize/rangestep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class RangeStepNormalizer implements NonFacetUnitNormalizer<UnitSpecWithR
...encoding,
[channel]: {
...defWithoutScale,
...(keys(scaleWithoutRangeStep).length ? {scale: scaleWithoutRangeStep} : {})
...(keys(scaleWithoutRangeStep).length > 0 ? {scale: scaleWithoutRangeStep} : {})
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/transformextract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TransformExtractMapper extends SpecMapper<{config: Config}, GenericUnitSpe
...(oldTransforms ? oldTransforms : []),
...bins,
...timeUnits,
...(!aggregate.length ? [] : [{aggregate, groupby}])
...(aggregate.length === 0 ? [] : [{aggregate, groupby}])
];

return {
Expand Down

0 comments on commit 473eefa

Please sign in to comment.