Skip to content

docs(charts): improve documentation & add tooltipConfig stories #6410

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

Merged
merged 5 commits into from
Sep 26, 2024
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
4 changes: 2 additions & 2 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const config: StorybookConfig = {
titlePrefix: 'Knowledge Base'
},
{
directory: '../packages/charts',
files: '**/*@(.stories.tsx)',
directory: '../packages/charts/src/components',
files: '**/*.@(mdx|stories.@(mdx|tsx))',
titlePrefix: 'Charts'
},
{
Expand Down
3 changes: 2 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default defineConfig({
'**/node_modules/**',
'packages/*/src/index.ts',
'packages/main/src/components/AnalyticalTable/types/*',
'packages/main/src/webComponents/**'
'packages/main/src/webComponents/**',
'packages/charts/src/resources/**'
]
}
},
Expand Down
3 changes: 3 additions & 0 deletions packages/charts/src/components/BarChart/BarChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './BarChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -62,4 +63,6 @@ You can set a reference line to any value by using the `referenceLine` `chartCon

<Canvas of={ComponentStories.WithHighlightedMeasure} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps.js';
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet, tooltipConfig } from '../../resources/DemoProps.js';
import { BarChart } from './BarChart.js';

const meta = {
Expand Down Expand Up @@ -152,3 +152,7 @@ export const WithHighlightedMeasure: Story = {
]
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/BulletChart/BulletChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './BulletChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -64,4 +65,6 @@ You can do this via the `measures` array:

<Canvas of={ComponentStories.LoadingPlaceholder} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { complexBulletDataset } from '../../resources/DemoProps.js';
import { complexBulletDataset, tooltipConfig } from '../../resources/DemoProps.js';
import { BulletChart } from './BulletChart.js';

const meta = {
Expand Down Expand Up @@ -116,3 +116,7 @@ export const LoadingPlaceholder: Story = {
dataset: []
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/ColumnChart/ColumnChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './ColumnChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -61,4 +62,6 @@ You can set a reference line to any value by using the `referenceLine` `chartCon

<Canvas of={ComponentStories.WithHighlightedMeasure} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />;

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps.js';
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet, tooltipConfig } from '../../resources/DemoProps.js';
import { ColumnChart } from './ColumnChart.js';

const meta = {
Expand Down Expand Up @@ -143,3 +143,7 @@ export const WithHighlightedMeasure: Story = {
]
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ interface DimensionConfig extends IChartDimension {
}

export interface ColumnChartWithTrendProps
extends Omit<IChartBaseProps<Omit<ICartesianChartConfig, 'secondYAxis' | 'secondYAxisConfig'>>, 'syncId'> {
extends Omit<
IChartBaseProps<Omit<ICartesianChartConfig, 'secondYAxis' | 'secondYAxisConfig'>>,
'syncId' | 'tooltipConfig'
> {
/**
* An array of config objects. Each object will define one dimension of the chart.
*
Expand All @@ -59,7 +62,7 @@ export interface ColumnChartWithTrendProps
*
* **Optional Properties**
* - `formatter`: function will be called for each data label and allows you to format it according to your needs
* - `interval`: number that controls how many ticks are rendered on the x axis
* - `interval`: number that controls how many ticks are rendered on the x-axis
*
*/
dimensions: DimensionConfig[];
Expand Down Expand Up @@ -160,7 +163,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
}
} as TooltipProps<any, any>;

const { chartConfig: _0, dimensions: _1, measures: _2, tooltipConfig: _3, ...propsWithoutOmitted } = rest;
const { chartConfig: _0, dimensions: _1, measures: _2, ...propsWithoutOmitted } = rest;

return (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './ComposedChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -62,4 +63,6 @@ You can set a reference line to any value by using the `referenceLine` `chartCon

<Canvas of={ComponentStories.LoadingPlaceholder} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { bigDataSet, complexDataSet, simpleDataSet } from '../../resources/DemoProps.js';
import { bigDataSet, complexDataSet, simpleDataSet, tooltipConfig } from '../../resources/DemoProps.js';
import { ComposedChart } from './index.js';

const meta = {
Expand Down Expand Up @@ -203,3 +203,7 @@ export const LoadingPlaceholder: Story = {
dataset: []
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/DonutChart/DonutChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Canvas, Meta } from '@storybook/addon-docs';
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './DonutChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -47,4 +48,6 @@ import * as ComponentStories from './DonutChart.stories';

<Canvas of={ComponentStories.HideLabels} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { simpleDataSet, simpleDataSetWithSmallValues } from '../../resources/DemoProps.js';
import { simpleDataSet, simpleDataSetWithSmallValues, tooltipConfig } from '../../resources/DemoProps.js';
import { DonutChart } from './DonutChart.js';

const meta = {
Expand Down Expand Up @@ -95,3 +95,7 @@ export const HideLabels: Story = {
dataset: simpleDataSetWithSmallValues
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/LineChart/LineChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Canvas, Meta } from '@storybook/addon-docs';
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './LineChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -89,4 +90,6 @@ export const LineChartWithLinearGradient = () => {
};
```

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
12 changes: 11 additions & 1 deletion packages/charts/src/components/LineChart/LineChart.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Meta, StoryObj } from '@storybook/react';
import { bigDataSet, complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps.js';
import {
bigDataSet,
complexDataSet,
secondaryDimensionDataSet,
simpleDataSet,
tooltipConfig
} from '../../resources/DemoProps.js';
import { LineChart } from './LineChart.js';

const meta = {
Expand Down Expand Up @@ -151,3 +157,7 @@ export const WithLinearGradient: Story = {
]
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/PieChart/PieChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './PieChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -35,4 +36,6 @@ import * as ComponentStories from './PieChart.stories';

<Canvas of={ComponentStories.HideLabels} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { simpleDataSet, simpleDataSetWithSmallValues } from '../../resources/DemoProps.js';
import { simpleDataSet, simpleDataSetWithSmallValues, tooltipConfig } from '../../resources/DemoProps.js';
import { PieChart } from './PieChart.js';

const meta = {
Expand Down Expand Up @@ -67,3 +67,7 @@ export const HideLabels: Story = {
dataset: simpleDataSetWithSmallValues
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
3 changes: 3 additions & 0 deletions packages/charts/src/components/RadarChart/RadarChart.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './RadarChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -35,4 +36,6 @@ import * as ComponentStories from './RadarChart.stories';

<Canvas of={ComponentStories.LoadingPlaceholder} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { complexDataSet, simpleDataSet } from '../../resources/DemoProps.js';
import { complexDataSet, simpleDataSet, tooltipConfig } from '../../resources/DemoProps.js';
import { RadarChart } from './RadarChart.js';

const meta = {
Expand Down Expand Up @@ -93,3 +93,7 @@ export const LoadingPlaceholder: Story = {
dataset: []
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
import { Canvas, Meta } from '@storybook/addon-docs';
import TooltipStory from '../../resources/TooltipConfig.mdx';
import * as ComponentStories from './ScatterChart.stories';

<Meta of={ComponentStories} />
Expand Down Expand Up @@ -27,4 +28,6 @@ import * as ComponentStories from './ScatterChart.stories';

<Canvas of={ComponentStories.LoadingPlaceholder} />

<TooltipStory of={ComponentStories.WithCustomTooltipConfig} />

<Footer />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { scatterColorDataSet, scatterComplexDataSet } from '../../resources/DemoProps.js';
import { scatterColorDataSet, scatterComplexDataSet, tooltipConfig } from '../../resources/DemoProps.js';
import { ScatterChart } from './ScatterChart.js';

const meta = {
Expand Down Expand Up @@ -64,3 +64,7 @@ export const LoadingPlaceholder: Story = {
dataset: []
}
};

export const WithCustomTooltipConfig: Story = {
args: tooltipConfig
};
44 changes: 44 additions & 0 deletions packages/charts/src/resources/DemoProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
import type { IChartBaseProps } from '@/interfaces/IChartBaseProps.js';

export const tooltipConfig: IChartBaseProps = {
tooltipConfig: {
wrapperStyle: {
border: '5px solid',
borderImage: 'linear-gradient(90deg, red, orange, yellow, green, blue, indigo, violet) 1',
padding: '5px',
borderRadius: '8px'
},
itemStyle: {
boxShadow: '0 10px 30px rgba(0, 0, 0, 0.15)',
backgroundColor: 'white',
borderRadius: '8px',
padding: '10px',
marginBlockStart: '2px'
},
contentStyle: {
background: 'black'
},
labelStyle: {
fontFamily: 'var(--sapFontBoldFamily)',
color: 'white'
},
cursor: { stroke: 'red', strokeWidth: 2, fill: 'transparent' },
separator: ':~:',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
formatter: (value, name, props) => {
if (name === 'Users') {
return [`${value}👨‍💻`, 'Custom Name in Tooltip!'];
}
return `${value}k`;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
labelFormatter: (label, payload) => {
return `${label}🗓️`;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
itemSorter: (item) => {
return -1;
}
}
};

export const singleData = [
{
name: 'January',
Expand Down
Loading
Loading