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

261 update stories to storybook 7 syntax #272

Merged
merged 2 commits into from
Aug 31, 2023
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ To run the app inside a Docker container:
$ export PATH="${PATH}:/root/local/bin"
```

### About Vue versions

Lume ships two packages, one for each Vue version (2 and 3).

Development is done in Vue 3, keeping in mind that the same source code must work the same way on both Vue versions, so some of the new Vue 3 APIs are restricted, unless provided with a fallback.

#### Storybook

Storybook is available by running the following command:
Expand Down
4 changes: 3 additions & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
},
"devDependencies": {
"@storybook/addon-actions": "7.2.1",
"@storybook/vue3": "7.2.1",
"@vue/test-utils": "^2.3.2",
"vitest": "^0.33.0"
"vitest": "^0.33.0",
"vue": "^3.2.47"
},
"keywords": [],
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ref } from 'vue';
import type { Meta, StoryObj } from '@storybook/vue3';

import {
actionEventHandlerTemplate,
captureAction,
Expand All @@ -13,7 +15,7 @@ import LumeAlluvialNodeValue from '../../groups/lume-alluvial-group/components/l
import LumeTooltip from '../../core/lume-tooltip';
import { options as defaultOptions } from './defaults';

export default {
const meta: Meta<typeof LumeAlluvialDiagram> = {
title: 'Charts/Alluvial diagram',
component: LumeAlluvialDiagram,
argTypes: {
Expand Down Expand Up @@ -46,60 +48,85 @@ export default {
},
};

const Template = ({ args }) => {
return {
export default meta;

type Story = StoryObj<typeof LumeAlluvialDiagram>;

export const Basic: Story = {
render: ({ args }) => ({
components: { LumeAlluvialDiagram },
setup() {
return { args };
return { args, captureAction };
},
methods: { captureAction },
template: `
<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>
`,
};
};

export const Basic = Template.bind({});
Basic.args = {
...DATASETS.Basic,
title: 'Students performance in science exam',
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>`,
}),
args: {
...DATASETS.Basic,
title: 'Students performance in science exam',
},
};

export const MultipleLevels = Template.bind({});
MultipleLevels.args = {
...withSizeArgs(),
...DATASETS.MultipleLevels,
options: {
...defaultOptions,
valueFormat: (part, _) => `USD ${part}`,
export const MultipleLevels: Story = {
render: ({ args }) => ({
components: { LumeAlluvialDiagram },
setup() {
return { args, captureAction };
},
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>`,
}),
args: {
...withSizeArgs(720),
...DATASETS.MultipleLevels,
options: {
valueFormat: (part, _) => `USD ${part}`,
gradient: true,
},
title: 'Yearly average pet expenses in USA',
},
title: 'Yearly average pet expenses in USA',
};

export const MultipleLevelsWithColorDerivationFromIncomingLinks = Template.bind(
{}
);
MultipleLevelsWithColorDerivationFromIncomingLinks.args = {
...withSizeArgs(),
...DATASETS.MultipleLevelsWithColorDerivationFromIncomingLinks,
title: 'Color derivation from incoming links',
export const MultipleLevelsWithColorDerivationFromIncomingLinks: Story = {
render: ({ args }) => ({
components: { LumeAlluvialDiagram },
setup() {
return { args, captureAction };
},
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>`,
}),
args: {
...DATASETS.MultipleLevelsWithColorDerivationFromIncomingLinks,
title: 'Color derivation from incoming links',
},
};

export const CustomCurveFunction = Template.bind({});
CustomCurveFunction.args = {
...withSizeArgs(540, 220),
...DATASETS.CustomCurveFunction,
options: {
...defaultOptions,
valueFormat: (part, _) => `USD ${part}`,
export const CustomCurveFunction: Story = {
render: ({ args }) => ({
components: { LumeAlluvialDiagram },
setup() {
return { args, captureAction };
},
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>`,
}),
args: {
...withSizeArgs(540, 220),
...DATASETS.CustomCurveFunction,
options: {
valueFormat: (part, _) => `USD ${part}`,
},
title: 'November expenses on my cats',
},
title: 'November expenses on my cats',
};

const CustomNodeSlotsTemplate = ({ args }) => {
return {
export const CustomNodeSlots: Story = {
render: ({ args }) => ({
components: {
LumeTooltip,
LumeAlluvialDiagram,
Expand All @@ -110,42 +137,45 @@ const CustomNodeSlotsTemplate = ({ args }) => {
const targetElement = ref(null);
return { args, targetElement };
},
methods: { captureAction },
template: `
<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args">
<template #node-text-students="{ node }">
<tspan
style="cursor: pointer;"
@mouseenter.native="targetElement = $event.target"
@mouseleave.native="targetElement = null"
>ℹ️</tspan>
<lume-alluvial-node-label dx="4">Custom label</lume-alluvial-node-label>
<lume-alluvial-node-value>
<tspan style="font-style: italic; fill: green">+{{ Math.round((node.transitionValue || node.value) * 0.12 * 100) / 100 }}%</tspan>
{{ node.transitionValue || node.value }}
</lume-alluvial-node-value>
</template>
<template #tooltip="props">
<lume-tooltip v-bind="props" v-if="!!targetElement" :opened="!!targetElement" :target-element="targetElement">
Some additional info about the node.
</lume-tooltip>
</template>
</lume-alluvial-diagram>
</div>
`,
};
};

export const CustomNodeSlots = CustomNodeSlotsTemplate.bind({});
CustomNodeSlots.args = {
...withSizeArgs(),
...DATASETS.Basic,
title: 'Students performance in science exam',
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args">
<template #node-text-students="{ node }">
<tspan
style="cursor: pointer;"
@mouseenter.native="targetElement = $event.target"
@mouseleave.native="targetElement = null"
>ℹ️</tspan>
<lume-alluvial-node-label dx="4">Custom label</lume-alluvial-node-label>
<lume-alluvial-node-value>
<tspan style="font-style: italic; fill: green">+{{ Math.round((node.transitionValue || node.value) * 0.12 * 100) / 100 }}%</tspan>
{{ node.transitionValue || node.value }}
</lume-alluvial-node-value>
</template>
<template #tooltip="props">
<lume-tooltip v-bind="props" v-if="!!targetElement" :opened="!!targetElement" :target-element="targetElement">
Some additional info about the node.
</lume-tooltip>
</template>
</lume-alluvial-diagram>
</div>`,
}),
args: {
...DATASETS.Basic,
title: 'Students performance in science exam',
},
};

export const Empty = Template.bind({});
Empty.args = {
...withSizeArgs(),
...DATASETS.Empty,
export const Empty: Story = {
render: ({ args }) => ({
components: { LumeAlluvialDiagram },
setup() {
return { args, captureAction };
},
template: `<div :style="{ width: args.width + 'px', height: args.height + 'px' }">
<lume-alluvial-diagram v-bind="args" ${actionEventHandlerTemplate} />
</div>`,
}),
args: {
...DATASETS.Empty,
},
};
Loading
Loading