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

Wrong bar width when displaying both negative and positive values in horizontal barchart #521

Open
vogelino opened this issue Jan 15, 2025 · 4 comments

Comments

@vogelino
Copy link

Hello and thank you for this great library which is very enjoyable to use!

I noticed that horizontal barcharts show negative bars incorrectly when both negative and positive values are displayed simultaneously (see screenshot). Charts with only negative values or only positive values are displayed correctly. Charts with both positive and negative values show positive values correctly but the negative bars are displayed smaller that then should be:

✅ Only positive values:
Screenshot 2025-01-15 at 10 54 19

✅ Only negative values:
Screenshot 2025-01-15 at 10 54 52

⚠️ Both values:
Screenshot 2025-01-15 at 10 49 16

This is how I use the chart:

<VisXYContainer padding={{ top: 8, bottom: 8, right: 16 }} height={chartHeight}>
	{#if $query.isSuccess && data.length > 0}
		<VisStackedBar
			{data}
			{x}
			{y}
			{color}
			numTicks={Math.max(2, data.length)}
			tickValues={data.length === 1 && firstValidValue === 0 ? [0, 5] : undefined}
			orientation="horizontal"
			barPadding={0.2}
			barMinHeight1Px
		/>
		<VisAxis type="x" tickFormat={xTickFormat} numTicks={5} />
		<VisAxis
			type="y"
			tickFormat={yTickFormat}
			tickValues={yTickValues}
			gridLine={false}
			numTicks={data.length}
			tickTextFitMode="trim"
			tickTextTrimType="end"
		/>
		<VisTooltip {triggers} />
	{:else if $query.isSuccess && data.length === 0}
		<div class="absolute inset-0 flex items-center justify-center">
			{$LL.pages.measurements.noDataAvailable()}
		</div>
	{/if}

	{#if $query.error}
		<div class="absolute inset-0 flex items-center justify-center">
			<ErrorAlert errorObject={$query.error} />
		</div>
	{/if}
</VisXYContainer>
@rokotyan
Copy link
Contributor

@vogelino Thank for reporting! Definitely a bug, we'll try to find time for it this week

@vogelino
Copy link
Author

@rokotyan Awesome. Thx a lot!

@rokotyan
Copy link
Contributor

@vogelino Released a beta version with the fix: 1.5.1-exf.10

@vogelino
Copy link
Author

@vogelino Released a beta version with the fix: 1.5.1-exf.10

Awesome! Thank you so much! Your'e the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants