Skip to content
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

Fix histogram widget filter for max/min values #671

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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Migrate multiples components from storybook away from makeStyles [#652](https://github.com/CartoDB/carto-react/pull/652)
- Remove makeStyles leftovers [#669](https://github.com/CartoDB/carto-react/pull/669)
- FormulaWidgetUI component migrated from makeStyles to styled-components + cleanup [#666](https://github.com/CartoDB/carto-react/pull/666)
- Fix histogram widget filter for max/min values [#671](https://github.com/CartoDB/carto-react/pull/671)

## 2.0

Expand Down
12 changes: 6 additions & 6 deletions packages/react-widgets/src/widgets/HistogramWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function HistogramWidget({
dataSource,
id,
column,
type: FilterTypes.CLOSED_OPEN
type: FilterTypes.BETWEEN
});

const selectedBars = useMemo(() => {
Expand All @@ -131,7 +131,7 @@ function HistogramWidget({
return ticks.length;
} else {
const idx = ticks.indexOf(from);
return idx !== -1 ? idx + 1 : null;
return idx !== -1 ? idx + 1 : 0;
}
})
.filter((v) => v !== null);
Expand All @@ -141,16 +141,16 @@ function HistogramWidget({
(selectedBars) => {
if (selectedBars?.length) {
const thresholds = selectedBars.map((i) => {
let left = ticks[i - 1];
let right = ticks.length !== i ? ticks[i] : undefined;
let left = ticks[i - 1] || min;
let right = ticks.length !== i ? ticks[i] : max;

return [left, right];
});
dispatch(
addFilter({
id: dataSource,
column,
type: FilterTypes.CLOSED_OPEN,
type: FilterTypes.BETWEEN,
values: thresholds,
owner: id
})
Expand All @@ -165,7 +165,7 @@ function HistogramWidget({
);
}
},
[column, dataSource, id, dispatch, ticks]
[column, dataSource, id, dispatch, ticks, min, max]
);

return (
Expand Down