Skip to content

Commit

Permalink
Use labels to calculate BarWidgetUI margin (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Clebal authored Jul 5, 2022
1 parent 1173ff2 commit 49f0745
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released

- Use labels to calculate BarWidgetUI margin [#444](https://github.com/CartoDB/carto-react/pull/444)

## 1.3

### 1.3.0-beta.4 (2022-07-01)
Expand Down
28 changes: 12 additions & 16 deletions packages/react-ui/src/widgets/BarWidgetUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ function BarWidgetUI(props) {

// xAxis
const xAxisDataWithLabels = useMemo(
() => xAxisData.map((name) => labels[name] || name),
[xAxisData, labels]
() =>
xAxisData.map((name) => processFormatterRes(xAxisFormatter(labels[name] || name))),
[xAxisData, labels, xAxisFormatter]
);

const xAxisOptions = useMemo(
Expand All @@ -101,12 +102,11 @@ function BarWidgetUI(props) {
},
axisLabel: {
...theme.typography.charts,
padding: [theme.spacing(0.5), 0, 0, 0],
formatter: (v) => processFormatterRes(xAxisFormatter(v))
padding: [theme.spacing(0.5), 0, 0, 0]
},
data: xAxisDataWithLabels
}),
[theme, xAxisDataWithLabels, xAxisFormatter]
[theme, xAxisDataWithLabels]
);

// yAxis
Expand Down Expand Up @@ -204,18 +204,15 @@ function BarWidgetUI(props) {
() => ({
grid: {
left:
xAxisData.length >= 4
? calculateMargin(
processFormatterRes(xAxisFormatter(xAxisData[0])),
xAxisData.length
)
xAxisDataWithLabels.length >= 4
? calculateMargin(xAxisDataWithLabels[0], xAxisDataWithLabels.length)
: 0,
top: theme.spacing(2),
right:
xAxisData.length >= 4
xAxisDataWithLabels.length >= 4
? calculateMargin(
processFormatterRes(xAxisFormatter(xAxisData[xAxisData.length - 1])),
xAxisData.length
xAxisDataWithLabels[xAxisDataWithLabels.length - 1],
xAxisDataWithLabels.length
)
: 0,
bottom: theme.spacing(0),
Expand All @@ -233,14 +230,13 @@ function BarWidgetUI(props) {
series: seriesOptions
}),
[
xAxisData,
xAxisDataWithLabels,
theme,
colors,
tooltipOptions,
xAxisOptions,
yAxisOptions,
seriesOptions,
xAxisFormatter
seriesOptions
]
);

Expand Down

0 comments on commit 49f0745

Please sign in to comment.