Skip to content
Open
40 changes: 31 additions & 9 deletions src/normalize/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
...(spec.name ? {name: [params.repeaterPrefix, spec.name].filter(n => n).join('_')} : {}),
...(encoding ? {encoding} : {})
};

if (parentEncoding || parentProjection) {
return this.mapUnitWithParentEncodingOrProjection(specWithReplacedEncoding, params);
}
Expand Down Expand Up @@ -212,6 +211,12 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec

return super.mapFacet(spec, params);
}
private isEmpty(obj: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a helper function outside of this class, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, move this outside the class

if (obj == null) {
return true;
}
return Object.keys(obj).length === 0;
}

private mapUnitWithParentEncodingOrProjection(
spec: FacetedUnitSpec<Field>,
Expand All @@ -225,14 +230,31 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
encoding: replaceRepeaterInEncoding(encoding, params.repeater)
});

return this.mapUnit(
{
...spec,
...(mergedProjection ? {projection: mergedProjection} : {}),
...(mergedEncoding ? {encoding: mergedEncoding} : {})
},
{config}
);
if (this.isEmpty(encoding) && !this.isEmpty(params.repeater)) {
Copy link
Member

@domoritz domoritz Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this check to the second argument of the map unit method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, simplify and updated!

return this.mapUnit(
{
...spec,
...(mergedProjection ? {projection: mergedProjection} : {}),
...(mergedEncoding ? {encoding: mergedEncoding} : {})
},
{
...params,
config: config,
repeater: params.repeater
}
);
} else {
return this.mapUnit(
{
...spec,
...(mergedProjection ? {projection: mergedProjection} : {}),
...(mergedEncoding ? {encoding: mergedEncoding} : {})
},
{
config
}
);
}
}

private mapFacetedUnit(spec: FacetedUnitSpec<Field>, normParams: NormalizerParams): NormalizedFacetSpec {
Expand Down