Skip to content

Commit 5f98e64

Browse files
authored
fix(ColumnChartWithTrend): correct height calculation (#7172)
Fixes #6204
1 parent 66648f1 commit 5f98e64

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

packages/charts/src/components/ColumnChartWithTrend/ColumnChartWithTrend.cy.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ describe('ColumnChartWithTrend', () => {
8585
cy.contains('Loading...').should('exist');
8686
});
8787

88+
it('in Grid', () => {
89+
cy.mount(
90+
<div
91+
style={{
92+
display: 'grid',
93+
gridTemplateColumns: '500px',
94+
gridTemplateRows: '500px'
95+
}}
96+
>
97+
<ColumnChartWithTrend
98+
dataset={complexDataSet}
99+
dimensions={dimensions}
100+
measures={measures}
101+
style={{ height: '100%' }}
102+
data-testid="ccwt"
103+
/>
104+
</div>
105+
);
106+
107+
cy.findByTestId('ccwt').should('be.visible').invoke('prop', 'offsetHeight').should('eq', 500);
108+
cy.findByTestId('ccwt').invoke('prop', 'offsetWidth').should('eq', 500);
109+
});
110+
88111
testChartZoomingTool(ColumnChartWithTrend, { dataset: complexDataSet, dimensions, measures });
89112

90113
testChartLegendConfig(ColumnChartWithTrend, { dataset: complexDataSet, dimensions, measures });
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.container {
2+
/*ChartContainer styles*/
3+
font-size: var(--sapFontSmallSize);
4+
color: var(--sapTextColor);
5+
font-family: var(--sapFontFamily);
6+
width: 100%;
7+
height: 400px;
8+
min-height: fit-content;
9+
position: relative;
10+
11+
display: flex;
12+
flex-direction: column;
13+
}
14+
15+
.trendContainer {
16+
height: auto;
17+
flex: 0 0 20%;
18+
}
19+
20+
.chartContainer {
21+
height: auto;
22+
flex-grow: 1;
23+
}

packages/charts/src/components/ColumnChartWithTrend/ColumnChartWithTrend.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

3-
import { ThemingParameters } from '@ui5/webcomponents-react-base';
3+
import { ThemingParameters, useStylesheet } from '@ui5/webcomponents-react-base';
4+
import { clsx } from 'clsx';
45
import type { CSSProperties } from 'react';
56
import { forwardRef, useId } from 'react';
67
import type { TooltipProps, YAxisProps } from 'recharts';
@@ -13,6 +14,7 @@ import type { IChartDimension } from '../../interfaces/IChartDimension.js';
1314
import type { IChartMeasure } from '../../interfaces/IChartMeasure.js';
1415
import { defaultFormatter } from '../../internal/defaults.js';
1516
import { ComposedChart } from '../ComposedChart/index.js';
17+
import { classNames, content } from './ColumnChartWithTrend.module.css.js';
1618
import { ColumnChartWithTrendPlaceholder } from './Placeholder.js';
1719

1820
interface MeasureConfig extends IChartMeasure {
@@ -111,9 +113,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
111113
loading,
112114
loadingDelay,
113115
dataset,
114-
style,
115116
className,
116-
slot,
117117
onClick,
118118
noLegend,
119119
noAnimation,
@@ -122,9 +122,10 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
122122
ChartPlaceholder,
123123
...rest
124124
} = props;
125-
126125
const syncId = useId();
127126

127+
useStylesheet(content, ColumnChartWithTrend.displayName);
128+
128129
const chartConfig: ColumnChartWithTrendProps['chartConfig'] = {
129130
yAxisVisible: false,
130131
xAxisVisible: true,
@@ -165,25 +166,19 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
165166
const { chartConfig: _0, dimensions: _1, measures: _2, ...propsWithoutOmitted } = rest;
166167

167168
return (
168-
<div
169-
ref={ref}
170-
style={{ display: 'flex', flexDirection: 'column', height: style?.height, width: style?.width, ...style }}
171-
className={className}
172-
slot={slot}
173-
{...propsWithoutOmitted}
174-
>
169+
<div ref={ref} className={clsx(className, classNames.container)} {...propsWithoutOmitted}>
175170
{dataset?.length !== 0 && (
176171
<ComposedChart
177-
className={
178-
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
179-
}
172+
className={clsx(
173+
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined,
174+
classNames.trendContainer
175+
)}
180176
tooltipConfig={lineTooltipConfig}
181177
noAnimation={noAnimation}
182178
loading={loading}
183179
loadingDelay={loadingDelay}
184180
onClick={onClick}
185181
syncId={syncId}
186-
style={{ ...style, height: `calc(${style?.height} * 0.2)` }}
187182
dataset={dataset}
188183
measures={lineMeasures}
189184
dimensions={dimensions}
@@ -201,6 +196,10 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
201196
/>
202197
)}
203198
<ComposedChart
199+
className={clsx(
200+
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined,
201+
classNames.chartContainer
202+
)}
204203
onLegendClick={onLegendClick}
205204
tooltipConfig={columnTooltipConfig}
206205
noAnimation={noAnimation}
@@ -215,10 +214,6 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
215214
measures={columnMeasures}
216215
dimensions={dimensions}
217216
chartConfig={chartConfig}
218-
style={{ ...style, height: `calc(${style?.height} * ${dataset?.length !== 0 ? 0.8 : 1})` }}
219-
className={
220-
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
221-
}
222217
/>
223218
</div>
224219
);

0 commit comments

Comments
 (0)