Skip to content

Commit 058c5a0

Browse files
committed
test: split knobs in axis tick truncation story
1 parent edbfcf1 commit 058c5a0

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

storybook/stories/axes/16_tick_label_truncation.story.tsx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/
1313

1414
import type { ChartsStory } from '../../types';
1515
import { useBaseTheme } from '../../use_base_theme';
16+
import { customKnobs } from '../utils/knobs';
1617

1718
const data = [
18-
{ x: 'com.example.something.host.23', y: 12 },
19-
{ x: 'com.example.something.host.11', y: 8 },
19+
{
20+
x: 'com.example.something.host.23com.example.something.com.example.something',
21+
y: 12,
22+
},
23+
{ x: 'com.example.something.host.11com.example.something.host.11', y: 8 },
2024
{ x: 'com.example.something.host.07', y: 17 },
2125
{ x: 'com.example.something.host.02', y: 5 },
2226
{ x: 'com.example.something.worker.04', y: 9 },
@@ -37,20 +41,35 @@ function parseThemeSize(raw: string): number | string | undefined {
3741
}
3842

3943
export const Example: ChartsStory = (_, { title, description }) => {
40-
const maxLength = parseThemeSize(text('maxLength', '120'));
41-
const truncate = select<EllipsisPosition>('truncate', { end: 'end', start: 'start', middle: 'middle' }, 'middle');
42-
const rotation = select('Chart rotation', { '0°': 0, '90°': 90, '-90°': -90 }, 90);
43-
44-
const tickLabel = {
45-
...(maxLength !== undefined ? { maxLength } : {}),
46-
truncate,
47-
};
44+
const xMaxLength = parseThemeSize(text('Max length (X)', ''));
45+
const xTruncate = select<EllipsisPosition>(
46+
'Truncate (X)',
47+
{ end: 'end', start: 'start', middle: 'middle' },
48+
'middle',
49+
);
50+
const yMaxLength = parseThemeSize(text('Max length (Y)', '120'));
51+
const yTruncate = select<EllipsisPosition>(
52+
'Truncate (Y)',
53+
{ end: 'end', start: 'start', middle: 'middle' },
54+
'middle',
55+
);
56+
const rotation = customKnobs.enum.rotation('Chart rotation', 90);
4857

4958
return (
5059
<Chart title={title} description={description}>
5160
<Settings baseTheme={useBaseTheme()} rotation={rotation} />
52-
<Axis id="bottom" position={Position.Bottom} title="Count" style={{ tickLabel }} />
53-
<Axis id="left" position={Position.Left} title="Team" style={{ tickLabel }} />
61+
<Axis
62+
id="bottom"
63+
position={Position.Bottom}
64+
title="Count"
65+
style={{ tickLabel: { maxLength: xMaxLength, truncate: xTruncate } }}
66+
/>
67+
<Axis
68+
id="left"
69+
position={Position.Left}
70+
title="Team"
71+
style={{ tickLabel: { maxLength: yMaxLength, truncate: yTruncate } }}
72+
/>
5473

5574
<BarSeries
5675
id="bars"

storybook/stories/utils/knobs/special_enums.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getMultiSelectKnob, getNumberSelectKnob } from './custom';
1717
/**
1818
* Negative numbers do not behave well with vrt slugified naming
1919
*/
20-
const getRotationKnob = (name = 'chartRotation') =>
20+
const getRotationKnob = (name = 'chartRotation', value: Rotation = 0) =>
2121
getNumberSelectKnob<Rotation>(
2222
name,
2323
{
@@ -26,7 +26,7 @@ const getRotationKnob = (name = 'chartRotation') =>
2626
'-90 deg': -90,
2727
'180 deg': 180,
2828
},
29-
0,
29+
value,
3030
);
3131

3232
const boundaryMap: Record<string, TooltipProps['boundary'] | null> = {

0 commit comments

Comments
 (0)