| 530 | }; |
| 531 | |
| 532 | export const setHistogramBrushFilter = ( |
| 533 | colId: string, |
| 534 | range: [number, number] | null, |
| 535 | stateRef: StateRef<AppState> |
| 536 | ) => { |
| 537 | let baseFE: FilterExp; |
| 538 | if (range !== null) { |
| 539 | const appState = mutableGet(stateRef); |
| 540 | const prevFE = appState.viewState.viewParams.filterExp; |
| 541 | // ensure that prevFE is either null or a top-level "AND" operator: |
| 542 | if (prevFE != null) { |
| 543 | if (prevFE.op !== "AND") { |
| 544 | log.info( |
| 545 | "setHistogramBrushFilter: unexpected structure for current filter expression, ignoring brush filter" |
| 546 | ); |
| 547 | return; |
| 548 | } |
| 549 | // drop any previous mentions of colId from the filter expression: |
| 550 | const cleanOpArgs = prevFE.opArgs.filter((subExp: SubExp) => { |
| 551 | if (subExp.expType === "BinRelExp") { |
| 552 | const lhs = subExp.lhs; |
| 553 | if (lhs.expType === "ColRef" && lhs.colName === colId) { |
| 554 | return false; |
| 555 | } |
| 556 | } |
| 557 | return true; |
| 558 | }); |
| 559 | baseFE = new FilterExp("AND", cleanOpArgs); |
| 560 | } else { |
| 561 | baseFE = and(); |
| 562 | } |
| 563 | const nextFE = baseFE |
| 564 | .ge(col(colId), constVal(range[0])) |
| 565 | .le(col(colId), constVal(range[1])); |
| 566 | update( |
| 567 | stateRef, |
| 568 | vpUpdate( |
| 569 | (viewParams) => viewParams.set("filterExp", nextFE) as ViewParams |
| 570 | ) |
| 571 | ); |
| 572 | } |
| 573 | }; |
| 574 | |
| 575 | export const setHistogramBrushRange = ( |
| 576 | colId: string, |