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

[Bug]: BarChart Legend Display Issue: Misaligned Indicator and Non-Reactive Legends #888

Open
2 tasks
tberk opened this issue Nov 11, 2024 · 0 comments
Open
2 tasks
Labels
bug Something isn't working

Comments

@tberk
Copy link

tberk commented Nov 11, 2024

Reproduction

https://www.shadcn-vue.com/docs/charts/bar

Describe the bug

When using the BarChart component, there are multiple issues with the legends:

  1. Misalignment on First Load:

    • On the initial load, legend items are displayed within a button component, but the indicator dot (used to denote color) is misaligned and out of place.
  2. Style Change on Click:

    • Clicking a legend item changes its UI style unexpectedly, diverging from the original style setup.
  3. Incorrect Button Size Definition:

    • In ChartLegend.vue, the button size is set to xs, but the button component itself does not support an xs size.
onMounted(() => {
  const selector = `.${BulletLegend.selectors.item}`
  nextTick(() => {
    const elements = elRef.value?.querySelectorAll(selector)
    const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')
    elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))
  })
})
  1. Legends Are Not Reactive:

    • While other parts of the BarChart component update as expected, the legend items do not react to changes. This could be due to the fact that legendItems is defined with ref in BarChart.vue, as shown below:
const legendItems = ref<BulletLegendItemInterface[]>(props.categories.map((category, i) => ({
  name: category,
  color: colors.value[i],
  inactive: false,
})))

Expected Behavior:

  • The indicator dot should be correctly aligned on the first load.
  • Clicking on a legend item should not alter its style unexpectedly.
  • The button size should align with available sizes or be adjusted for consistent styling.
  • Legend items should be reactive to data changes in the BarChart component.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
    Memory: 34.40 GB / 63.75 GB
  Binaries:
    Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.3 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@tberk tberk added the bug Something isn't working label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant