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

🐛 Horizontal bar charts without minimum size not calculating height on initial render #434

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ You can set up your chart with `lume-chart-container` like so:

### Props

| Name | Type | Default | Description |
| ----------------------- | --------------- | ------- | ----------------------------------------------------------- |
| `margins` | `Margins` | `{}` | Space around the chart. |
| `containerSize` | `ContainerSize` | `{}` | The calculated container size. |
| `transparentBackground` | `boolean` | `false` | Controls if the chart should have a transparent background. |
| `noMinSize` | `boolean` | `false` | Controls if the chart shouldn't have minimum width/height. |
| Name | Type | Default | Description |
| ----------------------- | ---------------------------- | ------------ | ----------------------------------------------------------- |
| `margins` | `Margins` | `{}` | Space around the chart. |
| `containerSize` | `ContainerSize` | `{}` | The calculated container size. |
| `transparentBackground` | `boolean` | `false` | Controls if the chart should have a transparent background. |
| `noMinSize` | `boolean` | `false` | Controls if the chart shouldn't have minimum width/height. |
| `orientation` | `'vertical' \| 'horizontal'` | `'vertical'` | The chart's orientation. |

### Events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
<script setup lang="ts">
import { computed, PropType, ref, toRefs, watchEffect } from 'vue';

import { orientationValidator } from '@/composables/props';
import { useResizeObserver } from '@/composables/resize';
import type { InternalMargins } from '@/types/utils';
import { ORIENTATIONS } from '@/utils/constants';
import type { InternalMargins, Orientation } from '@/types/utils';
import type { ContainerSize } from '@/types/size';

const props = defineProps({
Expand All @@ -60,6 +62,11 @@ const props = defineProps({
type: Boolean,
default: false,
},
orientation: {
type: String as PropType<Orientation>,
default: ORIENTATIONS.VERTICAL,
validator: orientationValidator,
},
});

const emit = defineEmits<{
Expand All @@ -84,7 +91,9 @@ watchEffect(() => {
const { width } = resizeState.dimensions;
const { height } = root.value.getBoundingClientRect();

if (!width || !height) return;
if (!width || (props.orientation === ORIENTATIONS.VERTICAL && !height)) {
return;
}

const contentWidth = width - margins.value.left - margins.value.right;
const contentHeight = height - margins.value.top - margins.value.bottom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:container-size="containerSize"
:no-min-size="allOptions.noMinSize"
:transparent-background="allOptions.transparentBackground"
:orientation="orientation"
data-j-lume-chart
@resize="handleResize"
@click="emit('chart-click', $event)"
Expand Down
Loading