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 when there is just one row of data #653

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
- New DS core component: table [#657](https://github.com/CartoDB/carto-react/pull/657)
- Improve upgrade guide documentation [#651](https://github.com/CartoDB/carto-react/pull/651)
- Fix storybook publication with Node 18 [#654](https://github.com/CartoDB/carto-react/pull/654)
- Fix Histogram widget when showing just one row of data [#653](https://github.com/CartoDB/carto-react/pull/653)

## 2.0

### 2.0.1 (2023-04-14)

- New DS core component: accordion [#632](https://github.com/CartoDB/carto-react/pull/632)
- New DS core component: Accordion [#632](https://github.com/CartoDB/carto-react/pull/632)
- DS update: Disable ligatures in the monospaced font family [#649](https://github.com/CartoDB/carto-react/pull/649)
- DS update: change action.disabledBackground color [#647](https://github.com/CartoDB/carto-react/pull/647)
- Storybook documentation and fixes [#629](https://github.com/CartoDB/carto-react/pull/629)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ function HistogramWidgetUI({

// Series
const seriesOptions = useMemo(() => {
const dataWithColor = formattedData.map((item, idx) => {
// We check if we have just one different value
const isUniqueDataRow = formattedData.filter((row) => row[2] !== 0).length === 1;

const data = isUniqueDataRow
? [formattedData[0], formattedData[formattedData.length - 1]]
: formattedData;

const dataWithColor = data.map((item, idx) => {
const isDisabled = selectedBars.length && selectedBars.indexOf(idx) === -1;
const color = isDisabled ? theme.palette.black[25] : theme.palette.secondary.main;

Expand All @@ -200,9 +207,9 @@ function HistogramWidgetUI({
return {
type: 'rect',
shape: {
x: x + (isFirst ? 0 : 1),
x: isUniqueDataRow ? x / 10 : x + (isFirst ? 0 : 1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, why 10 value here?

VictorVelarde marked this conversation as resolved.
Show resolved Hide resolved
y,
width: width - (isLast ? 0 : 1),
width: isUniqueDataRow ? x - x / 10 : width - (isLast ? 0 : 1),
height
},
style: { fill },
Expand Down