Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(legend): no truncation with single value (#1316)
- Loading branch information
1 parent
b4bb064
commit 7ec8a9f
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
Binary file added
BIN
+11.6 KB
...al-tests-for-all-stories-legend-single-series-visually-looks-correct-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters