diff --git a/CHANGELOG.md b/CHANGELOG.md index c4918c652..69a40e20c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Not released +- Fix HistogramWidget with one non-zero bucket [#901](https://github.com/CartoDB/carto-react/pull/901) - Spatial Index Sources use remote widgets calculation [#898](https://github.com/CartoDB/carto-react/pull/898) - Support for `hiddenColumnFields` parameter and `onRowClick` handler for Table Widget [#900](https://github.com/CartoDB/carto-react/pull/900) diff --git a/packages/react-ui/src/widgets/HistogramWidgetUI/HistogramWidgetUI.js b/packages/react-ui/src/widgets/HistogramWidgetUI/HistogramWidgetUI.js index 5628e12f1..e37778eab 100644 --- a/packages/react-ui/src/widgets/HistogramWidgetUI/HistogramWidgetUI.js +++ b/packages/react-ui/src/widgets/HistogramWidgetUI/HistogramWidgetUI.js @@ -195,7 +195,8 @@ function HistogramWidgetUI({ // Series const seriesOptions = useMemo(() => { // We check if we have just one different value - const isUniqueDataRow = formattedData.filter((row) => row[2] !== 0).length === 1; + const isUniqueDataRow = + min === max && formattedData.filter((row) => row[2] !== 0).length === 1; const data = isUniqueDataRow ? [formattedData[0], formattedData[formattedData.length - 1]] diff --git a/packages/react-ui/storybook/stories/widgetsUI/HistogramWidgetUI.stories.js b/packages/react-ui/storybook/stories/widgetsUI/HistogramWidgetUI.stories.js index 840531557..6e3afeb4d 100644 --- a/packages/react-ui/storybook/stories/widgetsUI/HistogramWidgetUI.stories.js +++ b/packages/react-ui/storybook/stories/widgetsUI/HistogramWidgetUI.stories.js @@ -93,3 +93,22 @@ const LoadingProps = { isLoading: true }; Loading.args = LoadingProps; + +export const OneNonZeroBinMid = LoadingTemplate.bind({}); +OneNonZeroBinMid.args = { + ...defaultProps, + data: [0, 300, 0, 0, 0, 0, 0] +}; + +export const OneNonZeroBinStart = LoadingTemplate.bind({}); +OneNonZeroBinStart.args = { + ...defaultProps, + data: [100, 0, 0, 0, 0, 0, 0] +}; + + +export const OneNonZeroBinEnd = LoadingTemplate.bind({}); +OneNonZeroBinEnd.args = { + ...defaultProps, + data: [0, 0, 0, 0, 0, 0, 100] +};