Skip to content

Commit

Permalink
fix(legend): no truncation with single value (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Aug 19, 2021
1 parent b4bb064 commit 7ec8a9f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/charts/src/components/legend/style_utils.ts
Expand Up @@ -51,7 +51,7 @@ export function getLegendListStyle(
return {
paddingLeft,
paddingRight,
gridTemplateColumns: `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, 1fr))`,
gridTemplateColumns: totalItems === 1 ? '1fr' : `repeat(auto-fill, minmax(${legendStyle.verticalWidth}px, 1fr))`,
};
}

Expand Down
66 changes: 66 additions & 0 deletions storybook/stories/legend/14_single_series.tsx
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { number } from '@storybook/addon-knobs';
import React from 'react';

import { BarSeries, Chart, ScaleType, Settings } from '@elastic/charts';
import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils';

import { useBaseTheme } from '../../use_base_theme';
import { getPositionKnob } from '../utils/knobs';

export const Example = () => {
const rng = getRandomNumberGenerator();
const maxLines = number('max label lines', 0, { min: 0, step: 1 });
const seriesCount = number('series count', 1, { min: 1, step: 1 });
const data = [
{ x: 0, y: 2 },
{ x: 1, y: 7 },
{ x: 2, y: 3 },
{ x: 3, y: 6 },
];
const renderMoreSeries = () => {
const series: JSX.Element[] = [];

for (let i = 1; i < seriesCount; i++) {
series.push(
<BarSeries
id={`bars${i}`}
name={`Another long series name - ${i}`}
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
data={data.map(({ x, y }) => ({ x, y: y + rng(0, 5) }))}
/>,
);
}

return series;
};
return (
<Chart>
<Settings
showLegend
showLegendExtra
legendPosition={getPositionKnob('legend position', 'top')}
theme={{
legend: { labelOptions: { maxLines } },
}}
baseTheme={useBaseTheme()}
/>
<BarSeries
id="bars0"
name="Id elit mollit ut est laborum. Lorem laboris laboris laboris quis dolore incididunt eiusmod fugiat nulla culpa dolore exercitation dolore. Voluptate ipsum cillum cillum in ullamco elit eiusmod labore incididunt excepteur. Duis id laboris consequat aliqua officia non ex nisi commodo. Ut do do voluptate sunt sunt cupidatat ea ad."
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
data={data}
/>
{renderMoreSeries()}
</Chart>
);
};
1 change: 1 addition & 0 deletions storybook/stories/legend/legend.stories.tsx
Expand Up @@ -29,3 +29,4 @@ export { Example as piechart } from './10_sunburst';
export { Example as piechartRepeatedLabels } from './10_sunburst_repeated_label';
export { Example as actions } from './11_legend_actions';
export { Example as margins } from './12_legend_margins';
export { Example as singleSeries } from './14_single_series';

0 comments on commit 7ec8a9f

Please sign in to comment.