Skip to content

fix derived facets #48

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

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions distiller.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export class DataChunks {
}

resetFacets() {
this.filters = {};
this.facetFns = {};
this.facetCombiners = {};
}
Expand Down
36 changes: 36 additions & 0 deletions test/distiller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,42 @@ describe('DataChunks.hasConversion', () => {
});
});

describe('DataChunks.addHistogramFacet()', () => {
it('should create a histogram facet based on a base facet', () => {
const d = new DataChunks();
d.load(chunks);

d.addFacet('pathlength', (bundle) => bundle.url.length);

d.addHistogramFacet('pathlengthHistogram', 'pathlength', {
count: 10,
min: 0,
max: Infinity,
steps: 'linear',
});

const { facets } = d;

assert.equal(facets.pathlength.length, 31);
assert.equal(facets.pathlengthHistogram.length, 10);

// reset the facets and re-define them again
d.resetFacets();
d.addFacet('pathlength', (bundle) => bundle.url.length);
d.addHistogramFacet('pathlengthHistogram', 'pathlength', {
count: 10,
min: 0,
max: Infinity,
steps: 'linear',
});

const { facets: facets2 } = d;

assert.equal(facets2.pathlength.length, 31);
assert.equal(facets2.pathlengthHistogram.length, 10);
});
});

describe('DataChunks.addClusterFacet()', () => {
it('should create clusters based on URL facet', () => {
const d = new DataChunks();
Expand Down