Skip to content

Commit

Permalink
🐛 Fix wrong assumption on external hover
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-m-santos authored and joao committed Jan 5, 2024
1 parent c418f6f commit ca3f936
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/lib/src/components/core/lume-chart/lume-chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,12 @@ function handleExternalHover(index: number) {
return;
}
handleInternalHover(index);
// If external index is null/undefined or -1, should hide
if (index == null || index === -1) {
handleHideTooltip();
} else {
handleInternalHover(index);
}
}
function handleMouseleave() {
Expand Down
81 changes: 81 additions & 0 deletions packages/lib/src/playground/synced-tooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ref } from 'vue';
import type { Meta, StoryObj } from '@storybook/vue3';

import { withSizeArgs, withSizeArgTypes } from '@/docs/storybook-helpers';
import DATASETS from '@/docs/storybook-data/base-data';

import LumeBarChart from '../components/charts/lume-bar-chart';

const meta: Meta<typeof LumeBarChart> = {
title: 'Playground/Synced tooltips',
component: LumeBarChart,
argTypes: {
...withSizeArgTypes(),
data: {
control: 'object',
description: 'Chart data.',
},
labels: {
control: 'object',
description: 'Chart labels.',
},
hoveredIndex: {
control: 'number',
description: 'Chart hovered index',
},
},
args: {
...withSizeArgs(),
options: {
margins: 'auto',
},
},
};

export default meta;

type Story = StoryObj<typeof LumeBarChart>;

export const Basic: Story = {
render: ({ args }) => ({
components: { LumeBarChart },
setup() {
const containerStyle = {
width: '480px',
height: '320px',
padding: '8px',
border: '1px solid var(--lume-color--grey-50)',
borderRadius: '4px',
overflow: 'hidden',
};
const hoveredIndex = ref(-1);
return { args, containerStyle, hoveredIndex };
},
template: `
<div :style="containerStyle" style="margin-bottom: 16px">
<lume-bar-chart
v-bind="args"
type="stacked"
:hovered-index="hoveredIndex"
@tooltip-opened="hoveredIndex = $event.index"
@tooltip-moved="hoveredIndex = $event.index"
@tooltip-closed="hoveredIndex = -1"
/>
</div>
<div :style="containerStyle">
<lume-bar-chart
v-bind="args"
type="stacked"
:hovered-index="hoveredIndex"
@tooltip-opened="hoveredIndex = $event.index"
@tooltip-moved="hoveredIndex = $event.index"
@tooltip-closed="hoveredIndex = -1"
/>
</div>
`,
}),
args: {
...DATASETS.AnimalsMetIn2023,
title: 'Synced tooltips',
},
};

0 comments on commit ca3f936

Please sign in to comment.