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

fix(legend): no truncation with single value #1316

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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';