Skip to content

Commit 2cdc114

Browse files
committed
Use dynamic y-axis width for lollipop charts
1 parent 90cbb9c commit 2cdc114

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

packages/chart/src/components/LinearChart.tsx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
261261
}, [isHorizontal, config.visualizationType, config.yAxis.labelPlacement, yScale, parentWidth])
262262

263263
const horizontalYAxisLabelSpace = runtime.yAxis.label && !config.hideYAxisLabel ? 30 : 0
264-
if (isHorizontal && config.visualizationType === 'Bar' && !config.isLollipopChart) {
264+
if (isHorizontal && config.visualizationType === 'Bar') {
265265
runtime.yAxis.size = categoryLabelSpace + horizontalYAxisLabelSpace
266266
}
267267

@@ -1171,13 +1171,22 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
11711171

11721172
{orientation === 'horizontal' &&
11731173
visualizationType === 'Bar' &&
1174-
!config.isLollipopChart &&
11751174
config.yAxis.labelPlacement === 'On Date/Category Axis' &&
11761175
!config.yAxis.hideLabel &&
11771176
(() => {
11781177
const barGroupCount =
11791178
config.visualizationSubType === 'stacked' ? 1 : config.runtime.seriesKeys.length
1180-
const barHeight = Number(config.barHeight) * barGroupCount
1179+
1180+
// Calculate barHeight based on chart type (regular bar vs lollipop)
1181+
let barHeight
1182+
if (config.isLollipopChart) {
1183+
const lollipopSizes = { large: 7, medium: 6, small: 5 }
1184+
const lollipopBarWidth = lollipopSizes[config.lollipopSize] || 5
1185+
barHeight = lollipopBarWidth * barGroupCount
1186+
} else {
1187+
barHeight = Number(config.barHeight) * barGroupCount
1188+
}
1189+
11811190
const totalBarHeight = barHeight + Number(config.barSpace)
11821191
const barGroupY = i === 0 ? 0 : totalBarHeight * i
11831192
const labelCenterY = barGroupY + barHeight / 2
@@ -1197,24 +1206,6 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
11971206
)
11981207
})()}
11991208

1200-
{orientation === 'horizontal' &&
1201-
visualizationType !== 'Box Plot' &&
1202-
visualizationSubType !== 'stacked' &&
1203-
config.isLollipopChart &&
1204-
config.yAxis.labelPlacement === 'On Date/Category Axis' &&
1205-
!config.yAxis.hideLabel && (
1206-
<Text
1207-
transform={`translate(${tick.to.x - 5}, ${tick.to.y - minY}) rotate(-${
1208-
config.runtime.horizontal ? config.runtime.yAxis.tickRotation || 0 : 0
1209-
})`}
1210-
verticalAnchor={'start'}
1211-
textAnchor={'end'}
1212-
fontSize={tickLabelFontSize}
1213-
>
1214-
{tick.formattedValue}
1215-
</Text>
1216-
)}
1217-
12181209
{orientation === 'horizontal' &&
12191210
visualizationType !== 'Bar' &&
12201211
visualizationSubType === 'stacked' &&

0 commit comments

Comments
 (0)