-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {FacetModel} from '../facet'; | ||
import {LayerModel} from '../layer'; | ||
import {RepeatModel} from '../repeat'; | ||
import {UnitModel} from '../unit'; | ||
import {Model} from '../model'; | ||
import {unique} from '../../util'; | ||
import {compileSelectionPredicate} from '../common'; | ||
|
||
import {DataComponent} from './data'; | ||
|
||
export namespace filterWith { | ||
function parse(model: UnitModel): string { | ||
return compileSelectionPredicate(model, model.transform().filterWith); | ||
} | ||
|
||
export const parseUnit = parse; | ||
|
||
export function parseFacet(model: FacetModel) { | ||
// todo | ||
return null; | ||
} | ||
|
||
export function parseLayer(model: LayerModel) { | ||
// Note that this `filter.parseLayer` method is called before `source.parseLayer` | ||
let filterComponent = ''; | ||
model.children().forEach((child) => { | ||
const childDataComponent = child.component.data; | ||
if (model.compatibleSource(child) && childDataComponent.filterWith && childDataComponent.filterWith === filterComponent) { | ||
// same filter in child so we can just delete it | ||
delete childDataComponent.filterWith; | ||
} | ||
}); | ||
return filterComponent; | ||
} | ||
|
||
export function parseRepeat(model: RepeatModel) { | ||
// Note that this `filter.parseLayer` method is called before `source.parseLayer` | ||
|
||
const filters = model.children().map((child) => child.component.data.filterWith); | ||
if (unique(filters).length === 1) { | ||
// all filters are the same | ||
model.children().forEach((child) => { | ||
const childDataComponent = child.component.data; | ||
delete childDataComponent.filterWith; | ||
}); | ||
return filters[0]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export function assemble(component: DataComponent) { | ||
const filter = component.filterWith; | ||
return filter ? [{ | ||
type: 'filter', | ||
test: filter | ||
}] : []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters